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;
}
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) +

View File

@ -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;

View File

@ -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