Skip to content

Commit

Permalink
fix min/max percentage constraints on measured nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
woehrl01 committed Oct 9, 2017
1 parent 7217471 commit 08295a0
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
52 changes: 52 additions & 0 deletions tests/YGMeasureTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,3 +614,55 @@ TEST(YogaTest, cant_call_negative_measure_horizontal) {
YGNodeFreeRecursive(root);
YGConfigFree(config);
}

static YGSize _measure_90_10(YGNodeRef node,
float width,
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode) {

return YGSize{
.width = 90, .height = 10,
};
}

TEST(YogaTest, percent_with_text_node) {
const YGConfigRef config = YGConfigNew();

const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
YGNodeStyleSetJustifyContent(root, YGJustifySpaceBetween);
YGNodeStyleSetAlignItems(root, YGAlignCenter);
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 20);

const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeInsertChild(root, root_child0, 0);

const YGNodeRef root_child1 = YGNodeNewWithConfig(config);

YGNodeSetMeasureFunc(root_child1, _measure_90_10);
YGNodeStyleSetMaxWidthPercent(root_child1, 50);
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(100, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root));

ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0));

ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1));
ASSERT_FLOAT_EQ(5, YGNodeLayoutGetTop(root_child1));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1));

YGNodeFreeRecursive(root);

YGConfigFree(config);
}
4 changes: 2 additions & 2 deletions yoga/Yoga.c
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,7 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions(const YGNodeRef node,
widthMeasureMode == YGMeasureModeAtMost)
? measuredSize.width + paddingAndBorderAxisRow
: availableWidth - marginAxisRow,
availableWidth,
parentWidth,
availableWidth);
node->layout.measuredDimensions[YGDimensionHeight] =
YGNodeBoundAxis(node,
Expand All @@ -1784,7 +1784,7 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions(const YGNodeRef node,
heightMeasureMode == YGMeasureModeAtMost)
? measuredSize.height + paddingAndBorderAxisColumn
: availableHeight - marginAxisColumn,
availableHeight,
parentHeight,
availableWidth);
}
}
Expand Down

0 comments on commit 08295a0

Please sign in to comment.