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);
}
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) {
case YGMeasureModeExactly:
case YGMeasureModeAtMost:
@ -1480,14 +1487,10 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node,
}
}
YGConstrainMaxSizeForMode(YGValueResolve(&child->style.maxDimensions[YGDimensionWidth],
parentWidth),
&childWidthMeasureMode,
&childWidth);
YGConstrainMaxSizeForMode(YGValueResolve(&child->style.maxDimensions[YGDimensionHeight],
parentHeight),
&childHeightMeasureMode,
&childHeight);
YGConstrainMaxSizeForMode(
child, YGFlexDirectionRow, parentWidth, parentWidth, &childWidthMeasureMode, &childWidth);
YGConstrainMaxSizeForMode(
child, YGFlexDirectionColumn, parentHeight, parentWidth, &childHeightMeasureMode, &childHeight);
// Measure the child
YGLayoutNodeInternal(child,
@ -2443,16 +2446,18 @@ static void YGNodelayoutImpl(const YGNodeRef node,
childCrossSize += marginCross;
}
YGConstrainMaxSizeForMode(
YGValueResolve(&currentRelativeChild->style.maxDimensions[dim[mainAxis]],
availableInnerWidth),
&childMainMeasureMode,
&childMainSize);
YGConstrainMaxSizeForMode(
YGValueResolve(&currentRelativeChild->style.maxDimensions[dim[crossAxis]],
availableInnerHeight),
&childCrossMeasureMode,
&childCrossSize);
YGConstrainMaxSizeForMode(currentRelativeChild,
mainAxis,
availableInnerMainDim,
availableInnerWidth,
&childMainMeasureMode,
&childMainSize);
YGConstrainMaxSizeForMode(currentRelativeChild,
crossAxis,
availableInnerCrossDim,
availableInnerWidth,
&childCrossMeasureMode,
&childCrossSize);
const bool requiresStretchLayout =
!YGNodeIsStyleDimDefined(currentRelativeChild, crossAxis, availableInnerCrossDim) &&
@ -2690,12 +2695,16 @@ static void YGNodelayoutImpl(const YGNodeRef node,
YGMeasureMode childMainMeasureMode = YGMeasureModeExactly;
YGMeasureMode childCrossMeasureMode = YGMeasureModeExactly;
YGConstrainMaxSizeForMode(YGValueResolve(&child->style.maxDimensions[dim[mainAxis]],
availableInnerMainDim),
YGConstrainMaxSizeForMode(child,
mainAxis,
availableInnerMainDim,
availableInnerWidth,
&childMainMeasureMode,
&childMainSize);
YGConstrainMaxSizeForMode(YGValueResolve(&child->style.maxDimensions[dim[crossAxis]],
availableInnerCrossDim),
YGConstrainMaxSizeForMode(child,
crossAxis,
availableInnerCrossDim,
availableInnerWidth,
&childCrossMeasureMode,
&childCrossSize);