fix wrong min-width percentage calculation for child
This commit is contained in:
@@ -107,3 +107,9 @@
|
|||||||
<div style="width: 100%;"></div>
|
<div style="width: 100%;"></div>
|
||||||
</div>
|
</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>
|
@@ -909,3 +909,81 @@ TEST(YogaTest, percent_padding_and_percent_margin_with_measure_func) {
|
|||||||
|
|
||||||
YGConfigFree(config);
|
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);
|
||||||
|
}
|
||||||
|
@@ -4,7 +4,8 @@
|
|||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
* file in the root directory of this source tree.
|
* 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 <gtest/gtest.h>
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
@@ -273,12 +274,12 @@ TEST(YogaTest, percentage_flex_basis_cross_min_height) {
|
|||||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
||||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(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(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(200, YGNodeLayoutGetWidth(root_child1));
|
||||||
ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root_child1));
|
ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child1));
|
||||||
|
|
||||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||||
|
|
||||||
@@ -290,12 +291,12 @@ TEST(YogaTest, percentage_flex_basis_cross_min_height) {
|
|||||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
||||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(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(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(200, YGNodeLayoutGetWidth(root_child1));
|
||||||
ASSERT_FLOAT_EQ(60, YGNodeLayoutGetHeight(root_child1));
|
ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child1));
|
||||||
|
|
||||||
YGNodeFreeRecursive(root);
|
YGNodeFreeRecursive(root);
|
||||||
|
|
||||||
@@ -647,9 +648,7 @@ TEST(YogaTest, percentage_flex_basis_cross_min_width) {
|
|||||||
YGConfigFree(config);
|
YGConfigFree(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(
|
TEST(YogaTest, percentage_multiple_nested_with_padding_margin_and_percentage_values) {
|
||||||
YogaTest,
|
|
||||||
percentage_multiple_nested_with_padding_margin_and_percentage_values) {
|
|
||||||
const YGConfigRef config = YGConfigNew();
|
const YGConfigRef config = YGConfigNew();
|
||||||
|
|
||||||
const YGNodeRef root = YGNodeNewWithConfig(config);
|
const YGNodeRef root = YGNodeNewWithConfig(config);
|
||||||
@@ -1194,78 +1193,56 @@ TEST(YogaTest, percent_absolute_position) {
|
|||||||
YGConfigFree(config);
|
YGConfigFree(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
static YGSize _measureCk_test_label_shrink_based_on_height(
|
TEST(YogaTest, percentage_nested_child) {
|
||||||
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 YGConfigRef config = YGConfigNew();
|
||||||
|
|
||||||
const YGNodeRef root = YGNodeNewWithConfig(config);
|
const YGNodeRef root = YGNodeNewWithConfig(config);
|
||||||
YGNodeStyleSetWidth(root, 320);
|
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
||||||
|
YGNodeStyleSetWidth(root, 40);
|
||||||
|
YGNodeStyleSetHeight(root, 20);
|
||||||
|
|
||||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||||
|
YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow);
|
||||||
|
YGNodeStyleSetWidth(root_child0, 10);
|
||||||
YGNodeInsertChild(root, root_child0, 0);
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config);
|
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);
|
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);
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
|
||||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||||
ASSERT_FLOAT_EQ(320, YGNodeLayoutGetWidth(root));
|
ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root));
|
||||||
ASSERT_FLOAT_EQ(450, YGNodeLayoutGetHeight(root));
|
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root));
|
||||||
|
|
||||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
||||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||||
ASSERT_FLOAT_EQ(320, YGNodeLayoutGetWidth(root_child0));
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0));
|
||||||
ASSERT_FLOAT_EQ(450, YGNodeLayoutGetHeight(root_child0));
|
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0));
|
||||||
|
|
||||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0));
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0));
|
||||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
|
||||||
ASSERT_FLOAT_EQ(320, YGNodeLayoutGetWidth(root_child0_child0));
|
ASSERT_FLOAT_EQ(5, YGNodeLayoutGetWidth(root_child0_child0));
|
||||||
ASSERT_FLOAT_EQ(450, YGNodeLayoutGetHeight(root_child0_child0));
|
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0_child0));
|
||||||
|
|
||||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0));
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||||
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, YGNodeLayoutGetLeft(root));
|
||||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0_child0));
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||||
ASSERT_FLOAT_EQ(290, YGNodeLayoutGetWidth(root_child0_child0_child0_child0));
|
ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root));
|
||||||
ASSERT_FLOAT_EQ(103, YGNodeLayoutGetHeight(root_child0_child0_child0_child0));
|
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);
|
YGNodeFreeRecursive(root);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user