Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions gentest/fixtures/YGPercentageTest.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,9 @@
<div style="width: 100%;"></div>
</div>
</div>

<div id="percentage_nested_child" style="flex-direction: row; width: 40px; height: 20px;">
<div style="flex-direction: row; width: 10px;">
<div style="flex-direction: row; min-width: 50%;"></div>
</div>
</div>
78 changes: 78 additions & 0 deletions tests/YGMeasureTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
101 changes: 39 additions & 62 deletions tests/YGPercentageTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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/YGPercentageTest.html
// @Generated by gentest/gentest.rb from
// gentest/fixtures/YGPercentageTest.html

#include <gtest/gtest.h>
#include <yoga/Yoga.h>
Expand Down Expand Up @@ -273,12 +274,12 @@ TEST(YogaTest, percentage_flex_basis_cross_min_height) {
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(140, YGNodeLayoutGetHeight(root_child0));
ASSERT_FLOAT_EQ(120, YGNodeLayoutGetHeight(root_child0));

ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
ASSERT_FLOAT_EQ(140, YGNodeLayoutGetTop(root_child1));
ASSERT_FLOAT_EQ(120, YGNodeLayoutGetTop(root_child1));
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child1));
ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root_child1));
ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child1));

YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);

Expand All @@ -290,12 +291,12 @@ TEST(YogaTest, percentage_flex_basis_cross_min_height) {
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(140, YGNodeLayoutGetHeight(root_child0));
ASSERT_FLOAT_EQ(120, YGNodeLayoutGetHeight(root_child0));

ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
ASSERT_FLOAT_EQ(140, YGNodeLayoutGetTop(root_child1));
ASSERT_FLOAT_EQ(120, YGNodeLayoutGetTop(root_child1));
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child1));
ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root_child1));
ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child1));

YGNodeFreeRecursive(root);

Expand Down Expand Up @@ -647,9 +648,7 @@ TEST(YogaTest, percentage_flex_basis_cross_min_width) {
YGConfigFree(config);
}

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

const YGNodeRef root = YGNodeNewWithConfig(config);
Expand Down Expand Up @@ -1194,78 +1193,56 @@ TEST(YogaTest, percent_absolute_position) {
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) {
TEST(YogaTest, percentage_nested_child) {
const YGConfigRef config = YGConfigNew();

const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root, 320);
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
YGNodeStyleSetWidth(root, 40);
YGNodeStyleSetHeight(root, 20);

const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow);
YGNodeStyleSetWidth(root_child0, 10);
YGNodeInsertChild(root, root_child0, 0);

const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetHeight(root_child0_child0, 450);
YGNodeStyleSetFlexDirection(root_child0_child0, YGFlexDirectionRow);
YGNodeStyleSetMinWidthPercent(root_child0_child0, 50);
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(40, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(20, 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(10, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(20, 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(5, YGNodeLayoutGetWidth(root_child0_child0));
ASSERT_FLOAT_EQ(20, 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));
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);

ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root));

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

ASSERT_FLOAT_EQ(5, YGNodeLayoutGetLeft(root_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
ASSERT_FLOAT_EQ(5, YGNodeLayoutGetWidth(root_child0_child0));
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0_child0));

YGNodeFreeRecursive(root);

Expand Down
4 changes: 2 additions & 2 deletions yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2070,7 +2070,7 @@ static float YGDistributeFreeSpaceSecondPass(
currentRelativeChild,
mainAxis,
currentRelativeChild->getLayout().computedFlexBasis,
mainAxisownerSize)
availableInnerMainDim)
.unwrap();
float updatedMainSize = childFlexBasis;

Expand Down Expand Up @@ -2256,7 +2256,7 @@ static void YGDistributeFreeSpaceFirstPass(
currentRelativeChild,
mainAxis,
currentRelativeChild->getLayout().computedFlexBasis,
mainAxisownerSize)
availableInnerMainDim)
.unwrap();

if (collectedFlexItemsValues.remainingFreeSpace < 0) {
Expand Down