Skip to content

Commit

Permalink
Do not stretch auto margined nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
woehrl01 committed Oct 8, 2017
1 parent 7217471 commit 65cccd3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
21 changes: 21 additions & 0 deletions tests/YGMeasureTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,27 @@ TEST(YogaTest, dont_measure_when_min_equals_max_percentages) {
YGNodeFreeRecursive(root);
}


TEST(YogaTest, measure_nodes_with_margin_auto_and_stretch) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 500);
YGNodeStyleSetHeight(root, 500);

const YGNodeRef root_child0 = YGNodeNew();
YGNodeSetMeasureFunc(root_child0, _measure);
YGNodeStyleSetMarginAuto(root_child0, YGEdgeLeft);
YGNodeInsertChild(root, root_child0, 0);

YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

EXPECT_EQ(490, YGNodeLayoutGetLeft(root_child0));
EXPECT_EQ(0, YGNodeLayoutGetTop(root_child0));
EXPECT_EQ(10, YGNodeLayoutGetWidth(root_child0));
EXPECT_EQ(10, YGNodeLayoutGetHeight(root_child0));

YGNodeFreeRecursive(root);
}

TEST(YogaTest, dont_measure_when_min_equals_max_mixed_width_percent) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
Expand Down
8 changes: 6 additions & 2 deletions yoga/Yoga.c
Original file line number Diff line number Diff line change
Expand Up @@ -2510,7 +2510,9 @@ static void YGNodelayoutImpl(const YGNodeRef node,
availableInnerCrossDim) &&
measureModeCrossDim == YGMeasureModeExactly &&
!(isNodeFlexWrap && flexBasisOverflows) &&
YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch) {
YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch &&
YGMarginLeadingValue(currentRelativeChild, crossAxis)->unit != YGUnitAuto &&
YGMarginTrailingValue(currentRelativeChild, crossAxis)->unit != YGUnitAuto) {
childCrossSize = availableInnerCrossDim;
childCrossMeasureMode = YGMeasureModeExactly;
} else if (!YGNodeIsStyleDimDefined(currentRelativeChild,
Expand Down Expand Up @@ -2546,7 +2548,9 @@ static void YGNodelayoutImpl(const YGNodeRef node,

const bool requiresStretchLayout =
!YGNodeIsStyleDimDefined(currentRelativeChild, crossAxis, availableInnerCrossDim) &&
YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch;
YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch &&
YGMarginLeadingValue(currentRelativeChild, crossAxis)->unit != YGUnitAuto &&
YGMarginTrailingValue(currentRelativeChild, crossAxis)->unit != YGUnitAuto;

const float childWidth = isMainAxisRow ? childMainSize : childCrossSize;
const float childHeight = !isMainAxisRow ? childMainSize : childCrossSize;
Expand Down

0 comments on commit 65cccd3

Please sign in to comment.