Change the return type of getMarginForAxis to YGFloatOptional

Reviewed By: emilsjolander

Differential Revision: D7350337

fbshipit-source-id: dd1ee2fcd295ccd14f7d414ab0c24090b24e91e0
This commit is contained in:
Pritesh Nandgaonkar 2018-04-04 07:55:54 -07:00 committed by Facebook Github Bot
parent 3a65fa56c5
commit 4841aed82c
3 changed files with 73 additions and 64 deletions

View File

@ -165,12 +165,10 @@ YGFloatOptional YGNode::getTrailingMargin(
widthSize); widthSize);
} }
// TODO: Make its return type to YGFloatOptional YGFloatOptional 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

View File

@ -114,7 +114,9 @@ struct YGNode {
YGFloatOptional getTrailingPaddingAndBorder( YGFloatOptional getTrailingPaddingAndBorder(
const YGFlexDirection& axis, const YGFlexDirection& axis,
const float& widthSize) const; const float& widthSize) const;
float getMarginForAxis(const YGFlexDirection axis, const float widthSize) const; YGFloatOptional getMarginForAxis(
const YGFlexDirection& axis,
const float& widthSize) const;
// Setters // Setters
void setContext(void* context); void setContext(void* context);

View File

@ -1264,10 +1264,10 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node,
childWidthMeasureMode = YGMeasureModeUndefined; childWidthMeasureMode = YGMeasureModeUndefined;
childHeightMeasureMode = YGMeasureModeUndefined; childHeightMeasureMode = YGMeasureModeUndefined;
const float marginRow = const float& marginRow = YGUnwrapFloatOptional(
child->getMarginForAxis(YGFlexDirectionRow, ownerWidth); child->getMarginForAxis(YGFlexDirectionRow, ownerWidth));
const float marginColumn = const float& marginColumn = YGUnwrapFloatOptional(
child->getMarginForAxis(YGFlexDirectionColumn, ownerWidth); child->getMarginForAxis(YGFlexDirectionColumn, ownerWidth));
if (isRowStyleDimDefined) { if (isRowStyleDimDefined) {
childWidth = childWidth =
@ -1392,9 +1392,10 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node,
YGMeasureMode childWidthMeasureMode = YGMeasureModeUndefined; YGMeasureMode childWidthMeasureMode = YGMeasureModeUndefined;
YGMeasureMode childHeightMeasureMode = YGMeasureModeUndefined; YGMeasureMode childHeightMeasureMode = YGMeasureModeUndefined;
const float marginRow = child->getMarginForAxis(YGFlexDirectionRow, width); const float& marginRow =
const float marginColumn = YGUnwrapFloatOptional(child->getMarginForAxis(YGFlexDirectionRow, width));
child->getMarginForAxis(YGFlexDirectionColumn, width); const float& marginColumn = YGUnwrapFloatOptional(
child->getMarginForAxis(YGFlexDirectionColumn, width));
if (YGNodeIsStyleDimDefined(child, YGFlexDirectionRow, width)) { if (YGNodeIsStyleDimDefined(child, YGFlexDirectionRow, width)) {
childWidth = childWidth =
@ -1481,9 +1482,11 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node,
"abs-measure", "abs-measure",
config); config);
childWidth = child->getLayout().measuredDimensions[YGDimensionWidth] + childWidth = child->getLayout().measuredDimensions[YGDimensionWidth] +
child->getMarginForAxis(YGFlexDirectionRow, width); YGUnwrapFloatOptional(
child->getMarginForAxis(YGFlexDirectionRow, width));
childHeight = child->getLayout().measuredDimensions[YGDimensionHeight] + childHeight = child->getLayout().measuredDimensions[YGDimensionHeight] +
child->getMarginForAxis(YGFlexDirectionColumn, width); YGUnwrapFloatOptional(
child->getMarginForAxis(YGFlexDirectionColumn, width));
} }
YGLayoutNodeInternal(child, YGLayoutNodeInternal(child,
@ -1571,10 +1574,10 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions(const YGNodeRef node,
YGNodePaddingAndBorderForAxis(node, YGFlexDirectionRow, availableWidth); YGNodePaddingAndBorderForAxis(node, YGFlexDirectionRow, availableWidth);
const float paddingAndBorderAxisColumn = const float paddingAndBorderAxisColumn =
YGNodePaddingAndBorderForAxis(node, YGFlexDirectionColumn, availableWidth); YGNodePaddingAndBorderForAxis(node, YGFlexDirectionColumn, availableWidth);
const float marginAxisRow = const float marginAxisRow = YGUnwrapFloatOptional(
node->getMarginForAxis(YGFlexDirectionRow, availableWidth); node->getMarginForAxis(YGFlexDirectionRow, availableWidth));
const float marginAxisColumn = const float marginAxisColumn = YGUnwrapFloatOptional(
node->getMarginForAxis(YGFlexDirectionColumn, availableWidth); node->getMarginForAxis(YGFlexDirectionColumn, availableWidth));
// We want to make sure we don't call measure with negative size // We want to make sure we don't call measure with negative size
const float innerWidth = YGFloatIsUndefined(availableWidth) const float innerWidth = YGFloatIsUndefined(availableWidth)
@ -1648,10 +1651,10 @@ static void YGNodeEmptyContainerSetMeasuredDimensions(const YGNodeRef node,
YGNodePaddingAndBorderForAxis(node, YGFlexDirectionRow, ownerWidth); YGNodePaddingAndBorderForAxis(node, YGFlexDirectionRow, ownerWidth);
const float paddingAndBorderAxisColumn = const float paddingAndBorderAxisColumn =
YGNodePaddingAndBorderForAxis(node, YGFlexDirectionColumn, ownerWidth); YGNodePaddingAndBorderForAxis(node, YGFlexDirectionColumn, ownerWidth);
const float marginAxisRow = const float marginAxisRow = YGUnwrapFloatOptional(
node->getMarginForAxis(YGFlexDirectionRow, ownerWidth); node->getMarginForAxis(YGFlexDirectionRow, ownerWidth));
const float marginAxisColumn = const float marginAxisColumn = YGUnwrapFloatOptional(
node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth); node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth));
node->setLayoutMeasuredDimension( node->setLayoutMeasuredDimension(
YGNodeBoundAxis( YGNodeBoundAxis(
@ -1691,10 +1694,10 @@ static bool YGNodeFixedSizeSetMeasuredDimensions(const YGNodeRef node,
heightMeasureMode == YGMeasureModeAtMost && availableHeight <= 0.0f) || heightMeasureMode == YGMeasureModeAtMost && availableHeight <= 0.0f) ||
(widthMeasureMode == YGMeasureModeExactly && (widthMeasureMode == YGMeasureModeExactly &&
heightMeasureMode == YGMeasureModeExactly)) { heightMeasureMode == YGMeasureModeExactly)) {
const float marginAxisColumn = const float& marginAxisColumn = YGUnwrapFloatOptional(
node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth); node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth));
const float marginAxisRow = const float& marginAxisRow = YGUnwrapFloatOptional(
node->getMarginForAxis(YGFlexDirectionRow, ownerWidth); node->getMarginForAxis(YGFlexDirectionRow, ownerWidth));
node->setLayoutMeasuredDimension( node->setLayoutMeasuredDimension(
YGNodeBoundAxis( YGNodeBoundAxis(
@ -1748,7 +1751,8 @@ static float YGNodeCalculateAvailableInnerDim(
YGDimension dimension = YGDimension dimension =
YGFlexDirectionIsRow(axis) ? YGDimensionWidth : YGDimensionHeight; YGFlexDirectionIsRow(axis) ? YGDimensionWidth : YGDimensionHeight;
const float margin = node->getMarginForAxis(direction, ownerDim); const float margin =
YGUnwrapFloatOptional(node->getMarginForAxis(direction, ownerDim));
const float paddingAndBorder = const float paddingAndBorder =
YGNodePaddingAndBorderForAxis(node, direction, ownerDim); YGNodePaddingAndBorderForAxis(node, direction, ownerDim);
@ -1850,9 +1854,9 @@ static void YGNodeComputeFlexBasisForChildren(
config); config);
} }
totalOuterFlexBasis += totalOuterFlexBasis += YGUnwrapFloatOptional(
YGUnwrapFloatOptional(child->getLayout().computedFlexBasis) + child->getLayout().computedFlexBasis +
child->getMarginForAxis(mainAxis, availableInnerWidth); child->getMarginForAxis(mainAxis, availableInnerWidth));
} }
} }
@ -1885,8 +1889,8 @@ static YGCollectFlexItemsRowValues YGCalculateCollectFlexItemsRowValues(
continue; continue;
} }
child->setLineIndex(lineCount); child->setLineIndex(lineCount);
const float childMarginMainAxis = const float childMarginMainAxis = YGUnwrapFloatOptional(
child->getMarginForAxis(mainAxis, availableInnerWidth); child->getMarginForAxis(mainAxis, availableInnerWidth));
const float flexBasisWithMinAndMaxConstraints = const float flexBasisWithMinAndMaxConstraints =
YGUnwrapFloatOptional(YGNodeBoundAxisWithinMinAndMax( YGUnwrapFloatOptional(YGNodeBoundAxisWithinMinAndMax(
child, child,
@ -2020,10 +2024,10 @@ static float YGDistributeFreeSpaceSecondPass(
deltaFreeSpace += updatedMainSize - childFlexBasis; deltaFreeSpace += updatedMainSize - childFlexBasis;
const float marginMain = const float marginMain = YGUnwrapFloatOptional(
currentRelativeChild->getMarginForAxis(mainAxis, availableInnerWidth); currentRelativeChild->getMarginForAxis(mainAxis, availableInnerWidth));
const float marginCross = const float marginCross = YGUnwrapFloatOptional(
currentRelativeChild->getMarginForAxis(crossAxis, availableInnerWidth); currentRelativeChild->getMarginForAxis(crossAxis, availableInnerWidth));
float childCrossSize; float childCrossSize;
float childMainSize = updatedMainSize + marginMain; float childMainSize = updatedMainSize + marginMain;
@ -2432,7 +2436,8 @@ static void YGJustifyMainAxis(
// they weren't computed. This means we can't call // they weren't computed. This means we can't call
// YGNodeDimWithMargin. // YGNodeDimWithMargin.
collectedFlexItemsValues.mainDim += betweenMainDim + collectedFlexItemsValues.mainDim += betweenMainDim +
child->getMarginForAxis(mainAxis, availableInnerWidth) + YGUnwrapFloatOptional(child->getMarginForAxis(
mainAxis, availableInnerWidth)) +
YGUnwrapFloatOptional(childLayout.computedFlexBasis); YGUnwrapFloatOptional(childLayout.computedFlexBasis);
collectedFlexItemsValues.crossDim = availableInnerCrossDim; collectedFlexItemsValues.crossDim = availableInnerCrossDim;
} else { } else {
@ -2678,10 +2683,10 @@ static void YGNodelayoutImpl(const YGNodeRef node,
const float paddingAndBorderAxisColumn = const float paddingAndBorderAxisColumn =
isMainAxisRow ? paddingAndBorderAxisCross : paddingAndBorderAxisMain; isMainAxisRow ? paddingAndBorderAxisCross : paddingAndBorderAxisMain;
const float marginAxisRow = const float marginAxisRow = YGUnwrapFloatOptional(
node->getMarginForAxis(YGFlexDirectionRow, ownerWidth); node->getMarginForAxis(YGFlexDirectionRow, ownerWidth));
const float marginAxisColumn = const float marginAxisColumn = YGUnwrapFloatOptional(
node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth); node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth));
const float minInnerWidth = const float minInnerWidth =
YGUnwrapFloatOptional(YGResolveValue(node->getStyle().minDimensions[YGDimensionWidth], ownerWidth)) - YGUnwrapFloatOptional(YGResolveValue(node->getStyle().minDimensions[YGDimensionWidth], ownerWidth)) -
@ -2945,15 +2950,16 @@ static void YGNodelayoutImpl(const YGNodeRef node,
child->getLayout().measuredDimensions[dim[mainAxis]]; child->getLayout().measuredDimensions[dim[mainAxis]];
float childCrossSize = float childCrossSize =
!child->getStyle().aspectRatio.isUndefined() !child->getStyle().aspectRatio.isUndefined()
? ((child->getMarginForAxis(crossAxis, availableInnerWidth) + ? ((YGUnwrapFloatOptional(child->getMarginForAxis(
crossAxis, availableInnerWidth)) +
(isMainAxisRow ? childMainSize / (isMainAxisRow ? childMainSize /
child->getStyle().aspectRatio.getValue() child->getStyle().aspectRatio.getValue()
: childMainSize * : childMainSize *
child->getStyle().aspectRatio.getValue()))) child->getStyle().aspectRatio.getValue())))
: collectedFlexItemsValues.crossDim; : collectedFlexItemsValues.crossDim;
childMainSize += childMainSize += YGUnwrapFloatOptional(
child->getMarginForAxis(mainAxis, availableInnerWidth); child->getMarginForAxis(mainAxis, availableInnerWidth));
YGMeasureMode childMainMeasureMode = YGMeasureModeExactly; YGMeasureMode childMainMeasureMode = YGMeasureModeExactly;
YGMeasureMode childCrossMeasureMode = YGMeasureModeExactly; YGMeasureMode childCrossMeasureMode = YGMeasureModeExactly;
@ -3091,7 +3097,8 @@ static void YGNodelayoutImpl(const YGNodeRef node,
lineHeight = YGFloatMax( lineHeight = YGFloatMax(
lineHeight, lineHeight,
child->getLayout().measuredDimensions[dim[crossAxis]] + child->getLayout().measuredDimensions[dim[crossAxis]] +
child->getMarginForAxis(crossAxis, availableInnerWidth)); YGUnwrapFloatOptional(child->getMarginForAxis(
crossAxis, availableInnerWidth)));
} }
if (YGNodeAlignItem(node, child) == YGAlignBaseline) { if (YGNodeAlignItem(node, child) == YGAlignBaseline) {
const float ascent = YGBaseline(child) + const float ascent = YGBaseline(child) +
@ -3099,8 +3106,8 @@ static void YGNodelayoutImpl(const YGNodeRef node,
YGFlexDirectionColumn, availableInnerWidth)); YGFlexDirectionColumn, availableInnerWidth));
const float descent = const float descent =
child->getLayout().measuredDimensions[YGDimensionHeight] + child->getLayout().measuredDimensions[YGDimensionHeight] +
child->getMarginForAxis( YGUnwrapFloatOptional(child->getMarginForAxis(
YGFlexDirectionColumn, availableInnerWidth) - YGFlexDirectionColumn, availableInnerWidth)) -
ascent; ascent;
maxAscentForCurrentLine = maxAscentForCurrentLine =
YGFloatMax(maxAscentForCurrentLine, ascent); YGFloatMax(maxAscentForCurrentLine, ascent);
@ -3161,14 +3168,15 @@ static void YGNodelayoutImpl(const YGNodeRef node,
const float childWidth = isMainAxisRow const float childWidth = isMainAxisRow
? (child->getLayout() ? (child->getLayout()
.measuredDimensions[YGDimensionWidth] + .measuredDimensions[YGDimensionWidth] +
child->getMarginForAxis(mainAxis, availableInnerWidth)) YGUnwrapFloatOptional(child->getMarginForAxis(
mainAxis, availableInnerWidth)))
: lineHeight; : lineHeight;
const float childHeight = !isMainAxisRow const float childHeight = !isMainAxisRow
? (child->getLayout() ? (child->getLayout()
.measuredDimensions[YGDimensionHeight] + .measuredDimensions[YGDimensionHeight] +
child->getMarginForAxis( YGUnwrapFloatOptional(child->getMarginForAxis(
crossAxis, availableInnerWidth)) crossAxis, availableInnerWidth)))
: lineHeight; : lineHeight;
if (!(YGFloatsEqual( if (!(YGFloatsEqual(
@ -3548,10 +3556,10 @@ bool YGLayoutNodeInternal(const YGNodeRef node,
// expensive to measure, so it's worth avoiding redundant measurements if at // expensive to measure, so it's worth avoiding redundant measurements if at
// all possible. // all possible.
if (node->getMeasure() != nullptr) { if (node->getMeasure() != nullptr) {
const float marginAxisRow = const float marginAxisRow = YGUnwrapFloatOptional(
node->getMarginForAxis(YGFlexDirectionRow, ownerWidth); node->getMarginForAxis(YGFlexDirectionRow, ownerWidth));
const float marginAxisColumn = const float marginAxisColumn = YGUnwrapFloatOptional(
node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth); node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth));
// First, try to use the layout cache. // First, try to use the layout cache.
if (YGNodeCanUseCachedMeasurement(widthMeasureMode, if (YGNodeCanUseCachedMeasurement(widthMeasureMode,
@ -3828,10 +3836,10 @@ void YGNodeCalculateLayout(
float width = YGUndefined; float width = YGUndefined;
YGMeasureMode widthMeasureMode = YGMeasureModeUndefined; YGMeasureMode widthMeasureMode = YGMeasureModeUndefined;
if (YGNodeIsStyleDimDefined(node, YGFlexDirectionRow, ownerWidth)) { if (YGNodeIsStyleDimDefined(node, YGFlexDirectionRow, ownerWidth)) {
width = width = YGUnwrapFloatOptional(
YGUnwrapFloatOptional(YGResolveValue( YGResolveValue(
node->getResolvedDimension(dim[YGFlexDirectionRow]), ownerWidth)) + node->getResolvedDimension(dim[YGFlexDirectionRow]), ownerWidth) +
node->getMarginForAxis(YGFlexDirectionRow, ownerWidth); node->getMarginForAxis(YGFlexDirectionRow, ownerWidth));
widthMeasureMode = YGMeasureModeExactly; widthMeasureMode = YGMeasureModeExactly;
} else if (!YGResolveValue( } else if (!YGResolveValue(
node->getStyle().maxDimensions[YGDimensionWidth], ownerWidth) node->getStyle().maxDimensions[YGDimensionWidth], ownerWidth)
@ -3848,10 +3856,11 @@ void YGNodeCalculateLayout(
float height = YGUndefined; float height = YGUndefined;
YGMeasureMode heightMeasureMode = YGMeasureModeUndefined; YGMeasureMode heightMeasureMode = YGMeasureModeUndefined;
if (YGNodeIsStyleDimDefined(node, YGFlexDirectionColumn, ownerHeight)) { if (YGNodeIsStyleDimDefined(node, YGFlexDirectionColumn, ownerHeight)) {
height = YGUnwrapFloatOptional(YGResolveValue( height = YGUnwrapFloatOptional(
YGResolveValue(
node->getResolvedDimension(dim[YGFlexDirectionColumn]), node->getResolvedDimension(dim[YGFlexDirectionColumn]),
ownerHeight)) + ownerHeight) +
node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth); node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth));
heightMeasureMode = YGMeasureModeExactly; heightMeasureMode = YGMeasureModeExactly;
} else if (!YGResolveValue( } else if (!YGResolveValue(
node->getStyle().maxDimensions[YGDimensionHeight], node->getStyle().maxDimensions[YGDimensionHeight],