diff --git a/gentest/fixtures/YGMarginTest.html b/gentest/fixtures/YGMarginTest.html
index 60924c8f..b7fb4fa1 100644
--- a/gentest/fixtures/YGMarginTest.html
+++ b/gentest/fixtures/YGMarginTest.html
@@ -149,4 +149,14 @@
\ No newline at end of file
+
+
+
+
+
diff --git a/tests/YGMarginTest.cpp b/tests/YGMarginTest.cpp
index e857da09..bc827281 100644
--- a/tests/YGMarginTest.cpp
+++ b/tests/YGMarginTest.cpp
@@ -4,7 +4,8 @@
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*/
-// @Generated by gentest/gentest.rb from gentest/fixtures/YGMarginTest.html
+// @Generated by gentest/gentest.rb from
+// gentest/fixtures/YGMarginTest.html
#include
#include
@@ -1714,3 +1715,111 @@ TEST(YogaTest, margin_auto_left_stretching_child) {
YGConfigFree(config);
}
+
+TEST(YogaTest, margin_top_auto_overflow_parent) {
+ const YGConfigRef config = YGConfigNew();
+
+ const YGNodeRef root = YGNodeNewWithConfig(config);
+ YGNodeStyleSetWidth(root, 20);
+ YGNodeStyleSetHeight(root, 500);
+
+ const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetHeight(root_child0, 300);
+ YGNodeInsertChild(root, root_child0, 0);
+
+ const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetMarginAuto(root_child1, YGEdgeTop);
+ YGNodeStyleSetHeight(root_child1, 300);
+ YGNodeInsertChild(root, root_child1, 1);
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(300, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(300, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(300, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(300, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(300, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(300, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeFreeRecursive(root);
+
+ YGConfigFree(config);
+}
+
+TEST(YogaTest, margin_bottom_auto_overflow_parent) {
+ const YGConfigRef config = YGConfigNew();
+
+ const YGNodeRef root = YGNodeNewWithConfig(config);
+ YGNodeStyleSetWidth(root, 20);
+ YGNodeStyleSetHeight(root, 500);
+
+ const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetHeight(root_child0, 300);
+ YGNodeInsertChild(root, root_child0, 0);
+
+ const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetMarginAuto(root_child1, YGEdgeTop);
+ YGNodeStyleSetHeight(root_child1, 300);
+ YGNodeInsertChild(root, root_child1, 1);
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(300, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(300, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(300, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(300, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(300, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(300, YGNodeLayoutGetHeight(root_child1));
+
+ YGNodeFreeRecursive(root);
+
+ YGConfigFree(config);
+}
diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp
index 91e09c15..0812995e 100644
--- a/yoga/Yoga.cpp
+++ b/yoga/Yoga.cpp
@@ -2590,7 +2590,8 @@ static void YGJustifyMainAxis(
// We need to do that only for relative elements. Absolute elements do not
// take part in that phase.
if (childStyle.positionType() == YGPositionTypeRelative) {
- if (child->marginLeadingValue(mainAxis).unit == YGUnitAuto) {
+ if (child->marginLeadingValue(mainAxis).unit == YGUnitAuto
+ && collectedFlexItemsValues.remainingFreeSpace > 0.0f) {
collectedFlexItemsValues.mainDim +=
collectedFlexItemsValues.remainingFreeSpace /
numberOfAutoMarginsOnCurrentLine;
@@ -2603,7 +2604,8 @@ static void YGJustifyMainAxis(
pos[mainAxis]);
}
- if (child->marginTrailingValue(mainAxis).unit == YGUnitAuto) {
+ if (child->marginTrailingValue(mainAxis).unit == YGUnitAuto
+ && collectedFlexItemsValues.remainingFreeSpace > 0.0f) {
collectedFlexItemsValues.mainDim +=
collectedFlexItemsValues.remainingFreeSpace /
numberOfAutoMarginsOnCurrentLine;