fix wrong min-width percentage calculation for child

This commit is contained in:
Lukas Wöhrl
2020-06-11 16:44:59 +02:00
parent ede65bbce4
commit 2e9c2d4d7a
3 changed files with 122 additions and 61 deletions

View File

@@ -909,3 +909,81 @@ TEST(YogaTest, percent_padding_and_percent_margin_with_measure_func) {
YGConfigFree(config);
}
static YGSize _measureCk_test_label_shrink_based_on_height(
YGNodeRef node,
float width,
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode) {
if (heightMode == YGMeasureModeAtMost) {
return YGSize{
.width = 290,
.height = 103,
};
} else {
return YGSize{
.width = 290,
.height = height,
};
}
}
TEST(YogaTest, margin_percent_with_measure_func) {
const YGConfigRef config = YGConfigNew();
const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root, 320);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetHeight(root_child0_child0, 450);
YGNodeInsertChild(root_child0, root_child0_child0, 0);
const YGNodeRef root_child0_child0_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexDirection(root_child0_child0_child0, YGFlexDirectionRow);
YGNodeStyleSetMarginPercent(root_child0_child0_child0, YGEdgeTop, 5);
YGNodeInsertChild(root_child0_child0, root_child0_child0_child0, 0);
const YGNodeRef root_child0_child0_child0_child0 =
YGNodeNewWithConfig(config);
YGNodeSetMeasureFunc(
root_child0_child0_child0_child0,
_measureCk_test_label_shrink_based_on_height);
YGNodeInsertChild(
root_child0_child0_child0, root_child0_child0_child0_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(320, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(450, YGNodeLayoutGetHeight(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(320, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(450, YGNodeLayoutGetHeight(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
ASSERT_FLOAT_EQ(320, YGNodeLayoutGetWidth(root_child0_child0));
ASSERT_FLOAT_EQ(450, YGNodeLayoutGetHeight(root_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0));
ASSERT_FLOAT_EQ(16, YGNodeLayoutGetTop(root_child0_child0_child0));
ASSERT_FLOAT_EQ(320, YGNodeLayoutGetWidth(root_child0_child0_child0));
ASSERT_FLOAT_EQ(103, YGNodeLayoutGetHeight(root_child0_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0_child0));
ASSERT_FLOAT_EQ(290, YGNodeLayoutGetWidth(root_child0_child0_child0_child0));
ASSERT_FLOAT_EQ(103, YGNodeLayoutGetHeight(root_child0_child0_child0_child0));
YGNodeFreeRecursive(root);
YGConfigFree(config);
}