diff --git a/tests/YGFloatOptionalTest.cpp b/tests/YGFloatOptionalTest.cpp index 3c73b0ba..38c7ebb3 100644 --- a/tests/YGFloatOptionalTest.cpp +++ b/tests/YGFloatOptionalTest.cpp @@ -200,8 +200,8 @@ TEST(YGFloatOptionalTest, YGFloatOptionalMax) { YGFloatOptional{1.125f}); } -TEST(YGFloatOptionalTest, YGUnwrapFloatOptional) { - ASSERT_TRUE(YGFloatIsUndefined(YGUnwrapFloatOptional(empty))); - ASSERT_EQ(YGUnwrapFloatOptional(zero), 0.0f); - ASSERT_EQ(YGUnwrapFloatOptional(YGFloatOptional{123456.78f}), 123456.78f); +TEST(YGFloatOptionalTest, unwrap) { + ASSERT_TRUE(YGFloatIsUndefined(empty.unwrap())); + ASSERT_EQ(zero.unwrap(), 0.0f); + ASSERT_EQ(YGFloatOptional{123456.78f}.unwrap(), 123456.78f); } diff --git a/yoga/Utils.cpp b/yoga/Utils.cpp index 74cc38c9..331cb660 100644 --- a/yoga/Utils.cpp +++ b/yoga/Utils.cpp @@ -55,10 +55,6 @@ float YGFloatSanitize(const float val) { return yoga::isUndefined(val) ? 0 : val; } -float YGUnwrapFloatOptional(const YGFloatOptional& op) { - return op.isUndefined() ? YGUndefined : op.getValue(); -} - YGFloatOptional YGFloatOptionalMax( const YGFloatOptional& op1, const YGFloatOptional& op2) { diff --git a/yoga/Utils.h b/yoga/Utils.h index d007ff54..e5e20ba3 100644 --- a/yoga/Utils.h +++ b/yoga/Utils.h @@ -82,11 +82,6 @@ bool YGFloatArrayEqual( // This function returns 0 if YGFloatIsUndefined(val) is true and val otherwise float YGFloatSanitize(const float val); -// This function unwraps optional and returns YGUndefined if not defined or -// op.value otherwise -// TODO: Get rid off this function -float YGUnwrapFloatOptional(const YGFloatOptional& op); - YGFlexDirection YGFlexDirectionCross( const YGFlexDirection flexDirection, const YGDirection direction); diff --git a/yoga/YGFloatOptional.h b/yoga/YGFloatOptional.h index 7b573d38..56bc8557 100644 --- a/yoga/YGFloatOptional.h +++ b/yoga/YGFloatOptional.h @@ -22,6 +22,11 @@ struct YGFloatOptional { // To check if float optional is defined, use `isUndefined()`. float getValue() const; + // returns the wrapped value, or a value x with YGIsUndefined(x) == true + float unwrap() const { + return value_; + } + bool isUndefined() const { return std::isnan(value_); } diff --git a/yoga/YGNode.cpp b/yoga/YGNode.cpp index 04c3c7f6..d930c51a 100644 --- a/yoga/YGNode.cpp +++ b/yoga/YGNode.cpp @@ -236,20 +236,18 @@ void YGNode::setPosition( relativePosition(crossAxis, crossSize); setLayoutPosition( - YGUnwrapFloatOptional( - getLeadingMargin(mainAxis, ownerWidth) + relativePositionMain), + (getLeadingMargin(mainAxis, ownerWidth) + relativePositionMain).unwrap(), leading[mainAxis]); setLayoutPosition( - YGUnwrapFloatOptional( - getTrailingMargin(mainAxis, ownerWidth) + relativePositionMain), + (getTrailingMargin(mainAxis, ownerWidth) + relativePositionMain).unwrap(), trailing[mainAxis]); setLayoutPosition( - YGUnwrapFloatOptional( - getLeadingMargin(crossAxis, ownerWidth) + relativePositionCross), + (getLeadingMargin(crossAxis, ownerWidth) + relativePositionCross) + .unwrap(), leading[crossAxis]); setLayoutPosition( - YGUnwrapFloatOptional( - getTrailingMargin(crossAxis, ownerWidth) + relativePositionCross), + (getTrailingMargin(crossAxis, ownerWidth) + relativePositionCross) + .unwrap(), trailing[crossAxis]); } diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 246e0f41..8db18e9e 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -1096,9 +1096,9 @@ static inline float YGNodePaddingAndBorderForAxis( const YGNodeRef node, const YGFlexDirection axis, const float widthSize) { - return YGUnwrapFloatOptional( - node->getLeadingPaddingAndBorder(axis, widthSize) + - node->getTrailingPaddingAndBorder(axis, widthSize)); + return (node->getLeadingPaddingAndBorder(axis, widthSize) + + node->getTrailingPaddingAndBorder(axis, widthSize)) + .unwrap(); } static inline YGAlign YGNodeAlignItem( @@ -1180,9 +1180,9 @@ static inline float YGNodeDimWithMargin( const YGFlexDirection axis, const float widthSize) { return node->getLayout().measuredDimensions[dim[axis]] + - YGUnwrapFloatOptional( - node->getLeadingMargin(axis, widthSize) + - node->getTrailingMargin(axis, widthSize)); + (node->getLeadingMargin(axis, widthSize) + + node->getTrailingMargin(axis, widthSize)) + .unwrap(); } static inline bool YGNodeIsStyleDimDefined( @@ -1249,8 +1249,7 @@ static inline float YGNodeBoundAxis( const float axisSize, const float widthSize) { return YGFloatMax( - YGUnwrapFloatOptional( - YGNodeBoundAxisWithinMinAndMax(node, axis, value, axisSize)), + YGNodeBoundAxisWithinMinAndMax(node, axis, value, axisSize).unwrap(), YGNodePaddingAndBorderForAxis(node, axis, widthSize)); } @@ -1357,22 +1356,24 @@ static void YGNodeComputeFlexBasisForChild( childWidthMeasureMode = YGMeasureModeUndefined; childHeightMeasureMode = YGMeasureModeUndefined; - auto marginRow = YGUnwrapFloatOptional( - child->getMarginForAxis(YGFlexDirectionRow, ownerWidth)); - auto marginColumn = YGUnwrapFloatOptional( - child->getMarginForAxis(YGFlexDirectionColumn, ownerWidth)); + auto marginRow = + child->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap(); + auto marginColumn = + child->getMarginForAxis(YGFlexDirectionColumn, ownerWidth).unwrap(); if (isRowStyleDimDefined) { childWidth = - YGUnwrapFloatOptional(YGResolveValue( - child->getResolvedDimension(YGDimensionWidth), ownerWidth)) + + YGResolveValue( + child->getResolvedDimension(YGDimensionWidth), ownerWidth) + .unwrap() + marginRow; childWidthMeasureMode = YGMeasureModeExactly; } if (isColumnStyleDimDefined) { childHeight = - YGUnwrapFloatOptional(YGResolveValue( - child->getResolvedDimension(YGDimensionHeight), ownerHeight)) + + YGResolveValue( + child->getResolvedDimension(YGDimensionHeight), ownerHeight) + .unwrap() + marginColumn; childHeightMeasureMode = YGMeasureModeExactly; } @@ -1500,14 +1501,14 @@ static void YGNodeAbsoluteLayoutChild( YGMeasureMode childWidthMeasureMode = YGMeasureModeUndefined; YGMeasureMode childHeightMeasureMode = YGMeasureModeUndefined; - auto marginRow = - YGUnwrapFloatOptional(child->getMarginForAxis(YGFlexDirectionRow, width)); - auto marginColumn = YGUnwrapFloatOptional( - child->getMarginForAxis(YGFlexDirectionColumn, width)); + auto marginRow = child->getMarginForAxis(YGFlexDirectionRow, width).unwrap(); + auto marginColumn = + child->getMarginForAxis(YGFlexDirectionColumn, width).unwrap(); if (YGNodeIsStyleDimDefined(child, YGFlexDirectionRow, width)) { - childWidth = YGUnwrapFloatOptional(YGResolveValue( - child->getResolvedDimension(YGDimensionWidth), width)) + + childWidth = + YGResolveValue(child->getResolvedDimension(YGDimensionWidth), width) + .unwrap() + marginRow; } else { // If the child doesn't have a specified width, compute the width based @@ -1518,17 +1519,18 @@ static void YGNodeAbsoluteLayoutChild( childWidth = node->getLayout().measuredDimensions[YGDimensionWidth] - (node->getLeadingBorder(YGFlexDirectionRow) + node->getTrailingBorder(YGFlexDirectionRow)) - - YGUnwrapFloatOptional( - child->getLeadingPosition(YGFlexDirectionRow, width) + - child->getTrailingPosition(YGFlexDirectionRow, width)); + (child->getLeadingPosition(YGFlexDirectionRow, width) + + child->getTrailingPosition(YGFlexDirectionRow, width)) + .unwrap(); childWidth = YGNodeBoundAxis(child, YGFlexDirectionRow, childWidth, width, width); } } if (YGNodeIsStyleDimDefined(child, YGFlexDirectionColumn, height)) { - childHeight = YGUnwrapFloatOptional(YGResolveValue( - child->getResolvedDimension(YGDimensionHeight), height)) + + childHeight = + YGResolveValue(child->getResolvedDimension(YGDimensionHeight), height) + .unwrap() + marginColumn; } else { // If the child doesn't have a specified height, compute the height @@ -1536,13 +1538,12 @@ static void YGNodeAbsoluteLayoutChild( // offsets if they're defined. if (child->isLeadingPositionDefined(YGFlexDirectionColumn) && child->isTrailingPosDefined(YGFlexDirectionColumn)) { - childHeight = - node->getLayout().measuredDimensions[YGDimensionHeight] - + childHeight = node->getLayout().measuredDimensions[YGDimensionHeight] - (node->getLeadingBorder(YGFlexDirectionColumn) + node->getTrailingBorder(YGFlexDirectionColumn)) - - YGUnwrapFloatOptional( - child->getLeadingPosition(YGFlexDirectionColumn, height) + - child->getTrailingPosition(YGFlexDirectionColumn, height)); + (child->getLeadingPosition(YGFlexDirectionColumn, height) + + child->getTrailingPosition(YGFlexDirectionColumn, height)) + .unwrap(); childHeight = YGNodeBoundAxis( child, YGFlexDirectionColumn, childHeight, height, width); } @@ -1597,11 +1598,9 @@ static void YGNodeAbsoluteLayoutChild( "abs-measure", config); childWidth = child->getLayout().measuredDimensions[YGDimensionWidth] + - YGUnwrapFloatOptional( - child->getMarginForAxis(YGFlexDirectionRow, width)); + child->getMarginForAxis(YGFlexDirectionRow, width).unwrap(); childHeight = child->getLayout().measuredDimensions[YGDimensionHeight] + - YGUnwrapFloatOptional( - child->getMarginForAxis(YGFlexDirectionColumn, width)); + child->getMarginForAxis(YGFlexDirectionColumn, width).unwrap(); } YGLayoutNodeInternal( @@ -1623,9 +1622,9 @@ static void YGNodeAbsoluteLayoutChild( node->getLayout().measuredDimensions[dim[mainAxis]] - child->getLayout().measuredDimensions[dim[mainAxis]] - node->getTrailingBorder(mainAxis) - - YGUnwrapFloatOptional(child->getTrailingMargin(mainAxis, width)) - - YGUnwrapFloatOptional(child->getTrailingPosition( - mainAxis, isMainAxisRow ? width : height)), + child->getTrailingMargin(mainAxis, width).unwrap() - + child->getTrailingPosition(mainAxis, isMainAxisRow ? width : height) + .unwrap(), leading[mainAxis]); } else if ( !child->isLeadingPositionDefined(mainAxis) && @@ -1650,9 +1649,10 @@ static void YGNodeAbsoluteLayoutChild( node->getLayout().measuredDimensions[dim[crossAxis]] - child->getLayout().measuredDimensions[dim[crossAxis]] - node->getTrailingBorder(crossAxis) - - YGUnwrapFloatOptional(child->getTrailingMargin(crossAxis, width)) - - YGUnwrapFloatOptional(child->getTrailingPosition( - crossAxis, isMainAxisRow ? height : width)), + child->getTrailingMargin(crossAxis, width).unwrap() - + child + ->getTrailingPosition(crossAxis, isMainAxisRow ? height : width) + .unwrap(), leading[crossAxis]); } else if ( @@ -1691,10 +1691,10 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions( YGNodePaddingAndBorderForAxis(node, YGFlexDirectionRow, availableWidth); const float paddingAndBorderAxisColumn = YGNodePaddingAndBorderForAxis( node, YGFlexDirectionColumn, availableWidth); - const float marginAxisRow = YGUnwrapFloatOptional( - node->getMarginForAxis(YGFlexDirectionRow, availableWidth)); - const float marginAxisColumn = YGUnwrapFloatOptional( - node->getMarginForAxis(YGFlexDirectionColumn, availableWidth)); + const float marginAxisRow = + node->getMarginForAxis(YGFlexDirectionRow, availableWidth).unwrap(); + const float marginAxisColumn = + node->getMarginForAxis(YGFlexDirectionColumn, availableWidth).unwrap(); // We want to make sure we don't call measure with negative size const float innerWidth = YGFloatIsUndefined(availableWidth) @@ -1769,10 +1769,10 @@ static void YGNodeEmptyContainerSetMeasuredDimensions( YGNodePaddingAndBorderForAxis(node, YGFlexDirectionRow, ownerWidth); const float paddingAndBorderAxisColumn = YGNodePaddingAndBorderForAxis(node, YGFlexDirectionColumn, ownerWidth); - const float marginAxisRow = YGUnwrapFloatOptional( - node->getMarginForAxis(YGFlexDirectionRow, ownerWidth)); - const float marginAxisColumn = YGUnwrapFloatOptional( - node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth)); + const float marginAxisRow = + node->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap(); + const float marginAxisColumn = + node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth).unwrap(); node->setLayoutMeasuredDimension( YGNodeBoundAxis( @@ -1813,10 +1813,10 @@ static bool YGNodeFixedSizeSetMeasuredDimensions( heightMeasureMode == YGMeasureModeAtMost && availableHeight <= 0.0f) || (widthMeasureMode == YGMeasureModeExactly && heightMeasureMode == YGMeasureModeExactly)) { - auto marginAxisColumn = YGUnwrapFloatOptional( - node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth)); - auto marginAxisRow = YGUnwrapFloatOptional( - node->getMarginForAxis(YGFlexDirectionRow, ownerWidth)); + auto marginAxisColumn = + node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth).unwrap(); + auto marginAxisRow = + node->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap(); node->setLayoutMeasuredDimension( YGNodeBoundAxis( @@ -1872,8 +1872,7 @@ static float YGNodeCalculateAvailableInnerDim( YGDimension dimension = YGFlexDirectionIsRow(axis) ? YGDimensionWidth : YGDimensionHeight; - const float margin = - YGUnwrapFloatOptional(node->getMarginForAxis(direction, ownerDim)); + const float margin = node->getMarginForAxis(direction, ownerDim).unwrap(); const float paddingAndBorder = YGNodePaddingAndBorderForAxis(node, direction, ownerDim); @@ -1978,9 +1977,10 @@ static float YGNodeComputeFlexBasisForChildren( config); } - totalOuterFlexBasis += YGUnwrapFloatOptional( - child->getLayout().computedFlexBasis + - child->getMarginForAxis(mainAxis, availableInnerWidth)); + totalOuterFlexBasis += + (child->getLayout().computedFlexBasis + + child->getMarginForAxis(mainAxis, availableInnerWidth)) + .unwrap(); } return totalOuterFlexBasis; @@ -2015,14 +2015,15 @@ static YGCollectFlexItemsRowValues YGCalculateCollectFlexItemsRowValues( continue; } child->setLineIndex(lineCount); - const float childMarginMainAxis = YGUnwrapFloatOptional( - child->getMarginForAxis(mainAxis, availableInnerWidth)); + const float childMarginMainAxis = + child->getMarginForAxis(mainAxis, availableInnerWidth).unwrap(); const float flexBasisWithMinAndMaxConstraints = - YGUnwrapFloatOptional(YGNodeBoundAxisWithinMinAndMax( + YGNodeBoundAxisWithinMinAndMax( child, mainAxis, - YGUnwrapFloatOptional(child->getLayout().computedFlexBasis), - mainAxisownerSize)); + child->getLayout().computedFlexBasis.unwrap(), + mainAxisownerSize) + .unwrap(); // If this is a multi-line flow and this item pushes us over the // available size, we've @@ -2048,7 +2049,7 @@ static YGCollectFlexItemsRowValues YGCalculateCollectFlexItemsRowValues( // child dimension. flexAlgoRowMeasurement.totalFlexShrinkScaledFactors += -child->resolveFlexShrink() * - YGUnwrapFloatOptional(child->getLayout().computedFlexBasis); + child->getLayout().computedFlexBasis.unwrap(); } flexAlgoRowMeasurement.relativeChildren.push_back(child); @@ -2095,12 +2096,13 @@ static float YGDistributeFreeSpaceSecondPass( const bool isNodeFlexWrap = node->getStyle().flexWrap != YGWrapNoWrap; for (auto currentRelativeChild : collectedFlexItemsValues.relativeChildren) { - childFlexBasis = YGUnwrapFloatOptional(YGNodeBoundAxisWithinMinAndMax( - currentRelativeChild, - mainAxis, - YGUnwrapFloatOptional( - currentRelativeChild->getLayout().computedFlexBasis), - mainAxisownerSize)); + childFlexBasis = + YGNodeBoundAxisWithinMinAndMax( + currentRelativeChild, + mainAxis, + currentRelativeChild->getLayout().computedFlexBasis.unwrap(), + mainAxisownerSize) + .unwrap(); float updatedMainSize = childFlexBasis; if (!YGFloatIsUndefined(collectedFlexItemsValues.remainingFreeSpace) && @@ -2150,10 +2152,12 @@ static float YGDistributeFreeSpaceSecondPass( deltaFreeSpace += updatedMainSize - childFlexBasis; - const float marginMain = YGUnwrapFloatOptional( - currentRelativeChild->getMarginForAxis(mainAxis, availableInnerWidth)); - const float marginCross = YGUnwrapFloatOptional( - currentRelativeChild->getMarginForAxis(crossAxis, availableInnerWidth)); + const float marginMain = + currentRelativeChild->getMarginForAxis(mainAxis, availableInnerWidth) + .unwrap(); + const float marginCross = + currentRelativeChild->getMarginForAxis(crossAxis, availableInnerWidth) + .unwrap(); float childCrossSize; float childMainSize = updatedMainSize + marginMain; @@ -2189,9 +2193,10 @@ static float YGDistributeFreeSpaceSecondPass( : YGMeasureModeAtMost; } else { childCrossSize = - YGUnwrapFloatOptional(YGResolveValue( + YGResolveValue( currentRelativeChild->getResolvedDimension(dim[crossAxis]), - availableInnerCrossDim)) + + availableInnerCrossDim) + .unwrap() + marginCross; const bool isLoosePercentageMeasurement = currentRelativeChild->getResolvedDimension(dim[crossAxis]).unit == @@ -2271,12 +2276,13 @@ static void YGDistributeFreeSpaceFirstPass( float deltaFreeSpace = 0; for (auto currentRelativeChild : collectedFlexItemsValues.relativeChildren) { - float childFlexBasis = YGUnwrapFloatOptional(YGNodeBoundAxisWithinMinAndMax( - currentRelativeChild, - mainAxis, - YGUnwrapFloatOptional( - currentRelativeChild->getLayout().computedFlexBasis), - mainAxisownerSize)); + float childFlexBasis = + YGNodeBoundAxisWithinMinAndMax( + currentRelativeChild, + mainAxis, + currentRelativeChild->getLayout().computedFlexBasis.unwrap(), + mainAxisownerSize) + .unwrap(); if (collectedFlexItemsValues.remainingFreeSpace < 0) { flexShrinkScaledFactor = @@ -2427,10 +2433,10 @@ static void YGJustifyMainAxis( const float availableInnerWidth, const bool performLayout) { const YGStyle& style = node->getStyle(); - const float leadingPaddingAndBorderMain = YGUnwrapFloatOptional( - node->getLeadingPaddingAndBorder(mainAxis, ownerWidth)); - const float trailingPaddingAndBorderMain = YGUnwrapFloatOptional( - node->getTrailingPaddingAndBorder(mainAxis, ownerWidth)); + const float leadingPaddingAndBorderMain = + node->getLeadingPaddingAndBorder(mainAxis, ownerWidth).unwrap(); + const float trailingPaddingAndBorderMain = + node->getTrailingPaddingAndBorder(mainAxis, ownerWidth).unwrap(); // If we are using "at most" rules in the main axis, make sure that // remainingFreeSpace is 0 when min main dimension is not given if (measureModeMainDim == YGMeasureModeAtMost && @@ -2446,8 +2452,8 @@ static void YGJustifyMainAxis( // `minAvailableMainDim` denotes minimum available space in which child // can be laid out, it will exclude space consumed by padding and border. const float minAvailableMainDim = - YGUnwrapFloatOptional(YGResolveValue( - style.minDimensions[dim[mainAxis]], mainAxisownerSize)) - + YGResolveValue(style.minDimensions[dim[mainAxis]], mainAxisownerSize) + .unwrap() - leadingPaddingAndBorderMain - trailingPaddingAndBorderMain; const float occupiedSpaceByChildNodes = availableInnerMainDim - collectedFlexItemsValues.remainingFreeSpace; @@ -2537,11 +2543,10 @@ static void YGJustifyMainAxis( // defined, we override the position to whatever the user said // (and margin/border). child->setLayoutPosition( - YGUnwrapFloatOptional( - child->getLeadingPosition(mainAxis, availableInnerMainDim)) + + child->getLeadingPosition(mainAxis, availableInnerMainDim) + .unwrap() + node->getLeadingBorder(mainAxis) + - YGUnwrapFloatOptional( - child->getLeadingMargin(mainAxis, availableInnerWidth)), + child->getLeadingMargin(mainAxis, availableInnerWidth).unwrap(), pos[mainAxis]); } } else { @@ -2575,9 +2580,8 @@ static void YGJustifyMainAxis( // they weren't computed. This means we can't call // YGNodeDimWithMargin. collectedFlexItemsValues.mainDim += betweenMainDim + - YGUnwrapFloatOptional(child->getMarginForAxis( - mainAxis, availableInnerWidth)) + - YGUnwrapFloatOptional(childLayout.computedFlexBasis); + child->getMarginForAxis(mainAxis, availableInnerWidth).unwrap() + + childLayout.computedFlexBasis.unwrap(); collectedFlexItemsValues.crossDim = availableInnerCrossDim; } else { // The main dimension is the sum of all the elements dimension plus @@ -2589,12 +2593,16 @@ static void YGJustifyMainAxis( // If the child is baseline aligned then the cross dimension is // calculated by adding maxAscent and maxDescent from the baseline. const float ascent = YGBaseline(child) + - YGUnwrapFloatOptional(child->getLeadingMargin( - YGFlexDirectionColumn, availableInnerWidth)); + child + ->getLeadingMargin( + YGFlexDirectionColumn, availableInnerWidth) + .unwrap(); const float descent = child->getLayout().measuredDimensions[YGDimensionHeight] + - YGUnwrapFloatOptional(child->getMarginForAxis( - YGFlexDirectionColumn, availableInnerWidth)) - + child + ->getMarginForAxis( + YGFlexDirectionColumn, availableInnerWidth) + .unwrap() - ascent; maxAscentForCurrentLine = @@ -2747,20 +2755,16 @@ static void YGNodelayoutImpl( YGResolveFlexDirection(YGFlexDirectionColumn, direction); node->setLayoutMargin( - YGUnwrapFloatOptional( - node->getLeadingMargin(flexRowDirection, ownerWidth)), + node->getLeadingMargin(flexRowDirection, ownerWidth).unwrap(), YGEdgeStart); node->setLayoutMargin( - YGUnwrapFloatOptional( - node->getTrailingMargin(flexRowDirection, ownerWidth)), + node->getTrailingMargin(flexRowDirection, ownerWidth).unwrap(), YGEdgeEnd); node->setLayoutMargin( - YGUnwrapFloatOptional( - node->getLeadingMargin(flexColumnDirection, ownerWidth)), + node->getLeadingMargin(flexColumnDirection, ownerWidth).unwrap(), YGEdgeTop); node->setLayoutMargin( - YGUnwrapFloatOptional( - node->getTrailingMargin(flexColumnDirection, ownerWidth)), + node->getTrailingMargin(flexColumnDirection, ownerWidth).unwrap(), YGEdgeBottom); node->setLayoutBorder(node->getLeadingBorder(flexRowDirection), YGEdgeStart); @@ -2770,20 +2774,16 @@ static void YGNodelayoutImpl( node->getTrailingBorder(flexColumnDirection), YGEdgeBottom); node->setLayoutPadding( - YGUnwrapFloatOptional( - node->getLeadingPadding(flexRowDirection, ownerWidth)), + node->getLeadingPadding(flexRowDirection, ownerWidth).unwrap(), YGEdgeStart); node->setLayoutPadding( - YGUnwrapFloatOptional( - node->getTrailingPadding(flexRowDirection, ownerWidth)), + node->getTrailingPadding(flexRowDirection, ownerWidth).unwrap(), YGEdgeEnd); node->setLayoutPadding( - YGUnwrapFloatOptional( - node->getLeadingPadding(flexColumnDirection, ownerWidth)), + node->getLeadingPadding(flexColumnDirection, ownerWidth).unwrap(), YGEdgeTop); node->setLayoutPadding( - YGUnwrapFloatOptional( - node->getTrailingPadding(flexColumnDirection, ownerWidth)), + node->getTrailingPadding(flexColumnDirection, ownerWidth).unwrap(), YGEdgeBottom); if (node->getMeasure() != nullptr) { @@ -2841,8 +2841,8 @@ static void YGNodelayoutImpl( const float mainAxisownerSize = isMainAxisRow ? ownerWidth : ownerHeight; const float crossAxisownerSize = isMainAxisRow ? ownerHeight : ownerWidth; - const float leadingPaddingAndBorderCross = YGUnwrapFloatOptional( - node->getLeadingPaddingAndBorder(crossAxis, ownerWidth)); + const float leadingPaddingAndBorderCross = + node->getLeadingPaddingAndBorder(crossAxis, ownerWidth).unwrap(); const float paddingAndBorderAxisMain = YGNodePaddingAndBorderForAxis(node, mainAxis, ownerWidth); const float paddingAndBorderAxisCross = @@ -2858,26 +2858,30 @@ static void YGNodelayoutImpl( const float paddingAndBorderAxisColumn = isMainAxisRow ? paddingAndBorderAxisCross : paddingAndBorderAxisMain; - const float marginAxisRow = YGUnwrapFloatOptional( - node->getMarginForAxis(YGFlexDirectionRow, ownerWidth)); - const float marginAxisColumn = YGUnwrapFloatOptional( - node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth)); + const float marginAxisRow = + node->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap(); + const float marginAxisColumn = + node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth).unwrap(); const float minInnerWidth = - YGUnwrapFloatOptional(YGResolveValue( - node->getStyle().minDimensions[YGDimensionWidth], ownerWidth)) - + YGResolveValue( + node->getStyle().minDimensions[YGDimensionWidth], ownerWidth) + .unwrap() - paddingAndBorderAxisRow; const float maxInnerWidth = - YGUnwrapFloatOptional(YGResolveValue( - node->getStyle().maxDimensions[YGDimensionWidth], ownerWidth)) - + YGResolveValue( + node->getStyle().maxDimensions[YGDimensionWidth], ownerWidth) + .unwrap() - paddingAndBorderAxisRow; const float minInnerHeight = - YGUnwrapFloatOptional(YGResolveValue( - node->getStyle().minDimensions[YGDimensionHeight], ownerHeight)) - + YGResolveValue( + node->getStyle().minDimensions[YGDimensionHeight], ownerHeight) + .unwrap() - paddingAndBorderAxisColumn; const float maxInnerHeight = - YGUnwrapFloatOptional(YGResolveValue( - node->getStyle().maxDimensions[YGDimensionHeight], ownerHeight)) - + YGResolveValue( + node->getStyle().maxDimensions[YGDimensionHeight], ownerHeight) + .unwrap() - paddingAndBorderAxisColumn; const float minInnerMainDim = isMainAxisRow ? minInnerWidth : minInnerHeight; @@ -3088,11 +3092,11 @@ static void YGNodelayoutImpl( child->isLeadingPositionDefined(crossAxis); if (isChildLeadingPosDefined) { child->setLayoutPosition( - YGUnwrapFloatOptional(child->getLeadingPosition( - crossAxis, availableInnerCrossDim)) + + child->getLeadingPosition(crossAxis, availableInnerCrossDim) + .unwrap() + node->getLeadingBorder(crossAxis) + - YGUnwrapFloatOptional(child->getLeadingMargin( - crossAxis, availableInnerWidth)), + child->getLeadingMargin(crossAxis, availableInnerWidth) + .unwrap(), pos[crossAxis]); } // If leading position is not defined or calculations result in Nan, @@ -3101,8 +3105,8 @@ static void YGNodelayoutImpl( YGFloatIsUndefined(child->getLayout().position[pos[crossAxis]])) { child->setLayoutPosition( node->getLeadingBorder(crossAxis) + - YGUnwrapFloatOptional(child->getLeadingMargin( - crossAxis, availableInnerWidth)), + child->getLeadingMargin(crossAxis, availableInnerWidth) + .unwrap(), pos[crossAxis]); } } else { @@ -3128,16 +3132,17 @@ static void YGNodelayoutImpl( child->getLayout().measuredDimensions[dim[mainAxis]]; float childCrossSize = !child->getStyle().aspectRatio.isUndefined() - ? ((YGUnwrapFloatOptional(child->getMarginForAxis( - crossAxis, availableInnerWidth)) + + ? child->getMarginForAxis(crossAxis, availableInnerWidth) + .unwrap() + (isMainAxisRow ? childMainSize / child->getStyle().aspectRatio.getValue() : childMainSize * - child->getStyle().aspectRatio.getValue()))) + child->getStyle().aspectRatio.getValue()) : collectedFlexItemsValues.crossDim; - childMainSize += YGUnwrapFloatOptional( - child->getMarginForAxis(mainAxis, availableInnerWidth)); + childMainSize += + child->getMarginForAxis(mainAxis, availableInnerWidth) + .unwrap(); YGMeasureMode childMainMeasureMode = YGMeasureModeExactly; YGMeasureMode childCrossMeasureMode = YGMeasureModeExactly; @@ -3279,17 +3284,21 @@ static void YGNodelayoutImpl( lineHeight = YGFloatMax( lineHeight, child->getLayout().measuredDimensions[dim[crossAxis]] + - YGUnwrapFloatOptional(child->getMarginForAxis( - crossAxis, availableInnerWidth))); + child->getMarginForAxis(crossAxis, availableInnerWidth) + .unwrap()); } if (YGNodeAlignItem(node, child) == YGAlignBaseline) { const float ascent = YGBaseline(child) + - YGUnwrapFloatOptional(child->getLeadingMargin( - YGFlexDirectionColumn, availableInnerWidth)); + child + ->getLeadingMargin( + YGFlexDirectionColumn, availableInnerWidth) + .unwrap(); const float descent = child->getLayout().measuredDimensions[YGDimensionHeight] + - YGUnwrapFloatOptional(child->getMarginForAxis( - YGFlexDirectionColumn, availableInnerWidth)) - + child + ->getMarginForAxis( + YGFlexDirectionColumn, availableInnerWidth) + .unwrap() - ascent; maxAscentForCurrentLine = YGFloatMax(maxAscentForCurrentLine, ascent); @@ -3314,16 +3323,16 @@ static void YGNodelayoutImpl( case YGAlignFlexStart: { child->setLayoutPosition( currentLead + - YGUnwrapFloatOptional(child->getLeadingMargin( - crossAxis, availableInnerWidth)), + child->getLeadingMargin(crossAxis, availableInnerWidth) + .unwrap(), pos[crossAxis]); break; } case YGAlignFlexEnd: { child->setLayoutPosition( currentLead + lineHeight - - YGUnwrapFloatOptional(child->getTrailingMargin( - crossAxis, availableInnerWidth)) - + child->getTrailingMargin(crossAxis, availableInnerWidth) + .unwrap() - child->getLayout().measuredDimensions[dim[crossAxis]], pos[crossAxis]); break; @@ -3340,8 +3349,8 @@ static void YGNodelayoutImpl( case YGAlignStretch: { child->setLayoutPosition( currentLead + - YGUnwrapFloatOptional(child->getLeadingMargin( - crossAxis, availableInnerWidth)), + child->getLeadingMargin(crossAxis, availableInnerWidth) + .unwrap(), pos[crossAxis]); // Remeasure child with the line height as it as been only @@ -3351,15 +3360,15 @@ static void YGNodelayoutImpl( const float childWidth = isMainAxisRow ? (child->getLayout() .measuredDimensions[YGDimensionWidth] + - YGUnwrapFloatOptional(child->getMarginForAxis( - mainAxis, availableInnerWidth))) + child->getMarginForAxis(mainAxis, availableInnerWidth) + .unwrap()) : lineHeight; const float childHeight = !isMainAxisRow ? (child->getLayout() .measuredDimensions[YGDimensionHeight] + - YGUnwrapFloatOptional(child->getMarginForAxis( - crossAxis, availableInnerWidth))) + child->getMarginForAxis(crossAxis, availableInnerWidth) + .unwrap()) : lineHeight; if (!(YGFloatsEqual( @@ -3389,8 +3398,10 @@ static void YGNodelayoutImpl( case YGAlignBaseline: { child->setLayoutPosition( currentLead + maxAscentForCurrentLine - YGBaseline(child) + - YGUnwrapFloatOptional(child->getLeadingPosition( - YGFlexDirectionColumn, availableInnerCrossDim)), + child + ->getLeadingPosition( + YGFlexDirectionColumn, availableInnerCrossDim) + .unwrap(), YGEdgeTop); break; @@ -3446,8 +3457,9 @@ static void YGNodelayoutImpl( YGFloatMax( YGFloatMin( availableInnerMainDim + paddingAndBorderAxisMain, - YGUnwrapFloatOptional(YGNodeBoundAxisWithinMinAndMax( - node, mainAxis, maxLineMainDim, mainAxisownerSize))), + YGNodeBoundAxisWithinMinAndMax( + node, mainAxis, maxLineMainDim, mainAxisownerSize) + .unwrap()), paddingAndBorderAxisMain), dim[mainAxis]); } @@ -3473,11 +3485,12 @@ static void YGNodelayoutImpl( YGFloatMax( YGFloatMin( availableInnerCrossDim + paddingAndBorderAxisCross, - YGUnwrapFloatOptional(YGNodeBoundAxisWithinMinAndMax( + YGNodeBoundAxisWithinMinAndMax( node, crossAxis, totalLineCrossDim + paddingAndBorderAxisCross, - crossAxisownerSize))), + crossAxisownerSize) + .unwrap()), paddingAndBorderAxisCross), dim[crossAxis]); } @@ -3777,10 +3790,10 @@ bool YGLayoutNodeInternal( // expensive to measure, so it's worth avoiding redundant measurements if at // all possible. if (node->getMeasure() != nullptr) { - const float marginAxisRow = YGUnwrapFloatOptional( - node->getMarginForAxis(YGFlexDirectionRow, ownerWidth)); - const float marginAxisColumn = YGUnwrapFloatOptional( - node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth)); + const float marginAxisRow = + node->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap(); + const float marginAxisColumn = + node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth).unwrap(); // First, try to use the layout cache. if (YGNodeCanUseCachedMeasurement( @@ -4080,16 +4093,18 @@ void YGNodeCalculateLayout( float width = YGUndefined; YGMeasureMode widthMeasureMode = YGMeasureModeUndefined; if (YGNodeIsStyleDimDefined(node, YGFlexDirectionRow, ownerWidth)) { - width = YGUnwrapFloatOptional( - YGResolveValue( - node->getResolvedDimension(dim[YGFlexDirectionRow]), ownerWidth) + - node->getMarginForAxis(YGFlexDirectionRow, ownerWidth)); + width = + (YGResolveValue( + node->getResolvedDimension(dim[YGFlexDirectionRow]), ownerWidth) + + node->getMarginForAxis(YGFlexDirectionRow, ownerWidth)) + .unwrap(); widthMeasureMode = YGMeasureModeExactly; } else if (!YGResolveValue( node->getStyle().maxDimensions[YGDimensionWidth], ownerWidth) .isUndefined()) { - width = YGUnwrapFloatOptional(YGResolveValue( - node->getStyle().maxDimensions[YGDimensionWidth], ownerWidth)); + width = YGResolveValue( + node->getStyle().maxDimensions[YGDimensionWidth], ownerWidth) + .unwrap(); widthMeasureMode = YGMeasureModeAtMost; } else { width = ownerWidth; @@ -4100,18 +4115,19 @@ void YGNodeCalculateLayout( float height = YGUndefined; YGMeasureMode heightMeasureMode = YGMeasureModeUndefined; if (YGNodeIsStyleDimDefined(node, YGFlexDirectionColumn, ownerHeight)) { - height = YGUnwrapFloatOptional( - YGResolveValue( - node->getResolvedDimension(dim[YGFlexDirectionColumn]), - ownerHeight) + - node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth)); + height = (YGResolveValue( + node->getResolvedDimension(dim[YGFlexDirectionColumn]), + ownerHeight) + + node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth)) + .unwrap(); heightMeasureMode = YGMeasureModeExactly; } else if (!YGResolveValue( node->getStyle().maxDimensions[YGDimensionHeight], ownerHeight) .isUndefined()) { - height = YGUnwrapFloatOptional(YGResolveValue( - node->getStyle().maxDimensions[YGDimensionHeight], ownerHeight)); + height = YGResolveValue( + node->getStyle().maxDimensions[YGDimensionHeight], ownerHeight) + .unwrap(); heightMeasureMode = YGMeasureModeAtMost; } else { height = ownerHeight;