Changed the return type of getLeadingMargin to YGFloatOptional

Reviewed By: emilsjolander

Differential Revision: D7349907

fbshipit-source-id: b20894fbc33fd5b29a28f3c9174d1b5f406774ab
This commit is contained in:
Pritesh Nandgaonkar 2018-04-04 07:55:49 -07:00 committed by Facebook Github Bot
parent f0490d1217
commit 1024e98b95
3 changed files with 34 additions and 23 deletions

View File

@ -139,18 +139,17 @@ bool YGNode::isTrailingPosDefined(const YGFlexDirection& axis) const {
->unit != YGUnitUndefined; ->unit != YGUnitUndefined;
} }
float YGNode::getLeadingMargin( YGFloatOptional YGNode::getLeadingMargin(
const YGFlexDirection axis, const YGFlexDirection& axis,
const float widthSize) const { const float& widthSize) const {
if (YGFlexDirectionIsRow(axis) && if (YGFlexDirectionIsRow(axis) &&
style_.margin[YGEdgeStart].unit != YGUnitUndefined) { style_.margin[YGEdgeStart].unit != YGUnitUndefined) {
return YGUnwrapFloatOptional( return YGResolveValueMargin(style_.margin[YGEdgeStart], widthSize);
YGResolveValueMargin(style_.margin[YGEdgeStart], widthSize));
} }
return YGUnwrapFloatOptional(YGResolveValueMargin( return YGResolveValueMargin(
*YGComputedEdgeValue(style_.margin, leading[axis], &YGValueZero), *YGComputedEdgeValue(style_.margin, leading[axis], &YGValueZero),
widthSize)); widthSize);
} }
float YGNode::getTrailingMargin( float YGNode::getTrailingMargin(
@ -171,7 +170,8 @@ float YGNode::getTrailingMargin(
float YGNode::getMarginForAxis( float YGNode::getMarginForAxis(
const YGFlexDirection axis, const YGFlexDirection axis,
const float widthSize) const { const float widthSize) const {
return getLeadingMargin(axis, widthSize) + getTrailingMargin(axis, widthSize); return YGUnwrapFloatOptional(getLeadingMargin(axis, widthSize)) +
getTrailingMargin(axis, widthSize);
} }
// Setters // Setters
@ -374,16 +374,16 @@ void YGNode::setPosition(
relativePosition(crossAxis, crossSize); relativePosition(crossAxis, crossSize);
setLayoutPosition( setLayoutPosition(
getLeadingMargin(mainAxis, ownerWidth) + YGUnwrapFloatOptional(
YGUnwrapFloatOptional(relativePositionMain), getLeadingMargin(mainAxis, ownerWidth) + relativePositionMain),
leading[mainAxis]); leading[mainAxis]);
setLayoutPosition( setLayoutPosition(
getTrailingMargin(mainAxis, ownerWidth) + getTrailingMargin(mainAxis, ownerWidth) +
YGUnwrapFloatOptional(relativePositionMain), YGUnwrapFloatOptional(relativePositionMain),
trailing[mainAxis]); trailing[mainAxis]);
setLayoutPosition( setLayoutPosition(
getLeadingMargin(crossAxis, ownerWidth) + YGUnwrapFloatOptional(
YGUnwrapFloatOptional(relativePositionCross), getLeadingMargin(crossAxis, ownerWidth) + relativePositionCross),
leading[crossAxis]); leading[crossAxis]);
setLayoutPosition( setLayoutPosition(
getTrailingMargin(crossAxis, ownerWidth) + getTrailingMargin(crossAxis, ownerWidth) +

View File

@ -94,7 +94,9 @@ struct YGNode {
YGFloatOptional getTrailingPosition( YGFloatOptional getTrailingPosition(
const YGFlexDirection& axis, const YGFlexDirection& axis,
const float& axisSize) const; 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 getTrailingMargin(const YGFlexDirection axis, const float widthSize) const;
float getLeadingBorder(const YGFlexDirection& flexDirection) const; float getLeadingBorder(const YGFlexDirection& flexDirection) const;
float getTrailingBorder(const YGFlexDirection& flexDirection) const; float getTrailingBorder(const YGFlexDirection& flexDirection) const;

View File

@ -1093,7 +1093,7 @@ static inline float YGNodeDimWithMargin(const YGNodeRef node,
const YGFlexDirection axis, const YGFlexDirection axis,
const float widthSize) { const float widthSize) {
return node->getLayout().measuredDimensions[dim[axis]] + return node->getLayout().measuredDimensions[dim[axis]] +
node->getLeadingMargin(axis, widthSize) + YGUnwrapFloatOptional(node->getLeadingMargin(axis, widthSize)) +
node->getTrailingMargin(axis, widthSize); node->getTrailingMargin(axis, widthSize);
} }
@ -2396,7 +2396,8 @@ static void YGJustifyMainAxis(
YGUnwrapFloatOptional( YGUnwrapFloatOptional(
child->getLeadingPosition(mainAxis, availableInnerMainDim)) + child->getLeadingPosition(mainAxis, availableInnerMainDim)) +
node->getLeadingBorder(mainAxis) + node->getLeadingBorder(mainAxis) +
child->getLeadingMargin(mainAxis, availableInnerWidth), YGUnwrapFloatOptional(
child->getLeadingMargin(mainAxis, availableInnerWidth)),
pos[mainAxis]); pos[mainAxis]);
} }
} else { } else {
@ -2573,11 +2574,15 @@ static void YGNodelayoutImpl(const YGNodeRef node,
YGResolveFlexDirection(YGFlexDirectionColumn, direction); YGResolveFlexDirection(YGFlexDirectionColumn, direction);
node->setLayoutMargin( node->setLayoutMargin(
node->getLeadingMargin(flexRowDirection, ownerWidth), YGEdgeStart); YGUnwrapFloatOptional(
node->getLeadingMargin(flexRowDirection, ownerWidth)),
YGEdgeStart);
node->setLayoutMargin( node->setLayoutMargin(
node->getTrailingMargin(flexRowDirection, ownerWidth), YGEdgeEnd); node->getTrailingMargin(flexRowDirection, ownerWidth), YGEdgeEnd);
node->setLayoutMargin( node->setLayoutMargin(
node->getLeadingMargin(flexColumnDirection, ownerWidth), YGEdgeTop); YGUnwrapFloatOptional(
node->getLeadingMargin(flexColumnDirection, ownerWidth)),
YGEdgeTop);
node->setLayoutMargin( node->setLayoutMargin(
node->getTrailingMargin(flexColumnDirection, ownerWidth), YGEdgeBottom); node->getTrailingMargin(flexColumnDirection, ownerWidth), YGEdgeBottom);
@ -2900,7 +2905,8 @@ static void YGNodelayoutImpl(const YGNodeRef node,
YGUnwrapFloatOptional(child->getLeadingPosition( YGUnwrapFloatOptional(child->getLeadingPosition(
crossAxis, availableInnerCrossDim)) + crossAxis, availableInnerCrossDim)) +
node->getLeadingBorder(crossAxis) + node->getLeadingBorder(crossAxis) +
child->getLeadingMargin(crossAxis, availableInnerWidth), YGUnwrapFloatOptional(child->getLeadingMargin(
crossAxis, availableInnerWidth)),
pos[crossAxis]); pos[crossAxis]);
} }
// If leading position is not defined or calculations result in Nan, default to border + margin // 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]])) { YGFloatIsUndefined(child->getLayout().position[pos[crossAxis]])) {
child->setLayoutPosition( child->setLayoutPosition(
node->getLeadingBorder(crossAxis) + node->getLeadingBorder(crossAxis) +
child->getLeadingMargin(crossAxis, availableInnerWidth), YGUnwrapFloatOptional(child->getLeadingMargin(
crossAxis, availableInnerWidth)),
pos[crossAxis]); pos[crossAxis]);
} }
} else { } else {
@ -3083,8 +3090,8 @@ static void YGNodelayoutImpl(const YGNodeRef node,
} }
if (YGNodeAlignItem(node, child) == YGAlignBaseline) { if (YGNodeAlignItem(node, child) == YGAlignBaseline) {
const float ascent = YGBaseline(child) + const float ascent = YGBaseline(child) +
child->getLeadingMargin( YGUnwrapFloatOptional(child->getLeadingMargin(
YGFlexDirectionColumn, availableInnerWidth); YGFlexDirectionColumn, availableInnerWidth));
const float descent = const float descent =
child->getLayout().measuredDimensions[YGDimensionHeight] + child->getLayout().measuredDimensions[YGDimensionHeight] +
child->getMarginForAxis( child->getMarginForAxis(
@ -3113,7 +3120,8 @@ static void YGNodelayoutImpl(const YGNodeRef node,
case YGAlignFlexStart: { case YGAlignFlexStart: {
child->setLayoutPosition( child->setLayoutPosition(
currentLead + currentLead +
child->getLeadingMargin(crossAxis, availableInnerWidth), YGUnwrapFloatOptional(child->getLeadingMargin(
crossAxis, availableInnerWidth)),
pos[crossAxis]); pos[crossAxis]);
break; break;
} }
@ -3138,7 +3146,8 @@ static void YGNodelayoutImpl(const YGNodeRef node,
case YGAlignStretch: { case YGAlignStretch: {
child->setLayoutPosition( child->setLayoutPosition(
currentLead + currentLead +
child->getLeadingMargin(crossAxis, availableInnerWidth), YGUnwrapFloatOptional(child->getLeadingMargin(
crossAxis, availableInnerWidth)),
pos[crossAxis]); pos[crossAxis]);
// Remeasure child with the line height as it as been only measured with the // Remeasure child with the line height as it as been only measured with the