diff --git a/tests/YGMeasureTest.cpp b/tests/YGMeasureTest.cpp index 6dba795546..3a03c8cd86 100644 --- a/tests/YGMeasureTest.cpp +++ b/tests/YGMeasureTest.cpp @@ -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); diff --git a/yoga/Yoga.c b/yoga/Yoga.c index 84aa5a7572..a83f63606e 100644 --- a/yoga/Yoga.c +++ b/yoga/Yoga.c @@ -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, @@ -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;