[YogaKit] support macOS, tvOS, Carthage; auto apply layout like AutoLayout. #1026

Closed
cntrump wants to merge 38 commits from yogakit_autoapplylayout_patch into main
94 changed files with 3769 additions and 650 deletions
Showing only changes of commit b7cc9f9dac - Show all commits

View File

@@ -251,7 +251,7 @@ TEST_F(EventTest, layout_events_has_max_measure_cache) {
TEST_F(EventTest, measure_functions_get_wrapped) { TEST_F(EventTest, measure_functions_get_wrapped) {
auto root = YGNodeNew(); auto root = YGNodeNew();
YGNodeSetMeasureFunc( YGNodeSetMeasureFunc(
root, [](YGNodeRef, float, YGMeasureMode, float, YGMeasureMode) { root, [](YGNodeRef, YGFloat, YGMeasureMode, YGFloat, YGMeasureMode) {
return YGSize{}; return YGSize{};
}); });
@@ -269,7 +269,7 @@ TEST_F(EventTest, baseline_functions_get_wrapped) {
auto child = YGNodeNew(); auto child = YGNodeNew();
YGNodeInsertChild(root, child, 0); YGNodeInsertChild(root, child, 0);
YGNodeSetBaselineFunc(child, [](YGNodeRef, float, float) { return 0.0f; }); YGNodeSetBaselineFunc(child, [](YGNodeRef, YGFloat, YGFloat) { return 0.0; });
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
YGNodeStyleSetAlignItems(root, YGAlignBaseline); YGNodeStyleSetAlignItems(root, YGAlignBaseline);

View File

@@ -9,18 +9,18 @@
#include <yoga/YGNode.h> #include <yoga/YGNode.h>
#include <yoga/Yoga.h> #include <yoga/Yoga.h>
static float _baselineFunc( static YGFloat _baselineFunc(
YGNodeRef node, YGNodeRef node,
const float width, const YGFloat width,
const float height) { const YGFloat height) {
return height / 2; return height / 2;
} }
static YGSize _measure1( static YGSize _measure1(
YGNodeRef node, YGNodeRef node,
float width, YGFloat width,
YGMeasureMode widthMode, YGMeasureMode widthMode,
float height, YGFloat height,
YGMeasureMode heightMode) { YGMeasureMode heightMode) {
return YGSize{ return YGSize{
.width = 42, .width = 42,
@@ -30,9 +30,9 @@ static YGSize _measure1(
static YGSize _measure2( static YGSize _measure2(
YGNodeRef node, YGNodeRef node,
float width, YGFloat width,
YGMeasureMode widthMode, YGMeasureMode widthMode,
float height, YGFloat height,
YGMeasureMode heightMode) { YGMeasureMode heightMode) {
return YGSize{ return YGSize{
.width = 279, .width = 279,

View File

@@ -11,9 +11,9 @@
static YGSize _measure( static YGSize _measure(
YGNodeRef node, YGNodeRef node,
float width, YGFloat width,
YGMeasureMode widthMode, YGMeasureMode widthMode,
float height, YGFloat height,
YGMeasureMode heightMode) { YGMeasureMode heightMode) {
return YGSize{ return YGSize{
.width = widthMode == YGMeasureModeExactly ? width : 50, .width = widthMode == YGMeasureModeExactly ? width : 50,

View File

@@ -9,8 +9,8 @@
#include <yoga/YGNode.h> #include <yoga/YGNode.h>
#include <yoga/Yoga.h> #include <yoga/Yoga.h>
static float _baseline(YGNodeRef node, const float width, const float height) { static YGFloat _baseline(YGNodeRef node, const YGFloat width, const YGFloat height) {
float* baseline = (float*) node->getContext(); YGFloat* baseline = (YGFloat*) node->getContext();
return *baseline; return *baseline;
} }
@@ -31,7 +31,7 @@ TEST(YogaTest, align_baseline_customer_func) {
YGNodeStyleSetHeight(root_child1, 20); YGNodeStyleSetHeight(root_child1, 20);
YGNodeInsertChild(root, root_child1, 1); YGNodeInsertChild(root, root_child1, 1);
float baselineValue = 10; YGFloat baselineValue = 10;
const YGNodeRef root_child1_child0 = YGNodeNew(); const YGNodeRef root_child1_child0 = YGNodeNew();
root_child1_child0->setContext(&baselineValue); root_child1_child0->setContext(&baselineValue);
YGNodeStyleSetWidth(root_child1_child0, 50); YGNodeStyleSetWidth(root_child1_child0, 50);

View File

@@ -11,9 +11,9 @@
static YGSize _measureMax( static YGSize _measureMax(
YGNodeRef node, YGNodeRef node,
float width, YGFloat width,
YGMeasureMode widthMode, YGMeasureMode widthMode,
float height, YGFloat height,
YGMeasureMode heightMode) { YGMeasureMode heightMode) {
int* measureCount = (int*) node->getContext(); int* measureCount = (int*) node->getContext();
(*measureCount)++; (*measureCount)++;
@@ -26,9 +26,9 @@ static YGSize _measureMax(
static YGSize _measureMin( static YGSize _measureMin(
YGNodeRef node, YGNodeRef node,
float width, YGFloat width,
YGMeasureMode widthMode, YGMeasureMode widthMode,
float height, YGFloat height,
YGMeasureMode heightMode) { YGMeasureMode heightMode) {
int* measureCount = (int*) node->getContext(); int* measureCount = (int*) node->getContext();
*measureCount = *measureCount + 1; *measureCount = *measureCount + 1;
@@ -46,9 +46,9 @@ static YGSize _measureMin(
static YGSize _measure_84_49( static YGSize _measure_84_49(
YGNodeRef node, YGNodeRef node,
float width, YGFloat width,
YGMeasureMode widthMode, YGMeasureMode widthMode,
float height, YGFloat height,
YGMeasureMode heightMode) { YGMeasureMode heightMode) {
int* measureCount = (int*) node->getContext(); int* measureCount = (int*) node->getContext();
if (measureCount) { if (measureCount) {

View File

@@ -10,9 +10,9 @@
#include <yoga/Yoga.h> #include <yoga/Yoga.h>
struct _MeasureConstraint { struct _MeasureConstraint {
float width; YGFloat width;
YGMeasureMode widthMode; YGMeasureMode widthMode;
float height; YGFloat height;
YGMeasureMode heightMode; YGMeasureMode heightMode;
}; };
@@ -23,9 +23,9 @@ struct _MeasureConstraintList {
static YGSize _measure( static YGSize _measure(
YGNodeRef node, YGNodeRef node,
float width, YGFloat width,
YGMeasureMode widthMode, YGMeasureMode widthMode,
float height, YGFloat height,
YGMeasureMode heightMode) { YGMeasureMode heightMode) {
struct _MeasureConstraintList* constraintList = struct _MeasureConstraintList* constraintList =
(struct _MeasureConstraintList*) node->getContext(); (struct _MeasureConstraintList*) node->getContext();

View File

@@ -11,9 +11,9 @@
static YGSize _measure( static YGSize _measure(
YGNodeRef node, YGNodeRef node,
float width, YGFloat width,
YGMeasureMode widthMode, YGMeasureMode widthMode,
float height, YGFloat height,
YGMeasureMode heightMode) { YGMeasureMode heightMode) {
int* measureCount = (int*) node->getContext(); int* measureCount = (int*) node->getContext();
if (measureCount) { if (measureCount) {
@@ -28,9 +28,9 @@ static YGSize _measure(
static YGSize _simulate_wrapping_text( static YGSize _simulate_wrapping_text(
YGNodeRef node, YGNodeRef node,
float width, YGFloat width,
YGMeasureMode widthMode, YGMeasureMode widthMode,
float height, YGFloat height,
YGMeasureMode heightMode) { YGMeasureMode heightMode) {
if (widthMode == YGMeasureModeUndefined || width >= 68) { if (widthMode == YGMeasureModeUndefined || width >= 68) {
return YGSize{.width = 68, .height = 16}; return YGSize{.width = 68, .height = 16};
@@ -44,9 +44,9 @@ static YGSize _simulate_wrapping_text(
static YGSize _measure_assert_negative( static YGSize _measure_assert_negative(
YGNodeRef node, YGNodeRef node,
float width, YGFloat width,
YGMeasureMode widthMode, YGMeasureMode widthMode,
float height, YGFloat height,
YGMeasureMode heightMode) { YGMeasureMode heightMode) {
EXPECT_GE(width, 0); EXPECT_GE(width, 0);
EXPECT_GE(height, 0); EXPECT_GE(height, 0);
@@ -643,9 +643,9 @@ TEST(YogaTest, cant_call_negative_measure_horizontal) {
static YGSize _measure_90_10( static YGSize _measure_90_10(
YGNodeRef node, YGNodeRef node,
float width, YGFloat width,
YGMeasureMode widthMode, YGMeasureMode widthMode,
float height, YGFloat height,
YGMeasureMode heightMode) { YGMeasureMode heightMode) {
return YGSize{ return YGSize{
@@ -656,9 +656,9 @@ static YGSize _measure_90_10(
static YGSize _measure_100_100( static YGSize _measure_100_100(
YGNodeRef node, YGNodeRef node,
float width, YGFloat width,
YGMeasureMode widthMode, YGMeasureMode widthMode,
float height, YGFloat height,
YGMeasureMode heightMode) { YGMeasureMode heightMode) {
return YGSize{ return YGSize{

View File

@@ -1298,9 +1298,9 @@ TEST(YogaTest, min_max_percent_no_width_height) {
static YGSize _measureCk_test_label_shrink_based_on_height( static YGSize _measureCk_test_label_shrink_based_on_height(
YGNodeRef node, YGNodeRef node,
float width, YGFloat width,
YGMeasureMode widthMode, YGMeasureMode widthMode,
float height, YGFloat height,
YGMeasureMode heightMode) { YGMeasureMode heightMode) {
if (heightMode == YGMeasureModeAtMost) { if (heightMode == YGMeasureModeAtMost) {

View File

@@ -22,7 +22,7 @@ TEST(YGNode, hasMeasureFunc_initial) {
TEST(YGNode, hasMeasureFunc_with_measure_fn) { TEST(YGNode, hasMeasureFunc_with_measure_fn) {
auto n = YGNode{}; auto n = YGNode{};
n.setMeasureFunc([](YGNode*, float, YGMeasureMode, float, YGMeasureMode) { n.setMeasureFunc([](YGNode*, YGFloat, YGMeasureMode, YGFloat, YGMeasureMode) {
return YGSize{}; return YGSize{};
}); });
ASSERT_TRUE(n.hasMeasureFunc()); ASSERT_TRUE(n.hasMeasureFunc());
@@ -32,7 +32,7 @@ TEST(YGNode, measure_with_measure_fn) {
auto n = YGNode{}; auto n = YGNode{};
n.setMeasureFunc( n.setMeasureFunc(
[](YGNode*, float w, YGMeasureMode wm, float h, YGMeasureMode hm) { [](YGNode*, YGFloat w, YGMeasureMode wm, YGFloat h, YGMeasureMode hm) {
return YGSize{w * wm, h / hm}; return YGSize{w * wm, h / hm};
}); });
@@ -44,7 +44,7 @@ TEST(YGNode, measure_with_measure_fn) {
TEST(YGNode, measure_with_context_measure_fn) { TEST(YGNode, measure_with_context_measure_fn) {
auto n = YGNode{}; auto n = YGNode{};
n.setMeasureFunc( n.setMeasureFunc(
[](YGNode*, float, YGMeasureMode, float, YGMeasureMode, void* ctx) { [](YGNode*, YGFloat, YGMeasureMode, YGFloat, YGMeasureMode, void* ctx) {
return *(YGSize*) ctx; return *(YGSize*) ctx;
}); });
@@ -57,11 +57,11 @@ TEST(YGNode, measure_with_context_measure_fn) {
TEST(YGNode, switching_measure_fn_types) { TEST(YGNode, switching_measure_fn_types) {
auto n = YGNode{}; auto n = YGNode{};
n.setMeasureFunc( n.setMeasureFunc(
[](YGNode*, float, YGMeasureMode, float, YGMeasureMode, void*) { [](YGNode*, YGFloat, YGMeasureMode, YGFloat, YGMeasureMode, void*) {
return YGSize{}; return YGSize{};
}); });
n.setMeasureFunc( n.setMeasureFunc(
[](YGNode*, float w, YGMeasureMode wm, float h, YGMeasureMode hm) { [](YGNode*, YGFloat w, YGMeasureMode wm, YGFloat h, YGMeasureMode hm) {
return YGSize{w * wm, h / hm}; return YGSize{w * wm, h / hm};
}); });
@@ -72,7 +72,7 @@ TEST(YGNode, switching_measure_fn_types) {
TEST(YGNode, hasMeasureFunc_after_unset) { TEST(YGNode, hasMeasureFunc_after_unset) {
auto n = YGNode{}; auto n = YGNode{};
n.setMeasureFunc([](YGNode*, float, YGMeasureMode, float, YGMeasureMode) { n.setMeasureFunc([](YGNode*, YGFloat, YGMeasureMode, YGFloat, YGMeasureMode) {
return YGSize{}; return YGSize{};
}); });
@@ -83,7 +83,7 @@ TEST(YGNode, hasMeasureFunc_after_unset) {
TEST(YGNode, hasMeasureFunc_after_unset_context) { TEST(YGNode, hasMeasureFunc_after_unset_context) {
auto n = YGNode{}; auto n = YGNode{};
n.setMeasureFunc( n.setMeasureFunc(
[](YGNode*, float, YGMeasureMode, float, YGMeasureMode, void*) { [](YGNode*, YGFloat, YGMeasureMode, YGFloat, YGMeasureMode, void*) {
return YGSize{}; return YGSize{};
}); });
@@ -98,20 +98,20 @@ TEST(YGNode, hasBaselineFunc_initial) {
TEST(YGNode, hasBaselineFunc_with_baseline_fn) { TEST(YGNode, hasBaselineFunc_with_baseline_fn) {
auto n = YGNode{}; auto n = YGNode{};
n.setBaselineFunc([](YGNode*, float, float) { return 0.0f; }); n.setBaselineFunc([](YGNode*, YGFloat, YGFloat) { return 0.0; });
ASSERT_TRUE(n.hasBaselineFunc()); ASSERT_TRUE(n.hasBaselineFunc());
} }
TEST(YGNode, baseline_with_baseline_fn) { TEST(YGNode, baseline_with_baseline_fn) {
auto n = YGNode{}; auto n = YGNode{};
n.setBaselineFunc([](YGNode*, float w, float h) { return w + h; }); n.setBaselineFunc([](YGNode*, YGFloat w, YGFloat h) { return w + h; });
ASSERT_EQ(n.baseline(1.25f, 2.5f, nullptr), 3.75f); ASSERT_EQ(n.baseline(1.25f, 2.5f, nullptr), 3.75f);
} }
TEST(YGNode, baseline_with_context_baseline_fn) { TEST(YGNode, baseline_with_context_baseline_fn) {
auto n = YGNode{}; auto n = YGNode{};
n.setBaselineFunc([](YGNode*, float w, float h, void* ctx) { n.setBaselineFunc([](YGNode*, YGFloat w, YGFloat h, void* ctx) {
return w + h + *(float*) ctx; return w + h + *(float*) ctx;
}); });
@@ -121,7 +121,7 @@ TEST(YGNode, baseline_with_context_baseline_fn) {
TEST(YGNode, hasBaselineFunc_after_unset) { TEST(YGNode, hasBaselineFunc_after_unset) {
auto n = YGNode{}; auto n = YGNode{};
n.setBaselineFunc([](YGNode*, float, float) { return 0.0f; }); n.setBaselineFunc([](YGNode*, YGFloat, YGFloat) { return 0.0; });
n.setBaselineFunc(nullptr); n.setBaselineFunc(nullptr);
ASSERT_FALSE(n.hasBaselineFunc()); ASSERT_FALSE(n.hasBaselineFunc());
@@ -129,7 +129,7 @@ TEST(YGNode, hasBaselineFunc_after_unset) {
TEST(YGNode, hasBaselineFunc_after_unset_context) { TEST(YGNode, hasBaselineFunc_after_unset_context) {
auto n = YGNode{}; auto n = YGNode{};
n.setBaselineFunc([](YGNode*, float, float, void*) { return 0.0f; }); n.setBaselineFunc([](YGNode*, YGFloat, YGFloat, void*) { return 0.0; });
n.setMeasureFunc(nullptr); n.setMeasureFunc(nullptr);
ASSERT_FALSE(n.hasMeasureFunc()); ASSERT_FALSE(n.hasMeasureFunc());
@@ -137,8 +137,8 @@ TEST(YGNode, hasBaselineFunc_after_unset_context) {
TEST(YGNode, switching_baseline_fn_types) { TEST(YGNode, switching_baseline_fn_types) {
auto n = YGNode{}; auto n = YGNode{};
n.setBaselineFunc([](YGNode*, float, float, void*) { return 0.0f; }); n.setBaselineFunc([](YGNode*, YGFloat, YGFloat, void*) { return 0.0; });
n.setBaselineFunc([](YGNode*, float, float) { return 1.0f; }); n.setBaselineFunc([](YGNode*, YGFloat, YGFloat) { return 1.0; });
ASSERT_EQ(n.baseline(1, 2, nullptr), 1.0f); ASSERT_EQ(n.baseline(1, 2, nullptr), 1.0f);
} }

View File

@@ -1196,9 +1196,9 @@ TEST(YogaTest, percent_absolute_position) {
static YGSize _measureCk_test_label_shrink_based_on_height( static YGSize _measureCk_test_label_shrink_based_on_height(
YGNodeRef node, YGNodeRef node,
float width, YGFloat width,
YGMeasureMode widthMode, YGMeasureMode widthMode,
float height, YGFloat height,
YGMeasureMode heightMode) { YGMeasureMode heightMode) {
if (heightMode == YGMeasureModeAtMost) { if (heightMode == YGMeasureModeAtMost) {

View File

@@ -44,9 +44,9 @@ TEST(YogaTest, rounding_value) {
static YGSize measureText( static YGSize measureText(
YGNodeRef node, YGNodeRef node,
float width, YGFloat width,
YGMeasureMode widthMode, YGMeasureMode widthMode,
float height, YGFloat height,
YGMeasureMode heightMode) { YGMeasureMode heightMode) {
return (YGSize){.width = 10, .height = 10}; return (YGSize){.width = 10, .height = 10};
} }

View File

@@ -11,9 +11,9 @@
static YGSize _measureFloor( static YGSize _measureFloor(
YGNodeRef node, YGNodeRef node,
float width, YGFloat width,
YGMeasureMode widthMode, YGMeasureMode widthMode,
float height, YGFloat height,
YGMeasureMode heightMode) { YGMeasureMode heightMode) {
return YGSize{ return YGSize{
width = 10.2f, width = 10.2f,
@@ -23,9 +23,9 @@ static YGSize _measureFloor(
static YGSize _measureCeil( static YGSize _measureCeil(
YGNodeRef node, YGNodeRef node,
float width, YGFloat width,
YGMeasureMode widthMode, YGMeasureMode widthMode,
float height, YGFloat height,
YGMeasureMode heightMode) { YGMeasureMode heightMode) {
return YGSize{ return YGSize{
width = 10.5f, width = 10.5f,
@@ -35,9 +35,9 @@ static YGSize _measureCeil(
static YGSize _measureFractial( static YGSize _measureFractial(
YGNodeRef node, YGNodeRef node,
float width, YGFloat width,
YGMeasureMode widthMode, YGMeasureMode widthMode,
float height, YGFloat height,
YGMeasureMode heightMode) { YGMeasureMode heightMode) {
return YGSize{ return YGSize{
width = 0.5f, width = 0.5f,