2019-06-06 19:36:56 -07:00
|
|
|
/*
|
2022-10-04 13:59:32 -07:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2016-11-21 10:12:26 -08:00
|
|
|
*
|
2019-10-15 10:30:08 -07:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-11-21 10:12:26 -08:00
|
|
|
*/
|
2019-10-15 10:30:08 -07:00
|
|
|
|
2016-11-21 10:12:26 -08:00
|
|
|
#include <gtest/gtest.h>
|
2017-01-31 09:28:10 -08:00
|
|
|
#include <yoga/Yoga.h>
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2019-03-25 05:37:36 -07:00
|
|
|
static YGSize _measure(
|
2023-09-11 19:51:40 -07:00
|
|
|
YGNodeConstRef /*node*/,
|
2019-03-25 05:37:36 -07:00
|
|
|
float width,
|
|
|
|
YGMeasureMode widthMode,
|
|
|
|
float height,
|
|
|
|
YGMeasureMode heightMode) {
|
2017-01-31 09:28:10 -08:00
|
|
|
return YGSize{
|
2023-01-09 13:59:19 -08:00
|
|
|
widthMode == YGMeasureModeExactly ? width : 50,
|
|
|
|
heightMode == YGMeasureModeExactly ? height : 50,
|
2016-11-21 10:12:26 -08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, aspect_ratio_cross_defined) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetWidth(root_child0, 50);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-11-21 10:12:26 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, aspect_ratio_main_defined) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetHeight(root_child0, 50);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-11-21 10:12:26 -08:00
|
|
|
}
|
|
|
|
|
2016-12-22 02:57:16 -08:00
|
|
|
TEST(YogaTest, aspect_ratio_both_dimensions_defined_row) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-22 02:57:16 -08:00
|
|
|
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-22 02:57:16 -08:00
|
|
|
YGNodeStyleSetWidth(root_child0, 100);
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetHeight(root_child0, 50);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetWidth(root_child0));
|
2016-12-22 02:57:16 -08:00
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(YogaTest, aspect_ratio_both_dimensions_defined_column) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-22 02:57:16 -08:00
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-22 02:57:16 -08:00
|
|
|
YGNodeStyleSetWidth(root_child0, 100);
|
|
|
|
YGNodeStyleSetHeight(root_child0, 50);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
2016-12-03 04:40:18 -08:00
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-11-21 10:12:26 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, aspect_ratio_align_stretch) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetHeight(root_child0));
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-11-21 10:12:26 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, aspect_ratio_flex_grow) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetHeight(root_child0, 50);
|
|
|
|
YGNodeStyleSetFlexGrow(root_child0, 1);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetHeight(root_child0));
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-11-21 10:12:26 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, aspect_ratio_flex_shrink) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetHeight(root_child0, 150);
|
|
|
|
YGNodeStyleSetFlexShrink(root_child0, 1);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetHeight(root_child0));
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-11-21 10:12:26 -08:00
|
|
|
}
|
|
|
|
|
2017-08-21 03:09:09 -07:00
|
|
|
TEST(YogaTest, aspect_ratio_flex_shrink_2) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2017-08-21 03:09:09 -07:00
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2017-08-21 03:09:09 -07:00
|
|
|
YGNodeStyleSetHeightPercent(root_child0, 100);
|
|
|
|
YGNodeStyleSetFlexShrink(root_child0, 1);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child1 = YGNodeNew();
|
2017-08-21 03:09:09 -07:00
|
|
|
YGNodeStyleSetHeightPercent(root_child1, 100);
|
|
|
|
YGNodeStyleSetFlexShrink(root_child1, 1);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child1, 1);
|
|
|
|
YGNodeInsertChild(root, root_child1, 1);
|
|
|
|
|
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child1));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetTop(root_child1));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
|
|
|
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, aspect_ratio_basis) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetFlexBasis(root_child0, 50);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-11-21 10:12:26 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, aspect_ratio_absolute_layout_width_defined) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute);
|
|
|
|
YGNodeStyleSetPosition(root_child0, YGEdgeLeft, 0);
|
|
|
|
YGNodeStyleSetPosition(root_child0, YGEdgeTop, 0);
|
|
|
|
YGNodeStyleSetWidth(root_child0, 50);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-11-21 10:12:26 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, aspect_ratio_absolute_layout_height_defined) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute);
|
|
|
|
YGNodeStyleSetPosition(root_child0, YGEdgeLeft, 0);
|
|
|
|
YGNodeStyleSetPosition(root_child0, YGEdgeTop, 0);
|
|
|
|
YGNodeStyleSetHeight(root_child0, 50);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-11-21 10:12:26 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, aspect_ratio_with_max_cross_defined) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetHeight(root_child0, 50);
|
|
|
|
YGNodeStyleSetMaxWidth(root_child0, 40);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_EQ(40, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-11-21 10:12:26 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, aspect_ratio_with_max_main_defined) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetWidth(root_child0, 50);
|
|
|
|
YGNodeStyleSetMaxHeight(root_child0, 40);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
2017-05-12 09:03:22 -07:00
|
|
|
ASSERT_EQ(40, YGNodeLayoutGetWidth(root_child0));
|
2016-12-03 04:40:18 -08:00
|
|
|
ASSERT_EQ(40, YGNodeLayoutGetHeight(root_child0));
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-11-21 10:12:26 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, aspect_ratio_with_min_cross_defined) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetHeight(root_child0, 30);
|
|
|
|
YGNodeStyleSetMinWidth(root_child0, 40);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_EQ(40, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(30, YGNodeLayoutGetHeight(root_child0));
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-11-21 10:12:26 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, aspect_ratio_with_min_main_defined) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetWidth(root_child0, 30);
|
|
|
|
YGNodeStyleSetMinHeight(root_child0, 40);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
2017-05-12 09:03:22 -07:00
|
|
|
ASSERT_EQ(40, YGNodeLayoutGetWidth(root_child0));
|
2016-12-03 04:40:18 -08:00
|
|
|
ASSERT_EQ(40, YGNodeLayoutGetHeight(root_child0));
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-11-21 10:12:26 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, aspect_ratio_double_cross) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetHeight(root_child0, 50);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 2);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-11-21 10:12:26 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, aspect_ratio_half_cross) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetHeight(root_child0, 100);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 0.5);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetHeight(root_child0));
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-11-21 10:12:26 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, aspect_ratio_double_main) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetWidth(root_child0, 50);
|
2016-12-22 02:57:15 -08:00
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 0.5);
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetHeight(root_child0));
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-11-21 10:12:26 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, aspect_ratio_half_main) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetWidth(root_child0, 100);
|
2016-12-22 02:57:15 -08:00
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 2);
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-11-21 10:12:26 -08:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
TEST(YogaTest, aspect_ratio_with_measure_func) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
C++ Cleanup 3/N: Reorganize YGNode (#1350)
Summary:
X-link: https://github.com/facebook/react-native/pull/39219
Pull Request resolved: https://github.com/facebook/yoga/pull/1350
X-link: https://github.com/facebook/react-native/pull/39170
## This diff
This diff adds a top level `node` directory for code related to Yoga nodes and data structures on them (inc moving `YGLayout` to `LayoutResults`).
The public API for config handles is `YGNodeRef`, which is forward declared to be a pointer to a struct named `YGNode`. The existing `YGNode` is split into `yoga::Node`, as the private C++ implementation, inheriting from `YGNode`, a marker type represented as an empty struct. The public API continues to accept `YGNodeRef`, which continues to be `YGNode *`, but it must be cast to its concrete internal representation at the API boundary before doing work on it.
This change ends up needing to touch quite a bit, due to the amount of code that mixed and matched private and public APIs. Don't be scared though, because these changes are very mechanical, and Phabricator's line-count is 3x the actual amount due to mirrors and dirsyncs.
## This stack
The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers
This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes
This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.
These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.
Changelog: [Internal]
bypass-github-export-checks
Reviewed By: shwanton
Differential Revision: D48847258
fbshipit-source-id: fc560893533b55a5c2d52c37d8e9a59f7369f174
2023-08-30 19:57:16 -07:00
|
|
|
YGNodeSetMeasureFunc(root_child0, _measure);
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
YGNodeFreeRecursive(root);
|
2016-11-21 10:12:26 -08:00
|
|
|
}
|
2016-12-22 02:57:16 -08:00
|
|
|
|
|
|
|
TEST(YogaTest, aspect_ratio_width_height_flex_grow_row) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-22 02:57:16 -08:00
|
|
|
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 200);
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-22 02:57:16 -08:00
|
|
|
YGNodeStyleSetWidth(root_child0, 50);
|
|
|
|
YGNodeStyleSetHeight(root_child0, 50);
|
|
|
|
YGNodeStyleSetFlexGrow(root_child0, 1);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(YogaTest, aspect_ratio_width_height_flex_grow_column) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-22 02:57:16 -08:00
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
|
|
|
YGNodeStyleSetWidth(root, 200);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-22 02:57:16 -08:00
|
|
|
YGNodeStyleSetWidth(root_child0, 50);
|
|
|
|
YGNodeStyleSetHeight(root_child0, 50);
|
|
|
|
YGNodeStyleSetFlexGrow(root_child0, 1);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(YogaTest, aspect_ratio_height_as_flex_basis) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-22 02:57:16 -08:00
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
|
|
|
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
|
|
|
YGNodeStyleSetWidth(root, 200);
|
|
|
|
YGNodeStyleSetHeight(root, 200);
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-22 02:57:16 -08:00
|
|
|
YGNodeStyleSetHeight(root_child0, 50);
|
|
|
|
YGNodeStyleSetFlexGrow(root_child0, 1);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child1 = YGNodeNew();
|
2016-12-22 02:57:16 -08:00
|
|
|
YGNodeStyleSetHeight(root_child1, 100);
|
|
|
|
YGNodeStyleSetFlexGrow(root_child1, 1);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child1, 1);
|
|
|
|
YGNodeInsertChild(root, root_child1, 1);
|
|
|
|
|
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_EQ(75, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(75, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
|
|
|
|
ASSERT_EQ(75, YGNodeLayoutGetLeft(root_child1));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child1));
|
|
|
|
ASSERT_EQ(125, YGNodeLayoutGetWidth(root_child1));
|
|
|
|
ASSERT_EQ(125, YGNodeLayoutGetHeight(root_child1));
|
|
|
|
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(YogaTest, aspect_ratio_width_as_flex_basis) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-22 02:57:16 -08:00
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
|
|
|
YGNodeStyleSetWidth(root, 200);
|
|
|
|
YGNodeStyleSetHeight(root, 200);
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-22 02:57:16 -08:00
|
|
|
YGNodeStyleSetWidth(root_child0, 50);
|
|
|
|
YGNodeStyleSetFlexGrow(root_child0, 1);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child1 = YGNodeNew();
|
2016-12-22 02:57:16 -08:00
|
|
|
YGNodeStyleSetWidth(root_child1, 100);
|
|
|
|
YGNodeStyleSetFlexGrow(root_child1, 1);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child1, 1);
|
|
|
|
YGNodeInsertChild(root, root_child1, 1);
|
|
|
|
|
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_EQ(75, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(75, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child1));
|
|
|
|
ASSERT_EQ(75, YGNodeLayoutGetTop(root_child1));
|
|
|
|
ASSERT_EQ(125, YGNodeLayoutGetWidth(root_child1));
|
|
|
|
ASSERT_EQ(125, YGNodeLayoutGetHeight(root_child1));
|
|
|
|
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(YogaTest, aspect_ratio_overrides_flex_grow_row) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-22 02:57:16 -08:00
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
|
|
|
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-22 02:57:16 -08:00
|
|
|
YGNodeStyleSetWidth(root_child0, 50);
|
|
|
|
YGNodeStyleSetFlexGrow(root_child0, 1);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 0.5);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
2017-08-21 03:09:09 -07:00
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(200, YGNodeLayoutGetHeight(root_child0));
|
2016-12-22 02:57:16 -08:00
|
|
|
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(YogaTest, aspect_ratio_overrides_flex_grow_column) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-22 02:57:16 -08:00
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-22 02:57:16 -08:00
|
|
|
YGNodeStyleSetHeight(root_child0, 50);
|
|
|
|
YGNodeStyleSetFlexGrow(root_child0, 1);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 2);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
2017-08-21 03:09:09 -07:00
|
|
|
ASSERT_EQ(200, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetHeight(root_child0));
|
2016-12-22 02:57:16 -08:00
|
|
|
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(YogaTest, aspect_ratio_left_right_absolute) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-22 02:57:16 -08:00
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-22 02:57:16 -08:00
|
|
|
YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute);
|
|
|
|
YGNodeStyleSetPosition(root_child0, YGEdgeLeft, 10);
|
|
|
|
YGNodeStyleSetPosition(root_child0, YGEdgeTop, 10);
|
|
|
|
YGNodeStyleSetPosition(root_child0, YGEdgeRight, 10);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
|
|
|
|
ASSERT_EQ(10, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(10, YGNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_EQ(80, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(80, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(YogaTest, aspect_ratio_top_bottom_absolute) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-22 02:57:16 -08:00
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-22 02:57:16 -08:00
|
|
|
YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute);
|
|
|
|
YGNodeStyleSetPosition(root_child0, YGEdgeLeft, 10);
|
|
|
|
YGNodeStyleSetPosition(root_child0, YGEdgeTop, 10);
|
|
|
|
YGNodeStyleSetPosition(root_child0, YGEdgeBottom, 10);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
|
|
|
|
ASSERT_EQ(10, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(10, YGNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_EQ(80, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(80, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(YogaTest, aspect_ratio_width_overrides_align_stretch_row) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-22 02:57:16 -08:00
|
|
|
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-22 02:57:16 -08:00
|
|
|
YGNodeStyleSetWidth(root_child0, 50);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(YogaTest, aspect_ratio_height_overrides_align_stretch_column) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2016-12-22 02:57:16 -08:00
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2016-12-22 02:57:16 -08:00
|
|
|
YGNodeStyleSetHeight(root_child0, 50);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
}
|
2017-01-10 08:26:50 -08:00
|
|
|
|
|
|
|
TEST(YogaTest, aspect_ratio_allow_child_overflow_parent_size) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2017-01-10 08:26:50 -08:00
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2017-01-10 08:26:50 -08:00
|
|
|
YGNodeStyleSetHeight(root_child0, 50);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 4);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetWidth(root));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetHeight(root));
|
|
|
|
|
|
|
|
ASSERT_EQ(200, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
}
|
2017-01-27 09:56:35 -08:00
|
|
|
|
|
|
|
TEST(YogaTest, aspect_ratio_defined_main_with_margin) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2017-01-27 09:56:35 -08:00
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignCenter);
|
|
|
|
YGNodeStyleSetJustifyContent(root, YGJustifyCenter);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2017-01-27 09:56:35 -08:00
|
|
|
YGNodeStyleSetHeight(root_child0, 50);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
|
|
|
YGNodeStyleSetMargin(root_child0, YGEdgeLeft, 10);
|
|
|
|
YGNodeStyleSetMargin(root_child0, YGEdgeRight, 10);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetWidth(root));
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetHeight(root));
|
|
|
|
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(YogaTest, aspect_ratio_defined_cross_with_margin) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2017-01-27 09:56:35 -08:00
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignCenter);
|
|
|
|
YGNodeStyleSetJustifyContent(root, YGJustifyCenter);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2017-01-27 09:56:35 -08:00
|
|
|
YGNodeStyleSetWidth(root_child0, 50);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
|
|
|
YGNodeStyleSetMargin(root_child0, YGEdgeLeft, 10);
|
|
|
|
YGNodeStyleSetMargin(root_child0, YGEdgeRight, 10);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetWidth(root));
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetHeight(root));
|
|
|
|
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
}
|
2017-08-21 03:09:09 -07:00
|
|
|
|
2018-02-15 07:16:59 -08:00
|
|
|
TEST(YogaTest, aspect_ratio_defined_cross_with_main_margin) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNew();
|
2018-02-15 07:16:59 -08:00
|
|
|
YGNodeStyleSetAlignItems(root, YGAlignCenter);
|
|
|
|
YGNodeStyleSetJustifyContent(root, YGJustifyCenter);
|
|
|
|
YGNodeStyleSetWidth(root, 100);
|
|
|
|
YGNodeStyleSetHeight(root, 100);
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNew();
|
2018-02-15 07:16:59 -08:00
|
|
|
YGNodeStyleSetWidth(root_child0, 50);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 1);
|
|
|
|
YGNodeStyleSetMargin(root_child0, YGEdgeTop, 10);
|
|
|
|
YGNodeStyleSetMargin(root_child0, YGEdgeBottom, 10);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetWidth(root));
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetHeight(root));
|
|
|
|
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
}
|
|
|
|
|
2017-08-21 03:09:09 -07:00
|
|
|
TEST(YogaTest, aspect_ratio_should_prefer_explicit_height) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGConfigRef config = YGConfigNew();
|
2017-08-21 03:09:09 -07:00
|
|
|
YGConfigSetUseWebDefaults(config, true);
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNewWithConfig(config);
|
2017-08-21 03:09:09 -07:00
|
|
|
YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn);
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
2017-08-21 03:09:09 -07:00
|
|
|
YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionColumn);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config);
|
2017-08-21 03:09:09 -07:00
|
|
|
YGNodeStyleSetFlexDirection(root_child0_child0, YGFlexDirectionColumn);
|
|
|
|
YGNodeStyleSetHeight(root_child0_child0, 100);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0_child0, 2);
|
|
|
|
YGNodeInsertChild(root_child0, root_child0_child0, 0);
|
|
|
|
|
|
|
|
YGNodeCalculateLayout(root, 100, 200, YGDirectionLTR);
|
|
|
|
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetWidth(root));
|
|
|
|
ASSERT_EQ(200, YGNodeLayoutGetHeight(root));
|
|
|
|
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
|
|
|
|
ASSERT_EQ(200, YGNodeLayoutGetWidth(root_child0_child0));
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetHeight(root_child0_child0));
|
|
|
|
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(YogaTest, aspect_ratio_should_prefer_explicit_width) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGConfigRef config = YGConfigNew();
|
2017-08-21 03:09:09 -07:00
|
|
|
YGConfigSetUseWebDefaults(config, true);
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNewWithConfig(config);
|
2017-08-21 03:09:09 -07:00
|
|
|
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
2017-08-21 03:09:09 -07:00
|
|
|
YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config);
|
2017-08-21 03:09:09 -07:00
|
|
|
YGNodeStyleSetFlexDirection(root_child0_child0, YGFlexDirectionRow);
|
|
|
|
YGNodeStyleSetWidth(root_child0_child0, 100);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0_child0, 0.5);
|
|
|
|
YGNodeInsertChild(root_child0, root_child0_child0, 0);
|
|
|
|
|
|
|
|
YGNodeCalculateLayout(root, 200, 100, YGDirectionLTR);
|
|
|
|
|
|
|
|
ASSERT_EQ(200, YGNodeLayoutGetWidth(root));
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetHeight(root));
|
|
|
|
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetWidth(root_child0_child0));
|
|
|
|
ASSERT_EQ(200, YGNodeLayoutGetHeight(root_child0_child0));
|
|
|
|
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(YogaTest, aspect_ratio_should_prefer_flexed_dimension) {
|
2024-07-03 17:30:10 -07:00
|
|
|
YGConfigRef config = YGConfigNew();
|
2017-08-21 03:09:09 -07:00
|
|
|
YGConfigSetUseWebDefaults(config, true);
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root = YGNodeNewWithConfig(config);
|
2017-08-21 03:09:09 -07:00
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
2017-08-21 03:09:09 -07:00
|
|
|
YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionColumn);
|
|
|
|
YGNodeStyleSetAspectRatio(root_child0, 2);
|
|
|
|
YGNodeStyleSetFlexGrow(root_child0, 1);
|
|
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
2024-07-03 17:30:10 -07:00
|
|
|
YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config);
|
2017-08-21 03:09:09 -07:00
|
|
|
YGNodeStyleSetAspectRatio(root_child0_child0, 4);
|
|
|
|
YGNodeStyleSetFlexGrow(root_child0_child0, 1);
|
|
|
|
YGNodeInsertChild(root_child0, root_child0_child0, 0);
|
|
|
|
|
|
|
|
YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR);
|
|
|
|
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetWidth(root));
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetHeight(root));
|
|
|
|
|
|
|
|
ASSERT_EQ(100, YGNodeLayoutGetWidth(root_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
|
|
|
|
ASSERT_EQ(200, YGNodeLayoutGetWidth(root_child0_child0));
|
|
|
|
ASSERT_EQ(50, YGNodeLayoutGetHeight(root_child0_child0));
|
|
|
|
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
}
|