diff --git a/CSSLayout/CSSLayout.c b/CSSLayout/CSSLayout.c index e44429b7..c50095bf 100644 --- a/CSSLayout/CSSLayout.c +++ b/CSSLayout/CSSLayout.c @@ -1514,10 +1514,14 @@ static void layoutNodeImpl(const CSSNodeRef node, // that are aligned "stretch". We need to compute these stretch values and // set the final positions. - // If we are using "at most" rules in the main axis, we won't distribute - // any remaining space at this point. + // If we are using "at most" rules in the main axis. Calculate the remaining space when + // constraint by the min size defined for the main axis. if (measureModeMainDim == CSSMeasureModeAtMost) { - remainingFreeSpace = 0; + if (!CSSValueIsUndefined(node->style.minDimensions[dim[mainAxis]]) && node->style.minDimensions[dim[mainAxis]] >= 0) { + remainingFreeSpace = fmaxf(0, node->style.minDimensions[dim[mainAxis]] - (availableInnerMainDim - remainingFreeSpace)); + } else { + remainingFreeSpace = 0; + } } switch (justifyContent) { diff --git a/tests/CSSLayoutMinMaxDimensionTest.cpp b/tests/CSSLayoutMinMaxDimensionTest.cpp index 4bcb4911..72501e43 100644 --- a/tests/CSSLayoutMinMaxDimensionTest.cpp +++ b/tests/CSSLayoutMinMaxDimensionTest.cpp @@ -27,6 +27,14 @@
+ +
+
+
+ +
+
+
* */ @@ -206,3 +214,79 @@ TEST(CSSLayoutTest, min_width) { CSSNodeFreeRecursive(root); } + +TEST(CSSLayoutTest, justify_content_min_max) { + const CSSNodeRef root = CSSNodeNew(); + CSSNodeStyleSetJustifyContent(root, CSSJustifyCenter); + CSSNodeStyleSetWidth(root, 100); + CSSNodeStyleSetMinHeight(root, 100); + CSSNodeStyleSetMaxHeight(root, 200); + + const CSSNodeRef root_child0 = CSSNodeNew(); + CSSNodeStyleSetWidth(root_child0, 60); + CSSNodeStyleSetHeight(root_child0, 60); + CSSNodeInsertChild(root, root_child0, 0); + CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); + + ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); + ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); + ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); + ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); + + ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(20, CSSNodeLayoutGetTop(root_child0)); + ASSERT_EQ(60, CSSNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(60, CSSNodeLayoutGetHeight(root_child0)); + + CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); + + ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); + ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); + ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); + ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); + + ASSERT_EQ(40, CSSNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(20, CSSNodeLayoutGetTop(root_child0)); + ASSERT_EQ(60, CSSNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(60, CSSNodeLayoutGetHeight(root_child0)); + + CSSNodeFreeRecursive(root); +} + +TEST(CSSLayoutTest, align_items_min_max) { + const CSSNodeRef root = CSSNodeNew(); + CSSNodeStyleSetAlignItems(root, CSSAlignCenter); + CSSNodeStyleSetMinWidth(root, 100); + CSSNodeStyleSetMaxWidth(root, 200); + CSSNodeStyleSetHeight(root, 100); + + const CSSNodeRef root_child0 = CSSNodeNew(); + CSSNodeStyleSetWidth(root_child0, 60); + CSSNodeStyleSetHeight(root_child0, 60); + CSSNodeInsertChild(root, root_child0, 0); + CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); + + ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); + ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); + ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); + ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); + + ASSERT_EQ(20, CSSNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); + ASSERT_EQ(60, CSSNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(60, CSSNodeLayoutGetHeight(root_child0)); + + CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); + + ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); + ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); + ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); + ASSERT_EQ(100, CSSNodeLayoutGetHeight(root)); + + ASSERT_EQ(20, CSSNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0)); + ASSERT_EQ(60, CSSNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(60, CSSNodeLayoutGetHeight(root_child0)); + + CSSNodeFreeRecursive(root); +}