Take margin into account on max dimension

Summary:
We need to take the margin into account if we clip on max dimension. Fixes #466.
Closes https://github.com/facebook/yoga/pull/467

Differential Revision: D4681342

Pulled By: emilsjolander

fbshipit-source-id: 56311df9864a284d553c31f1c6db382f337f1fad
This commit is contained in:
Lukas Wöhrl 2017-03-09 03:48:33 -08:00 committed by Facebook Github Bot
parent 21c229119d
commit 751addcb73
1 changed files with 32 additions and 23 deletions

View File

@ -1334,7 +1334,14 @@ static float YGNodeRelativePosition(const YGNodeRef node,
: -YGNodeTrailingPosition(node, axis, axisSize); : -YGNodeTrailingPosition(node, axis, axisSize);
} }
static void YGConstrainMaxSizeForMode(const float maxSize, YGMeasureMode *mode, float *size) { static void YGConstrainMaxSizeForMode(const YGNodeRef node,
const enum YGFlexDirection axis,
const float parentAxisSize,
const float parentWidth,
YGMeasureMode *mode,
float *size) {
const float maxSize = YGValueResolve(&node->style.maxDimensions[dim[axis]], parentAxisSize) +
YGNodeMarginForAxis(node, axis, parentWidth);
switch (*mode) { switch (*mode) {
case YGMeasureModeExactly: case YGMeasureModeExactly:
case YGMeasureModeAtMost: case YGMeasureModeAtMost:
@ -1480,14 +1487,10 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node,
} }
} }
YGConstrainMaxSizeForMode(YGValueResolve(&child->style.maxDimensions[YGDimensionWidth], YGConstrainMaxSizeForMode(
parentWidth), child, YGFlexDirectionRow, parentWidth, parentWidth, &childWidthMeasureMode, &childWidth);
&childWidthMeasureMode, YGConstrainMaxSizeForMode(
&childWidth); child, YGFlexDirectionColumn, parentHeight, parentWidth, &childHeightMeasureMode, &childHeight);
YGConstrainMaxSizeForMode(YGValueResolve(&child->style.maxDimensions[YGDimensionHeight],
parentHeight),
&childHeightMeasureMode,
&childHeight);
// Measure the child // Measure the child
YGLayoutNodeInternal(child, YGLayoutNodeInternal(child,
@ -2443,16 +2446,18 @@ static void YGNodelayoutImpl(const YGNodeRef node,
childCrossSize += marginCross; childCrossSize += marginCross;
} }
YGConstrainMaxSizeForMode( YGConstrainMaxSizeForMode(currentRelativeChild,
YGValueResolve(&currentRelativeChild->style.maxDimensions[dim[mainAxis]], mainAxis,
availableInnerWidth), availableInnerMainDim,
&childMainMeasureMode, availableInnerWidth,
&childMainSize); &childMainMeasureMode,
YGConstrainMaxSizeForMode( &childMainSize);
YGValueResolve(&currentRelativeChild->style.maxDimensions[dim[crossAxis]], YGConstrainMaxSizeForMode(currentRelativeChild,
availableInnerHeight), crossAxis,
&childCrossMeasureMode, availableInnerCrossDim,
&childCrossSize); availableInnerWidth,
&childCrossMeasureMode,
&childCrossSize);
const bool requiresStretchLayout = const bool requiresStretchLayout =
!YGNodeIsStyleDimDefined(currentRelativeChild, crossAxis, availableInnerCrossDim) && !YGNodeIsStyleDimDefined(currentRelativeChild, crossAxis, availableInnerCrossDim) &&
@ -2690,12 +2695,16 @@ static void YGNodelayoutImpl(const YGNodeRef node,
YGMeasureMode childMainMeasureMode = YGMeasureModeExactly; YGMeasureMode childMainMeasureMode = YGMeasureModeExactly;
YGMeasureMode childCrossMeasureMode = YGMeasureModeExactly; YGMeasureMode childCrossMeasureMode = YGMeasureModeExactly;
YGConstrainMaxSizeForMode(YGValueResolve(&child->style.maxDimensions[dim[mainAxis]], YGConstrainMaxSizeForMode(child,
availableInnerMainDim), mainAxis,
availableInnerMainDim,
availableInnerWidth,
&childMainMeasureMode, &childMainMeasureMode,
&childMainSize); &childMainSize);
YGConstrainMaxSizeForMode(YGValueResolve(&child->style.maxDimensions[dim[crossAxis]], YGConstrainMaxSizeForMode(child,
availableInnerCrossDim), crossAxis,
availableInnerCrossDim,
availableInnerWidth,
&childCrossMeasureMode, &childCrossMeasureMode,
&childCrossSize); &childCrossSize);