From 0a314012f489c5061eb928a9b29af99bec29eaf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Sj=C3=B6lander?= Date: Sat, 24 Nov 2018 14:31:14 +0000 Subject: [PATCH 1/2] Add failing test --- tests/YGAspectRatioTest.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/YGAspectRatioTest.cpp b/tests/YGAspectRatioTest.cpp index 8f2dc8e3..4b222626 100644 --- a/tests/YGAspectRatioTest.cpp +++ b/tests/YGAspectRatioTest.cpp @@ -896,3 +896,24 @@ TEST(YogaTest, aspect_ratio_should_prefer_flexed_dimension) { YGNodeFreeRecursive(root); } + +TEST(YogaTest, aspect_ratio_defined_by_cross_stretch_should_not_be_effected_by_margin_on_main_axis) { + const YGConfigRef config = YGConfigNew(); + YGConfigSetUseWebDefaults(config, true); + + const YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetWidth(root, 200); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetMargin(root_child0, YGEdgeStart, 50); + YGNodeStyleSetAspectRatio(root_child0, 1); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_EQ(100, YGNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); +} -- 2.50.1.windows.1 From 58af41b5462672b3591f0c3bcaeb7c61b845cdff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Sj=C3=B6lander?= Date: Sat, 24 Nov 2018 15:41:58 +0000 Subject: [PATCH 2/2] Set stretch to mean exact measurement --- yoga/Yoga.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 10f27bf0..f3863e15 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -1371,6 +1371,16 @@ static void YGNodeComputeFlexBasisForChild( auto marginColumn = YGUnwrapFloatOptional( child->getMarginForAxis(YGFlexDirectionColumn, ownerWidth)); + if (YGNodeAlignItem(node, child) == YGAlignStretch) { + if (isMainAxisRow && !YGFloatIsUndefined(height)) { + childHeight = height; + childHeightMeasureMode = YGMeasureModeExactly; + } else if (!isMainAxisRow && !YGFloatIsUndefined(width)) { + childWidth = width; + childWidthMeasureMode = YGMeasureModeExactly; + } + } + if (isRowStyleDimDefined) { childWidth = YGUnwrapFloatOptional(YGResolveValue( -- 2.50.1.windows.1