Remove usage of Dimension arrays and YGDimension as index (#1402)
Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1402 X-link: https://github.com/facebook/react-native/pull/39567 This change hides away most usages of YGDimension as an index. We do this for a couple reasons: 1. Right now the style interface may return a full array of resolved edge or dimension values, as a CompactValue. As we abstract away from CompactValue, and move towards ValuePool, this will no longer be the internal interface, and cheap to return. We instead change the interface to return a single value at once, which lets us resolve values lazily. 2. As we move internal usage to scoped enums, enums are not implicitly convertible to intergers (broadly a good thing). Hiding the enum as index prevents the need for callers to cast or convert to underlying. Instead of making a new version of `IdxRef` for this, I converted to a more traditional setter. I will be making similar changes later for other styles, when I hide CompactValue from the public interface. To review I would recommend filtering to changes in `xplat`, or viewing this in a single one of the OSS PRs exported. Everything apart from the below 20 files is a mirror. {F1096792573} Changelog: [Internal] Reviewed By: javache Differential Revision: D49362819 fbshipit-source-id: 30d730d78e62f36597d43f477120f65694e51ea3
This commit is contained in:
committed by
Facebook GitHub Bot
parent
81754d8cb2
commit
83705c2942
@@ -203,33 +203,6 @@ INDEX_ACCESSOR_TEST(
|
||||
CompactValue::of<YGUnitPoint>(-7777.77f),
|
||||
CompactValue::ofUndefined())
|
||||
|
||||
INDEX_ACCESSOR_TEST(
|
||||
dimensions,
|
||||
CompactValue::ofAuto(),
|
||||
YGDimensionWidth,
|
||||
CompactValue::ofUndefined(),
|
||||
CompactValue::ofAuto(),
|
||||
CompactValue::of<YGUnitPoint>(7777.77f),
|
||||
CompactValue::of<YGUnitPercent>(-100.0f))
|
||||
|
||||
INDEX_ACCESSOR_TEST(
|
||||
minDimensions,
|
||||
CompactValue::ofUndefined(),
|
||||
YGDimensionHeight,
|
||||
CompactValue::ofAuto(),
|
||||
CompactValue::ofUndefined(),
|
||||
CompactValue::of<YGUnitPoint>(7777.77f),
|
||||
CompactValue::of<YGUnitPercent>(-100.0f))
|
||||
|
||||
INDEX_ACCESSOR_TEST(
|
||||
maxDimensions,
|
||||
CompactValue::ofUndefined(),
|
||||
YGDimensionHeight,
|
||||
CompactValue::ofAuto(),
|
||||
CompactValue::ofUndefined(),
|
||||
CompactValue::of<YGUnitPoint>(7777.77f),
|
||||
CompactValue::of<YGUnitPercent>(-100.0f))
|
||||
|
||||
ACCESSOR_TEST(
|
||||
aspectRatio,
|
||||
FloatOptional{},
|
||||
|
@@ -419,6 +419,15 @@ void updateIndexedStyleProp(
|
||||
[idx, prop](Style& s, CompactValue x) { (s.*prop)()[idx] = x; });
|
||||
}
|
||||
|
||||
template <auto GetterT, auto SetterT, typename IdxT>
|
||||
void updateIndexedStyleProp(YGNodeRef node, IdxT idx, CompactValue value) {
|
||||
updateStyle(
|
||||
resolveRef(node),
|
||||
value,
|
||||
[idx](Style& s, CompactValue x) { return (s.*GetterT)(idx) != x; },
|
||||
[idx](Style& s, CompactValue x) { (s.*SetterT)(idx, x); });
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// MSVC has trouble inferring the return type of pointer to member functions
|
||||
@@ -664,98 +673,98 @@ void YGNodeStyleSetAspectRatio(const YGNodeRef node, const float aspectRatio) {
|
||||
|
||||
void YGNodeStyleSetWidth(YGNodeRef node, float points) {
|
||||
auto value = CompactValue::ofMaybe<YGUnitPoint>(points);
|
||||
updateIndexedStyleProp<MSVC_HINT(dimensions)>(
|
||||
node, &Style::dimensions, YGDimensionWidth, value);
|
||||
updateIndexedStyleProp<&Style::dimension, &Style::setDimension>(
|
||||
node, YGDimensionWidth, value);
|
||||
}
|
||||
void YGNodeStyleSetWidthPercent(YGNodeRef node, float percent) {
|
||||
auto value = CompactValue::ofMaybe<YGUnitPercent>(percent);
|
||||
updateIndexedStyleProp<MSVC_HINT(dimensions)>(
|
||||
node, &Style::dimensions, YGDimensionWidth, value);
|
||||
updateIndexedStyleProp<&Style::dimension, &Style::setDimension>(
|
||||
node, YGDimensionWidth, value);
|
||||
}
|
||||
void YGNodeStyleSetWidthAuto(YGNodeRef node) {
|
||||
updateIndexedStyleProp<MSVC_HINT(dimensions)>(
|
||||
node, &Style::dimensions, YGDimensionWidth, CompactValue::ofAuto());
|
||||
updateIndexedStyleProp<&Style::dimension, &Style::setDimension>(
|
||||
node, YGDimensionWidth, CompactValue::ofAuto());
|
||||
}
|
||||
YGValue YGNodeStyleGetWidth(YGNodeConstRef node) {
|
||||
return resolveRef(node)->getStyle().dimensions()[YGDimensionWidth];
|
||||
return resolveRef(node)->getStyle().dimension(YGDimensionWidth);
|
||||
}
|
||||
|
||||
void YGNodeStyleSetHeight(YGNodeRef node, float points) {
|
||||
auto value = CompactValue::ofMaybe<YGUnitPoint>(points);
|
||||
updateIndexedStyleProp<MSVC_HINT(dimensions)>(
|
||||
node, &Style::dimensions, YGDimensionHeight, value);
|
||||
updateIndexedStyleProp<&Style::dimension, &Style::setDimension>(
|
||||
node, YGDimensionHeight, value);
|
||||
}
|
||||
void YGNodeStyleSetHeightPercent(YGNodeRef node, float percent) {
|
||||
auto value = CompactValue::ofMaybe<YGUnitPercent>(percent);
|
||||
updateIndexedStyleProp<MSVC_HINT(dimensions)>(
|
||||
node, &Style::dimensions, YGDimensionHeight, value);
|
||||
updateIndexedStyleProp<&Style::dimension, &Style::setDimension>(
|
||||
node, YGDimensionHeight, value);
|
||||
}
|
||||
void YGNodeStyleSetHeightAuto(YGNodeRef node) {
|
||||
updateIndexedStyleProp<MSVC_HINT(dimensions)>(
|
||||
node, &Style::dimensions, YGDimensionHeight, CompactValue::ofAuto());
|
||||
updateIndexedStyleProp<&Style::dimension, &Style::setDimension>(
|
||||
node, YGDimensionHeight, CompactValue::ofAuto());
|
||||
}
|
||||
YGValue YGNodeStyleGetHeight(YGNodeConstRef node) {
|
||||
return resolveRef(node)->getStyle().dimensions()[YGDimensionHeight];
|
||||
return resolveRef(node)->getStyle().dimension(YGDimensionHeight);
|
||||
}
|
||||
|
||||
void YGNodeStyleSetMinWidth(const YGNodeRef node, const float minWidth) {
|
||||
auto value = CompactValue::ofMaybe<YGUnitPoint>(minWidth);
|
||||
updateIndexedStyleProp<MSVC_HINT(minDimensions)>(
|
||||
node, &Style::minDimensions, YGDimensionWidth, value);
|
||||
updateIndexedStyleProp<&Style::minDimension, &Style::setMinDimension>(
|
||||
node, YGDimensionWidth, value);
|
||||
}
|
||||
void YGNodeStyleSetMinWidthPercent(const YGNodeRef node, const float minWidth) {
|
||||
auto value = CompactValue::ofMaybe<YGUnitPercent>(minWidth);
|
||||
updateIndexedStyleProp<MSVC_HINT(minDimensions)>(
|
||||
node, &Style::minDimensions, YGDimensionWidth, value);
|
||||
updateIndexedStyleProp<&Style::minDimension, &Style::setMinDimension>(
|
||||
node, YGDimensionWidth, value);
|
||||
}
|
||||
YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) {
|
||||
return resolveRef(node)->getStyle().minDimensions()[YGDimensionWidth];
|
||||
return resolveRef(node)->getStyle().minDimension(YGDimensionWidth);
|
||||
}
|
||||
|
||||
void YGNodeStyleSetMinHeight(const YGNodeRef node, const float minHeight) {
|
||||
auto value = CompactValue::ofMaybe<YGUnitPoint>(minHeight);
|
||||
updateIndexedStyleProp<MSVC_HINT(minDimensions)>(
|
||||
node, &Style::minDimensions, YGDimensionHeight, value);
|
||||
updateIndexedStyleProp<&Style::minDimension, &Style::setMinDimension>(
|
||||
node, YGDimensionHeight, value);
|
||||
}
|
||||
void YGNodeStyleSetMinHeightPercent(
|
||||
const YGNodeRef node,
|
||||
const float minHeight) {
|
||||
auto value = CompactValue::ofMaybe<YGUnitPercent>(minHeight);
|
||||
updateIndexedStyleProp<MSVC_HINT(minDimensions)>(
|
||||
node, &Style::minDimensions, YGDimensionHeight, value);
|
||||
updateIndexedStyleProp<&Style::minDimension, &Style::setMinDimension>(
|
||||
node, YGDimensionHeight, value);
|
||||
}
|
||||
YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) {
|
||||
return resolveRef(node)->getStyle().minDimensions()[YGDimensionHeight];
|
||||
return resolveRef(node)->getStyle().minDimension(YGDimensionHeight);
|
||||
}
|
||||
|
||||
void YGNodeStyleSetMaxWidth(const YGNodeRef node, const float maxWidth) {
|
||||
auto value = CompactValue::ofMaybe<YGUnitPoint>(maxWidth);
|
||||
updateIndexedStyleProp<MSVC_HINT(maxDimensions)>(
|
||||
node, &Style::maxDimensions, YGDimensionWidth, value);
|
||||
updateIndexedStyleProp<&Style::maxDimension, &Style::setMaxDimension>(
|
||||
node, YGDimensionWidth, value);
|
||||
}
|
||||
void YGNodeStyleSetMaxWidthPercent(const YGNodeRef node, const float maxWidth) {
|
||||
auto value = CompactValue::ofMaybe<YGUnitPercent>(maxWidth);
|
||||
updateIndexedStyleProp<MSVC_HINT(maxDimensions)>(
|
||||
node, &Style::maxDimensions, YGDimensionWidth, value);
|
||||
updateIndexedStyleProp<&Style::maxDimension, &Style::setMaxDimension>(
|
||||
node, YGDimensionWidth, value);
|
||||
}
|
||||
YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) {
|
||||
return resolveRef(node)->getStyle().maxDimensions()[YGDimensionWidth];
|
||||
return resolveRef(node)->getStyle().maxDimension(YGDimensionWidth);
|
||||
}
|
||||
|
||||
void YGNodeStyleSetMaxHeight(const YGNodeRef node, const float maxHeight) {
|
||||
auto value = CompactValue::ofMaybe<YGUnitPoint>(maxHeight);
|
||||
updateIndexedStyleProp<MSVC_HINT(maxDimensions)>(
|
||||
node, &Style::maxDimensions, YGDimensionHeight, value);
|
||||
updateIndexedStyleProp<&Style::maxDimension, &Style::setMaxDimension>(
|
||||
node, YGDimensionHeight, value);
|
||||
}
|
||||
void YGNodeStyleSetMaxHeightPercent(
|
||||
const YGNodeRef node,
|
||||
const float maxHeight) {
|
||||
auto value = CompactValue::ofMaybe<YGUnitPercent>(maxHeight);
|
||||
updateIndexedStyleProp<MSVC_HINT(maxDimensions)>(
|
||||
node, &Style::maxDimensions, YGDimensionHeight, value);
|
||||
updateIndexedStyleProp<&Style::maxDimension, &Style::setMaxDimension>(
|
||||
node, YGDimensionHeight, value);
|
||||
}
|
||||
YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) {
|
||||
return resolveRef(node)->getStyle().maxDimensions()[YGDimensionHeight];
|
||||
return resolveRef(node)->getStyle().maxDimension(YGDimensionHeight);
|
||||
}
|
||||
|
||||
namespace {
|
||||
@@ -808,11 +817,11 @@ float YGNodeLayoutGetBottom(const YGNodeConstRef node) {
|
||||
}
|
||||
|
||||
float YGNodeLayoutGetWidth(const YGNodeConstRef node) {
|
||||
return resolveRef(node)->getLayout().dimensions[YGDimensionWidth];
|
||||
return resolveRef(node)->getLayout().dimension(YGDimensionWidth);
|
||||
}
|
||||
|
||||
float YGNodeLayoutGetHeight(const YGNodeConstRef node) {
|
||||
return resolveRef(node)->getLayout().dimensions[YGDimensionHeight];
|
||||
return resolveRef(node)->getLayout().dimension(YGDimensionHeight);
|
||||
}
|
||||
|
||||
YGDirection YGNodeLayoutGetDirection(const YGNodeConstRef node) {
|
||||
|
@@ -19,8 +19,8 @@ float calculateBaseline(const yoga::Node* node) {
|
||||
Event::publish<Event::NodeBaselineStart>(node);
|
||||
|
||||
const float baseline = node->baseline(
|
||||
node->getLayout().measuredDimensions[YGDimensionWidth],
|
||||
node->getLayout().measuredDimensions[YGDimensionHeight]);
|
||||
node->getLayout().measuredDimension(YGDimensionWidth),
|
||||
node->getLayout().measuredDimension(YGDimensionHeight));
|
||||
|
||||
Event::publish<Event::NodeBaselineEnd>(node);
|
||||
|
||||
@@ -53,7 +53,7 @@ float calculateBaseline(const yoga::Node* node) {
|
||||
}
|
||||
|
||||
if (baselineChild == nullptr) {
|
||||
return node->getLayout().measuredDimensions[YGDimensionHeight];
|
||||
return node->getLayout().measuredDimension(YGDimensionHeight);
|
||||
}
|
||||
|
||||
const float baseline = calculateBaseline(baselineChild);
|
||||
|
@@ -35,14 +35,14 @@ inline FloatOptional boundAxisWithinMinAndMax(
|
||||
|
||||
if (isColumn(axis)) {
|
||||
min = yoga::resolveValue(
|
||||
node->getStyle().minDimensions()[YGDimensionHeight], axisSize);
|
||||
node->getStyle().minDimension(YGDimensionHeight), axisSize);
|
||||
max = yoga::resolveValue(
|
||||
node->getStyle().maxDimensions()[YGDimensionHeight], axisSize);
|
||||
node->getStyle().maxDimension(YGDimensionHeight), axisSize);
|
||||
} else if (isRow(axis)) {
|
||||
min = yoga::resolveValue(
|
||||
node->getStyle().minDimensions()[YGDimensionWidth], axisSize);
|
||||
node->getStyle().minDimension(YGDimensionWidth), axisSize);
|
||||
max = yoga::resolveValue(
|
||||
node->getStyle().maxDimensions()[YGDimensionWidth], axisSize);
|
||||
node->getStyle().maxDimension(YGDimensionWidth), axisSize);
|
||||
}
|
||||
|
||||
if (max >= FloatOptional{0} && value > max) {
|
||||
|
@@ -53,7 +53,7 @@ static inline float dimensionWithMargin(
|
||||
const yoga::Node* const node,
|
||||
const FlexDirection axis,
|
||||
const float widthSize) {
|
||||
return node->getLayout().measuredDimensions[dimension(axis)] +
|
||||
return node->getLayout().measuredDimension(dimension(axis)) +
|
||||
(node->getLeadingMargin(axis, widthSize) +
|
||||
node->getTrailingMargin(axis, widthSize))
|
||||
.unwrap();
|
||||
@@ -79,7 +79,7 @@ static inline bool styleDefinesDimension(
|
||||
static inline bool isLayoutDimensionDefined(
|
||||
const yoga::Node* const node,
|
||||
const FlexDirection axis) {
|
||||
const float value = node->getLayout().measuredDimensions[dimension(axis)];
|
||||
const float value = node->getLayout().measuredDimension(dimension(axis));
|
||||
return !yoga::isUndefined(value) && value >= 0.0f;
|
||||
}
|
||||
|
||||
@@ -87,9 +87,9 @@ static void setChildTrailingPosition(
|
||||
const yoga::Node* const node,
|
||||
yoga::Node* const child,
|
||||
const FlexDirection axis) {
|
||||
const float size = child->getLayout().measuredDimensions[dimension(axis)];
|
||||
const float size = child->getLayout().measuredDimension(dimension(axis));
|
||||
child->setLayoutPosition(
|
||||
node->getLayout().measuredDimensions[dimension(axis)] - size -
|
||||
node->getLayout().measuredDimension(dimension(axis)) - size -
|
||||
child->getLayout().position[leadingEdge(axis)],
|
||||
trailingEdge(axis));
|
||||
}
|
||||
@@ -103,7 +103,7 @@ static void constrainMaxSizeForMode(
|
||||
float* size) {
|
||||
const FloatOptional maxSize =
|
||||
yoga::resolveValue(
|
||||
node->getStyle().maxDimensions()[dimension(axis)], ownerAxisSize) +
|
||||
node->getStyle().maxDimension(dimension(axis)), ownerAxisSize) +
|
||||
FloatOptional(node->getMarginForAxis(axis, ownerWidth));
|
||||
switch (*mode) {
|
||||
case MeasureMode::Exactly:
|
||||
@@ -169,7 +169,7 @@ static void computeFlexBasisForChild(
|
||||
|
||||
child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
|
||||
yoga::resolveValue(
|
||||
child->getResolvedDimensions()[YGDimensionWidth], ownerWidth),
|
||||
child->getResolvedDimension(YGDimensionWidth), ownerWidth),
|
||||
paddingAndBorder));
|
||||
} else if (!isMainAxisRow && isColumnStyleDimDefined) {
|
||||
// The height is definite, so use that as the flex basis.
|
||||
@@ -177,7 +177,7 @@ static void computeFlexBasisForChild(
|
||||
paddingAndBorderForAxis(child, FlexDirection::Column, ownerWidth));
|
||||
child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
|
||||
yoga::resolveValue(
|
||||
child->getResolvedDimensions()[YGDimensionHeight], ownerHeight),
|
||||
child->getResolvedDimension(YGDimensionHeight), ownerHeight),
|
||||
paddingAndBorder));
|
||||
} else {
|
||||
// Compute the flex basis and hypothetical main size (i.e. the clamped flex
|
||||
@@ -195,7 +195,7 @@ static void computeFlexBasisForChild(
|
||||
if (isRowStyleDimDefined) {
|
||||
childWidth =
|
||||
yoga::resolveValue(
|
||||
child->getResolvedDimensions()[YGDimensionWidth], ownerWidth)
|
||||
child->getResolvedDimension(YGDimensionWidth), ownerWidth)
|
||||
.unwrap() +
|
||||
marginRow;
|
||||
childWidthMeasureMode = MeasureMode::Exactly;
|
||||
@@ -203,7 +203,7 @@ static void computeFlexBasisForChild(
|
||||
if (isColumnStyleDimDefined) {
|
||||
childHeight =
|
||||
yoga::resolveValue(
|
||||
child->getResolvedDimensions()[YGDimensionHeight], ownerHeight)
|
||||
child->getResolvedDimension(YGDimensionHeight), ownerHeight)
|
||||
.unwrap() +
|
||||
marginColumn;
|
||||
childHeightMeasureMode = MeasureMode::Exactly;
|
||||
@@ -309,7 +309,7 @@ static void computeFlexBasisForChild(
|
||||
generationCount);
|
||||
|
||||
child->setLayoutComputedFlexBasis(FloatOptional(yoga::maxOrDefined(
|
||||
child->getLayout().measuredDimensions[dimension(mainAxis)],
|
||||
child->getLayout().measuredDimension(dimension(mainAxis)),
|
||||
paddingAndBorderForAxis(child, mainAxis, ownerWidth))));
|
||||
}
|
||||
child->setLayoutComputedFlexBasisGeneration(generationCount);
|
||||
@@ -340,8 +340,8 @@ static void layoutAbsoluteChild(
|
||||
child->getMarginForAxis(FlexDirection::Column, width).unwrap();
|
||||
|
||||
if (styleDefinesDimension(child, FlexDirection::Row, width)) {
|
||||
childWidth = yoga::resolveValue(
|
||||
child->getResolvedDimensions()[YGDimensionWidth], width)
|
||||
childWidth =
|
||||
yoga::resolveValue(child->getResolvedDimension(YGDimensionWidth), width)
|
||||
.unwrap() +
|
||||
marginRow;
|
||||
} else {
|
||||
@@ -349,7 +349,7 @@ static void layoutAbsoluteChild(
|
||||
// the left/right offsets if they're defined.
|
||||
if (child->isLeadingPositionDefined(FlexDirection::Row) &&
|
||||
child->isTrailingPosDefined(FlexDirection::Row)) {
|
||||
childWidth = node->getLayout().measuredDimensions[YGDimensionWidth] -
|
||||
childWidth = node->getLayout().measuredDimension(YGDimensionWidth) -
|
||||
(node->getLeadingBorder(FlexDirection::Row) +
|
||||
node->getTrailingBorder(FlexDirection::Row)) -
|
||||
(child->getLeadingPosition(FlexDirection::Row, width) +
|
||||
@@ -362,7 +362,7 @@ static void layoutAbsoluteChild(
|
||||
|
||||
if (styleDefinesDimension(child, FlexDirection::Column, height)) {
|
||||
childHeight = yoga::resolveValue(
|
||||
child->getResolvedDimensions()[YGDimensionHeight], height)
|
||||
child->getResolvedDimension(YGDimensionHeight), height)
|
||||
.unwrap() +
|
||||
marginColumn;
|
||||
} else {
|
||||
@@ -370,7 +370,7 @@ static void layoutAbsoluteChild(
|
||||
// the top/bottom offsets if they're defined.
|
||||
if (child->isLeadingPositionDefined(FlexDirection::Column) &&
|
||||
child->isTrailingPosDefined(FlexDirection::Column)) {
|
||||
childHeight = node->getLayout().measuredDimensions[YGDimensionHeight] -
|
||||
childHeight = node->getLayout().measuredDimension(YGDimensionHeight) -
|
||||
(node->getLeadingBorder(FlexDirection::Column) +
|
||||
node->getTrailingBorder(FlexDirection::Column)) -
|
||||
(child->getLeadingPosition(FlexDirection::Column, height) +
|
||||
@@ -431,9 +431,9 @@ static void layoutAbsoluteChild(
|
||||
layoutMarkerData,
|
||||
depth,
|
||||
generationCount);
|
||||
childWidth = child->getLayout().measuredDimensions[YGDimensionWidth] +
|
||||
childWidth = child->getLayout().measuredDimension(YGDimensionWidth) +
|
||||
child->getMarginForAxis(FlexDirection::Row, width).unwrap();
|
||||
childHeight = child->getLayout().measuredDimensions[YGDimensionHeight] +
|
||||
childHeight = child->getLayout().measuredDimension(YGDimensionHeight) +
|
||||
child->getMarginForAxis(FlexDirection::Column, width).unwrap();
|
||||
}
|
||||
|
||||
@@ -455,8 +455,8 @@ static void layoutAbsoluteChild(
|
||||
if (child->isTrailingPosDefined(mainAxis) &&
|
||||
!child->isLeadingPositionDefined(mainAxis)) {
|
||||
child->setLayoutPosition(
|
||||
node->getLayout().measuredDimensions[dimension(mainAxis)] -
|
||||
child->getLayout().measuredDimensions[dimension(mainAxis)] -
|
||||
node->getLayout().measuredDimension(dimension(mainAxis)) -
|
||||
child->getLayout().measuredDimension(dimension(mainAxis)) -
|
||||
node->getTrailingBorder(mainAxis) -
|
||||
child->getTrailingMargin(mainAxis, isMainAxisRow ? width : height)
|
||||
.unwrap() -
|
||||
@@ -467,16 +467,16 @@ static void layoutAbsoluteChild(
|
||||
!child->isLeadingPositionDefined(mainAxis) &&
|
||||
node->getStyle().justifyContent() == Justify::Center) {
|
||||
child->setLayoutPosition(
|
||||
(node->getLayout().measuredDimensions[dimension(mainAxis)] -
|
||||
child->getLayout().measuredDimensions[dimension(mainAxis)]) /
|
||||
(node->getLayout().measuredDimension(dimension(mainAxis)) -
|
||||
child->getLayout().measuredDimension(dimension(mainAxis))) /
|
||||
2.0f,
|
||||
leadingEdge(mainAxis));
|
||||
} else if (
|
||||
!child->isLeadingPositionDefined(mainAxis) &&
|
||||
node->getStyle().justifyContent() == Justify::FlexEnd) {
|
||||
child->setLayoutPosition(
|
||||
(node->getLayout().measuredDimensions[dimension(mainAxis)] -
|
||||
child->getLayout().measuredDimensions[dimension(mainAxis)]),
|
||||
(node->getLayout().measuredDimension(dimension(mainAxis)) -
|
||||
child->getLayout().measuredDimension(dimension(mainAxis))),
|
||||
leadingEdge(mainAxis));
|
||||
} else if (
|
||||
node->getConfig()->isExperimentalFeatureEnabled(
|
||||
@@ -485,13 +485,13 @@ static void layoutAbsoluteChild(
|
||||
child->setLayoutPosition(
|
||||
child->getLeadingPosition(
|
||||
mainAxis,
|
||||
node->getLayout().measuredDimensions[dimension(mainAxis)])
|
||||
node->getLayout().measuredDimension(dimension(mainAxis)))
|
||||
.unwrap() +
|
||||
node->getLeadingBorder(mainAxis) +
|
||||
child
|
||||
->getLeadingMargin(
|
||||
mainAxis,
|
||||
node->getLayout().measuredDimensions[dimension(mainAxis)])
|
||||
node->getLayout().measuredDimension(dimension(mainAxis)))
|
||||
.unwrap(),
|
||||
leadingEdge(mainAxis));
|
||||
}
|
||||
@@ -499,8 +499,8 @@ static void layoutAbsoluteChild(
|
||||
if (child->isTrailingPosDefined(crossAxis) &&
|
||||
!child->isLeadingPositionDefined(crossAxis)) {
|
||||
child->setLayoutPosition(
|
||||
node->getLayout().measuredDimensions[dimension(crossAxis)] -
|
||||
child->getLayout().measuredDimensions[dimension(crossAxis)] -
|
||||
node->getLayout().measuredDimension(dimension(crossAxis)) -
|
||||
child->getLayout().measuredDimension(dimension(crossAxis)) -
|
||||
node->getTrailingBorder(crossAxis) -
|
||||
child->getTrailingMargin(crossAxis, isMainAxisRow ? height : width)
|
||||
.unwrap() -
|
||||
@@ -513,8 +513,8 @@ static void layoutAbsoluteChild(
|
||||
!child->isLeadingPositionDefined(crossAxis) &&
|
||||
resolveChildAlignment(node, child) == Align::Center) {
|
||||
child->setLayoutPosition(
|
||||
(node->getLayout().measuredDimensions[dimension(crossAxis)] -
|
||||
child->getLayout().measuredDimensions[dimension(crossAxis)]) /
|
||||
(node->getLayout().measuredDimension(dimension(crossAxis)) -
|
||||
child->getLayout().measuredDimension(dimension(crossAxis))) /
|
||||
2.0f,
|
||||
leadingEdge(crossAxis));
|
||||
} else if (
|
||||
@@ -522,8 +522,8 @@ static void layoutAbsoluteChild(
|
||||
((resolveChildAlignment(node, child) == Align::FlexEnd) ^
|
||||
(node->getStyle().flexWrap() == Wrap::WrapReverse))) {
|
||||
child->setLayoutPosition(
|
||||
(node->getLayout().measuredDimensions[dimension(crossAxis)] -
|
||||
child->getLayout().measuredDimensions[dimension(crossAxis)]),
|
||||
(node->getLayout().measuredDimension(dimension(crossAxis)) -
|
||||
child->getLayout().measuredDimension(dimension(crossAxis))),
|
||||
leadingEdge(crossAxis));
|
||||
} else if (
|
||||
node->getConfig()->isExperimentalFeatureEnabled(
|
||||
@@ -532,13 +532,13 @@ static void layoutAbsoluteChild(
|
||||
child->setLayoutPosition(
|
||||
child->getLeadingPosition(
|
||||
crossAxis,
|
||||
node->getLayout().measuredDimensions[dimension(crossAxis)])
|
||||
node->getLayout().measuredDimension(dimension(crossAxis)))
|
||||
.unwrap() +
|
||||
node->getLeadingBorder(crossAxis) +
|
||||
child
|
||||
->getLeadingMargin(
|
||||
crossAxis,
|
||||
node->getLayout().measuredDimensions[dimension(crossAxis)])
|
||||
node->getLayout().measuredDimension(dimension(crossAxis)))
|
||||
.unwrap(),
|
||||
leadingEdge(crossAxis));
|
||||
}
|
||||
@@ -746,14 +746,14 @@ static float calculateAvailableInnerDimension(
|
||||
if (!yoga::isUndefined(availableInnerDim)) {
|
||||
// We want to make sure our available height does not violate min and max
|
||||
// constraints
|
||||
const FloatOptional minDimensionOptional = yoga::resolveValue(
|
||||
node->getStyle().minDimensions()[dimension], ownerDim);
|
||||
const FloatOptional minDimensionOptional =
|
||||
yoga::resolveValue(node->getStyle().minDimension(dimension), ownerDim);
|
||||
const float minInnerDim = minDimensionOptional.isUndefined()
|
||||
? 0.0f
|
||||
: minDimensionOptional.unwrap() - paddingAndBorder;
|
||||
|
||||
const FloatOptional maxDimensionOptional = yoga::resolveValue(
|
||||
node->getStyle().maxDimensions()[dimension], ownerDim);
|
||||
const FloatOptional maxDimensionOptional =
|
||||
yoga::resolveValue(node->getStyle().maxDimension(dimension), ownerDim);
|
||||
|
||||
const float maxInnerDim = maxDimensionOptional.isUndefined()
|
||||
? FLT_MAX
|
||||
@@ -1220,9 +1220,9 @@ static void justifyMainAxis(
|
||||
// remainingFreeSpace is 0 when min main dimension is not given
|
||||
if (measureModeMainDim == MeasureMode::AtMost &&
|
||||
flexLine.layout.remainingFreeSpace > 0) {
|
||||
if (!style.minDimensions()[dimension(mainAxis)].isUndefined() &&
|
||||
if (!style.minDimension(dimension(mainAxis)).isUndefined() &&
|
||||
!yoga::resolveValue(
|
||||
style.minDimensions()[dimension(mainAxis)], mainAxisownerSize)
|
||||
style.minDimension(dimension(mainAxis)), mainAxisownerSize)
|
||||
.isUndefined()) {
|
||||
// This condition makes sure that if the size of main dimension(after
|
||||
// considering child nodes main dim, leading and trailing padding etc)
|
||||
@@ -1233,7 +1233,7 @@ static void justifyMainAxis(
|
||||
// can be laid out, it will exclude space consumed by padding and border.
|
||||
const float minAvailableMainDim =
|
||||
yoga::resolveValue(
|
||||
style.minDimensions()[dimension(mainAxis)], mainAxisownerSize)
|
||||
style.minDimension(dimension(mainAxis)), mainAxisownerSize)
|
||||
.unwrap() -
|
||||
leadingPaddingAndBorderMain - trailingPaddingAndBorderMain;
|
||||
const float occupiedSpaceByChildNodes =
|
||||
@@ -1373,7 +1373,7 @@ static void justifyMainAxis(
|
||||
FlexDirection::Column, availableInnerWidth)
|
||||
.unwrap();
|
||||
const float descent =
|
||||
child->getLayout().measuredDimensions[YGDimensionHeight] +
|
||||
child->getLayout().measuredDimension(YGDimensionHeight) +
|
||||
child
|
||||
->getMarginForAxis(
|
||||
FlexDirection::Column, availableInnerWidth)
|
||||
@@ -1723,22 +1723,21 @@ static void calculateLayoutImpl(
|
||||
// If we don't measure with exact main dimension we want to ensure we don't
|
||||
// violate min and max
|
||||
if (measureModeMainDim != MeasureMode::Exactly) {
|
||||
const auto& minDimensions = node->getStyle().minDimensions();
|
||||
const auto& maxDimensions = node->getStyle().maxDimensions();
|
||||
const auto& style = node->getStyle();
|
||||
const float minInnerWidth =
|
||||
yoga::resolveValue(minDimensions[YGDimensionWidth], ownerWidth)
|
||||
yoga::resolveValue(style.minDimension(YGDimensionWidth), ownerWidth)
|
||||
.unwrap() -
|
||||
paddingAndBorderAxisRow;
|
||||
const float maxInnerWidth =
|
||||
yoga::resolveValue(maxDimensions[YGDimensionWidth], ownerWidth)
|
||||
yoga::resolveValue(style.maxDimension(YGDimensionWidth), ownerWidth)
|
||||
.unwrap() -
|
||||
paddingAndBorderAxisRow;
|
||||
const float minInnerHeight =
|
||||
yoga::resolveValue(minDimensions[YGDimensionHeight], ownerHeight)
|
||||
yoga::resolveValue(style.minDimension(YGDimensionHeight), ownerHeight)
|
||||
.unwrap() -
|
||||
paddingAndBorderAxisColumn;
|
||||
const float maxInnerHeight =
|
||||
yoga::resolveValue(maxDimensions[YGDimensionHeight], ownerHeight)
|
||||
yoga::resolveValue(style.maxDimension(YGDimensionHeight), ownerHeight)
|
||||
.unwrap() -
|
||||
paddingAndBorderAxisColumn;
|
||||
|
||||
@@ -1911,7 +1910,7 @@ static void calculateLayoutImpl(
|
||||
if (!styleDefinesDimension(
|
||||
child, crossAxis, availableInnerCrossDim)) {
|
||||
float childMainSize =
|
||||
child->getLayout().measuredDimensions[dimension(mainAxis)];
|
||||
child->getLayout().measuredDimension(dimension(mainAxis));
|
||||
const auto& childStyle = child->getStyle();
|
||||
float childCrossSize = !childStyle.aspectRatio().isUndefined()
|
||||
? child->getMarginForAxis(crossAxis, availableInnerWidth)
|
||||
@@ -2079,7 +2078,7 @@ static void calculateLayoutImpl(
|
||||
if (isLayoutDimensionDefined(child, crossAxis)) {
|
||||
lineHeight = yoga::maxOrDefined(
|
||||
lineHeight,
|
||||
child->getLayout().measuredDimensions[dimension(crossAxis)] +
|
||||
child->getLayout().measuredDimension(dimension(crossAxis)) +
|
||||
child->getMarginForAxis(crossAxis, availableInnerWidth)
|
||||
.unwrap());
|
||||
}
|
||||
@@ -2090,7 +2089,7 @@ static void calculateLayoutImpl(
|
||||
FlexDirection::Column, availableInnerWidth)
|
||||
.unwrap();
|
||||
const float descent =
|
||||
child->getLayout().measuredDimensions[YGDimensionHeight] +
|
||||
child->getLayout().measuredDimension(YGDimensionHeight) +
|
||||
child
|
||||
->getMarginForAxis(
|
||||
FlexDirection::Column, availableInnerWidth)
|
||||
@@ -2130,14 +2129,14 @@ static void calculateLayoutImpl(
|
||||
currentLead + lineHeight -
|
||||
child->getTrailingMargin(crossAxis, availableInnerWidth)
|
||||
.unwrap() -
|
||||
child->getLayout()
|
||||
.measuredDimensions[dimension(crossAxis)],
|
||||
child->getLayout().measuredDimension(
|
||||
dimension(crossAxis)),
|
||||
leadingEdge(crossAxis));
|
||||
break;
|
||||
}
|
||||
case Align::Center: {
|
||||
float childHeight =
|
||||
child->getLayout().measuredDimensions[dimension(crossAxis)];
|
||||
child->getLayout().measuredDimension(dimension(crossAxis));
|
||||
|
||||
child->setLayoutPosition(
|
||||
currentLead + (lineHeight - childHeight) / 2,
|
||||
@@ -2156,27 +2155,27 @@ static void calculateLayoutImpl(
|
||||
if (!styleDefinesDimension(
|
||||
child, crossAxis, availableInnerCrossDim)) {
|
||||
const float childWidth = isMainAxisRow
|
||||
? (child->getLayout()
|
||||
.measuredDimensions[YGDimensionWidth] +
|
||||
? (child->getLayout().measuredDimension(
|
||||
YGDimensionWidth) +
|
||||
child->getMarginForAxis(mainAxis, availableInnerWidth)
|
||||
.unwrap())
|
||||
: lineHeight;
|
||||
|
||||
const float childHeight = !isMainAxisRow
|
||||
? (child->getLayout()
|
||||
.measuredDimensions[YGDimensionHeight] +
|
||||
? (child->getLayout().measuredDimension(
|
||||
YGDimensionHeight) +
|
||||
child->getMarginForAxis(crossAxis, availableInnerWidth)
|
||||
.unwrap())
|
||||
: lineHeight;
|
||||
|
||||
if (!(yoga::inexactEquals(
|
||||
childWidth,
|
||||
child->getLayout()
|
||||
.measuredDimensions[YGDimensionWidth]) &&
|
||||
child->getLayout().measuredDimension(
|
||||
YGDimensionWidth)) &&
|
||||
yoga::inexactEquals(
|
||||
childHeight,
|
||||
child->getLayout()
|
||||
.measuredDimensions[YGDimensionHeight]))) {
|
||||
child->getLayout().measuredDimension(
|
||||
YGDimensionHeight)))) {
|
||||
calculateLayoutInternal(
|
||||
child,
|
||||
childWidth,
|
||||
@@ -2307,9 +2306,9 @@ static void calculateLayoutImpl(
|
||||
const auto child = node->getChild(i);
|
||||
if (child->getStyle().positionType() != PositionType::Absolute) {
|
||||
child->setLayoutPosition(
|
||||
node->getLayout().measuredDimensions[dimension(crossAxis)] -
|
||||
node->getLayout().measuredDimension(dimension(crossAxis)) -
|
||||
child->getLayout().position[leadingEdge(crossAxis)] -
|
||||
child->getLayout().measuredDimensions[dimension(crossAxis)],
|
||||
child->getLayout().measuredDimension(dimension(crossAxis)),
|
||||
leadingEdge(crossAxis));
|
||||
}
|
||||
}
|
||||
@@ -2330,11 +2329,11 @@ static void calculateLayoutImpl(
|
||||
node,
|
||||
child,
|
||||
absolutePercentageAgainstPaddingEdge
|
||||
? node->getLayout().measuredDimensions[YGDimensionWidth]
|
||||
? node->getLayout().measuredDimension(YGDimensionWidth)
|
||||
: availableInnerWidth,
|
||||
isMainAxisRow ? measureModeMainDim : measureModeCrossDim,
|
||||
absolutePercentageAgainstPaddingEdge
|
||||
? node->getLayout().measuredDimensions[YGDimensionHeight]
|
||||
? node->getLayout().measuredDimension(YGDimensionHeight)
|
||||
: availableInnerHeight,
|
||||
direction,
|
||||
layoutMarkerData,
|
||||
@@ -2516,9 +2515,10 @@ bool calculateLayoutInternal(
|
||||
}
|
||||
|
||||
if (!needToVisitNode && cachedResults != nullptr) {
|
||||
layout->measuredDimensions[YGDimensionWidth] = cachedResults->computedWidth;
|
||||
layout->measuredDimensions[YGDimensionHeight] =
|
||||
cachedResults->computedHeight;
|
||||
layout->setMeasuredDimension(
|
||||
YGDimensionWidth, cachedResults->computedWidth);
|
||||
layout->setMeasuredDimension(
|
||||
YGDimensionHeight, cachedResults->computedHeight);
|
||||
|
||||
(performLayout ? layoutMarkerData.cachedLayouts
|
||||
: layoutMarkerData.cachedMeasures) += 1;
|
||||
@@ -2594,8 +2594,8 @@ bool calculateLayoutInternal(
|
||||
"wm: %s, hm: %s, d: (%f, %f) %s\n",
|
||||
measureModeName(widthMeasureMode, performLayout),
|
||||
measureModeName(heightMeasureMode, performLayout),
|
||||
layout->measuredDimensions[YGDimensionWidth],
|
||||
layout->measuredDimensions[YGDimensionHeight],
|
||||
layout->measuredDimension(YGDimensionWidth),
|
||||
layout->measuredDimension(YGDimensionHeight),
|
||||
LayoutPassReasonToString(reason));
|
||||
}
|
||||
|
||||
@@ -2630,18 +2630,18 @@ bool calculateLayoutInternal(
|
||||
newCacheEntry->widthMeasureMode = widthMeasureMode;
|
||||
newCacheEntry->heightMeasureMode = heightMeasureMode;
|
||||
newCacheEntry->computedWidth =
|
||||
layout->measuredDimensions[YGDimensionWidth];
|
||||
layout->measuredDimension(YGDimensionWidth);
|
||||
newCacheEntry->computedHeight =
|
||||
layout->measuredDimensions[YGDimensionHeight];
|
||||
layout->measuredDimension(YGDimensionHeight);
|
||||
}
|
||||
}
|
||||
|
||||
if (performLayout) {
|
||||
node->setLayoutDimension(
|
||||
node->getLayout().measuredDimensions[YGDimensionWidth],
|
||||
node->getLayout().measuredDimension(YGDimensionWidth),
|
||||
YGDimensionWidth);
|
||||
node->setLayoutDimension(
|
||||
node->getLayout().measuredDimensions[YGDimensionHeight],
|
||||
node->getLayout().measuredDimension(YGDimensionHeight),
|
||||
YGDimensionHeight);
|
||||
|
||||
node->setHasNewLayout(true);
|
||||
@@ -2679,7 +2679,7 @@ void calculateLayout(
|
||||
node->resolveDimension();
|
||||
float width = YGUndefined;
|
||||
MeasureMode widthMeasureMode = MeasureMode::Undefined;
|
||||
const auto& maxDimensions = node->getStyle().maxDimensions();
|
||||
const auto& style = node->getStyle();
|
||||
if (styleDefinesDimension(node, FlexDirection::Row, ownerWidth)) {
|
||||
width = (yoga::resolveValue(
|
||||
node->getResolvedDimension(dimension(FlexDirection::Row)),
|
||||
@@ -2687,9 +2687,10 @@ void calculateLayout(
|
||||
node->getMarginForAxis(FlexDirection::Row, ownerWidth))
|
||||
.unwrap();
|
||||
widthMeasureMode = MeasureMode::Exactly;
|
||||
} else if (!yoga::resolveValue(maxDimensions[YGDimensionWidth], ownerWidth)
|
||||
} else if (!yoga::resolveValue(
|
||||
style.maxDimension(YGDimensionWidth), ownerWidth)
|
||||
.isUndefined()) {
|
||||
width = yoga::resolveValue(maxDimensions[YGDimensionWidth], ownerWidth)
|
||||
width = yoga::resolveValue(style.maxDimension(YGDimensionWidth), ownerWidth)
|
||||
.unwrap();
|
||||
widthMeasureMode = MeasureMode::AtMost;
|
||||
} else {
|
||||
@@ -2707,9 +2708,11 @@ void calculateLayout(
|
||||
node->getMarginForAxis(FlexDirection::Column, ownerWidth))
|
||||
.unwrap();
|
||||
heightMeasureMode = MeasureMode::Exactly;
|
||||
} else if (!yoga::resolveValue(maxDimensions[YGDimensionHeight], ownerHeight)
|
||||
} else if (!yoga::resolveValue(
|
||||
style.maxDimension(YGDimensionHeight), ownerHeight)
|
||||
.isUndefined()) {
|
||||
height = yoga::resolveValue(maxDimensions[YGDimensionHeight], ownerHeight)
|
||||
height =
|
||||
yoga::resolveValue(style.maxDimension(YGDimensionHeight), ownerHeight)
|
||||
.unwrap();
|
||||
heightMeasureMode = MeasureMode::AtMost;
|
||||
} else {
|
||||
|
@@ -71,8 +71,8 @@ void roundLayoutResultsToPixelGrid(
|
||||
const double nodeLeft = node->getLayout().position[YGEdgeLeft];
|
||||
const double nodeTop = node->getLayout().position[YGEdgeTop];
|
||||
|
||||
const double nodeWidth = node->getLayout().dimensions[YGDimensionWidth];
|
||||
const double nodeHeight = node->getLayout().dimensions[YGDimensionHeight];
|
||||
const double nodeWidth = node->getLayout().dimension(YGDimensionWidth);
|
||||
const double nodeHeight = node->getLayout().dimension(YGDimensionHeight);
|
||||
|
||||
const double absoluteNodeLeft = absoluteLeft + nodeLeft;
|
||||
const double absoluteNodeTop = absoluteTop + nodeTop;
|
||||
|
@@ -127,9 +127,9 @@ void nodeToString(
|
||||
if ((options & PrintOptions::Layout) == PrintOptions::Layout) {
|
||||
appendFormattedString(str, "layout=\"");
|
||||
appendFormattedString(
|
||||
str, "width: %g; ", node->getLayout().dimensions[YGDimensionWidth]);
|
||||
str, "width: %g; ", node->getLayout().dimension(YGDimensionWidth));
|
||||
appendFormattedString(
|
||||
str, "height: %g; ", node->getLayout().dimensions[YGDimensionHeight]);
|
||||
str, "height: %g; ", node->getLayout().dimension(YGDimensionHeight));
|
||||
appendFormattedString(
|
||||
str, "top: %g; ", node->getLayout().position[YGEdgeTop]);
|
||||
appendFormattedString(
|
||||
@@ -193,16 +193,16 @@ void nodeToString(
|
||||
appendNumberIfNotUndefined(str, "row-gap", style.gap()[YGGutterRow]);
|
||||
}
|
||||
|
||||
appendNumberIfNotAuto(str, "width", style.dimensions()[YGDimensionWidth]);
|
||||
appendNumberIfNotAuto(str, "height", style.dimensions()[YGDimensionHeight]);
|
||||
appendNumberIfNotAuto(str, "width", style.dimension(YGDimensionWidth));
|
||||
appendNumberIfNotAuto(str, "height", style.dimension(YGDimensionHeight));
|
||||
appendNumberIfNotAuto(
|
||||
str, "max-width", style.maxDimensions()[YGDimensionWidth]);
|
||||
str, "max-width", style.maxDimension(YGDimensionWidth));
|
||||
appendNumberIfNotAuto(
|
||||
str, "max-height", style.maxDimensions()[YGDimensionHeight]);
|
||||
str, "max-height", style.maxDimension(YGDimensionHeight));
|
||||
appendNumberIfNotAuto(
|
||||
str, "min-width", style.minDimensions()[YGDimensionWidth]);
|
||||
str, "min-width", style.minDimension(YGDimensionWidth));
|
||||
appendNumberIfNotAuto(
|
||||
str, "min-height", style.minDimensions()[YGDimensionHeight]);
|
||||
str, "min-height", style.minDimension(YGDimensionHeight));
|
||||
|
||||
if (style.positionType() != yoga::Node{}.getStyle().positionType()) {
|
||||
appendFormattedString(
|
||||
|
@@ -14,7 +14,7 @@ namespace facebook::yoga {
|
||||
|
||||
bool LayoutResults::operator==(LayoutResults layout) const {
|
||||
bool isEqual = yoga::inexactEquals(position, layout.position) &&
|
||||
yoga::inexactEquals(dimensions, layout.dimensions) &&
|
||||
yoga::inexactEquals(dimensions_, layout.dimensions_) &&
|
||||
yoga::inexactEquals(margin, layout.margin) &&
|
||||
yoga::inexactEquals(border, layout.border) &&
|
||||
yoga::inexactEquals(padding, layout.padding) &&
|
||||
@@ -30,15 +30,15 @@ bool LayoutResults::operator==(LayoutResults layout) const {
|
||||
isEqual = isEqual && cachedMeasurements[i] == layout.cachedMeasurements[i];
|
||||
}
|
||||
|
||||
if (!yoga::isUndefined(measuredDimensions[0]) ||
|
||||
!yoga::isUndefined(layout.measuredDimensions[0])) {
|
||||
if (!yoga::isUndefined(measuredDimensions_[0]) ||
|
||||
!yoga::isUndefined(layout.measuredDimensions_[0])) {
|
||||
isEqual =
|
||||
isEqual && (measuredDimensions[0] == layout.measuredDimensions[0]);
|
||||
isEqual && (measuredDimensions_[0] == layout.measuredDimensions_[0]);
|
||||
}
|
||||
if (!yoga::isUndefined(measuredDimensions[1]) ||
|
||||
!yoga::isUndefined(layout.measuredDimensions[1])) {
|
||||
if (!yoga::isUndefined(measuredDimensions_[1]) ||
|
||||
!yoga::isUndefined(layout.measuredDimensions_[1])) {
|
||||
isEqual =
|
||||
isEqual && (measuredDimensions[1] == layout.measuredDimensions[1]);
|
||||
isEqual && (measuredDimensions_[1] == layout.measuredDimensions_[1]);
|
||||
}
|
||||
|
||||
return isEqual;
|
||||
|
@@ -22,7 +22,6 @@ struct LayoutResults {
|
||||
static constexpr int32_t MaxCachedMeasurements = 8;
|
||||
|
||||
std::array<float, 4> position = {};
|
||||
std::array<float, 2> dimensions = {{YGUndefined, YGUndefined}};
|
||||
std::array<float, 4> margin = {};
|
||||
std::array<float, 4> border = {};
|
||||
std::array<float, 4> padding = {};
|
||||
@@ -31,6 +30,9 @@ struct LayoutResults {
|
||||
Direction direction_ : bitCount<Direction>() = Direction::Inherit;
|
||||
bool hadOverflow_ : 1 = false;
|
||||
|
||||
std::array<float, 2> dimensions_ = {{YGUndefined, YGUndefined}};
|
||||
std::array<float, 2> measuredDimensions_ = {{YGUndefined, YGUndefined}};
|
||||
|
||||
public:
|
||||
uint32_t computedFlexBasisGeneration = 0;
|
||||
FloatOptional computedFlexBasis = {};
|
||||
@@ -42,7 +44,6 @@ struct LayoutResults {
|
||||
|
||||
uint32_t nextCachedMeasurementsIndex = 0;
|
||||
std::array<CachedMeasurement, MaxCachedMeasurements> cachedMeasurements = {};
|
||||
std::array<float, 2> measuredDimensions = {{YGUndefined, YGUndefined}};
|
||||
|
||||
CachedMeasurement cachedLayout{};
|
||||
|
||||
@@ -57,10 +58,27 @@ struct LayoutResults {
|
||||
bool hadOverflow() const {
|
||||
return hadOverflow_;
|
||||
}
|
||||
|
||||
void setHadOverflow(bool hadOverflow) {
|
||||
hadOverflow_ = hadOverflow;
|
||||
}
|
||||
|
||||
float dimension(YGDimension axis) const {
|
||||
return dimensions_[axis];
|
||||
}
|
||||
|
||||
void setDimension(YGDimension axis, float dimension) {
|
||||
dimensions_[axis] = dimension;
|
||||
}
|
||||
|
||||
float measuredDimension(YGDimension axis) const {
|
||||
return measuredDimensions_[axis];
|
||||
}
|
||||
|
||||
void setMeasuredDimension(YGDimension axis, float dimension) {
|
||||
measuredDimensions_[axis] = dimension;
|
||||
}
|
||||
|
||||
bool operator==(LayoutResults layout) const;
|
||||
bool operator!=(LayoutResults layout) const {
|
||||
return !(*this == layout);
|
||||
|
@@ -340,8 +340,7 @@ void Node::setLayoutComputedFlexBasisGeneration(
|
||||
void Node::setLayoutMeasuredDimension(
|
||||
float measuredDimension,
|
||||
YGDimension dimension) {
|
||||
layout_.measuredDimensions[static_cast<size_t>(dimension)] =
|
||||
measuredDimension;
|
||||
layout_.setMeasuredDimension(dimension, measuredDimension);
|
||||
}
|
||||
|
||||
void Node::setLayoutHadOverflow(bool hadOverflow) {
|
||||
@@ -349,7 +348,7 @@ void Node::setLayoutHadOverflow(bool hadOverflow) {
|
||||
}
|
||||
|
||||
void Node::setLayoutDimension(float dimensionValue, YGDimension dimension) {
|
||||
layout_.dimensions[static_cast<size_t>(dimension)] = dimensionValue;
|
||||
layout_.setDimension(dimension, dimensionValue);
|
||||
}
|
||||
|
||||
// If both left and right are defined, then use left. Otherwise return +left or
|
||||
@@ -437,12 +436,11 @@ void Node::resolveDimension() {
|
||||
using namespace yoga;
|
||||
const Style& style = getStyle();
|
||||
for (auto dim : {YGDimensionWidth, YGDimensionHeight}) {
|
||||
if (!style.maxDimensions()[dim].isUndefined() &&
|
||||
yoga::inexactEquals(
|
||||
style.maxDimensions()[dim], style.minDimensions()[dim])) {
|
||||
resolvedDimensions_[dim] = style.maxDimensions()[dim];
|
||||
if (!style.maxDimension(dim).isUndefined() &&
|
||||
yoga::inexactEquals(style.maxDimension(dim), style.minDimension(dim))) {
|
||||
resolvedDimensions_[dim] = style.maxDimension(dim);
|
||||
} else {
|
||||
resolvedDimensions_[dim] = style.dimensions()[dim];
|
||||
resolvedDimensions_[dim] = style.dimension(dim);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,6 @@
|
||||
|
||||
#include <yoga/Yoga.h>
|
||||
#include <yoga/numeric/FloatOptional.h>
|
||||
#include <yoga/style/CompactValue.h>
|
||||
|
||||
namespace facebook::yoga {
|
||||
|
||||
@@ -61,6 +60,10 @@ inline bool inexactEquals(const double a, const double b) {
|
||||
return yoga::isUndefined(a) && yoga::isUndefined(b);
|
||||
}
|
||||
|
||||
inline bool inexactEquals(const FloatOptional a, const FloatOptional b) {
|
||||
return inexactEquals(a.unwrap(), b.unwrap());
|
||||
}
|
||||
|
||||
inline bool inexactEquals(const YGValue& a, const YGValue& b) {
|
||||
if (a.unit != b.unit) {
|
||||
return false;
|
||||
@@ -74,10 +77,6 @@ inline bool inexactEquals(const YGValue& a, const YGValue& b) {
|
||||
return fabs(a.value - b.value) < 0.0001f;
|
||||
}
|
||||
|
||||
inline bool inexactEquals(CompactValue a, CompactValue b) {
|
||||
return inexactEquals((YGValue)a, (YGValue)b);
|
||||
}
|
||||
|
||||
template <std::size_t Size, typename ElementT>
|
||||
bool inexactEquals(
|
||||
const std::array<ElementT, Size>& val1,
|
||||
|
@@ -15,6 +15,7 @@
|
||||
#include <yoga/YGValue.h>
|
||||
|
||||
#include <yoga/bits/BitCast.h>
|
||||
#include <yoga/numeric/Comparison.h>
|
||||
|
||||
static_assert(
|
||||
std::numeric_limits<float>::is_iec559,
|
||||
@@ -176,4 +177,8 @@ constexpr bool operator!=(CompactValue a, CompactValue b) noexcept {
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
inline bool inexactEquals(CompactValue a, CompactValue b) {
|
||||
return inexactEquals((YGValue)a, (YGValue)b);
|
||||
}
|
||||
|
||||
} // namespace facebook::yoga
|
||||
|
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include <yoga/numeric/Comparison.h>
|
||||
#include <yoga/style/Style.h>
|
||||
|
||||
namespace facebook::yoga {
|
||||
|
||||
// Yoga specific properties, not compatible with flexbox specification
|
||||
bool operator==(const Style& lhs, const Style& rhs) {
|
||||
bool areNonFloatValuesEqual = lhs.direction() == rhs.direction() &&
|
||||
lhs.flexDirection() == rhs.flexDirection() &&
|
||||
lhs.justifyContent() == rhs.justifyContent() &&
|
||||
lhs.alignContent() == rhs.alignContent() &&
|
||||
lhs.alignItems() == rhs.alignItems() &&
|
||||
lhs.alignSelf() == rhs.alignSelf() &&
|
||||
lhs.positionType() == rhs.positionType() &&
|
||||
lhs.flexWrap() == rhs.flexWrap() && lhs.overflow() == rhs.overflow() &&
|
||||
lhs.display() == rhs.display() &&
|
||||
yoga::inexactEquals(lhs.flexBasis(), rhs.flexBasis()) &&
|
||||
lhs.margin() == rhs.margin() && lhs.position() == rhs.position() &&
|
||||
lhs.padding() == rhs.padding() && lhs.border() == rhs.border() &&
|
||||
lhs.gap() == rhs.gap() && lhs.dimensions() == rhs.dimensions() &&
|
||||
lhs.minDimensions() == rhs.minDimensions() &&
|
||||
lhs.maxDimensions() == rhs.maxDimensions();
|
||||
|
||||
areNonFloatValuesEqual = areNonFloatValuesEqual &&
|
||||
lhs.flex().isUndefined() == rhs.flex().isUndefined();
|
||||
if (areNonFloatValuesEqual && !lhs.flex().isUndefined() &&
|
||||
!rhs.flex().isUndefined()) {
|
||||
areNonFloatValuesEqual = areNonFloatValuesEqual && lhs.flex() == rhs.flex();
|
||||
}
|
||||
|
||||
areNonFloatValuesEqual = areNonFloatValuesEqual &&
|
||||
lhs.flexGrow().isUndefined() == rhs.flexGrow().isUndefined();
|
||||
if (areNonFloatValuesEqual && !lhs.flexGrow().isUndefined()) {
|
||||
areNonFloatValuesEqual =
|
||||
areNonFloatValuesEqual && lhs.flexGrow() == rhs.flexGrow();
|
||||
}
|
||||
|
||||
areNonFloatValuesEqual = areNonFloatValuesEqual &&
|
||||
lhs.flexShrink().isUndefined() == rhs.flexShrink().isUndefined();
|
||||
if (areNonFloatValuesEqual && !rhs.flexShrink().isUndefined()) {
|
||||
areNonFloatValuesEqual =
|
||||
areNonFloatValuesEqual && lhs.flexShrink() == rhs.flexShrink();
|
||||
}
|
||||
|
||||
if (!(lhs.aspectRatio().isUndefined() && rhs.aspectRatio().isUndefined())) {
|
||||
areNonFloatValuesEqual =
|
||||
areNonFloatValuesEqual && lhs.aspectRatio() == rhs.aspectRatio();
|
||||
}
|
||||
|
||||
return areNonFloatValuesEqual;
|
||||
}
|
||||
|
||||
} // namespace facebook::yoga
|
@@ -280,25 +280,25 @@ class YG_EXPORT Style {
|
||||
return {*this};
|
||||
}
|
||||
|
||||
const Dimensions& dimensions() const {
|
||||
return dimensions_;
|
||||
CompactValue dimension(YGDimension axis) const {
|
||||
return dimensions_[axis];
|
||||
}
|
||||
IdxRef<YGDimension, &Style::dimensions_> dimensions() {
|
||||
return {*this};
|
||||
void setDimension(YGDimension axis, CompactValue value) {
|
||||
dimensions_[axis] = value;
|
||||
}
|
||||
|
||||
const Dimensions& minDimensions() const {
|
||||
return minDimensions_;
|
||||
CompactValue minDimension(YGDimension axis) const {
|
||||
return minDimensions_[axis];
|
||||
}
|
||||
IdxRef<YGDimension, &Style::minDimensions_> minDimensions() {
|
||||
return {*this};
|
||||
void setMinDimension(YGDimension axis, CompactValue value) {
|
||||
minDimensions_[axis] = value;
|
||||
}
|
||||
|
||||
const Dimensions& maxDimensions() const {
|
||||
return maxDimensions_;
|
||||
CompactValue maxDimension(YGDimension axis) const {
|
||||
return maxDimensions_[axis];
|
||||
}
|
||||
IdxRef<YGDimension, &Style::maxDimensions_> maxDimensions() {
|
||||
return {*this};
|
||||
void setMaxDimension(YGDimension axis, CompactValue value) {
|
||||
maxDimensions_[axis] = value;
|
||||
}
|
||||
|
||||
// Yoga specific properties, not compatible with flexbox specification
|
||||
@@ -308,10 +308,26 @@ class YG_EXPORT Style {
|
||||
Ref<FloatOptional, &Style::aspectRatio_> aspectRatio() {
|
||||
return {*this};
|
||||
}
|
||||
|
||||
bool operator==(const Style& other) const {
|
||||
return flags == other.flags && inexactEquals(flex_, other.flex_) &&
|
||||
inexactEquals(flexGrow_, other.flexGrow_) &&
|
||||
inexactEquals(flexShrink_, other.flexShrink_) &&
|
||||
inexactEquals(flexBasis_, other.flexBasis_) &&
|
||||
inexactEquals(margin_, other.margin_) &&
|
||||
inexactEquals(position_, other.position_) &&
|
||||
inexactEquals(padding_, other.padding_) &&
|
||||
inexactEquals(border_, other.border_) &&
|
||||
inexactEquals(gap_, other.gap_) &&
|
||||
inexactEquals(dimensions_, other.dimensions_) &&
|
||||
inexactEquals(minDimensions_, other.minDimensions_) &&
|
||||
inexactEquals(maxDimensions_, other.maxDimensions_) &&
|
||||
inexactEquals(aspectRatio_, other.aspectRatio_);
|
||||
}
|
||||
|
||||
bool operator!=(const Style& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
};
|
||||
|
||||
YG_EXPORT bool operator==(const Style& lhs, const Style& rhs);
|
||||
YG_EXPORT inline bool operator!=(const Style& lhs, const Style& rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
} // namespace facebook::yoga
|
||||
|
Reference in New Issue
Block a user