Fix style resolution functions returning FloatOptional (#1404)

Summary:
X-link: https://github.com/facebook/react-native/pull/39595

Pull Request resolved: https://github.com/facebook/yoga/pull/1404

These functions all ensure their returns are defined, but return FloatOptional anyway, making their callers have to deal with that possibility. Return `float` instead of `FloatOptional`, and do some additional cleanup.

Reviewed By: rshest

Differential Revision: D49531421

fbshipit-source-id: 95b21cade74e501dd54c7b6ca667c8c3859c5dae
This commit is contained in:
Nick Gerleman
2023-10-03 15:36:01 -07:00
committed by Facebook GitHub Bot
parent ce8fe99bf9
commit 2734784ddb
7 changed files with 205 additions and 341 deletions

View File

@@ -21,9 +21,8 @@ inline float paddingAndBorderForAxis(
const yoga::Node* const node, const yoga::Node* const node,
const FlexDirection axis, const FlexDirection axis,
const float widthSize) { const float widthSize) {
return (node->getLeadingPaddingAndBorder(axis, widthSize) + return node->getLeadingPaddingAndBorder(axis, widthSize) +
node->getTrailingPaddingAndBorder(axis, widthSize)) node->getTrailingPaddingAndBorder(axis, widthSize);
.unwrap();
} }
inline FloatOptional boundAxisWithinMinAndMax( inline FloatOptional boundAxisWithinMinAndMax(

View File

@@ -55,8 +55,7 @@ static inline float dimensionWithMargin(
const float widthSize) { const float widthSize) {
return node->getLayout().measuredDimension(dimension(axis)) + return node->getLayout().measuredDimension(dimension(axis)) +
(node->getLeadingMargin(axis, widthSize) + (node->getLeadingMargin(axis, widthSize) +
node->getTrailingMargin(axis, widthSize)) node->getTrailingMargin(axis, widthSize));
.unwrap();
} }
static inline bool styleDefinesDimension( static inline bool styleDefinesDimension(
@@ -187,10 +186,9 @@ static void computeFlexBasisForChild(
childWidthMeasureMode = MeasureMode::Undefined; childWidthMeasureMode = MeasureMode::Undefined;
childHeightMeasureMode = MeasureMode::Undefined; childHeightMeasureMode = MeasureMode::Undefined;
auto marginRow = auto marginRow = child->getMarginForAxis(FlexDirection::Row, ownerWidth);
child->getMarginForAxis(FlexDirection::Row, ownerWidth).unwrap();
auto marginColumn = auto marginColumn =
child->getMarginForAxis(FlexDirection::Column, ownerWidth).unwrap(); child->getMarginForAxis(FlexDirection::Column, ownerWidth);
if (isRowStyleDimDefined) { if (isRowStyleDimDefined) {
childWidth = childWidth =
@@ -335,9 +333,8 @@ static void layoutAbsoluteChild(
MeasureMode childWidthMeasureMode = MeasureMode::Undefined; MeasureMode childWidthMeasureMode = MeasureMode::Undefined;
MeasureMode childHeightMeasureMode = MeasureMode::Undefined; MeasureMode childHeightMeasureMode = MeasureMode::Undefined;
auto marginRow = child->getMarginForAxis(FlexDirection::Row, width).unwrap(); auto marginRow = child->getMarginForAxis(FlexDirection::Row, width);
auto marginColumn = auto marginColumn = child->getMarginForAxis(FlexDirection::Column, width);
child->getMarginForAxis(FlexDirection::Column, width).unwrap();
if (styleDefinesDimension(child, FlexDirection::Row, width)) { if (styleDefinesDimension(child, FlexDirection::Row, width)) {
childWidth = childWidth =
@@ -353,8 +350,7 @@ static void layoutAbsoluteChild(
(node->getLeadingBorder(FlexDirection::Row) + (node->getLeadingBorder(FlexDirection::Row) +
node->getTrailingBorder(FlexDirection::Row)) - node->getTrailingBorder(FlexDirection::Row)) -
(child->getLeadingPosition(FlexDirection::Row, width) + (child->getLeadingPosition(FlexDirection::Row, width) +
child->getTrailingPosition(FlexDirection::Row, width)) child->getTrailingPosition(FlexDirection::Row, width));
.unwrap();
childWidth = childWidth =
boundAxis(child, FlexDirection::Row, childWidth, width, width); boundAxis(child, FlexDirection::Row, childWidth, width, width);
} }
@@ -374,8 +370,7 @@ static void layoutAbsoluteChild(
(node->getLeadingBorder(FlexDirection::Column) + (node->getLeadingBorder(FlexDirection::Column) +
node->getTrailingBorder(FlexDirection::Column)) - node->getTrailingBorder(FlexDirection::Column)) -
(child->getLeadingPosition(FlexDirection::Column, height) + (child->getLeadingPosition(FlexDirection::Column, height) +
child->getTrailingPosition(FlexDirection::Column, height)) child->getTrailingPosition(FlexDirection::Column, height));
.unwrap();
childHeight = childHeight =
boundAxis(child, FlexDirection::Column, childHeight, height, width); boundAxis(child, FlexDirection::Column, childHeight, height, width);
} }
@@ -432,9 +427,9 @@ static void layoutAbsoluteChild(
depth, depth,
generationCount); generationCount);
childWidth = child->getLayout().measuredDimension(Dimension::Width) + childWidth = child->getLayout().measuredDimension(Dimension::Width) +
child->getMarginForAxis(FlexDirection::Row, width).unwrap(); child->getMarginForAxis(FlexDirection::Row, width);
childHeight = child->getLayout().measuredDimension(Dimension::Height) + childHeight = child->getLayout().measuredDimension(Dimension::Height) +
child->getMarginForAxis(FlexDirection::Column, width).unwrap(); child->getMarginForAxis(FlexDirection::Column, width);
} }
calculateLayoutInternal( calculateLayoutInternal(
@@ -458,10 +453,9 @@ static void layoutAbsoluteChild(
node->getLayout().measuredDimension(dimension(mainAxis)) - node->getLayout().measuredDimension(dimension(mainAxis)) -
child->getLayout().measuredDimension(dimension(mainAxis)) - child->getLayout().measuredDimension(dimension(mainAxis)) -
node->getTrailingBorder(mainAxis) - node->getTrailingBorder(mainAxis) -
child->getTrailingMargin(mainAxis, isMainAxisRow ? width : height) child->getTrailingMargin(mainAxis, isMainAxisRow ? width : height) -
.unwrap() - child->getTrailingPosition(
child->getTrailingPosition(mainAxis, isMainAxisRow ? width : height) mainAxis, isMainAxisRow ? width : height),
.unwrap(),
leadingEdge(mainAxis)); leadingEdge(mainAxis));
} else if ( } else if (
!child->isLeadingPositionDefined(mainAxis) && !child->isLeadingPositionDefined(mainAxis) &&
@@ -485,14 +479,11 @@ static void layoutAbsoluteChild(
child->setLayoutPosition( child->setLayoutPosition(
child->getLeadingPosition( child->getLeadingPosition(
mainAxis, mainAxis,
node->getLayout().measuredDimension(dimension(mainAxis))) node->getLayout().measuredDimension(dimension(mainAxis))) +
.unwrap() +
node->getLeadingBorder(mainAxis) + node->getLeadingBorder(mainAxis) +
child child->getLeadingMargin(
->getLeadingMargin(
mainAxis, mainAxis,
node->getLayout().measuredDimension(dimension(mainAxis))) node->getLayout().measuredDimension(dimension(mainAxis))),
.unwrap(),
leadingEdge(mainAxis)); leadingEdge(mainAxis));
} }
@@ -502,11 +493,10 @@ static void layoutAbsoluteChild(
node->getLayout().measuredDimension(dimension(crossAxis)) - node->getLayout().measuredDimension(dimension(crossAxis)) -
child->getLayout().measuredDimension(dimension(crossAxis)) - child->getLayout().measuredDimension(dimension(crossAxis)) -
node->getTrailingBorder(crossAxis) - node->getTrailingBorder(crossAxis) -
child->getTrailingMargin(crossAxis, isMainAxisRow ? height : width) child->getTrailingMargin(
.unwrap() - crossAxis, isMainAxisRow ? height : width) -
child child->getTrailingPosition(
->getTrailingPosition(crossAxis, isMainAxisRow ? height : width) crossAxis, isMainAxisRow ? height : width),
.unwrap(),
leadingEdge(crossAxis)); leadingEdge(crossAxis));
} else if ( } else if (
@@ -532,14 +522,11 @@ static void layoutAbsoluteChild(
child->setLayoutPosition( child->setLayoutPosition(
child->getLeadingPosition( child->getLeadingPosition(
crossAxis, crossAxis,
node->getLayout().measuredDimension(dimension(crossAxis))) node->getLayout().measuredDimension(dimension(crossAxis))) +
.unwrap() +
node->getLeadingBorder(crossAxis) + node->getLeadingBorder(crossAxis) +
child child->getLeadingMargin(
->getLeadingMargin(
crossAxis, crossAxis,
node->getLayout().measuredDimension(dimension(crossAxis))) node->getLayout().measuredDimension(dimension(crossAxis))),
.unwrap(),
leadingEdge(crossAxis)); leadingEdge(crossAxis));
} }
} }
@@ -844,9 +831,8 @@ static float computeFlexBasisForChildren(
} }
totalOuterFlexBasis += totalOuterFlexBasis +=
(child->getLayout().computedFlexBasis + (child->getLayout().computedFlexBasis.unwrap() +
child->getMarginForAxis(mainAxis, availableInnerWidth)) child->getMarginForAxis(mainAxis, availableInnerWidth));
.unwrap();
} }
return totalOuterFlexBasis; return totalOuterFlexBasis;
@@ -934,11 +920,9 @@ static float distributeFreeSpaceSecondPass(
deltaFreeSpace += updatedMainSize - childFlexBasis; deltaFreeSpace += updatedMainSize - childFlexBasis;
const float marginMain = const float marginMain =
currentLineChild->getMarginForAxis(mainAxis, availableInnerWidth) currentLineChild->getMarginForAxis(mainAxis, availableInnerWidth);
.unwrap();
const float marginCross = const float marginCross =
currentLineChild->getMarginForAxis(crossAxis, availableInnerWidth) currentLineChild->getMarginForAxis(crossAxis, availableInnerWidth);
.unwrap();
float childCrossSize; float childCrossSize;
float childMainSize = updatedMainSize + marginMain; float childMainSize = updatedMainSize + marginMain;
@@ -1212,9 +1196,9 @@ static void justifyMainAxis(
const bool performLayout) { const bool performLayout) {
const auto& style = node->getStyle(); const auto& style = node->getStyle();
const float leadingPaddingAndBorderMain = const float leadingPaddingAndBorderMain =
node->getLeadingPaddingAndBorder(mainAxis, ownerWidth).unwrap(); node->getLeadingPaddingAndBorder(mainAxis, ownerWidth);
const float trailingPaddingAndBorderMain = const float trailingPaddingAndBorderMain =
node->getTrailingPaddingAndBorder(mainAxis, ownerWidth).unwrap(); node->getTrailingPaddingAndBorder(mainAxis, ownerWidth);
const float gap = node->getGapForAxis(mainAxis); const float gap = node->getGapForAxis(mainAxis);
// If we are using "at most" rules in the main axis, make sure that // If we are using "at most" rules in the main axis, make sure that
// remainingFreeSpace is 0 when min main dimension is not given // remainingFreeSpace is 0 when min main dimension is not given
@@ -1317,10 +1301,9 @@ static void justifyMainAxis(
// defined, we override the position to whatever the user said (and // defined, we override the position to whatever the user said (and
// margin/border). // margin/border).
child->setLayoutPosition( child->setLayoutPosition(
child->getLeadingPosition(mainAxis, availableInnerMainDim) child->getLeadingPosition(mainAxis, availableInnerMainDim) +
.unwrap() +
node->getLeadingBorder(mainAxis) + node->getLeadingBorder(mainAxis) +
child->getLeadingMargin(mainAxis, availableInnerWidth).unwrap(), child->getLeadingMargin(mainAxis, availableInnerWidth),
leadingEdge(mainAxis)); leadingEdge(mainAxis));
} }
} else { } else {
@@ -1355,7 +1338,7 @@ static void justifyMainAxis(
// because they weren't computed. This means we can't call // because they weren't computed. This means we can't call
// dimensionWithMargin. // dimensionWithMargin.
flexLine.layout.mainDim += flexLine.layout.mainDim +=
child->getMarginForAxis(mainAxis, availableInnerWidth).unwrap() + child->getMarginForAxis(mainAxis, availableInnerWidth) +
childLayout.computedFlexBasis.unwrap(); childLayout.computedFlexBasis.unwrap();
flexLine.layout.crossDim = availableInnerCrossDim; flexLine.layout.crossDim = availableInnerCrossDim;
} else { } else {
@@ -1368,16 +1351,12 @@ static void justifyMainAxis(
// If the child is baseline aligned then the cross dimension is // If the child is baseline aligned then the cross dimension is
// calculated by adding maxAscent and maxDescent from the baseline. // calculated by adding maxAscent and maxDescent from the baseline.
const float ascent = calculateBaseline(child) + const float ascent = calculateBaseline(child) +
child child->getLeadingMargin(
->getLeadingMargin( FlexDirection::Column, availableInnerWidth);
FlexDirection::Column, availableInnerWidth)
.unwrap();
const float descent = const float descent =
child->getLayout().measuredDimension(Dimension::Height) + child->getLayout().measuredDimension(Dimension::Height) +
child child->getMarginForAxis(
->getMarginForAxis( FlexDirection::Column, availableInnerWidth) -
FlexDirection::Column, availableInnerWidth)
.unwrap() -
ascent; ascent;
maxAscentForCurrentLine = maxAscentForCurrentLine =
@@ -1519,16 +1498,16 @@ static void calculateLayoutImpl(
const YGEdge endEdge = direction == Direction::LTR ? YGEdgeRight : YGEdgeLeft; const YGEdge endEdge = direction == Direction::LTR ? YGEdgeRight : YGEdgeLeft;
const float marginRowLeading = const float marginRowLeading =
node->getLeadingMargin(flexRowDirection, ownerWidth).unwrap(); node->getLeadingMargin(flexRowDirection, ownerWidth);
node->setLayoutMargin(marginRowLeading, startEdge); node->setLayoutMargin(marginRowLeading, startEdge);
const float marginRowTrailing = const float marginRowTrailing =
node->getTrailingMargin(flexRowDirection, ownerWidth).unwrap(); node->getTrailingMargin(flexRowDirection, ownerWidth);
node->setLayoutMargin(marginRowTrailing, endEdge); node->setLayoutMargin(marginRowTrailing, endEdge);
const float marginColumnLeading = const float marginColumnLeading =
node->getLeadingMargin(flexColumnDirection, ownerWidth).unwrap(); node->getLeadingMargin(flexColumnDirection, ownerWidth);
node->setLayoutMargin(marginColumnLeading, YGEdgeTop); node->setLayoutMargin(marginColumnLeading, YGEdgeTop);
const float marginColumnTrailing = const float marginColumnTrailing =
node->getTrailingMargin(flexColumnDirection, ownerWidth).unwrap(); node->getTrailingMargin(flexColumnDirection, ownerWidth);
node->setLayoutMargin(marginColumnTrailing, YGEdgeBottom); node->setLayoutMargin(marginColumnTrailing, YGEdgeBottom);
const float marginAxisRow = marginRowLeading + marginRowTrailing; const float marginAxisRow = marginRowLeading + marginRowTrailing;
@@ -1541,16 +1520,13 @@ static void calculateLayoutImpl(
node->getTrailingBorder(flexColumnDirection), YGEdgeBottom); node->getTrailingBorder(flexColumnDirection), YGEdgeBottom);
node->setLayoutPadding( node->setLayoutPadding(
node->getLeadingPadding(flexRowDirection, ownerWidth).unwrap(), node->getLeadingPadding(flexRowDirection, ownerWidth), startEdge);
startEdge);
node->setLayoutPadding( node->setLayoutPadding(
node->getTrailingPadding(flexRowDirection, ownerWidth).unwrap(), endEdge); node->getTrailingPadding(flexRowDirection, ownerWidth), endEdge);
node->setLayoutPadding( node->setLayoutPadding(
node->getLeadingPadding(flexColumnDirection, ownerWidth).unwrap(), node->getLeadingPadding(flexColumnDirection, ownerWidth), YGEdgeTop);
YGEdgeTop);
node->setLayoutPadding( node->setLayoutPadding(
node->getTrailingPadding(flexColumnDirection, ownerWidth).unwrap(), node->getTrailingPadding(flexColumnDirection, ownerWidth), YGEdgeBottom);
YGEdgeBottom);
if (node->hasMeasureFunc()) { if (node->hasMeasureFunc()) {
measureNodeWithMeasureFunc( measureNodeWithMeasureFunc(
@@ -1612,9 +1588,9 @@ static void calculateLayoutImpl(
const float paddingAndBorderAxisMain = const float paddingAndBorderAxisMain =
paddingAndBorderForAxis(node, mainAxis, ownerWidth); paddingAndBorderForAxis(node, mainAxis, ownerWidth);
const float leadingPaddingAndBorderCross = const float leadingPaddingAndBorderCross =
node->getLeadingPaddingAndBorder(crossAxis, ownerWidth).unwrap(); node->getLeadingPaddingAndBorder(crossAxis, ownerWidth);
const float trailingPaddingAndBorderCross = const float trailingPaddingAndBorderCross =
node->getTrailingPaddingAndBorder(crossAxis, ownerWidth).unwrap(); node->getTrailingPaddingAndBorder(crossAxis, ownerWidth);
const float paddingAndBorderAxisCross = const float paddingAndBorderAxisCross =
leadingPaddingAndBorderCross + trailingPaddingAndBorderCross; leadingPaddingAndBorderCross + trailingPaddingAndBorderCross;
@@ -1871,11 +1847,9 @@ static void calculateLayoutImpl(
child->isLeadingPositionDefined(crossAxis); child->isLeadingPositionDefined(crossAxis);
if (isChildLeadingPosDefined) { if (isChildLeadingPosDefined) {
child->setLayoutPosition( child->setLayoutPosition(
child->getLeadingPosition(crossAxis, availableInnerCrossDim) child->getLeadingPosition(crossAxis, availableInnerCrossDim) +
.unwrap() +
node->getLeadingBorder(crossAxis) + node->getLeadingBorder(crossAxis) +
child->getLeadingMargin(crossAxis, availableInnerWidth) child->getLeadingMargin(crossAxis, availableInnerWidth),
.unwrap(),
leadingEdge(crossAxis)); leadingEdge(crossAxis));
} }
// If leading position is not defined or calculations result in Nan, // If leading position is not defined or calculations result in Nan,
@@ -1885,8 +1859,7 @@ static void calculateLayoutImpl(
child->getLayout().position[leadingEdge(crossAxis)])) { child->getLayout().position[leadingEdge(crossAxis)])) {
child->setLayoutPosition( child->setLayoutPosition(
node->getLeadingBorder(crossAxis) + node->getLeadingBorder(crossAxis) +
child->getLeadingMargin(crossAxis, availableInnerWidth) child->getLeadingMargin(crossAxis, availableInnerWidth),
.unwrap(),
leadingEdge(crossAxis)); leadingEdge(crossAxis));
} }
} else { } else {
@@ -1911,16 +1884,14 @@ static void calculateLayoutImpl(
child->getLayout().measuredDimension(dimension(mainAxis)); child->getLayout().measuredDimension(dimension(mainAxis));
const auto& childStyle = child->getStyle(); const auto& childStyle = child->getStyle();
float childCrossSize = !childStyle.aspectRatio().isUndefined() float childCrossSize = !childStyle.aspectRatio().isUndefined()
? child->getMarginForAxis(crossAxis, availableInnerWidth) ? child->getMarginForAxis(crossAxis, availableInnerWidth) +
.unwrap() +
(isMainAxisRow (isMainAxisRow
? childMainSize / childStyle.aspectRatio().unwrap() ? childMainSize / childStyle.aspectRatio().unwrap()
: childMainSize * childStyle.aspectRatio().unwrap()) : childMainSize * childStyle.aspectRatio().unwrap())
: flexLine.layout.crossDim; : flexLine.layout.crossDim;
childMainSize += childMainSize +=
child->getMarginForAxis(mainAxis, availableInnerWidth) child->getMarginForAxis(mainAxis, availableInnerWidth);
.unwrap();
MeasureMode childMainMeasureMode = MeasureMode::Exactly; MeasureMode childMainMeasureMode = MeasureMode::Exactly;
MeasureMode childCrossMeasureMode = MeasureMode::Exactly; MeasureMode childCrossMeasureMode = MeasureMode::Exactly;
@@ -2077,21 +2048,16 @@ static void calculateLayoutImpl(
lineHeight = yoga::maxOrDefined( lineHeight = yoga::maxOrDefined(
lineHeight, lineHeight,
child->getLayout().measuredDimension(dimension(crossAxis)) + child->getLayout().measuredDimension(dimension(crossAxis)) +
child->getMarginForAxis(crossAxis, availableInnerWidth) child->getMarginForAxis(crossAxis, availableInnerWidth));
.unwrap());
} }
if (resolveChildAlignment(node, child) == Align::Baseline) { if (resolveChildAlignment(node, child) == Align::Baseline) {
const float ascent = calculateBaseline(child) + const float ascent = calculateBaseline(child) +
child child->getLeadingMargin(
->getLeadingMargin( FlexDirection::Column, availableInnerWidth);
FlexDirection::Column, availableInnerWidth)
.unwrap();
const float descent = const float descent =
child->getLayout().measuredDimension(Dimension::Height) + child->getLayout().measuredDimension(Dimension::Height) +
child child->getMarginForAxis(
->getMarginForAxis( FlexDirection::Column, availableInnerWidth) -
FlexDirection::Column, availableInnerWidth)
.unwrap() -
ascent; ascent;
maxAscentForCurrentLine = maxAscentForCurrentLine =
yoga::maxOrDefined(maxAscentForCurrentLine, ascent); yoga::maxOrDefined(maxAscentForCurrentLine, ascent);
@@ -2117,16 +2083,15 @@ static void calculateLayoutImpl(
case Align::FlexStart: { case Align::FlexStart: {
child->setLayoutPosition( child->setLayoutPosition(
currentLead + currentLead +
child->getLeadingMargin(crossAxis, availableInnerWidth) child->getLeadingMargin(crossAxis, availableInnerWidth),
.unwrap(),
leadingEdge(crossAxis)); leadingEdge(crossAxis));
break; break;
} }
case Align::FlexEnd: { case Align::FlexEnd: {
child->setLayoutPosition( child->setLayoutPosition(
currentLead + lineHeight - currentLead + lineHeight -
child->getTrailingMargin(crossAxis, availableInnerWidth) child->getTrailingMargin(
.unwrap() - crossAxis, availableInnerWidth) -
child->getLayout().measuredDimension( child->getLayout().measuredDimension(
dimension(crossAxis)), dimension(crossAxis)),
leadingEdge(crossAxis)); leadingEdge(crossAxis));
@@ -2144,8 +2109,7 @@ static void calculateLayoutImpl(
case Align::Stretch: { case Align::Stretch: {
child->setLayoutPosition( child->setLayoutPosition(
currentLead + currentLead +
child->getLeadingMargin(crossAxis, availableInnerWidth) child->getLeadingMargin(crossAxis, availableInnerWidth),
.unwrap(),
leadingEdge(crossAxis)); leadingEdge(crossAxis));
// Remeasure child with the line height as it as been only // Remeasure child with the line height as it as been only
@@ -2155,15 +2119,14 @@ static void calculateLayoutImpl(
const float childWidth = isMainAxisRow const float childWidth = isMainAxisRow
? (child->getLayout().measuredDimension( ? (child->getLayout().measuredDimension(
Dimension::Width) + Dimension::Width) +
child->getMarginForAxis(mainAxis, availableInnerWidth) child->getMarginForAxis(mainAxis, availableInnerWidth))
.unwrap())
: lineHeight; : lineHeight;
const float childHeight = !isMainAxisRow const float childHeight = !isMainAxisRow
? (child->getLayout().measuredDimension( ? (child->getLayout().measuredDimension(
Dimension::Height) + Dimension::Height) +
child->getMarginForAxis(crossAxis, availableInnerWidth) child->getMarginForAxis(
.unwrap()) crossAxis, availableInnerWidth))
: lineHeight; : lineHeight;
if (!(yoga::inexactEquals( if (!(yoga::inexactEquals(
@@ -2196,10 +2159,8 @@ static void calculateLayoutImpl(
child->setLayoutPosition( child->setLayoutPosition(
currentLead + maxAscentForCurrentLine - currentLead + maxAscentForCurrentLine -
calculateBaseline(child) + calculateBaseline(child) +
child child->getLeadingPosition(
->getLeadingPosition( FlexDirection::Column, availableInnerCrossDim),
FlexDirection::Column, availableInnerCrossDim)
.unwrap(),
YGEdgeTop); YGEdgeTop);
break; break;
@@ -2446,9 +2407,9 @@ bool calculateLayoutInternal(
// measurements if at all possible. // measurements if at all possible.
if (node->hasMeasureFunc()) { if (node->hasMeasureFunc()) {
const float marginAxisRow = const float marginAxisRow =
node->getMarginForAxis(FlexDirection::Row, ownerWidth).unwrap(); node->getMarginForAxis(FlexDirection::Row, ownerWidth);
const float marginAxisColumn = const float marginAxisColumn =
node->getMarginForAxis(FlexDirection::Column, ownerWidth).unwrap(); node->getMarginForAxis(FlexDirection::Column, ownerWidth);
// First, try to use the layout cache. // First, try to use the layout cache.
if (canUseCachedMeasurement( if (canUseCachedMeasurement(
@@ -2679,11 +2640,12 @@ void calculateLayout(
MeasureMode widthMeasureMode = MeasureMode::Undefined; MeasureMode widthMeasureMode = MeasureMode::Undefined;
const auto& style = node->getStyle(); const auto& style = node->getStyle();
if (styleDefinesDimension(node, FlexDirection::Row, ownerWidth)) { if (styleDefinesDimension(node, FlexDirection::Row, ownerWidth)) {
width = (yoga::resolveValue( width =
(yoga::resolveValue(
node->getResolvedDimension(dimension(FlexDirection::Row)), node->getResolvedDimension(dimension(FlexDirection::Row)),
ownerWidth) + ownerWidth)
node->getMarginForAxis(FlexDirection::Row, ownerWidth)) .unwrap() +
.unwrap(); node->getMarginForAxis(FlexDirection::Row, ownerWidth));
widthMeasureMode = MeasureMode::Exactly; widthMeasureMode = MeasureMode::Exactly;
} else if (!yoga::resolveValue( } else if (!yoga::resolveValue(
style.maxDimension(Dimension::Width), ownerWidth) style.maxDimension(Dimension::Width), ownerWidth)
@@ -2700,11 +2662,12 @@ void calculateLayout(
float height = YGUndefined; float height = YGUndefined;
MeasureMode heightMeasureMode = MeasureMode::Undefined; MeasureMode heightMeasureMode = MeasureMode::Undefined;
if (styleDefinesDimension(node, FlexDirection::Column, ownerHeight)) { if (styleDefinesDimension(node, FlexDirection::Column, ownerHeight)) {
height = (yoga::resolveValue( height =
(yoga::resolveValue(
node->getResolvedDimension(dimension(FlexDirection::Column)), node->getResolvedDimension(dimension(FlexDirection::Column)),
ownerHeight) + ownerHeight)
node->getMarginForAxis(FlexDirection::Column, ownerWidth)) .unwrap() +
.unwrap(); node->getMarginForAxis(FlexDirection::Column, ownerWidth));
heightMeasureMode = MeasureMode::Exactly; heightMeasureMode = MeasureMode::Exactly;
} else if (!yoga::resolveValue( } else if (!yoga::resolveValue(
style.maxDimension(Dimension::Height), ownerHeight) style.maxDimension(Dimension::Height), ownerHeight)

View File

@@ -53,7 +53,7 @@ FlexLine calculateFlexLine(
child->setLineIndex(lineCount); child->setLineIndex(lineCount);
const float childMarginMainAxis = const float childMarginMainAxis =
child->getMarginForAxis(mainAxis, availableInnerWidth).unwrap(); child->getMarginForAxis(mainAxis, availableInnerWidth);
const float childLeadingGapMainAxis = isFirstElementInLine ? 0.0f : gap; const float childLeadingGapMainAxis = isFirstElementInLine ? 0.0f : gap;
const float flexBasisWithMinAndMaxConstraints = const float flexBasisWithMinAndMaxConstraints =
boundAxisWithinMinAndMax( boundAxisWithinMinAndMax(

View File

@@ -91,9 +91,8 @@ static void appendEdges(
const std::string& key, const std::string& key,
const Style::Edges& edges) { const Style::Edges& edges) {
if (areFourValuesEqual(edges)) { if (areFourValuesEqual(edges)) {
auto edgeValue = yoga::Node::computeEdgeValueForColumn( auto edgeValue = yoga::Node::computeEdgeValueForColumn(edges, YGEdgeLeft);
edges, YGEdgeLeft, CompactValue::ofZero()); appendNumberIfNotUndefined(base, key, edgeValue);
appendNumberIfNotZero(base, key, edgeValue);
} else { } else {
for (int edge = YGEdgeLeft; edge != YGEdgeAll; ++edge) { for (int edge = YGEdgeLeft; edge != YGEdgeAll; ++edge) {
std::string str = key + "-" + YGEdgeToString(static_cast<YGEdge>(edge)); std::string str = key + "-" + YGEdgeToString(static_cast<YGEdge>(edge));
@@ -109,10 +108,8 @@ static void appendEdgeIfNotUndefined(
const YGEdge edge) { const YGEdge edge) {
// TODO: this doesn't take RTL / YGEdgeStart / YGEdgeEnd into account // TODO: this doesn't take RTL / YGEdgeStart / YGEdgeEnd into account
auto value = (edge == YGEdgeLeft || edge == YGEdgeRight) auto value = (edge == YGEdgeLeft || edge == YGEdgeRight)
? yoga::Node::computeEdgeValueForRow( ? yoga::Node::computeEdgeValueForRow(edges, edge, edge)
edges, edge, edge, CompactValue::ofUndefined()) : yoga::Node::computeEdgeValueForColumn(edges, edge);
: yoga::Node::computeEdgeValueForColumn(
edges, edge, CompactValue::ofUndefined());
appendNumberIfNotUndefined(base, str, value); appendNumberIfNotUndefined(base, str, value);
} }

View File

@@ -59,131 +59,131 @@ void Node::print() {
CompactValue Node::computeEdgeValueForRow( CompactValue Node::computeEdgeValueForRow(
const Style::Edges& edges, const Style::Edges& edges,
YGEdge rowEdge, YGEdge rowEdge,
YGEdge edge, YGEdge edge) {
CompactValue defaultValue) {
if (!edges[rowEdge].isUndefined()) { if (!edges[rowEdge].isUndefined()) {
return edges[rowEdge]; return edges[rowEdge];
} else if (!edges[edge].isUndefined()) { } else if (!edges[edge].isUndefined()) {
return edges[edge]; return edges[edge];
} else if (!edges[YGEdgeHorizontal].isUndefined()) { } else if (!edges[YGEdgeHorizontal].isUndefined()) {
return edges[YGEdgeHorizontal]; return edges[YGEdgeHorizontal];
} else if (!edges[YGEdgeAll].isUndefined()) {
return edges[YGEdgeAll];
} else { } else {
return defaultValue; return edges[YGEdgeAll];
} }
} }
CompactValue Node::computeEdgeValueForColumn( CompactValue Node::computeEdgeValueForColumn(
const Style::Edges& edges, const Style::Edges& edges,
YGEdge edge, YGEdge edge) {
CompactValue defaultValue) {
if (!edges[edge].isUndefined()) { if (!edges[edge].isUndefined()) {
return edges[edge]; return edges[edge];
} else if (!edges[YGEdgeVertical].isUndefined()) { } else if (!edges[YGEdgeVertical].isUndefined()) {
return edges[YGEdgeVertical]; return edges[YGEdgeVertical];
} else if (!edges[YGEdgeAll].isUndefined()) {
return edges[YGEdgeAll];
} else { } else {
return defaultValue; return edges[YGEdgeAll];
} }
} }
FloatOptional Node::getLeadingPosition( bool Node::isLeadingPositionDefined(FlexDirection axis) const {
const FlexDirection axis,
const float axisSize) const {
auto leadingPosition = isRow(axis) auto leadingPosition = isRow(axis)
? computeEdgeValueForRow( ? computeEdgeValueForRow(
style_.position(), style_.position(), YGEdgeStart, leadingEdge(axis))
YGEdgeStart, : computeEdgeValueForColumn(style_.position(), leadingEdge(axis));
leadingEdge(axis),
CompactValue::ofZero())
: computeEdgeValueForColumn(
style_.position(), leadingEdge(axis), CompactValue::ofZero());
return yoga::resolveValue(leadingPosition, axisSize);
}
FloatOptional Node::getTrailingPosition(
const FlexDirection axis,
const float axisSize) const {
auto trailingPosition = isRow(axis)
? computeEdgeValueForRow(
style_.position(),
YGEdgeEnd,
trailingEdge(axis),
CompactValue::ofZero())
: computeEdgeValueForColumn(
style_.position(), trailingEdge(axis), CompactValue::ofZero());
return yoga::resolveValue(trailingPosition, axisSize);
}
bool Node::isLeadingPositionDefined(const FlexDirection axis) const {
auto leadingPosition = isRow(axis)
? computeEdgeValueForRow(
style_.position(),
YGEdgeStart,
leadingEdge(axis),
CompactValue::ofUndefined())
: computeEdgeValueForColumn(
style_.position(), leadingEdge(axis), CompactValue::ofUndefined());
return !leadingPosition.isUndefined(); return !leadingPosition.isUndefined();
} }
bool Node::isTrailingPosDefined(const FlexDirection axis) const { bool Node::isTrailingPosDefined(FlexDirection axis) const {
auto trailingPosition = isRow(axis) auto trailingPosition = isRow(axis)
? computeEdgeValueForRow( ? computeEdgeValueForRow(style_.position(), YGEdgeEnd, trailingEdge(axis))
style_.position(), : computeEdgeValueForColumn(style_.position(), trailingEdge(axis));
YGEdgeEnd,
trailingEdge(axis),
CompactValue::ofUndefined())
: computeEdgeValueForColumn(
style_.position(), trailingEdge(axis), CompactValue::ofUndefined());
return !trailingPosition.isUndefined(); return !trailingPosition.isUndefined();
} }
FloatOptional Node::getLeadingMargin( float Node::getLeadingPosition(FlexDirection axis, float axisSize) const {
const FlexDirection axis, auto leadingPosition = isRow(axis)
const float widthSize) const { ? computeEdgeValueForRow(
style_.position(), YGEdgeStart, leadingEdge(axis))
: computeEdgeValueForColumn(style_.position(), leadingEdge(axis));
return resolveValue(leadingPosition, axisSize).unwrapOrDefault(0.0f);
}
float Node::getTrailingPosition(FlexDirection axis, float axisSize) const {
auto trailingPosition = isRow(axis)
? computeEdgeValueForRow(style_.position(), YGEdgeEnd, trailingEdge(axis))
: computeEdgeValueForColumn(style_.position(), trailingEdge(axis));
return resolveValue(trailingPosition, axisSize).unwrapOrDefault(0.0f);
}
float Node::getLeadingMargin(FlexDirection axis, float widthSize) const {
auto leadingMargin = isRow(axis) auto leadingMargin = isRow(axis)
? computeEdgeValueForRow( ? computeEdgeValueForRow(style_.margin(), YGEdgeStart, leadingEdge(axis))
style_.margin(), : computeEdgeValueForColumn(style_.margin(), leadingEdge(axis));
YGEdgeStart,
leadingEdge(axis), return resolveValue(leadingMargin, widthSize).unwrapOrDefault(0.0f);
CompactValue::ofZero())
: computeEdgeValueForColumn(
style_.margin(), leadingEdge(axis), CompactValue::ofZero());
return leadingMargin.isAuto() ? FloatOptional{0}
: yoga::resolveValue(leadingMargin, widthSize);
} }
FloatOptional Node::getTrailingMargin( float Node::getTrailingMargin(FlexDirection axis, float widthSize) const {
const FlexDirection axis,
const float widthSize) const {
auto trailingMargin = isRow(axis) auto trailingMargin = isRow(axis)
? computeEdgeValueForRow( ? computeEdgeValueForRow(style_.margin(), YGEdgeEnd, trailingEdge(axis))
style_.margin(), : computeEdgeValueForColumn(style_.margin(), trailingEdge(axis));
YGEdgeEnd,
trailingEdge(axis), return resolveValue(trailingMargin, widthSize).unwrapOrDefault(0.0f);
CompactValue::ofZero())
: computeEdgeValueForColumn(
style_.margin(), trailingEdge(axis), CompactValue::ofZero());
return trailingMargin.isAuto()
? FloatOptional{0}
: yoga::resolveValue(trailingMargin, widthSize);
} }
FloatOptional Node::getMarginForAxis( float Node::getLeadingBorder(FlexDirection axis) const {
const FlexDirection axis, YGValue leadingBorder = isRow(axis)
const float widthSize) const { ? computeEdgeValueForRow(style_.border(), YGEdgeStart, leadingEdge(axis))
: computeEdgeValueForColumn(style_.border(), leadingEdge(axis));
return maxOrDefined(leadingBorder.value, 0.0f);
}
float Node::getTrailingBorder(FlexDirection axis) const {
YGValue trailingBorder = isRow(axis)
? computeEdgeValueForRow(style_.border(), YGEdgeEnd, trailingEdge(axis))
: computeEdgeValueForColumn(style_.border(), trailingEdge(axis));
return maxOrDefined(trailingBorder.value, 0.0f);
}
float Node::getLeadingPadding(FlexDirection axis, float widthSize) const {
auto leadingPadding = isRow(axis)
? computeEdgeValueForRow(style_.padding(), YGEdgeStart, leadingEdge(axis))
: computeEdgeValueForColumn(style_.padding(), leadingEdge(axis));
return maxOrDefined(resolveValue(leadingPadding, widthSize).unwrap(), 0.0f);
}
float Node::getTrailingPadding(FlexDirection axis, float widthSize) const {
auto trailingPadding = isRow(axis)
? computeEdgeValueForRow(style_.padding(), YGEdgeEnd, trailingEdge(axis))
: computeEdgeValueForColumn(style_.padding(), trailingEdge(axis));
return maxOrDefined(resolveValue(trailingPadding, widthSize).unwrap(), 0.0f);
}
float Node::getLeadingPaddingAndBorder(FlexDirection axis, float widthSize)
const {
return getLeadingPadding(axis, widthSize) + getLeadingBorder(axis);
}
float Node::getTrailingPaddingAndBorder(FlexDirection axis, float widthSize)
const {
return getTrailingPadding(axis, widthSize) + getTrailingBorder(axis);
}
float Node::getMarginForAxis(FlexDirection axis, float widthSize) const {
return getLeadingMargin(axis, widthSize) + getTrailingMargin(axis, widthSize); return getLeadingMargin(axis, widthSize) + getTrailingMargin(axis, widthSize);
} }
float Node::getGapForAxis(const FlexDirection axis) const { float Node::getGapForAxis(FlexDirection axis) const {
auto gap = isRow(axis) ? style_.resolveColumnGap() : style_.resolveRowGap(); auto gap = isRow(axis) ? style_.resolveColumnGap() : style_.resolveRowGap();
// TODO: Validate percentage gap, and expose ability to set percentage to // TODO: Validate percentage gap, and expose ability to set percentage to
// public API // public API
auto resolvedGap = yoga::resolveValue(gap, 0.0f /*ownerSize*/); return maxOrDefined(resolveValue(gap, 0.0f /*ownerSize*/).unwrap(), 0.0f);
return maxOrDefined(resolvedGap.unwrap(), 0.0f);
} }
YGSize Node::measure( YGSize Node::measure(
@@ -328,18 +328,12 @@ void Node::setLayoutDimension(float dimensionValue, Dimension dimension) {
// If both left and right are defined, then use left. Otherwise return +left or // If both left and right are defined, then use left. Otherwise return +left or
// -right depending on which is defined. // -right depending on which is defined.
FloatOptional Node::relativePosition( float Node::relativePosition(FlexDirection axis, float axisSize) const {
const FlexDirection axis,
const float axisSize) const {
if (isLeadingPositionDefined(axis)) { if (isLeadingPositionDefined(axis)) {
return getLeadingPosition(axis, axisSize); return getLeadingPosition(axis, axisSize);
} }
FloatOptional trailingPosition = getTrailingPosition(axis, axisSize); return -1 * getTrailingPosition(axis, axisSize);
if (!trailingPosition.isUndefined()) {
trailingPosition = FloatOptional{-1 * trailingPosition.unwrap()};
}
return trailingPosition;
} }
void Node::setPosition( void Node::setPosition(
@@ -359,28 +353,24 @@ void Node::setPosition(
// Here we should check for `PositionType::Static` and in this case zero inset // Here we should check for `PositionType::Static` and in this case zero inset
// properties (left, right, top, bottom, begin, end). // properties (left, right, top, bottom, begin, end).
// https://www.w3.org/TR/css-position-3/#valdef-position-static // https://www.w3.org/TR/css-position-3/#valdef-position-static
const FloatOptional relativePositionMain = const float relativePositionMain = relativePosition(mainAxis, mainSize);
relativePosition(mainAxis, mainSize); const float relativePositionCross = relativePosition(crossAxis, crossSize);
const FloatOptional relativePositionCross =
relativePosition(crossAxis, crossSize);
setLayoutPosition( setLayoutPosition(
(getLeadingMargin(mainAxis, ownerWidth) + relativePositionMain).unwrap(), (getLeadingMargin(mainAxis, ownerWidth) + relativePositionMain),
leadingEdge(mainAxis)); leadingEdge(mainAxis));
setLayoutPosition( setLayoutPosition(
(getTrailingMargin(mainAxis, ownerWidth) + relativePositionMain).unwrap(), (getTrailingMargin(mainAxis, ownerWidth) + relativePositionMain),
trailingEdge(mainAxis)); trailingEdge(mainAxis));
setLayoutPosition( setLayoutPosition(
(getLeadingMargin(crossAxis, ownerWidth) + relativePositionCross) (getLeadingMargin(crossAxis, ownerWidth) + relativePositionCross),
.unwrap(),
leadingEdge(crossAxis)); leadingEdge(crossAxis));
setLayoutPosition( setLayoutPosition(
(getTrailingMargin(crossAxis, ownerWidth) + relativePositionCross) (getTrailingMargin(crossAxis, ownerWidth) + relativePositionCross),
.unwrap(),
trailingEdge(crossAxis)); trailingEdge(crossAxis));
} }
YGValue Node::marginLeadingValue(const FlexDirection axis) const { YGValue Node::marginLeadingValue(FlexDirection axis) const {
if (isRow(axis) && !style_.margin()[YGEdgeStart].isUndefined()) { if (isRow(axis) && !style_.margin()[YGEdgeStart].isUndefined()) {
return style_.margin()[YGEdgeStart]; return style_.margin()[YGEdgeStart];
} else { } else {
@@ -388,7 +378,7 @@ YGValue Node::marginLeadingValue(const FlexDirection axis) const {
} }
} }
YGValue Node::marginTrailingValue(const FlexDirection axis) const { YGValue Node::marginTrailingValue(FlexDirection axis) const {
if (isRow(axis) && !style_.margin()[YGEdgeEnd].isUndefined()) { if (isRow(axis) && !style_.margin()[YGEdgeEnd].isUndefined()) {
return style_.margin()[YGEdgeEnd]; return style_.margin()[YGEdgeEnd];
} else { } else {
@@ -498,74 +488,6 @@ bool Node::isNodeFlexible() {
(resolveFlexGrow() != 0 || resolveFlexShrink() != 0)); (resolveFlexGrow() != 0 || resolveFlexShrink() != 0));
} }
float Node::getLeadingBorder(const FlexDirection axis) const {
YGValue leadingBorder = isRow(axis)
? computeEdgeValueForRow(
style_.border(),
YGEdgeStart,
leadingEdge(axis),
CompactValue::ofZero())
: computeEdgeValueForColumn(
style_.border(), leadingEdge(axis), CompactValue::ofZero());
return fmaxf(leadingBorder.value, 0.0f);
}
float Node::getTrailingBorder(const FlexDirection axis) const {
YGValue trailingBorder = isRow(axis)
? computeEdgeValueForRow(
style_.border(),
YGEdgeEnd,
trailingEdge(axis),
CompactValue::ofZero())
: computeEdgeValueForColumn(
style_.border(), trailingEdge(axis), CompactValue::ofZero());
return fmaxf(trailingBorder.value, 0.0f);
}
FloatOptional Node::getLeadingPadding(
const FlexDirection axis,
const float widthSize) const {
auto leadingPadding = isRow(axis)
? computeEdgeValueForRow(
style_.padding(),
YGEdgeStart,
leadingEdge(axis),
CompactValue::ofZero())
: computeEdgeValueForColumn(
style_.padding(), leadingEdge(axis), CompactValue::ofZero());
return yoga::maxOrDefined(
yoga::resolveValue(leadingPadding, widthSize), FloatOptional(0.0f));
}
FloatOptional Node::getTrailingPadding(
const FlexDirection axis,
const float widthSize) const {
auto trailingPadding = isRow(axis)
? computeEdgeValueForRow(
style_.padding(),
YGEdgeEnd,
trailingEdge(axis),
CompactValue::ofZero())
: computeEdgeValueForColumn(
style_.padding(), trailingEdge(axis), CompactValue::ofZero());
return yoga::maxOrDefined(
yoga::resolveValue(trailingPadding, widthSize), FloatOptional(0.0f));
}
FloatOptional Node::getLeadingPaddingAndBorder(
const FlexDirection axis,
const float widthSize) const {
return getLeadingPadding(axis, widthSize) +
FloatOptional(getLeadingBorder(axis));
}
FloatOptional Node::getTrailingPaddingAndBorder(
const FlexDirection axis,
const float widthSize) const {
return getTrailingPadding(axis, widthSize) +
FloatOptional(getTrailingBorder(axis));
}
void Node::reset() { void Node::reset() {
yoga::assertFatalWithNode( yoga::assertFatalWithNode(
this, this,

View File

@@ -48,8 +48,7 @@ class YG_EXPORT Node : public ::YGNode {
std::array<YGValue, 2> resolvedDimensions_ = { std::array<YGValue, 2> resolvedDimensions_ = {
{YGValueUndefined, YGValueUndefined}}; {YGValueUndefined, YGValueUndefined}};
FloatOptional relativePosition(const FlexDirection axis, const float axisSize) float relativePosition(FlexDirection axis, const float axisSize) const;
const;
void useWebDefaults() { void useWebDefaults() {
style_.flexDirection() = FlexDirection::Row; style_.flexDirection() = FlexDirection::Row;
@@ -182,48 +181,28 @@ class YG_EXPORT Node : public ::YGNode {
static CompactValue computeEdgeValueForColumn( static CompactValue computeEdgeValueForColumn(
const Style::Edges& edges, const Style::Edges& edges,
YGEdge edge, YGEdge edge);
CompactValue defaultValue);
static CompactValue computeEdgeValueForRow( static CompactValue computeEdgeValueForRow(
const Style::Edges& edges, const Style::Edges& edges,
YGEdge rowEdge, YGEdge rowEdge,
YGEdge edge, YGEdge edge);
CompactValue defaultValue);
// Methods related to positions, margin, padding and border // Methods related to positions, margin, padding and border
FloatOptional getLeadingPosition( bool isLeadingPositionDefined(FlexDirection axis) const;
const FlexDirection axis, bool isTrailingPosDefined(FlexDirection axis) const;
const float axisSize) const; float getLeadingPosition(FlexDirection axis, float axisSize) const;
bool isLeadingPositionDefined(const FlexDirection axis) const; float getTrailingPosition(FlexDirection axis, float axisSize) const;
bool isTrailingPosDefined(const FlexDirection axis) const; float getLeadingMargin(FlexDirection axis, float widthSize) const;
FloatOptional getTrailingPosition( float getTrailingMargin(FlexDirection axis, float widthSize) const;
const FlexDirection axis, float getLeadingBorder(FlexDirection flexDirection) const;
const float axisSize) const; float getTrailingBorder(FlexDirection flexDirection) const;
FloatOptional getLeadingMargin( float getLeadingPadding(FlexDirection axis, float widthSize) const;
const FlexDirection axis, float getTrailingPadding(FlexDirection axis, float widthSize) const;
const float widthSize) const; float getLeadingPaddingAndBorder(FlexDirection axis, float widthSize) const;
FloatOptional getTrailingMargin( float getTrailingPaddingAndBorder(FlexDirection axis, float widthSize) const;
const FlexDirection axis, float getMarginForAxis(FlexDirection axis, float widthSize) const;
const float widthSize) const; float getGapForAxis(FlexDirection axis) const;
float getLeadingBorder(const FlexDirection flexDirection) const;
float getTrailingBorder(const FlexDirection flexDirection) const;
FloatOptional getLeadingPadding(
const FlexDirection axis,
const float widthSize) const;
FloatOptional getTrailingPadding(
const FlexDirection axis,
const float widthSize) const;
FloatOptional getLeadingPaddingAndBorder(
const FlexDirection axis,
const float widthSize) const;
FloatOptional getTrailingPaddingAndBorder(
const FlexDirection axis,
const float widthSize) const;
FloatOptional getMarginForAxis(
const FlexDirection axis,
const float widthSize) const;
float getGapForAxis(const FlexDirection axis) const;
// Setters // Setters
void setContext(void* context) { void setContext(void* context) {
@@ -301,8 +280,8 @@ class YG_EXPORT Node : public ::YGNode {
void markDirtyAndPropagateDownwards(); void markDirtyAndPropagateDownwards();
// Other methods // Other methods
YGValue marginLeadingValue(const FlexDirection axis) const; YGValue marginLeadingValue(FlexDirection axis) const;
YGValue marginTrailingValue(const FlexDirection axis) const; YGValue marginTrailingValue(FlexDirection axis) const;
YGValue resolveFlexBasisPtr() const; YGValue resolveFlexBasisPtr() const;
void resolveDimension(); void resolveDimension();
Direction resolveDirection(const Direction ownerDirection); Direction resolveDirection(const Direction ownerDirection);

View File

@@ -25,6 +25,10 @@ struct FloatOptional {
return value_; return value_;
} }
constexpr float unwrapOrDefault(float defaultValue) const {
return isUndefined() ? defaultValue : value_;
}
bool isUndefined() const { bool isUndefined() const {
return std::isnan(value_); return std::isnan(value_);
} }