From 6a77a6939e33e3f374a252dc24b877dabeb0a490 Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Wed, 4 Apr 2018 07:55:49 -0700 Subject: [PATCH] Changed the return type of getLeadingMargin to YGFloatOptional Summary: Changed the return type of getLeadingMargin to YGFloatOptional Reviewed By: emilsjolander Differential Revision: D7349907 fbshipit-source-id: b20894fbc33fd5b29a28f3c9174d1b5f406774ab --- yoga/YGNode.cpp | 24 ++++++++++++------------ yoga/YGNode.h | 4 +++- yoga/Yoga.cpp | 29 +++++++++++++++++++---------- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/yoga/YGNode.cpp b/yoga/YGNode.cpp index 7d29caf0..f388f91d 100644 --- a/yoga/YGNode.cpp +++ b/yoga/YGNode.cpp @@ -139,18 +139,17 @@ bool YGNode::isTrailingPosDefined(const YGFlexDirection& axis) const { ->unit != YGUnitUndefined; } -float YGNode::getLeadingMargin( - const YGFlexDirection axis, - const float widthSize) const { +YGFloatOptional YGNode::getLeadingMargin( + const YGFlexDirection& axis, + const float& widthSize) const { if (YGFlexDirectionIsRow(axis) && style_.margin[YGEdgeStart].unit != YGUnitUndefined) { - return YGUnwrapFloatOptional( - YGResolveValueMargin(style_.margin[YGEdgeStart], widthSize)); + return YGResolveValueMargin(style_.margin[YGEdgeStart], widthSize); } - return YGUnwrapFloatOptional(YGResolveValueMargin( + return YGResolveValueMargin( *YGComputedEdgeValue(style_.margin, leading[axis], &YGValueZero), - widthSize)); + widthSize); } float YGNode::getTrailingMargin( @@ -171,7 +170,8 @@ float YGNode::getTrailingMargin( float YGNode::getMarginForAxis( const YGFlexDirection axis, const float widthSize) const { - return getLeadingMargin(axis, widthSize) + getTrailingMargin(axis, widthSize); + return YGUnwrapFloatOptional(getLeadingMargin(axis, widthSize)) + + getTrailingMargin(axis, widthSize); } // Setters @@ -374,16 +374,16 @@ void YGNode::setPosition( relativePosition(crossAxis, crossSize); setLayoutPosition( - getLeadingMargin(mainAxis, ownerWidth) + - YGUnwrapFloatOptional(relativePositionMain), + YGUnwrapFloatOptional( + getLeadingMargin(mainAxis, ownerWidth) + relativePositionMain), leading[mainAxis]); setLayoutPosition( getTrailingMargin(mainAxis, ownerWidth) + YGUnwrapFloatOptional(relativePositionMain), trailing[mainAxis]); setLayoutPosition( - getLeadingMargin(crossAxis, ownerWidth) + - YGUnwrapFloatOptional(relativePositionCross), + YGUnwrapFloatOptional( + getLeadingMargin(crossAxis, ownerWidth) + relativePositionCross), leading[crossAxis]); setLayoutPosition( getTrailingMargin(crossAxis, ownerWidth) + diff --git a/yoga/YGNode.h b/yoga/YGNode.h index 95fac721..7b2275ea 100644 --- a/yoga/YGNode.h +++ b/yoga/YGNode.h @@ -94,7 +94,9 @@ struct YGNode { YGFloatOptional getTrailingPosition( const YGFlexDirection& axis, const float& axisSize) const; - float getLeadingMargin(const YGFlexDirection axis, const float widthSize) const; + YGFloatOptional getLeadingMargin( + const YGFlexDirection& axis, + const float& widthSize) const; float getTrailingMargin(const YGFlexDirection axis, const float widthSize) const; float getLeadingBorder(const YGFlexDirection& flexDirection) const; float getTrailingBorder(const YGFlexDirection& flexDirection) const; diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 2805e7f6..1bcb4a20 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -1093,7 +1093,7 @@ static inline float YGNodeDimWithMargin(const YGNodeRef node, const YGFlexDirection axis, const float widthSize) { return node->getLayout().measuredDimensions[dim[axis]] + - node->getLeadingMargin(axis, widthSize) + + YGUnwrapFloatOptional(node->getLeadingMargin(axis, widthSize)) + node->getTrailingMargin(axis, widthSize); } @@ -2396,7 +2396,8 @@ static void YGJustifyMainAxis( YGUnwrapFloatOptional( child->getLeadingPosition(mainAxis, availableInnerMainDim)) + node->getLeadingBorder(mainAxis) + - child->getLeadingMargin(mainAxis, availableInnerWidth), + YGUnwrapFloatOptional( + child->getLeadingMargin(mainAxis, availableInnerWidth)), pos[mainAxis]); } } else { @@ -2573,11 +2574,15 @@ static void YGNodelayoutImpl(const YGNodeRef node, YGResolveFlexDirection(YGFlexDirectionColumn, direction); node->setLayoutMargin( - node->getLeadingMargin(flexRowDirection, ownerWidth), YGEdgeStart); + YGUnwrapFloatOptional( + node->getLeadingMargin(flexRowDirection, ownerWidth)), + YGEdgeStart); node->setLayoutMargin( node->getTrailingMargin(flexRowDirection, ownerWidth), YGEdgeEnd); node->setLayoutMargin( - node->getLeadingMargin(flexColumnDirection, ownerWidth), YGEdgeTop); + YGUnwrapFloatOptional( + node->getLeadingMargin(flexColumnDirection, ownerWidth)), + YGEdgeTop); node->setLayoutMargin( node->getTrailingMargin(flexColumnDirection, ownerWidth), YGEdgeBottom); @@ -2900,7 +2905,8 @@ static void YGNodelayoutImpl(const YGNodeRef node, YGUnwrapFloatOptional(child->getLeadingPosition( crossAxis, availableInnerCrossDim)) + node->getLeadingBorder(crossAxis) + - child->getLeadingMargin(crossAxis, availableInnerWidth), + YGUnwrapFloatOptional(child->getLeadingMargin( + crossAxis, availableInnerWidth)), pos[crossAxis]); } // If leading position is not defined or calculations result in Nan, default to border + margin @@ -2908,7 +2914,8 @@ static void YGNodelayoutImpl(const YGNodeRef node, YGFloatIsUndefined(child->getLayout().position[pos[crossAxis]])) { child->setLayoutPosition( node->getLeadingBorder(crossAxis) + - child->getLeadingMargin(crossAxis, availableInnerWidth), + YGUnwrapFloatOptional(child->getLeadingMargin( + crossAxis, availableInnerWidth)), pos[crossAxis]); } } else { @@ -3083,8 +3090,8 @@ static void YGNodelayoutImpl(const YGNodeRef node, } if (YGNodeAlignItem(node, child) == YGAlignBaseline) { const float ascent = YGBaseline(child) + - child->getLeadingMargin( - YGFlexDirectionColumn, availableInnerWidth); + YGUnwrapFloatOptional(child->getLeadingMargin( + YGFlexDirectionColumn, availableInnerWidth)); const float descent = child->getLayout().measuredDimensions[YGDimensionHeight] + child->getMarginForAxis( @@ -3113,7 +3120,8 @@ static void YGNodelayoutImpl(const YGNodeRef node, case YGAlignFlexStart: { child->setLayoutPosition( currentLead + - child->getLeadingMargin(crossAxis, availableInnerWidth), + YGUnwrapFloatOptional(child->getLeadingMargin( + crossAxis, availableInnerWidth)), pos[crossAxis]); break; } @@ -3138,7 +3146,8 @@ static void YGNodelayoutImpl(const YGNodeRef node, case YGAlignStretch: { child->setLayoutPosition( currentLead + - child->getLeadingMargin(crossAxis, availableInnerWidth), + YGUnwrapFloatOptional(child->getLeadingMargin( + crossAxis, availableInnerWidth)), pos[crossAxis]); // Remeasure child with the line height as it as been only measured with the