Breaking: size_t indices #1366
@@ -76,7 +76,7 @@ static void __printBenchmarkResult(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static YGSize _measure(
|
static YGSize _measure(
|
||||||
YGNodeRef node,
|
YGNodeConstRef node,
|
||||||
float width,
|
float width,
|
||||||
YGMeasureMode widthMode,
|
YGMeasureMode widthMode,
|
||||||
float height,
|
float height,
|
||||||
|
@@ -27,7 +27,7 @@ using namespace facebook::yoga;
|
|||||||
using namespace facebook::yoga::vanillajni;
|
using namespace facebook::yoga::vanillajni;
|
||||||
|
|
||||||
static inline ScopedLocalRef<jobject> YGNodeJobject(
|
static inline ScopedLocalRef<jobject> YGNodeJobject(
|
||||||
YGNodeRef node,
|
YGNodeConstRef node,
|
||||||
void* layoutContext) {
|
void* layoutContext) {
|
||||||
return reinterpret_cast<PtrJNodeMapVanilla*>(layoutContext)->ref(node);
|
return reinterpret_cast<PtrJNodeMapVanilla*>(layoutContext)->ref(node);
|
||||||
}
|
}
|
||||||
@@ -138,8 +138,8 @@ static jlong jni_YGNodeNewWithConfigJNI(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int YGJNILogFunc(
|
static int YGJNILogFunc(
|
||||||
const YGConfigRef config,
|
const YGConfigConstRef config,
|
||||||
const YGNodeRef /*node*/,
|
const YGNodeConstRef /*node*/,
|
||||||
YGLogLevel level,
|
YGLogLevel level,
|
||||||
void* /*layoutContext*/,
|
void* /*layoutContext*/,
|
||||||
const char* format,
|
const char* format,
|
||||||
@@ -362,7 +362,7 @@ static void YGTransferLayoutOutputsRecursive(
|
|||||||
|
|
||||||
YGNodeSetHasNewLayout(root, false);
|
YGNodeSetHasNewLayout(root, false);
|
||||||
|
|
||||||
for (uint32_t i = 0; i < YGNodeGetChildCount(root); i++) {
|
for (size_t i = 0; i < YGNodeGetChildCount(root); i++) {
|
||||||
YGTransferLayoutOutputsRecursive(
|
YGTransferLayoutOutputsRecursive(
|
||||||
env, thiz, YGNodeGetChild(root, i), layoutContext);
|
env, thiz, YGNodeGetChild(root, i), layoutContext);
|
||||||
}
|
}
|
||||||
@@ -639,7 +639,7 @@ static void jni_YGNodeStyleSetBorderJNI(
|
|||||||
yogaNodeRef, static_cast<YGEdge>(edge), static_cast<float>(border));
|
yogaNodeRef, static_cast<YGEdge>(edge), static_cast<float>(border));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void YGTransferLayoutDirection(YGNodeRef node, jobject javaNode) {
|
static void YGTransferLayoutDirection(YGNodeConstRef node, jobject javaNode) {
|
||||||
// Don't change this field name without changing the name of the field in
|
// Don't change this field name without changing the name of the field in
|
||||||
// Database.java
|
// Database.java
|
||||||
JNIEnv* env = getCurrentEnv();
|
JNIEnv* env = getCurrentEnv();
|
||||||
@@ -655,7 +655,7 @@ static void YGTransferLayoutDirection(YGNodeRef node, jobject javaNode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static YGSize YGJNIMeasureFunc(
|
static YGSize YGJNIMeasureFunc(
|
||||||
YGNodeRef node,
|
YGNodeConstRef node,
|
||||||
float width,
|
float width,
|
||||||
YGMeasureMode widthMode,
|
YGMeasureMode widthMode,
|
||||||
float height,
|
float height,
|
||||||
@@ -700,7 +700,7 @@ static void jni_YGNodeSetHasMeasureFuncJNI(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static float YGJNIBaselineFunc(
|
static float YGJNIBaselineFunc(
|
||||||
YGNodeRef node,
|
YGNodeConstRef node,
|
||||||
float width,
|
float width,
|
||||||
float height,
|
float height,
|
||||||
void* layoutContext) {
|
void* layoutContext) {
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
#include "./Config.h"
|
#include "./Config.h"
|
||||||
|
|
||||||
static YGSize globalMeasureFunc(
|
static YGSize globalMeasureFunc(
|
||||||
YGNodeRef nodeRef,
|
YGNodeConstRef nodeRef,
|
||||||
float width,
|
float width,
|
||||||
YGMeasureMode widthMode,
|
YGMeasureMode widthMode,
|
||||||
float height,
|
float height,
|
||||||
@@ -29,7 +29,7 @@ static YGSize globalMeasureFunc(
|
|||||||
return ygSize;
|
return ygSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void globalDirtiedFunc(YGNodeRef nodeRef) {
|
static void globalDirtiedFunc(YGNodeConstRef nodeRef) {
|
||||||
Node const& node = *reinterpret_cast<Node const*>(YGNodeGetContext(nodeRef));
|
Node const& node = *reinterpret_cast<Node const*>(YGNodeGetContext(nodeRef));
|
||||||
|
|
||||||
node.callDirtiedFunc();
|
node.callDirtiedFunc();
|
||||||
|
@@ -249,7 +249,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, [](YGNodeConstRef, float, YGMeasureMode, float, YGMeasureMode) {
|
||||||
return YGSize{};
|
return YGSize{};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -267,7 +267,8 @@ 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, [](YGNodeConstRef, float, float) { return 0.0f; });
|
||||||
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
||||||
YGNodeStyleSetAlignItems(root, YGAlignBaseline);
|
YGNodeStyleSetAlignItems(root, YGAlignBaseline);
|
||||||
|
|
||||||
|
@@ -9,14 +9,14 @@
|
|||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
|
|
||||||
static float _baselineFunc(
|
static float _baselineFunc(
|
||||||
YGNodeRef /*node*/,
|
YGNodeConstRef /*node*/,
|
||||||
const float /*width*/,
|
const float /*width*/,
|
||||||
const float height) {
|
const float height) {
|
||||||
return height / 2;
|
return height / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static YGSize _measure1(
|
static YGSize _measure1(
|
||||||
YGNodeRef /*node*/,
|
YGNodeConstRef /*node*/,
|
||||||
float /*width*/,
|
float /*width*/,
|
||||||
YGMeasureMode /*widthMode*/,
|
YGMeasureMode /*widthMode*/,
|
||||||
float /*height*/,
|
float /*height*/,
|
||||||
@@ -25,7 +25,7 @@ static YGSize _measure1(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static YGSize _measure2(
|
static YGSize _measure2(
|
||||||
YGNodeRef /*node*/,
|
YGNodeConstRef /*node*/,
|
||||||
float /*width*/,
|
float /*width*/,
|
||||||
YGMeasureMode /*widthMode*/,
|
YGMeasureMode /*widthMode*/,
|
||||||
float /*height*/,
|
float /*height*/,
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
|
|
||||||
static YGSize _measure(
|
static YGSize _measure(
|
||||||
YGNodeRef /*node*/,
|
YGNodeConstRef /*node*/,
|
||||||
float width,
|
float width,
|
||||||
YGMeasureMode widthMode,
|
YGMeasureMode widthMode,
|
||||||
float height,
|
float height,
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
|
|
||||||
static float _baseline(
|
static float _baseline(
|
||||||
YGNodeRef node,
|
YGNodeConstRef node,
|
||||||
const float /*width*/,
|
const float /*width*/,
|
||||||
const float /*height*/) {
|
const float /*height*/) {
|
||||||
float* baseline = (float*) YGNodeGetContext(node);
|
float* baseline = (float*) YGNodeGetContext(node);
|
||||||
|
@@ -5,8 +5,6 @@
|
|||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// @Generated by gentest/gentest.rb from gentest/fixtures/YGDisplayTest.html
|
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
#include <yoga/config/Config.h>
|
#include <yoga/config/Config.h>
|
||||||
@@ -23,8 +21,12 @@ struct ConfigCloningTest : public ::testing::Test {
|
|||||||
void TearDown() override;
|
void TearDown() override;
|
||||||
|
|
||||||
static yoga::Node clonedNode;
|
static yoga::Node clonedNode;
|
||||||
static YGNodeRef cloneNode(YGNodeRef, YGNodeRef, int) { return &clonedNode; }
|
static YGNodeRef cloneNode(YGNodeConstRef, YGNodeConstRef, size_t) {
|
||||||
static YGNodeRef doNotClone(YGNodeRef, YGNodeRef, int) { return nullptr; }
|
return &clonedNode;
|
||||||
|
}
|
||||||
|
static YGNodeRef doNotClone(YGNodeConstRef, YGNodeConstRef, size_t) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(ConfigCloningTest, uses_values_provided_by_cloning_callback) {
|
TEST_F(ConfigCloningTest, uses_values_provided_by_cloning_callback) {
|
||||||
@@ -49,7 +51,8 @@ TEST_F(
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ConfigCloningTest, can_clone_with_context) {
|
TEST_F(ConfigCloningTest, can_clone_with_context) {
|
||||||
config->setCloneNodeCallback([](YGNodeRef, YGNodeRef, int, void* context) {
|
config->setCloneNodeCallback(
|
||||||
|
[](YGNodeConstRef, YGNodeConstRef, size_t, void* context) {
|
||||||
return (YGNodeRef) context;
|
return (YGNodeRef) context;
|
||||||
});
|
});
|
||||||
|
|
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
using namespace facebook;
|
using namespace facebook;
|
||||||
|
|
||||||
static void _dirtied(YGNodeRef node) {
|
static void _dirtied(YGNodeConstRef node) {
|
||||||
int* dirtiedCount = (int*) YGNodeGetContext(node);
|
int* dirtiedCount = (int*) YGNodeGetContext(node);
|
||||||
(*dirtiedCount)++;
|
(*dirtiedCount)++;
|
||||||
}
|
}
|
||||||
|
@@ -147,7 +147,7 @@ TEST(YogaTest, dirty_propagation_changing_benign_config) {
|
|||||||
YGConfigRef newConfig = YGConfigNew();
|
YGConfigRef newConfig = YGConfigNew();
|
||||||
YGConfigSetLogger(
|
YGConfigSetLogger(
|
||||||
newConfig,
|
newConfig,
|
||||||
[](const YGConfigRef, const YGNodeRef, YGLogLevel, const char*, va_list) {
|
[](YGConfigConstRef, YGNodeConstRef, YGLogLevel, const char*, va_list) {
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
YGNodeSetConfig(root_child0, newConfig);
|
YGNodeSetConfig(root_child0, newConfig);
|
||||||
|
@@ -14,8 +14,8 @@
|
|||||||
namespace {
|
namespace {
|
||||||
char writeBuffer[4096];
|
char writeBuffer[4096];
|
||||||
int _unmanagedLogger(
|
int _unmanagedLogger(
|
||||||
const YGConfigRef /*config*/,
|
const YGConfigConstRef /*config*/,
|
||||||
const YGNodeRef /*node*/,
|
const YGNodeConstRef /*node*/,
|
||||||
YGLogLevel /*level*/,
|
YGLogLevel /*level*/,
|
||||||
const char* format,
|
const char* format,
|
||||||
va_list args) {
|
va_list args) {
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
|
|
||||||
static YGSize _measureMax(
|
static YGSize _measureMax(
|
||||||
YGNodeRef node,
|
YGNodeConstRef node,
|
||||||
float width,
|
float width,
|
||||||
YGMeasureMode widthMode,
|
YGMeasureMode widthMode,
|
||||||
float height,
|
float height,
|
||||||
@@ -24,7 +24,7 @@ static YGSize _measureMax(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static YGSize _measureMin(
|
static YGSize _measureMin(
|
||||||
YGNodeRef node,
|
YGNodeConstRef node,
|
||||||
float width,
|
float width,
|
||||||
YGMeasureMode widthMode,
|
YGMeasureMode widthMode,
|
||||||
float height,
|
float height,
|
||||||
@@ -44,7 +44,7 @@ static YGSize _measureMin(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static YGSize _measure_84_49(
|
static YGSize _measure_84_49(
|
||||||
YGNodeRef node,
|
YGNodeConstRef node,
|
||||||
float /*width*/,
|
float /*width*/,
|
||||||
YGMeasureMode /*widthMode*/,
|
YGMeasureMode /*widthMode*/,
|
||||||
float /*height*/,
|
float /*height*/,
|
||||||
|
@@ -21,7 +21,7 @@ struct _MeasureConstraintList {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static YGSize _measure(
|
static YGSize _measure(
|
||||||
YGNodeRef node,
|
YGNodeConstRef node,
|
||||||
float width,
|
float width,
|
||||||
YGMeasureMode widthMode,
|
YGMeasureMode widthMode,
|
||||||
float height,
|
float height,
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
|
|
||||||
static YGSize _measure(
|
static YGSize _measure(
|
||||||
YGNodeRef node,
|
YGNodeConstRef node,
|
||||||
float /*width*/,
|
float /*width*/,
|
||||||
YGMeasureMode /*widthMode*/,
|
YGMeasureMode /*widthMode*/,
|
||||||
float /*height*/,
|
float /*height*/,
|
||||||
@@ -23,7 +23,7 @@ static YGSize _measure(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static YGSize _simulate_wrapping_text(
|
static YGSize _simulate_wrapping_text(
|
||||||
YGNodeRef /*node*/,
|
YGNodeConstRef /*node*/,
|
||||||
float width,
|
float width,
|
||||||
YGMeasureMode widthMode,
|
YGMeasureMode widthMode,
|
||||||
float /*height*/,
|
float /*height*/,
|
||||||
@@ -36,7 +36,7 @@ static YGSize _simulate_wrapping_text(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static YGSize _measure_assert_negative(
|
static YGSize _measure_assert_negative(
|
||||||
YGNodeRef /*node*/,
|
YGNodeConstRef /*node*/,
|
||||||
float width,
|
float width,
|
||||||
YGMeasureMode /*widthMode*/,
|
YGMeasureMode /*widthMode*/,
|
||||||
float height,
|
float height,
|
||||||
@@ -640,7 +640,7 @@ TEST(YogaTest, cant_call_negative_measure_horizontal) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static YGSize _measure_90_10(
|
static YGSize _measure_90_10(
|
||||||
YGNodeRef /*node*/,
|
YGNodeConstRef /*node*/,
|
||||||
float /*width*/,
|
float /*width*/,
|
||||||
YGMeasureMode /*widthMode*/,
|
YGMeasureMode /*widthMode*/,
|
||||||
float /*height*/,
|
float /*height*/,
|
||||||
@@ -650,7 +650,7 @@ static YGSize _measure_90_10(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static YGSize _measure_100_100(
|
static YGSize _measure_100_100(
|
||||||
YGNodeRef /*node*/,
|
YGNodeConstRef /*node*/,
|
||||||
float /*width*/,
|
float /*width*/,
|
||||||
YGMeasureMode /*widthMode*/,
|
YGMeasureMode /*widthMode*/,
|
||||||
float /*height*/,
|
float /*height*/,
|
||||||
|
@@ -22,7 +22,8 @@ TEST(Node, hasMeasureFunc_initial) {
|
|||||||
|
|
||||||
TEST(Node, hasMeasureFunc_with_measure_fn) {
|
TEST(Node, hasMeasureFunc_with_measure_fn) {
|
||||||
auto n = Node{};
|
auto n = Node{};
|
||||||
n.setMeasureFunc([](YGNodeRef, float, YGMeasureMode, float, YGMeasureMode) {
|
n.setMeasureFunc(
|
||||||
|
[](YGNodeConstRef, float, YGMeasureMode, float, YGMeasureMode) {
|
||||||
return YGSize{};
|
return YGSize{};
|
||||||
});
|
});
|
||||||
ASSERT_TRUE(n.hasMeasureFunc());
|
ASSERT_TRUE(n.hasMeasureFunc());
|
||||||
@@ -32,7 +33,7 @@ TEST(Node, measure_with_measure_fn) {
|
|||||||
auto n = Node{};
|
auto n = Node{};
|
||||||
|
|
||||||
n.setMeasureFunc(
|
n.setMeasureFunc(
|
||||||
[](YGNodeRef, float w, YGMeasureMode wm, float h, YGMeasureMode hm) {
|
[](YGNodeConstRef, float w, YGMeasureMode wm, float h, YGMeasureMode hm) {
|
||||||
return YGSize{w * static_cast<float>(wm), h / static_cast<float>(hm)};
|
return YGSize{w * static_cast<float>(wm), h / static_cast<float>(hm)};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -43,10 +44,12 @@ TEST(Node, measure_with_measure_fn) {
|
|||||||
|
|
||||||
TEST(Node, measure_with_context_measure_fn) {
|
TEST(Node, measure_with_context_measure_fn) {
|
||||||
auto n = Node{};
|
auto n = Node{};
|
||||||
n.setMeasureFunc(
|
n.setMeasureFunc([](YGNodeConstRef,
|
||||||
[](YGNodeRef, float, YGMeasureMode, float, YGMeasureMode, void* ctx) {
|
float,
|
||||||
return *(YGSize*) ctx;
|
YGMeasureMode,
|
||||||
});
|
float,
|
||||||
|
YGMeasureMode,
|
||||||
|
void* ctx) { return *(YGSize*) ctx; });
|
||||||
|
|
||||||
auto result = YGSize{123.4f, -56.7f};
|
auto result = YGSize{123.4f, -56.7f};
|
||||||
ASSERT_EQ(
|
ASSERT_EQ(
|
||||||
@@ -57,11 +60,11 @@ TEST(Node, measure_with_context_measure_fn) {
|
|||||||
TEST(Node, switching_measure_fn_types) {
|
TEST(Node, switching_measure_fn_types) {
|
||||||
auto n = Node{};
|
auto n = Node{};
|
||||||
n.setMeasureFunc(
|
n.setMeasureFunc(
|
||||||
[](YGNodeRef, float, YGMeasureMode, float, YGMeasureMode, void*) {
|
[](YGNodeConstRef, float, YGMeasureMode, float, YGMeasureMode, void*) {
|
||||||
return YGSize{};
|
return YGSize{};
|
||||||
});
|
});
|
||||||
n.setMeasureFunc(
|
n.setMeasureFunc(
|
||||||
[](YGNodeRef, float w, YGMeasureMode wm, float h, YGMeasureMode hm) {
|
[](YGNodeConstRef, float w, YGMeasureMode wm, float h, YGMeasureMode hm) {
|
||||||
return YGSize{w * static_cast<float>(wm), h / static_cast<float>(hm)};
|
return YGSize{w * static_cast<float>(wm), h / static_cast<float>(hm)};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -72,7 +75,8 @@ TEST(Node, switching_measure_fn_types) {
|
|||||||
|
|
||||||
TEST(Node, hasMeasureFunc_after_unset) {
|
TEST(Node, hasMeasureFunc_after_unset) {
|
||||||
auto n = Node{};
|
auto n = Node{};
|
||||||
n.setMeasureFunc([](YGNodeRef, float, YGMeasureMode, float, YGMeasureMode) {
|
n.setMeasureFunc(
|
||||||
|
[](YGNodeConstRef, float, YGMeasureMode, float, YGMeasureMode) {
|
||||||
return YGSize{};
|
return YGSize{};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -83,7 +87,7 @@ TEST(Node, hasMeasureFunc_after_unset) {
|
|||||||
TEST(Node, hasMeasureFunc_after_unset_context) {
|
TEST(Node, hasMeasureFunc_after_unset_context) {
|
||||||
auto n = Node{};
|
auto n = Node{};
|
||||||
n.setMeasureFunc(
|
n.setMeasureFunc(
|
||||||
[](YGNodeRef, float, YGMeasureMode, float, YGMeasureMode, void*) {
|
[](YGNodeConstRef, float, YGMeasureMode, float, YGMeasureMode, void*) {
|
||||||
return YGSize{};
|
return YGSize{};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -98,20 +102,20 @@ TEST(Node, hasBaselineFunc_initial) {
|
|||||||
|
|
||||||
TEST(Node, hasBaselineFunc_with_baseline_fn) {
|
TEST(Node, hasBaselineFunc_with_baseline_fn) {
|
||||||
auto n = Node{};
|
auto n = Node{};
|
||||||
n.setBaselineFunc([](YGNodeRef, float, float) { return 0.0f; });
|
n.setBaselineFunc([](YGNodeConstRef, float, float) { return 0.0f; });
|
||||||
ASSERT_TRUE(n.hasBaselineFunc());
|
ASSERT_TRUE(n.hasBaselineFunc());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Node, baseline_with_baseline_fn) {
|
TEST(Node, baseline_with_baseline_fn) {
|
||||||
auto n = Node{};
|
auto n = Node{};
|
||||||
n.setBaselineFunc([](YGNodeRef, float w, float h) { return w + h; });
|
n.setBaselineFunc([](YGNodeConstRef, float w, float 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(Node, baseline_with_context_baseline_fn) {
|
TEST(Node, baseline_with_context_baseline_fn) {
|
||||||
auto n = Node{};
|
auto n = Node{};
|
||||||
n.setBaselineFunc([](YGNodeRef, float w, float h, void* ctx) {
|
n.setBaselineFunc([](YGNodeConstRef, float w, float h, void* ctx) {
|
||||||
return w + h + *(float*) ctx;
|
return w + h + *(float*) ctx;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -121,7 +125,7 @@ TEST(Node, baseline_with_context_baseline_fn) {
|
|||||||
|
|
||||||
TEST(Node, hasBaselineFunc_after_unset) {
|
TEST(Node, hasBaselineFunc_after_unset) {
|
||||||
auto n = Node{};
|
auto n = Node{};
|
||||||
n.setBaselineFunc([](YGNodeRef, float, float) { return 0.0f; });
|
n.setBaselineFunc([](YGNodeConstRef, float, float) { return 0.0f; });
|
||||||
|
|
||||||
n.setBaselineFunc(nullptr);
|
n.setBaselineFunc(nullptr);
|
||||||
ASSERT_FALSE(n.hasBaselineFunc());
|
ASSERT_FALSE(n.hasBaselineFunc());
|
||||||
@@ -129,7 +133,7 @@ TEST(Node, hasBaselineFunc_after_unset) {
|
|||||||
|
|
||||||
TEST(Node, hasBaselineFunc_after_unset_context) {
|
TEST(Node, hasBaselineFunc_after_unset_context) {
|
||||||
auto n = Node{};
|
auto n = Node{};
|
||||||
n.setBaselineFunc([](YGNodeRef, float, float, void*) { return 0.0f; });
|
n.setBaselineFunc([](YGNodeConstRef, float, float, void*) { return 0.0f; });
|
||||||
|
|
||||||
n.setMeasureFunc(nullptr);
|
n.setMeasureFunc(nullptr);
|
||||||
ASSERT_FALSE(n.hasMeasureFunc());
|
ASSERT_FALSE(n.hasMeasureFunc());
|
||||||
@@ -137,7 +141,7 @@ TEST(Node, hasBaselineFunc_after_unset_context) {
|
|||||||
|
|
||||||
TEST(Node, switching_baseline_fn_types) {
|
TEST(Node, switching_baseline_fn_types) {
|
||||||
auto n = Node{};
|
auto n = Node{};
|
||||||
n.setBaselineFunc([](YGNodeRef, float, float, void*) { return 0.0f; });
|
n.setBaselineFunc([](YGNodeConstRef, float, float, void*) { return 0.0f; });
|
||||||
n.setBaselineFunc([](YGNodeRef, float, float) { return 1.0f; });
|
n.setBaselineFunc([](YGNodeConstRef, float, float) { return 1.0f; });
|
||||||
ASSERT_EQ(n.baseline(1, 2, nullptr), 1.0f);
|
ASSERT_EQ(n.baseline(1, 2, nullptr), 1.0f);
|
||||||
}
|
}
|
||||||
|
@@ -43,7 +43,7 @@ TEST(YogaTest, rounding_value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static YGSize measureText(
|
static YGSize measureText(
|
||||||
YGNodeRef /*node*/,
|
YGNodeConstRef /*node*/,
|
||||||
float /*width*/,
|
float /*width*/,
|
||||||
YGMeasureMode /*widthMode*/,
|
YGMeasureMode /*widthMode*/,
|
||||||
float /*height*/,
|
float /*height*/,
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
|
|
||||||
static YGSize _measureFloor(
|
static YGSize _measureFloor(
|
||||||
YGNodeRef /*node*/,
|
YGNodeConstRef /*node*/,
|
||||||
float width,
|
float width,
|
||||||
YGMeasureMode /*widthMode*/,
|
YGMeasureMode /*widthMode*/,
|
||||||
float height,
|
float height,
|
||||||
@@ -21,7 +21,7 @@ static YGSize _measureFloor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static YGSize _measureCeil(
|
static YGSize _measureCeil(
|
||||||
YGNodeRef /*node*/,
|
YGNodeConstRef /*node*/,
|
||||||
float width,
|
float width,
|
||||||
YGMeasureMode /*widthMode*/,
|
YGMeasureMode /*widthMode*/,
|
||||||
float height,
|
float height,
|
||||||
@@ -33,7 +33,7 @@ static YGSize _measureCeil(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static YGSize _measureFractial(
|
static YGSize _measureFractial(
|
||||||
YGNodeRef /*node*/,
|
YGNodeConstRef /*node*/,
|
||||||
float width,
|
float width,
|
||||||
YGMeasureMode /*widthMode*/,
|
YGMeasureMode /*widthMode*/,
|
||||||
float height,
|
float height,
|
||||||
|
@@ -9,10 +9,10 @@
|
|||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
|
|
||||||
static std::vector<YGNodeRef> getChildren(YGNodeRef const node) {
|
static std::vector<YGNodeRef> getChildren(YGNodeRef const node) {
|
||||||
const uint32_t count = YGNodeGetChildCount(node);
|
const auto count = YGNodeGetChildCount(node);
|
||||||
std::vector<YGNodeRef> children;
|
std::vector<YGNodeRef> children;
|
||||||
children.reserve(count);
|
children.reserve(count);
|
||||||
for (uint32_t i = 0; i < count; i++) {
|
for (size_t i = 0; i < count; i++) {
|
||||||
children.push_back(YGNodeGetChild(node, i));
|
children.push_back(YGNodeGetChild(node, i));
|
||||||
}
|
}
|
||||||
return children;
|
return children;
|
||||||
|
307
yoga/Yoga.cpp
307
yoga/Yoga.cpp
@@ -22,15 +22,15 @@ using namespace facebook::yoga;
|
|||||||
|
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
static int YGAndroidLog(
|
static int YGAndroidLog(
|
||||||
const YGConfigRef config,
|
const YGConfigConstRef config,
|
||||||
const YGNodeRef node,
|
const YGNodeConstRef node,
|
||||||
YGLogLevel level,
|
YGLogLevel level,
|
||||||
const char* format,
|
const char* format,
|
||||||
va_list args);
|
va_list args);
|
||||||
#else
|
#else
|
||||||
static int YGDefaultLog(
|
static int YGDefaultLog(
|
||||||
const YGConfigRef config,
|
const YGConfigConstRef config,
|
||||||
const YGNodeRef node,
|
const YGNodeConstRef node,
|
||||||
YGLogLevel level,
|
YGLogLevel level,
|
||||||
const char* format,
|
const char* format,
|
||||||
va_list args);
|
va_list args);
|
||||||
@@ -39,8 +39,8 @@ static int YGDefaultLog(
|
|||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
static int YGAndroidLog(
|
static int YGAndroidLog(
|
||||||
const YGConfigRef /*config*/,
|
const YGConfigConstRef /*config*/,
|
||||||
const YGNodeRef /*node*/,
|
const YGNodeConstRef /*node*/,
|
||||||
YGLogLevel level,
|
YGLogLevel level,
|
||||||
const char* format,
|
const char* format,
|
||||||
va_list args) {
|
va_list args) {
|
||||||
@@ -69,16 +69,12 @@ static int YGAndroidLog(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#define YG_UNUSED(x) (void) (x);
|
|
||||||
|
|
||||||
static int YGDefaultLog(
|
static int YGDefaultLog(
|
||||||
const YGConfigRef config,
|
const YGConfigConstRef /*config*/,
|
||||||
const YGNodeRef node,
|
const YGNodeConstRef /*node*/,
|
||||||
YGLogLevel level,
|
YGLogLevel level,
|
||||||
const char* format,
|
const char* format,
|
||||||
va_list args) {
|
va_list args) {
|
||||||
YG_UNUSED(config);
|
|
||||||
YG_UNUSED(node);
|
|
||||||
switch (level) {
|
switch (level) {
|
||||||
case YGLogLevelError:
|
case YGLogLevelError:
|
||||||
case YGLogLevelFatal:
|
case YGLogLevelFatal:
|
||||||
@@ -91,101 +87,101 @@ static int YGDefaultLog(
|
|||||||
return vprintf(format, args);
|
return vprintf(format, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef YG_UNUSED
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
YOGA_EXPORT bool YGFloatIsUndefined(const float value) {
|
YOGA_EXPORT bool YGFloatIsUndefined(const float value) {
|
||||||
return yoga::isUndefined(value);
|
return yoga::isUndefined(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void* YGNodeGetContext(YGNodeRef node) {
|
YOGA_EXPORT void* YGNodeGetContext(YGNodeConstRef node) {
|
||||||
return static_cast<yoga::Node*>(node)->getContext();
|
return resolveRef(node)->getContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeSetContext(YGNodeRef node, void* context) {
|
YOGA_EXPORT void YGNodeSetContext(YGNodeRef node, void* context) {
|
||||||
return static_cast<yoga::Node*>(node)->setContext(context);
|
return resolveRef(node)->setContext(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT YGConfigRef YGNodeGetConfig(YGNodeRef node) {
|
YOGA_EXPORT YGConfigRef YGNodeGetConfig(YGNodeRef node) {
|
||||||
return static_cast<yoga::Node*>(node)->getConfig();
|
return resolveRef(node)->getConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeSetConfig(YGNodeRef node, YGConfigRef config) {
|
YOGA_EXPORT void YGNodeSetConfig(YGNodeRef node, YGConfigRef config) {
|
||||||
static_cast<yoga::Node*>(node)->setConfig(static_cast<yoga::Config*>(config));
|
resolveRef(node)->setConfig(resolveRef(config));
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT bool YGNodeHasMeasureFunc(YGNodeRef node) {
|
YOGA_EXPORT bool YGNodeHasMeasureFunc(YGNodeConstRef node) {
|
||||||
return static_cast<yoga::Node*>(node)->hasMeasureFunc();
|
return resolveRef(node)->hasMeasureFunc();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeSetMeasureFunc(
|
YOGA_EXPORT void YGNodeSetMeasureFunc(
|
||||||
YGNodeRef node,
|
YGNodeRef node,
|
||||||
YGMeasureFunc measureFunc) {
|
YGMeasureFunc measureFunc) {
|
||||||
static_cast<yoga::Node*>(node)->setMeasureFunc(measureFunc);
|
resolveRef(node)->setMeasureFunc(measureFunc);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT bool YGNodeHasBaselineFunc(YGNodeRef node) {
|
YOGA_EXPORT bool YGNodeHasBaselineFunc(YGNodeConstRef node) {
|
||||||
return static_cast<yoga::Node*>(node)->hasBaselineFunc();
|
return resolveRef(node)->hasBaselineFunc();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeSetBaselineFunc(
|
YOGA_EXPORT void YGNodeSetBaselineFunc(
|
||||||
YGNodeRef node,
|
YGNodeRef node,
|
||||||
YGBaselineFunc baselineFunc) {
|
YGBaselineFunc baselineFunc) {
|
||||||
static_cast<yoga::Node*>(node)->setBaselineFunc(baselineFunc);
|
resolveRef(node)->setBaselineFunc(baselineFunc);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT YGDirtiedFunc YGNodeGetDirtiedFunc(YGNodeRef node) {
|
YOGA_EXPORT YGDirtiedFunc YGNodeGetDirtiedFunc(YGNodeConstRef node) {
|
||||||
return static_cast<yoga::Node*>(node)->getDirtied();
|
return resolveRef(node)->getDirtied();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeSetDirtiedFunc(
|
YOGA_EXPORT void YGNodeSetDirtiedFunc(
|
||||||
YGNodeRef node,
|
YGNodeRef node,
|
||||||
YGDirtiedFunc dirtiedFunc) {
|
YGDirtiedFunc dirtiedFunc) {
|
||||||
static_cast<yoga::Node*>(node)->setDirtiedFunc(dirtiedFunc);
|
resolveRef(node)->setDirtiedFunc(dirtiedFunc);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc) {
|
YOGA_EXPORT void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc) {
|
||||||
static_cast<yoga::Node*>(node)->setPrintFunc(printFunc);
|
resolveRef(node)->setPrintFunc(printFunc);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT bool YGNodeGetHasNewLayout(YGNodeRef node) {
|
YOGA_EXPORT bool YGNodeGetHasNewLayout(YGNodeConstRef node) {
|
||||||
return static_cast<yoga::Node*>(node)->getHasNewLayout();
|
return resolveRef(node)->getHasNewLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGConfigSetPrintTreeFlag(YGConfigRef config, bool enabled) {
|
YOGA_EXPORT void YGConfigSetPrintTreeFlag(YGConfigRef config, bool enabled) {
|
||||||
static_cast<yoga::Config*>(config)->setShouldPrintTree(enabled);
|
resolveRef(config)->setShouldPrintTree(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout) {
|
YOGA_EXPORT void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout) {
|
||||||
static_cast<yoga::Node*>(node)->setHasNewLayout(hasNewLayout);
|
resolveRef(node)->setHasNewLayout(hasNewLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT YGNodeType YGNodeGetNodeType(YGNodeRef node) {
|
YOGA_EXPORT YGNodeType YGNodeGetNodeType(YGNodeConstRef node) {
|
||||||
return static_cast<yoga::Node*>(node)->getNodeType();
|
return resolveRef(node)->getNodeType();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType) {
|
YOGA_EXPORT void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType) {
|
||||||
return static_cast<yoga::Node*>(node)->setNodeType(nodeType);
|
return resolveRef(node)->setNodeType(nodeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT bool YGNodeIsDirty(YGNodeRef node) {
|
YOGA_EXPORT bool YGNodeIsDirty(YGNodeConstRef node) {
|
||||||
return static_cast<yoga::Node*>(node)->isDirty();
|
return resolveRef(node)->isDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeMarkDirtyAndPropagateToDescendants(
|
YOGA_EXPORT void YGNodeMarkDirtyAndPropagateToDescendants(
|
||||||
const YGNodeRef node) {
|
const YGNodeRef node) {
|
||||||
return static_cast<yoga::Node*>(node)->markDirtyAndPropagateDownwards();
|
return resolveRef(node)->markDirtyAndPropagateDownwards();
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t gConfigInstanceCount = 0;
|
int32_t gConfigInstanceCount = 0;
|
||||||
|
|
||||||
YOGA_EXPORT WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config) {
|
YOGA_EXPORT WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config) {
|
||||||
auto* node = new yoga::Node{static_cast<yoga::Config*>(config)};
|
auto* node = new yoga::Node{resolveRef(config)};
|
||||||
yoga::assertFatal(
|
yoga::assertFatal(
|
||||||
config != nullptr, "Tried to construct YGNode with null config");
|
config != nullptr, "Tried to construct YGNode with null config");
|
||||||
yoga::assertFatalWithConfig(
|
yoga::assertFatalWithConfig(
|
||||||
config, node != nullptr, "Could not allocate memory for node");
|
resolveRef(config),
|
||||||
|
node != nullptr,
|
||||||
|
"Could not allocate memory for node");
|
||||||
Event::publish<Event::NodeAllocation>(node, {config});
|
Event::publish<Event::NodeAllocation>(node, {config});
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
@@ -200,9 +196,9 @@ YOGA_EXPORT YGNodeRef YGNodeNew(void) {
|
|||||||
return YGNodeNewWithConfig(YGConfigGetDefault());
|
return YGNodeNewWithConfig(YGConfigGetDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT YGNodeRef YGNodeClone(YGNodeRef oldNodeRef) {
|
YOGA_EXPORT YGNodeRef YGNodeClone(YGNodeConstRef oldNodeRef) {
|
||||||
auto oldNode = static_cast<yoga::Node*>(oldNodeRef);
|
auto oldNode = resolveRef(oldNodeRef);
|
||||||
auto node = new yoga::Node(*oldNode);
|
const auto node = new yoga::Node(*oldNode);
|
||||||
yoga::assertFatalWithConfig(
|
yoga::assertFatalWithConfig(
|
||||||
oldNode->getConfig(),
|
oldNode->getConfig(),
|
||||||
node != nullptr,
|
node != nullptr,
|
||||||
@@ -213,15 +209,15 @@ YOGA_EXPORT YGNodeRef YGNodeClone(YGNodeRef oldNodeRef) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeFree(const YGNodeRef nodeRef) {
|
YOGA_EXPORT void YGNodeFree(const YGNodeRef nodeRef) {
|
||||||
auto node = static_cast<yoga::Node*>(nodeRef);
|
const auto node = resolveRef(nodeRef);
|
||||||
|
|
||||||
if (auto owner = node->getOwner()) {
|
if (auto owner = node->getOwner()) {
|
||||||
owner->removeChild(node);
|
owner->removeChild(node);
|
||||||
node->setOwner(nullptr);
|
node->setOwner(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint32_t childCount = YGNodeGetChildCount(node);
|
const size_t childCount = node->getChildCount();
|
||||||
for (uint32_t i = 0; i < childCount; i++) {
|
for (size_t i = 0; i < childCount; i++) {
|
||||||
auto child = node->getChild(i);
|
auto child = node->getChild(i);
|
||||||
child->setOwner(nullptr);
|
child->setOwner(nullptr);
|
||||||
}
|
}
|
||||||
@@ -232,16 +228,16 @@ YOGA_EXPORT void YGNodeFree(const YGNodeRef nodeRef) {
|
|||||||
|
|
||||||
YOGA_EXPORT void YGNodeDeallocate(const YGNodeRef node) {
|
YOGA_EXPORT void YGNodeDeallocate(const YGNodeRef node) {
|
||||||
Event::publish<Event::NodeDeallocation>(node, {YGNodeGetConfig(node)});
|
Event::publish<Event::NodeDeallocation>(node, {YGNodeGetConfig(node)});
|
||||||
delete static_cast<yoga::Node*>(node);
|
delete resolveRef(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeFreeRecursiveWithCleanupFunc(
|
YOGA_EXPORT void YGNodeFreeRecursiveWithCleanupFunc(
|
||||||
const YGNodeRef rootRef,
|
const YGNodeRef rootRef,
|
||||||
YGNodeCleanupFunc cleanup) {
|
YGNodeCleanupFunc cleanup) {
|
||||||
const auto root = static_cast<yoga::Node*>(rootRef);
|
const auto root = resolveRef(rootRef);
|
||||||
|
|
||||||
uint32_t skipped = 0;
|
size_t skipped = 0;
|
||||||
while (YGNodeGetChildCount(root) > skipped) {
|
while (root->getChildCount() > skipped) {
|
||||||
const auto child = root->getChild(skipped);
|
const auto child = root->getChild(skipped);
|
||||||
if (child->getOwner() != root) {
|
if (child->getOwner() != root) {
|
||||||
// Don't free shared nodes that we don't own.
|
// Don't free shared nodes that we don't own.
|
||||||
@@ -262,7 +258,7 @@ YOGA_EXPORT void YGNodeFreeRecursive(const YGNodeRef root) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeReset(YGNodeRef node) {
|
YOGA_EXPORT void YGNodeReset(YGNodeRef node) {
|
||||||
static_cast<yoga::Node*>(node)->reset();
|
resolveRef(node)->reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT int32_t YGConfigGetInstanceCount(void) {
|
YOGA_EXPORT int32_t YGConfigGetInstanceCount(void) {
|
||||||
@@ -280,30 +276,30 @@ YOGA_EXPORT YGConfigRef YGConfigNew(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGConfigFree(const YGConfigRef config) {
|
YOGA_EXPORT void YGConfigFree(const YGConfigRef config) {
|
||||||
delete static_cast<yoga::Config*>(config);
|
delete resolveRef(config);
|
||||||
gConfigInstanceCount--;
|
gConfigInstanceCount--;
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeSetIsReferenceBaseline(
|
YOGA_EXPORT void YGNodeSetIsReferenceBaseline(
|
||||||
YGNodeRef nodeRef,
|
YGNodeRef nodeRef,
|
||||||
bool isReferenceBaseline) {
|
bool isReferenceBaseline) {
|
||||||
auto node = static_cast<yoga::Node*>(nodeRef);
|
const auto node = resolveRef(nodeRef);
|
||||||
if (node->isReferenceBaseline() != isReferenceBaseline) {
|
if (node->isReferenceBaseline() != isReferenceBaseline) {
|
||||||
node->setIsReferenceBaseline(isReferenceBaseline);
|
node->setIsReferenceBaseline(isReferenceBaseline);
|
||||||
node->markDirtyAndPropagate();
|
node->markDirtyAndPropagate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT bool YGNodeIsReferenceBaseline(YGNodeRef node) {
|
YOGA_EXPORT bool YGNodeIsReferenceBaseline(YGNodeConstRef node) {
|
||||||
return static_cast<yoga::Node*>(node)->isReferenceBaseline();
|
return resolveRef(node)->isReferenceBaseline();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeInsertChild(
|
YOGA_EXPORT void YGNodeInsertChild(
|
||||||
const YGNodeRef ownerRef,
|
const YGNodeRef ownerRef,
|
||||||
const YGNodeRef childRef,
|
const YGNodeRef childRef,
|
||||||
const uint32_t index) {
|
const size_t index) {
|
||||||
auto owner = static_cast<yoga::Node*>(ownerRef);
|
auto owner = resolveRef(ownerRef);
|
||||||
auto child = static_cast<yoga::Node*>(childRef);
|
auto child = resolveRef(childRef);
|
||||||
|
|
||||||
yoga::assertFatalWithNode(
|
yoga::assertFatalWithNode(
|
||||||
owner,
|
owner,
|
||||||
@@ -323,9 +319,9 @@ YOGA_EXPORT void YGNodeInsertChild(
|
|||||||
YOGA_EXPORT void YGNodeSwapChild(
|
YOGA_EXPORT void YGNodeSwapChild(
|
||||||
const YGNodeRef ownerRef,
|
const YGNodeRef ownerRef,
|
||||||
const YGNodeRef childRef,
|
const YGNodeRef childRef,
|
||||||
const uint32_t index) {
|
const size_t index) {
|
||||||
auto owner = static_cast<yoga::Node*>(ownerRef);
|
auto owner = resolveRef(ownerRef);
|
||||||
auto child = static_cast<yoga::Node*>(childRef);
|
auto child = resolveRef(childRef);
|
||||||
|
|
||||||
owner->replaceChild(child, index);
|
owner->replaceChild(child, index);
|
||||||
child->setOwner(owner);
|
child->setOwner(owner);
|
||||||
@@ -334,10 +330,10 @@ YOGA_EXPORT void YGNodeSwapChild(
|
|||||||
YOGA_EXPORT void YGNodeRemoveChild(
|
YOGA_EXPORT void YGNodeRemoveChild(
|
||||||
const YGNodeRef ownerRef,
|
const YGNodeRef ownerRef,
|
||||||
const YGNodeRef excludedChildRef) {
|
const YGNodeRef excludedChildRef) {
|
||||||
auto owner = static_cast<yoga::Node*>(ownerRef);
|
auto owner = resolveRef(ownerRef);
|
||||||
auto excludedChild = static_cast<yoga::Node*>(excludedChildRef);
|
auto excludedChild = resolveRef(excludedChildRef);
|
||||||
|
|
||||||
if (YGNodeGetChildCount(owner) == 0) {
|
if (owner->getChildCount() == 0) {
|
||||||
// This is an empty set. Nothing to remove.
|
// This is an empty set. Nothing to remove.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -356,9 +352,9 @@ YOGA_EXPORT void YGNodeRemoveChild(
|
|||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeRemoveAllChildren(const YGNodeRef ownerRef) {
|
YOGA_EXPORT void YGNodeRemoveAllChildren(const YGNodeRef ownerRef) {
|
||||||
auto owner = static_cast<yoga::Node*>(ownerRef);
|
auto owner = resolveRef(ownerRef);
|
||||||
|
|
||||||
const uint32_t childCount = YGNodeGetChildCount(owner);
|
const size_t childCount = owner->getChildCount();
|
||||||
if (childCount == 0) {
|
if (childCount == 0) {
|
||||||
// This is an empty set already. Nothing to do.
|
// This is an empty set already. Nothing to do.
|
||||||
return;
|
return;
|
||||||
@@ -367,7 +363,7 @@ YOGA_EXPORT void YGNodeRemoveAllChildren(const YGNodeRef ownerRef) {
|
|||||||
if (firstChild->getOwner() == owner) {
|
if (firstChild->getOwner() == owner) {
|
||||||
// If the first child has this node as its owner, we assume that this child
|
// If the first child has this node as its owner, we assume that this child
|
||||||
// set is unique.
|
// set is unique.
|
||||||
for (uint32_t i = 0; i < childCount; i++) {
|
for (size_t i = 0; i < childCount; i++) {
|
||||||
yoga::Node* oldChild = owner->getChild(i);
|
yoga::Node* oldChild = owner->getChild(i);
|
||||||
oldChild->setLayout({}); // layout is no longer valid
|
oldChild->setLayout({}); // layout is no longer valid
|
||||||
oldChild->setOwner(nullptr);
|
oldChild->setOwner(nullptr);
|
||||||
@@ -385,8 +381,8 @@ YOGA_EXPORT void YGNodeRemoveAllChildren(const YGNodeRef ownerRef) {
|
|||||||
YOGA_EXPORT void YGNodeSetChildren(
|
YOGA_EXPORT void YGNodeSetChildren(
|
||||||
const YGNodeRef ownerRef,
|
const YGNodeRef ownerRef,
|
||||||
const YGNodeRef* childrenRefs,
|
const YGNodeRef* childrenRefs,
|
||||||
const uint32_t count) {
|
const size_t count) {
|
||||||
auto owner = static_cast<yoga::Node*>(ownerRef);
|
auto owner = resolveRef(ownerRef);
|
||||||
auto children = reinterpret_cast<yoga::Node* const*>(childrenRefs);
|
auto children = reinterpret_cast<yoga::Node* const*>(childrenRefs);
|
||||||
|
|
||||||
if (!owner) {
|
if (!owner) {
|
||||||
@@ -395,7 +391,7 @@ YOGA_EXPORT void YGNodeSetChildren(
|
|||||||
|
|
||||||
const std::vector<yoga::Node*> childrenVector = {children, children + count};
|
const std::vector<yoga::Node*> childrenVector = {children, children + count};
|
||||||
if (childrenVector.size() == 0) {
|
if (childrenVector.size() == 0) {
|
||||||
if (YGNodeGetChildCount(owner) > 0) {
|
if (owner->getChildCount() > 0) {
|
||||||
for (auto* child : owner->getChildren()) {
|
for (auto* child : owner->getChildren()) {
|
||||||
child->setLayout({});
|
child->setLayout({});
|
||||||
child->setOwner(nullptr);
|
child->setOwner(nullptr);
|
||||||
@@ -404,7 +400,7 @@ YOGA_EXPORT void YGNodeSetChildren(
|
|||||||
owner->markDirtyAndPropagate();
|
owner->markDirtyAndPropagate();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (YGNodeGetChildCount(owner) > 0) {
|
if (owner->getChildCount() > 0) {
|
||||||
for (auto* oldChild : owner->getChildren()) {
|
for (auto* oldChild : owner->getChildren()) {
|
||||||
// Our new children may have nodes in common with the old children. We
|
// Our new children may have nodes in common with the old children. We
|
||||||
// don't reset these common nodes.
|
// don't reset these common nodes.
|
||||||
@@ -424,8 +420,8 @@ YOGA_EXPORT void YGNodeSetChildren(
|
|||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT YGNodeRef
|
YOGA_EXPORT YGNodeRef
|
||||||
YGNodeGetChild(const YGNodeRef nodeRef, const uint32_t index) {
|
YGNodeGetChild(const YGNodeRef nodeRef, const size_t index) {
|
||||||
auto node = static_cast<yoga::Node*>(nodeRef);
|
const auto node = resolveRef(nodeRef);
|
||||||
|
|
||||||
if (index < node->getChildren().size()) {
|
if (index < node->getChildren().size()) {
|
||||||
return node->getChild(index);
|
return node->getChild(index);
|
||||||
@@ -433,21 +429,20 @@ YGNodeGetChild(const YGNodeRef nodeRef, const uint32_t index) {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT uint32_t YGNodeGetChildCount(const YGNodeConstRef node) {
|
YOGA_EXPORT size_t YGNodeGetChildCount(const YGNodeConstRef node) {
|
||||||
return static_cast<uint32_t>(
|
return resolveRef(node)->getChildren().size();
|
||||||
static_cast<const yoga::Node*>(node)->getChildren().size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT YGNodeRef YGNodeGetOwner(const YGNodeRef node) {
|
YOGA_EXPORT YGNodeRef YGNodeGetOwner(const YGNodeRef node) {
|
||||||
return static_cast<yoga::Node*>(node)->getOwner();
|
return resolveRef(node)->getOwner();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT YGNodeRef YGNodeGetParent(const YGNodeRef node) {
|
YOGA_EXPORT YGNodeRef YGNodeGetParent(const YGNodeRef node) {
|
||||||
return static_cast<yoga::Node*>(node)->getOwner();
|
return resolveRef(node)->getOwner();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeMarkDirty(const YGNodeRef nodeRef) {
|
YOGA_EXPORT void YGNodeMarkDirty(const YGNodeRef nodeRef) {
|
||||||
auto node = static_cast<yoga::Node*>(nodeRef);
|
const auto node = resolveRef(nodeRef);
|
||||||
|
|
||||||
yoga::assertFatalWithNode(
|
yoga::assertFatalWithNode(
|
||||||
node,
|
node,
|
||||||
@@ -460,9 +455,9 @@ YOGA_EXPORT void YGNodeMarkDirty(const YGNodeRef nodeRef) {
|
|||||||
|
|
||||||
YOGA_EXPORT void YGNodeCopyStyle(
|
YOGA_EXPORT void YGNodeCopyStyle(
|
||||||
const YGNodeRef dstNodeRef,
|
const YGNodeRef dstNodeRef,
|
||||||
const YGNodeRef srcNodeRef) {
|
const YGNodeConstRef srcNodeRef) {
|
||||||
auto dstNode = static_cast<yoga::Node*>(dstNodeRef);
|
auto dstNode = resolveRef(dstNodeRef);
|
||||||
auto srcNode = static_cast<yoga::Node*>(srcNodeRef);
|
auto srcNode = resolveRef(srcNodeRef);
|
||||||
|
|
||||||
if (!(dstNode->getStyle() == srcNode->getStyle())) {
|
if (!(dstNode->getStyle() == srcNode->getStyle())) {
|
||||||
dstNode->setStyle(srcNode->getStyle());
|
dstNode->setStyle(srcNode->getStyle());
|
||||||
@@ -471,14 +466,14 @@ YOGA_EXPORT void YGNodeCopyStyle(
|
|||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT float YGNodeStyleGetFlexGrow(const YGNodeConstRef nodeRef) {
|
YOGA_EXPORT float YGNodeStyleGetFlexGrow(const YGNodeConstRef nodeRef) {
|
||||||
auto node = static_cast<const yoga::Node*>(nodeRef);
|
const auto node = resolveRef(nodeRef);
|
||||||
return node->getStyle().flexGrow().isUndefined()
|
return node->getStyle().flexGrow().isUndefined()
|
||||||
? Style::DefaultFlexGrow
|
? Style::DefaultFlexGrow
|
||||||
: node->getStyle().flexGrow().unwrap();
|
: node->getStyle().flexGrow().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT float YGNodeStyleGetFlexShrink(const YGNodeConstRef nodeRef) {
|
YOGA_EXPORT float YGNodeStyleGetFlexShrink(const YGNodeConstRef nodeRef) {
|
||||||
auto node = static_cast<const yoga::Node*>(nodeRef);
|
const auto node = resolveRef(nodeRef);
|
||||||
return node->getStyle().flexShrink().isUndefined()
|
return node->getStyle().flexShrink().isUndefined()
|
||||||
? (node->getConfig()->useWebDefaults() ? Style::WebDefaultFlexShrink
|
? (node->getConfig()->useWebDefaults() ? Style::WebDefaultFlexShrink
|
||||||
: Style::DefaultFlexShrink)
|
: Style::DefaultFlexShrink)
|
||||||
@@ -502,7 +497,7 @@ void updateStyle(
|
|||||||
template <typename Ref, typename T>
|
template <typename Ref, typename T>
|
||||||
void updateStyle(YGNodeRef node, Ref (Style::*prop)(), T value) {
|
void updateStyle(YGNodeRef node, Ref (Style::*prop)(), T value) {
|
||||||
updateStyle(
|
updateStyle(
|
||||||
static_cast<yoga::Node*>(node),
|
resolveRef(node),
|
||||||
value,
|
value,
|
||||||
[prop](Style& s, T x) { return (s.*prop)() != x; },
|
[prop](Style& s, T x) { return (s.*prop)() != x; },
|
||||||
[prop](Style& s, T x) { (s.*prop)() = x; });
|
[prop](Style& s, T x) { (s.*prop)() = x; });
|
||||||
@@ -515,7 +510,7 @@ void updateIndexedStyleProp(
|
|||||||
Idx idx,
|
Idx idx,
|
||||||
CompactValue value) {
|
CompactValue value) {
|
||||||
updateStyle(
|
updateStyle(
|
||||||
static_cast<yoga::Node*>(node),
|
resolveRef(node),
|
||||||
value,
|
value,
|
||||||
[idx, prop](Style& s, CompactValue x) { return (s.*prop)()[idx] != x; },
|
[idx, prop](Style& s, CompactValue x) { return (s.*prop)()[idx] != x; },
|
||||||
[idx, prop](Style& s, CompactValue x) { (s.*prop)()[idx] = x; });
|
[idx, prop](Style& s, CompactValue x) { (s.*prop)()[idx] = x; });
|
||||||
@@ -536,7 +531,7 @@ YOGA_EXPORT void YGNodeStyleSetDirection(
|
|||||||
updateStyle<MSVC_HINT(direction)>(node, &Style::direction, value);
|
updateStyle<MSVC_HINT(direction)>(node, &Style::direction, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGDirection YGNodeStyleGetDirection(const YGNodeConstRef node) {
|
YOGA_EXPORT YGDirection YGNodeStyleGetDirection(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)->getStyle().direction();
|
return resolveRef(node)->getStyle().direction();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetFlexDirection(
|
YOGA_EXPORT void YGNodeStyleSetFlexDirection(
|
||||||
@@ -547,7 +542,7 @@ YOGA_EXPORT void YGNodeStyleSetFlexDirection(
|
|||||||
}
|
}
|
||||||
YOGA_EXPORT YGFlexDirection
|
YOGA_EXPORT YGFlexDirection
|
||||||
YGNodeStyleGetFlexDirection(const YGNodeConstRef node) {
|
YGNodeStyleGetFlexDirection(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)->getStyle().flexDirection();
|
return resolveRef(node)->getStyle().flexDirection();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetJustifyContent(
|
YOGA_EXPORT void YGNodeStyleSetJustifyContent(
|
||||||
@@ -557,7 +552,7 @@ YOGA_EXPORT void YGNodeStyleSetJustifyContent(
|
|||||||
node, &Style::justifyContent, justifyContent);
|
node, &Style::justifyContent, justifyContent);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGJustify YGNodeStyleGetJustifyContent(const YGNodeConstRef node) {
|
YOGA_EXPORT YGJustify YGNodeStyleGetJustifyContent(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)->getStyle().justifyContent();
|
return resolveRef(node)->getStyle().justifyContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetAlignContent(
|
YOGA_EXPORT void YGNodeStyleSetAlignContent(
|
||||||
@@ -567,7 +562,7 @@ YOGA_EXPORT void YGNodeStyleSetAlignContent(
|
|||||||
node, &Style::alignContent, alignContent);
|
node, &Style::alignContent, alignContent);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGAlign YGNodeStyleGetAlignContent(const YGNodeConstRef node) {
|
YOGA_EXPORT YGAlign YGNodeStyleGetAlignContent(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)->getStyle().alignContent();
|
return resolveRef(node)->getStyle().alignContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetAlignItems(
|
YOGA_EXPORT void YGNodeStyleSetAlignItems(
|
||||||
@@ -576,7 +571,7 @@ YOGA_EXPORT void YGNodeStyleSetAlignItems(
|
|||||||
updateStyle<MSVC_HINT(alignItems)>(node, &Style::alignItems, alignItems);
|
updateStyle<MSVC_HINT(alignItems)>(node, &Style::alignItems, alignItems);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGAlign YGNodeStyleGetAlignItems(const YGNodeConstRef node) {
|
YOGA_EXPORT YGAlign YGNodeStyleGetAlignItems(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)->getStyle().alignItems();
|
return resolveRef(node)->getStyle().alignItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetAlignSelf(
|
YOGA_EXPORT void YGNodeStyleSetAlignSelf(
|
||||||
@@ -585,7 +580,7 @@ YOGA_EXPORT void YGNodeStyleSetAlignSelf(
|
|||||||
updateStyle<MSVC_HINT(alignSelf)>(node, &Style::alignSelf, alignSelf);
|
updateStyle<MSVC_HINT(alignSelf)>(node, &Style::alignSelf, alignSelf);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGAlign YGNodeStyleGetAlignSelf(const YGNodeConstRef node) {
|
YOGA_EXPORT YGAlign YGNodeStyleGetAlignSelf(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)->getStyle().alignSelf();
|
return resolveRef(node)->getStyle().alignSelf();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetPositionType(
|
YOGA_EXPORT void YGNodeStyleSetPositionType(
|
||||||
@@ -596,7 +591,7 @@ YOGA_EXPORT void YGNodeStyleSetPositionType(
|
|||||||
}
|
}
|
||||||
YOGA_EXPORT YGPositionType
|
YOGA_EXPORT YGPositionType
|
||||||
YGNodeStyleGetPositionType(const YGNodeConstRef node) {
|
YGNodeStyleGetPositionType(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)->getStyle().positionType();
|
return resolveRef(node)->getStyle().positionType();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetFlexWrap(
|
YOGA_EXPORT void YGNodeStyleSetFlexWrap(
|
||||||
@@ -605,7 +600,7 @@ YOGA_EXPORT void YGNodeStyleSetFlexWrap(
|
|||||||
updateStyle<MSVC_HINT(flexWrap)>(node, &Style::flexWrap, flexWrap);
|
updateStyle<MSVC_HINT(flexWrap)>(node, &Style::flexWrap, flexWrap);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGWrap YGNodeStyleGetFlexWrap(const YGNodeConstRef node) {
|
YOGA_EXPORT YGWrap YGNodeStyleGetFlexWrap(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)->getStyle().flexWrap();
|
return resolveRef(node)->getStyle().flexWrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetOverflow(
|
YOGA_EXPORT void YGNodeStyleSetOverflow(
|
||||||
@@ -614,7 +609,7 @@ YOGA_EXPORT void YGNodeStyleSetOverflow(
|
|||||||
updateStyle<MSVC_HINT(overflow)>(node, &Style::overflow, overflow);
|
updateStyle<MSVC_HINT(overflow)>(node, &Style::overflow, overflow);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGOverflow YGNodeStyleGetOverflow(const YGNodeConstRef node) {
|
YOGA_EXPORT YGOverflow YGNodeStyleGetOverflow(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)->getStyle().overflow();
|
return resolveRef(node)->getStyle().overflow();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetDisplay(
|
YOGA_EXPORT void YGNodeStyleSetDisplay(
|
||||||
@@ -623,7 +618,7 @@ YOGA_EXPORT void YGNodeStyleSetDisplay(
|
|||||||
updateStyle<MSVC_HINT(display)>(node, &Style::display, display);
|
updateStyle<MSVC_HINT(display)>(node, &Style::display, display);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGDisplay YGNodeStyleGetDisplay(const YGNodeConstRef node) {
|
YOGA_EXPORT YGDisplay YGNodeStyleGetDisplay(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)->getStyle().display();
|
return resolveRef(node)->getStyle().display();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(T26792433): Change the API to accept FloatOptional.
|
// TODO(T26792433): Change the API to accept FloatOptional.
|
||||||
@@ -633,7 +628,7 @@ YOGA_EXPORT void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {
|
|||||||
|
|
||||||
// TODO(T26792433): Change the API to accept FloatOptional.
|
// TODO(T26792433): Change the API to accept FloatOptional.
|
||||||
YOGA_EXPORT float YGNodeStyleGetFlex(const YGNodeConstRef nodeRef) {
|
YOGA_EXPORT float YGNodeStyleGetFlex(const YGNodeConstRef nodeRef) {
|
||||||
auto node = static_cast<const yoga::Node*>(nodeRef);
|
const auto node = resolveRef(nodeRef);
|
||||||
return node->getStyle().flex().isUndefined()
|
return node->getStyle().flex().isUndefined()
|
||||||
? YGUndefined
|
? YGUndefined
|
||||||
: node->getStyle().flex().unwrap();
|
: node->getStyle().flex().unwrap();
|
||||||
@@ -656,8 +651,7 @@ YOGA_EXPORT void YGNodeStyleSetFlexShrink(
|
|||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) {
|
YOGA_EXPORT YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) {
|
||||||
YGValue flexBasis =
|
YGValue flexBasis = resolveRef(node)->getStyle().flexBasis();
|
||||||
static_cast<const yoga::Node*>(node)->getStyle().flexBasis();
|
|
||||||
if (flexBasis.unit == YGUnitUndefined || flexBasis.unit == YGUnitAuto) {
|
if (flexBasis.unit == YGUnitUndefined || flexBasis.unit == YGUnitAuto) {
|
||||||
// TODO(T26792433): Get rid off the use of YGUndefined at client side
|
// TODO(T26792433): Get rid off the use of YGUndefined at client side
|
||||||
flexBasis.value = YGUndefined;
|
flexBasis.value = YGUndefined;
|
||||||
@@ -701,7 +695,7 @@ YOGA_EXPORT void YGNodeStyleSetPositionPercent(
|
|||||||
node, &Style::position, edge, value);
|
node, &Style::position, edge, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) {
|
YOGA_EXPORT YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) {
|
||||||
return static_cast<const yoga::Node*>(node)->getStyle().position()[edge];
|
return resolveRef(node)->getStyle().position()[edge];
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetMargin(
|
YOGA_EXPORT void YGNodeStyleSetMargin(
|
||||||
@@ -723,7 +717,7 @@ YOGA_EXPORT void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge) {
|
|||||||
node, &Style::margin, edge, CompactValue::ofAuto());
|
node, &Style::margin, edge, CompactValue::ofAuto());
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) {
|
YOGA_EXPORT YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) {
|
||||||
return static_cast<const yoga::Node*>(node)->getStyle().margin()[edge];
|
return resolveRef(node)->getStyle().margin()[edge];
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetPadding(
|
YOGA_EXPORT void YGNodeStyleSetPadding(
|
||||||
@@ -743,7 +737,7 @@ YOGA_EXPORT void YGNodeStyleSetPaddingPercent(
|
|||||||
node, &Style::padding, edge, value);
|
node, &Style::padding, edge, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge) {
|
YOGA_EXPORT YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge) {
|
||||||
return static_cast<const yoga::Node*>(node)->getStyle().padding()[edge];
|
return resolveRef(node)->getStyle().padding()[edge];
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(T26792433): Change the API to accept FloatOptional.
|
// TODO(T26792433): Change the API to accept FloatOptional.
|
||||||
@@ -758,7 +752,7 @@ YOGA_EXPORT void YGNodeStyleSetBorder(
|
|||||||
YOGA_EXPORT float YGNodeStyleGetBorder(
|
YOGA_EXPORT float YGNodeStyleGetBorder(
|
||||||
const YGNodeConstRef node,
|
const YGNodeConstRef node,
|
||||||
const YGEdge edge) {
|
const YGEdge edge) {
|
||||||
auto border = static_cast<const yoga::Node*>(node)->getStyle().border()[edge];
|
auto border = resolveRef(node)->getStyle().border()[edge];
|
||||||
if (border.isUndefined() || border.isAuto()) {
|
if (border.isUndefined() || border.isAuto()) {
|
||||||
// TODO(T26792433): Rather than returning YGUndefined, change the api to
|
// TODO(T26792433): Rather than returning YGUndefined, change the api to
|
||||||
// return FloatOptional.
|
// return FloatOptional.
|
||||||
@@ -779,8 +773,7 @@ YOGA_EXPORT void YGNodeStyleSetGap(
|
|||||||
YOGA_EXPORT float YGNodeStyleGetGap(
|
YOGA_EXPORT float YGNodeStyleGetGap(
|
||||||
const YGNodeConstRef node,
|
const YGNodeConstRef node,
|
||||||
const YGGutter gutter) {
|
const YGGutter gutter) {
|
||||||
auto gapLength =
|
auto gapLength = resolveRef(node)->getStyle().gap()[gutter];
|
||||||
static_cast<const yoga::Node*>(node)->getStyle().gap()[gutter];
|
|
||||||
if (gapLength.isUndefined() || gapLength.isAuto()) {
|
if (gapLength.isUndefined() || gapLength.isAuto()) {
|
||||||
// TODO(T26792433): Rather than returning YGUndefined, change the api to
|
// TODO(T26792433): Rather than returning YGUndefined, change the api to
|
||||||
// return FloatOptional.
|
// return FloatOptional.
|
||||||
@@ -794,8 +787,7 @@ YOGA_EXPORT float YGNodeStyleGetGap(
|
|||||||
|
|
||||||
// TODO(T26792433): Change the API to accept FloatOptional.
|
// TODO(T26792433): Change the API to accept FloatOptional.
|
||||||
YOGA_EXPORT float YGNodeStyleGetAspectRatio(const YGNodeConstRef node) {
|
YOGA_EXPORT float YGNodeStyleGetAspectRatio(const YGNodeConstRef node) {
|
||||||
const FloatOptional op =
|
const FloatOptional op = resolveRef(node)->getStyle().aspectRatio();
|
||||||
static_cast<const yoga::Node*>(node)->getStyle().aspectRatio();
|
|
||||||
return op.isUndefined() ? YGUndefined : op.unwrap();
|
return op.isUndefined() ? YGUndefined : op.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -822,9 +814,7 @@ YOGA_EXPORT void YGNodeStyleSetWidthAuto(YGNodeRef node) {
|
|||||||
node, &Style::dimensions, YGDimensionWidth, CompactValue::ofAuto());
|
node, &Style::dimensions, YGDimensionWidth, CompactValue::ofAuto());
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetWidth(YGNodeConstRef node) {
|
YOGA_EXPORT YGValue YGNodeStyleGetWidth(YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)
|
return resolveRef(node)->getStyle().dimensions()[YGDimensionWidth];
|
||||||
->getStyle()
|
|
||||||
.dimensions()[YGDimensionWidth];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetHeight(YGNodeRef node, float points) {
|
YOGA_EXPORT void YGNodeStyleSetHeight(YGNodeRef node, float points) {
|
||||||
@@ -842,9 +832,7 @@ YOGA_EXPORT void YGNodeStyleSetHeightAuto(YGNodeRef node) {
|
|||||||
node, &Style::dimensions, YGDimensionHeight, CompactValue::ofAuto());
|
node, &Style::dimensions, YGDimensionHeight, CompactValue::ofAuto());
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetHeight(YGNodeConstRef node) {
|
YOGA_EXPORT YGValue YGNodeStyleGetHeight(YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)
|
return resolveRef(node)->getStyle().dimensions()[YGDimensionHeight];
|
||||||
->getStyle()
|
|
||||||
.dimensions()[YGDimensionHeight];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetMinWidth(
|
YOGA_EXPORT void YGNodeStyleSetMinWidth(
|
||||||
@@ -862,9 +850,7 @@ YOGA_EXPORT void YGNodeStyleSetMinWidthPercent(
|
|||||||
node, &Style::minDimensions, YGDimensionWidth, value);
|
node, &Style::minDimensions, YGDimensionWidth, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) {
|
YOGA_EXPORT YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)
|
return resolveRef(node)->getStyle().minDimensions()[YGDimensionWidth];
|
||||||
->getStyle()
|
|
||||||
.minDimensions()[YGDimensionWidth];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetMinHeight(
|
YOGA_EXPORT void YGNodeStyleSetMinHeight(
|
||||||
@@ -882,9 +868,7 @@ YOGA_EXPORT void YGNodeStyleSetMinHeightPercent(
|
|||||||
node, &Style::minDimensions, YGDimensionHeight, value);
|
node, &Style::minDimensions, YGDimensionHeight, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) {
|
YOGA_EXPORT YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)
|
return resolveRef(node)->getStyle().minDimensions()[YGDimensionHeight];
|
||||||
->getStyle()
|
|
||||||
.minDimensions()[YGDimensionHeight];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetMaxWidth(
|
YOGA_EXPORT void YGNodeStyleSetMaxWidth(
|
||||||
@@ -902,9 +886,7 @@ YOGA_EXPORT void YGNodeStyleSetMaxWidthPercent(
|
|||||||
node, &Style::maxDimensions, YGDimensionWidth, value);
|
node, &Style::maxDimensions, YGDimensionWidth, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) {
|
YOGA_EXPORT YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)
|
return resolveRef(node)->getStyle().maxDimensions()[YGDimensionWidth];
|
||||||
->getStyle()
|
|
||||||
.maxDimensions()[YGDimensionWidth];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetMaxHeight(
|
YOGA_EXPORT void YGNodeStyleSetMaxHeight(
|
||||||
@@ -922,20 +904,18 @@ YOGA_EXPORT void YGNodeStyleSetMaxHeightPercent(
|
|||||||
node, &Style::maxDimensions, YGDimensionHeight, value);
|
node, &Style::maxDimensions, YGDimensionHeight, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) {
|
YOGA_EXPORT YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) {
|
||||||
return static_cast<const yoga::Node*>(node)
|
return resolveRef(node)->getStyle().maxDimensions()[YGDimensionHeight];
|
||||||
->getStyle()
|
|
||||||
.maxDimensions()[YGDimensionHeight];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define YG_NODE_LAYOUT_PROPERTY_IMPL(type, name, instanceName) \
|
#define YG_NODE_LAYOUT_PROPERTY_IMPL(type, name, instanceName) \
|
||||||
YOGA_EXPORT type YGNodeLayoutGet##name(const YGNodeRef node) { \
|
YOGA_EXPORT type YGNodeLayoutGet##name(const YGNodeConstRef node) { \
|
||||||
return static_cast<yoga::Node*>(node)->getLayout().instanceName; \
|
return resolveRef(node)->getLayout().instanceName; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(type, name, instanceName) \
|
#define YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(type, name, instanceName) \
|
||||||
YOGA_EXPORT type YGNodeLayoutGet##name( \
|
YOGA_EXPORT type YGNodeLayoutGet##name( \
|
||||||
const YGNodeRef nodeRef, const YGEdge edge) { \
|
const YGNodeConstRef nodeRef, const YGEdge edge) { \
|
||||||
auto node = static_cast<yoga::Node*>(nodeRef); \
|
const auto node = resolveRef(nodeRef); \
|
||||||
yoga::assertFatalWithNode( \
|
yoga::assertFatalWithNode( \
|
||||||
node, \
|
node, \
|
||||||
edge <= YGEdgeEnd, \
|
edge <= YGEdgeEnd, \
|
||||||
@@ -975,9 +955,9 @@ YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Padding, padding)
|
|||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
YOGA_EXPORT void YGNodePrint(
|
YOGA_EXPORT void YGNodePrint(
|
||||||
const YGNodeRef nodeRef,
|
const YGNodeConstRef nodeRef,
|
||||||
const YGPrintOptions options) {
|
const YGPrintOptions options) {
|
||||||
const auto node = static_cast<yoga::Node*>(nodeRef);
|
const auto node = resolveRef(nodeRef);
|
||||||
std::string str;
|
std::string str;
|
||||||
yoga::nodeToString(str, node, options, 0);
|
yoga::nodeToString(str, node, options, 0);
|
||||||
yoga::log(node, YGLogLevelDebug, nullptr, str.c_str());
|
yoga::log(node, YGLogLevelDebug, nullptr, str.c_str());
|
||||||
@@ -986,12 +966,12 @@ YOGA_EXPORT void YGNodePrint(
|
|||||||
|
|
||||||
YOGA_EXPORT void YGConfigSetLogger(const YGConfigRef config, YGLogger logger) {
|
YOGA_EXPORT void YGConfigSetLogger(const YGConfigRef config, YGLogger logger) {
|
||||||
if (logger != nullptr) {
|
if (logger != nullptr) {
|
||||||
static_cast<yoga::Config*>(config)->setLogger(logger);
|
resolveRef(config)->setLogger(logger);
|
||||||
} else {
|
} else {
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
static_cast<yoga::Config*>(config)->setLogger(&YGAndroidLog);
|
resolveRef(config)->setLogger(&YGAndroidLog);
|
||||||
#else
|
#else
|
||||||
static_cast<yoga::Config*>(config)->setLogger(&YGDefaultLog);
|
resolveRef(config)->setLogger(&YGDefaultLog);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1000,21 +980,21 @@ YOGA_EXPORT void YGConfigSetPointScaleFactor(
|
|||||||
const YGConfigRef config,
|
const YGConfigRef config,
|
||||||
const float pixelsInPoint) {
|
const float pixelsInPoint) {
|
||||||
yoga::assertFatalWithConfig(
|
yoga::assertFatalWithConfig(
|
||||||
config,
|
resolveRef(config),
|
||||||
pixelsInPoint >= 0.0f,
|
pixelsInPoint >= 0.0f,
|
||||||
"Scale factor should not be less than zero");
|
"Scale factor should not be less than zero");
|
||||||
|
|
||||||
// We store points for Pixel as we will use it for rounding
|
// We store points for Pixel as we will use it for rounding
|
||||||
if (pixelsInPoint == 0.0f) {
|
if (pixelsInPoint == 0.0f) {
|
||||||
// Zero is used to skip rounding
|
// Zero is used to skip rounding
|
||||||
static_cast<yoga::Config*>(config)->setPointScaleFactor(0.0f);
|
resolveRef(config)->setPointScaleFactor(0.0f);
|
||||||
} else {
|
} else {
|
||||||
static_cast<yoga::Config*>(config)->setPointScaleFactor(pixelsInPoint);
|
resolveRef(config)->setPointScaleFactor(pixelsInPoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT float YGConfigGetPointScaleFactor(const YGConfigRef config) {
|
YOGA_EXPORT float YGConfigGetPointScaleFactor(const YGConfigConstRef config) {
|
||||||
return static_cast<yoga::Config*>(config)->getPointScaleFactor();
|
return resolveRef(config)->getPointScaleFactor();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT float YGRoundValueToPixelGrid(
|
YOGA_EXPORT float YGRoundValueToPixelGrid(
|
||||||
@@ -1030,63 +1010,60 @@ YOGA_EXPORT void YGConfigSetExperimentalFeatureEnabled(
|
|||||||
const YGConfigRef config,
|
const YGConfigRef config,
|
||||||
const YGExperimentalFeature feature,
|
const YGExperimentalFeature feature,
|
||||||
const bool enabled) {
|
const bool enabled) {
|
||||||
static_cast<yoga::Config*>(config)->setExperimentalFeatureEnabled(
|
resolveRef(config)->setExperimentalFeatureEnabled(feature, enabled);
|
||||||
feature, enabled);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT bool YGConfigIsExperimentalFeatureEnabled(
|
YOGA_EXPORT bool YGConfigIsExperimentalFeatureEnabled(
|
||||||
const YGConfigRef config,
|
const YGConfigConstRef config,
|
||||||
const YGExperimentalFeature feature) {
|
const YGExperimentalFeature feature) {
|
||||||
return static_cast<yoga::Config*>(config)->isExperimentalFeatureEnabled(
|
return resolveRef(config)->isExperimentalFeatureEnabled(feature);
|
||||||
feature);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGConfigSetUseWebDefaults(
|
YOGA_EXPORT void YGConfigSetUseWebDefaults(
|
||||||
const YGConfigRef config,
|
const YGConfigRef config,
|
||||||
const bool enabled) {
|
const bool enabled) {
|
||||||
static_cast<yoga::Config*>(config)->setUseWebDefaults(enabled);
|
resolveRef(config)->setUseWebDefaults(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT bool YGConfigGetUseLegacyStretchBehaviour(
|
YOGA_EXPORT bool YGConfigGetUseLegacyStretchBehaviour(
|
||||||
const YGConfigRef config) {
|
const YGConfigConstRef config) {
|
||||||
return static_cast<yoga::Config*>(config)->hasErrata(
|
return resolveRef(config)->hasErrata(YGErrataStretchFlexBasis);
|
||||||
YGErrataStretchFlexBasis);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGConfigSetUseLegacyStretchBehaviour(
|
YOGA_EXPORT void YGConfigSetUseLegacyStretchBehaviour(
|
||||||
const YGConfigRef config,
|
const YGConfigRef config,
|
||||||
const bool useLegacyStretchBehaviour) {
|
const bool useLegacyStretchBehaviour) {
|
||||||
if (useLegacyStretchBehaviour) {
|
if (useLegacyStretchBehaviour) {
|
||||||
static_cast<yoga::Config*>(config)->addErrata(YGErrataStretchFlexBasis);
|
resolveRef(config)->addErrata(YGErrataStretchFlexBasis);
|
||||||
} else {
|
} else {
|
||||||
static_cast<yoga::Config*>(config)->removeErrata(YGErrataStretchFlexBasis);
|
resolveRef(config)->removeErrata(YGErrataStretchFlexBasis);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool YGConfigGetUseWebDefaults(const YGConfigRef config) {
|
bool YGConfigGetUseWebDefaults(const YGConfigConstRef config) {
|
||||||
return static_cast<yoga::Config*>(config)->useWebDefaults();
|
return resolveRef(config)->useWebDefaults();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGConfigSetContext(const YGConfigRef config, void* context) {
|
YOGA_EXPORT void YGConfigSetContext(const YGConfigRef config, void* context) {
|
||||||
static_cast<yoga::Config*>(config)->setContext(context);
|
resolveRef(config)->setContext(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void* YGConfigGetContext(const YGConfigRef config) {
|
YOGA_EXPORT void* YGConfigGetContext(const YGConfigConstRef config) {
|
||||||
return static_cast<yoga::Config*>(config)->getContext();
|
return resolveRef(config)->getContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGConfigSetErrata(YGConfigRef config, YGErrata errata) {
|
YOGA_EXPORT void YGConfigSetErrata(YGConfigRef config, YGErrata errata) {
|
||||||
static_cast<yoga::Config*>(config)->setErrata(errata);
|
resolveRef(config)->setErrata(errata);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT YGErrata YGConfigGetErrata(YGConfigRef config) {
|
YOGA_EXPORT YGErrata YGConfigGetErrata(YGConfigConstRef config) {
|
||||||
return static_cast<yoga::Config*>(config)->getErrata();
|
return resolveRef(config)->getErrata();
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGConfigSetCloneNodeFunc(
|
YOGA_EXPORT void YGConfigSetCloneNodeFunc(
|
||||||
const YGConfigRef config,
|
const YGConfigRef config,
|
||||||
const YGCloneNodeFunc callback) {
|
const YGCloneNodeFunc callback) {
|
||||||
static_cast<yoga::Config*>(config)->setCloneNodeCallback(callback);
|
resolveRef(config)->setCloneNodeCallback(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This should not be part of the public API. Remove after removing
|
// TODO: This should not be part of the public API. Remove after removing
|
||||||
@@ -1118,7 +1095,7 @@ YOGA_EXPORT bool YGNodeCanUseCachedMeasurement(
|
|||||||
lastComputedHeight,
|
lastComputedHeight,
|
||||||
marginRow,
|
marginRow,
|
||||||
marginColumn,
|
marginColumn,
|
||||||
static_cast<yoga::Config*>(config));
|
resolveRef(config));
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeCalculateLayout(
|
YOGA_EXPORT void YGNodeCalculateLayout(
|
||||||
@@ -1131,15 +1108,11 @@ YOGA_EXPORT void YGNodeCalculateLayout(
|
|||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeCalculateLayoutWithContext(
|
YOGA_EXPORT void YGNodeCalculateLayoutWithContext(
|
||||||
const YGNodeRef nodeRef,
|
const YGNodeRef node,
|
||||||
const float ownerWidth,
|
const float ownerWidth,
|
||||||
const float ownerHeight,
|
const float ownerHeight,
|
||||||
const YGDirection ownerDirection,
|
const YGDirection ownerDirection,
|
||||||
void* layoutContext) {
|
void* layoutContext) {
|
||||||
yoga::calculateLayout(
|
yoga::calculateLayout(
|
||||||
static_cast<Node*>(nodeRef),
|
resolveRef(node), ownerWidth, ownerHeight, ownerDirection, layoutContext);
|
||||||
ownerWidth,
|
|
||||||
ownerHeight,
|
|
||||||
ownerDirection,
|
|
||||||
layoutContext);
|
|
||||||
}
|
}
|
||||||
|
92
yoga/Yoga.h
92
yoga/Yoga.h
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <yoga/YGEnums.h>
|
#include <yoga/YGEnums.h>
|
||||||
@@ -23,33 +24,36 @@ typedef struct YGSize {
|
|||||||
} YGSize;
|
} YGSize;
|
||||||
|
|
||||||
typedef struct YGConfig* YGConfigRef;
|
typedef struct YGConfig* YGConfigRef;
|
||||||
|
typedef const struct YGConfig* YGConfigConstRef;
|
||||||
|
|
||||||
typedef struct YGNode* YGNodeRef;
|
typedef struct YGNode* YGNodeRef;
|
||||||
typedef const struct YGNode* YGNodeConstRef;
|
typedef const struct YGNode* YGNodeConstRef;
|
||||||
|
|
||||||
typedef YGSize (*YGMeasureFunc)(
|
typedef YGSize (*YGMeasureFunc)(
|
||||||
YGNodeRef node,
|
YGNodeConstRef node,
|
||||||
float width,
|
float width,
|
||||||
YGMeasureMode widthMode,
|
YGMeasureMode widthMode,
|
||||||
float height,
|
float height,
|
||||||
YGMeasureMode heightMode);
|
YGMeasureMode heightMode);
|
||||||
typedef float (*YGBaselineFunc)(YGNodeRef node, float width, float height);
|
typedef float (*YGBaselineFunc)(YGNodeConstRef node, float width, float height);
|
||||||
typedef void (*YGDirtiedFunc)(YGNodeRef node);
|
typedef void (*YGDirtiedFunc)(YGNodeConstRef node);
|
||||||
typedef void (*YGPrintFunc)(YGNodeRef node);
|
typedef void (*YGPrintFunc)(YGNodeConstRef node);
|
||||||
typedef void (*YGNodeCleanupFunc)(YGNodeRef node);
|
typedef void (*YGNodeCleanupFunc)(YGNodeConstRef node);
|
||||||
typedef int (*YGLogger)(
|
typedef int (*YGLogger)(
|
||||||
YGConfigRef config,
|
YGConfigConstRef config,
|
||||||
YGNodeRef node,
|
YGNodeConstRef node,
|
||||||
YGLogLevel level,
|
YGLogLevel level,
|
||||||
const char* format,
|
const char* format,
|
||||||
va_list args);
|
va_list args);
|
||||||
typedef YGNodeRef (
|
typedef YGNodeRef (*YGCloneNodeFunc)(
|
||||||
*YGCloneNodeFunc)(YGNodeRef oldNode, YGNodeRef owner, int childIndex);
|
YGNodeConstRef oldNode,
|
||||||
|
YGNodeConstRef owner,
|
||||||
|
size_t childIndex);
|
||||||
|
|
||||||
// YGNode
|
// YGNode
|
||||||
WIN_EXPORT YGNodeRef YGNodeNew(void);
|
WIN_EXPORT YGNodeRef YGNodeNew(void);
|
||||||
WIN_EXPORT YGNodeRef YGNodeNewWithConfig(YGConfigRef config);
|
WIN_EXPORT YGNodeRef YGNodeNewWithConfig(YGConfigRef config);
|
||||||
WIN_EXPORT YGNodeRef YGNodeClone(YGNodeRef node);
|
WIN_EXPORT YGNodeRef YGNodeClone(YGNodeConstRef node);
|
||||||
WIN_EXPORT void YGNodeFree(YGNodeRef node);
|
WIN_EXPORT void YGNodeFree(YGNodeRef node);
|
||||||
WIN_EXPORT void YGNodeFreeRecursiveWithCleanupFunc(
|
WIN_EXPORT void YGNodeFreeRecursiveWithCleanupFunc(
|
||||||
YGNodeRef node,
|
YGNodeRef node,
|
||||||
@@ -60,29 +64,26 @@ WIN_EXPORT void YGNodeReset(YGNodeRef node);
|
|||||||
WIN_EXPORT void YGNodeInsertChild(
|
WIN_EXPORT void YGNodeInsertChild(
|
||||||
YGNodeRef node,
|
YGNodeRef node,
|
||||||
YGNodeRef child,
|
YGNodeRef child,
|
||||||
uint32_t index);
|
size_t index);
|
||||||
|
|
||||||
WIN_EXPORT void YGNodeSwapChild(
|
WIN_EXPORT void YGNodeSwapChild(YGNodeRef node, YGNodeRef child, size_t index);
|
||||||
YGNodeRef node,
|
|
||||||
YGNodeRef child,
|
|
||||||
uint32_t index);
|
|
||||||
|
|
||||||
WIN_EXPORT void YGNodeRemoveChild(YGNodeRef node, YGNodeRef child);
|
WIN_EXPORT void YGNodeRemoveChild(YGNodeRef node, YGNodeRef child);
|
||||||
WIN_EXPORT void YGNodeRemoveAllChildren(YGNodeRef node);
|
WIN_EXPORT void YGNodeRemoveAllChildren(YGNodeRef node);
|
||||||
WIN_EXPORT YGNodeRef YGNodeGetChild(YGNodeRef node, uint32_t index);
|
WIN_EXPORT YGNodeRef YGNodeGetChild(YGNodeRef node, size_t index);
|
||||||
WIN_EXPORT YGNodeRef YGNodeGetOwner(YGNodeRef node);
|
WIN_EXPORT YGNodeRef YGNodeGetOwner(YGNodeRef node);
|
||||||
WIN_EXPORT YGNodeRef YGNodeGetParent(YGNodeRef node);
|
WIN_EXPORT YGNodeRef YGNodeGetParent(YGNodeRef node);
|
||||||
WIN_EXPORT uint32_t YGNodeGetChildCount(YGNodeConstRef node);
|
WIN_EXPORT size_t YGNodeGetChildCount(YGNodeConstRef node);
|
||||||
WIN_EXPORT void YGNodeSetChildren(
|
WIN_EXPORT void YGNodeSetChildren(
|
||||||
YGNodeRef owner,
|
YGNodeRef owner,
|
||||||
const YGNodeRef* children,
|
const YGNodeRef* children,
|
||||||
uint32_t count);
|
size_t count);
|
||||||
|
|
||||||
WIN_EXPORT void YGNodeSetIsReferenceBaseline(
|
WIN_EXPORT void YGNodeSetIsReferenceBaseline(
|
||||||
YGNodeRef node,
|
YGNodeRef node,
|
||||||
bool isReferenceBaseline);
|
bool isReferenceBaseline);
|
||||||
|
|
||||||
WIN_EXPORT bool YGNodeIsReferenceBaseline(YGNodeRef node);
|
WIN_EXPORT bool YGNodeIsReferenceBaseline(YGNodeConstRef node);
|
||||||
|
|
||||||
WIN_EXPORT void YGNodeCalculateLayout(
|
WIN_EXPORT void YGNodeCalculateLayout(
|
||||||
YGNodeRef node,
|
YGNodeRef node,
|
||||||
@@ -104,7 +105,7 @@ WIN_EXPORT void YGNodeMarkDirty(YGNodeRef node);
|
|||||||
// `YGCalculateLayout` will cause the recalculation of each and every node.
|
// `YGCalculateLayout` will cause the recalculation of each and every node.
|
||||||
WIN_EXPORT void YGNodeMarkDirtyAndPropagateToDescendants(YGNodeRef node);
|
WIN_EXPORT void YGNodeMarkDirtyAndPropagateToDescendants(YGNodeRef node);
|
||||||
|
|
||||||
WIN_EXPORT void YGNodePrint(YGNodeRef node, YGPrintOptions options);
|
WIN_EXPORT void YGNodePrint(YGNodeConstRef node, YGPrintOptions options);
|
||||||
|
|
||||||
WIN_EXPORT bool YGFloatIsUndefined(float value);
|
WIN_EXPORT bool YGFloatIsUndefined(float value);
|
||||||
|
|
||||||
@@ -125,27 +126,27 @@ WIN_EXPORT bool YGNodeCanUseCachedMeasurement(
|
|||||||
float marginColumn,
|
float marginColumn,
|
||||||
YGConfigRef config);
|
YGConfigRef config);
|
||||||
|
|
||||||
WIN_EXPORT void YGNodeCopyStyle(YGNodeRef dstNode, YGNodeRef srcNode);
|
WIN_EXPORT void YGNodeCopyStyle(YGNodeRef dstNode, YGNodeConstRef srcNode);
|
||||||
|
|
||||||
WIN_EXPORT void* YGNodeGetContext(YGNodeRef node);
|
WIN_EXPORT void* YGNodeGetContext(YGNodeConstRef node);
|
||||||
WIN_EXPORT void YGNodeSetContext(YGNodeRef node, void* context);
|
WIN_EXPORT void YGNodeSetContext(YGNodeRef node, void* context);
|
||||||
|
|
||||||
WIN_EXPORT YGConfigRef YGNodeGetConfig(YGNodeRef node);
|
WIN_EXPORT YGConfigRef YGNodeGetConfig(YGNodeRef node);
|
||||||
WIN_EXPORT void YGNodeSetConfig(YGNodeRef node, YGConfigRef config);
|
WIN_EXPORT void YGNodeSetConfig(YGNodeRef node, YGConfigRef config);
|
||||||
|
|
||||||
void YGConfigSetPrintTreeFlag(YGConfigRef config, bool enabled);
|
void YGConfigSetPrintTreeFlag(YGConfigRef config, bool enabled);
|
||||||
bool YGNodeHasMeasureFunc(YGNodeRef node);
|
bool YGNodeHasMeasureFunc(YGNodeConstRef node);
|
||||||
WIN_EXPORT void YGNodeSetMeasureFunc(YGNodeRef node, YGMeasureFunc measureFunc);
|
WIN_EXPORT void YGNodeSetMeasureFunc(YGNodeRef node, YGMeasureFunc measureFunc);
|
||||||
bool YGNodeHasBaselineFunc(YGNodeRef node);
|
bool YGNodeHasBaselineFunc(YGNodeConstRef node);
|
||||||
void YGNodeSetBaselineFunc(YGNodeRef node, YGBaselineFunc baselineFunc);
|
void YGNodeSetBaselineFunc(YGNodeRef node, YGBaselineFunc baselineFunc);
|
||||||
YGDirtiedFunc YGNodeGetDirtiedFunc(YGNodeRef node);
|
YGDirtiedFunc YGNodeGetDirtiedFunc(YGNodeConstRef node);
|
||||||
void YGNodeSetDirtiedFunc(YGNodeRef node, YGDirtiedFunc dirtiedFunc);
|
void YGNodeSetDirtiedFunc(YGNodeRef node, YGDirtiedFunc dirtiedFunc);
|
||||||
void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc);
|
void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc);
|
||||||
WIN_EXPORT bool YGNodeGetHasNewLayout(YGNodeRef node);
|
WIN_EXPORT bool YGNodeGetHasNewLayout(YGNodeConstRef node);
|
||||||
WIN_EXPORT void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout);
|
WIN_EXPORT void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout);
|
||||||
YGNodeType YGNodeGetNodeType(YGNodeRef node);
|
YGNodeType YGNodeGetNodeType(YGNodeConstRef node);
|
||||||
void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType);
|
void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType);
|
||||||
WIN_EXPORT bool YGNodeIsDirty(YGNodeRef node);
|
WIN_EXPORT bool YGNodeIsDirty(YGNodeConstRef node);
|
||||||
|
|
||||||
WIN_EXPORT void YGNodeStyleSetDirection(YGNodeRef node, YGDirection direction);
|
WIN_EXPORT void YGNodeStyleSetDirection(YGNodeRef node, YGDirection direction);
|
||||||
WIN_EXPORT YGDirection YGNodeStyleGetDirection(YGNodeConstRef node);
|
WIN_EXPORT YGDirection YGNodeStyleGetDirection(YGNodeConstRef node);
|
||||||
@@ -280,22 +281,22 @@ WIN_EXPORT YGValue YGNodeStyleGetMaxHeight(YGNodeConstRef node);
|
|||||||
WIN_EXPORT void YGNodeStyleSetAspectRatio(YGNodeRef node, float aspectRatio);
|
WIN_EXPORT void YGNodeStyleSetAspectRatio(YGNodeRef node, float aspectRatio);
|
||||||
WIN_EXPORT float YGNodeStyleGetAspectRatio(YGNodeConstRef node);
|
WIN_EXPORT float YGNodeStyleGetAspectRatio(YGNodeConstRef node);
|
||||||
|
|
||||||
WIN_EXPORT float YGNodeLayoutGetLeft(YGNodeRef node);
|
WIN_EXPORT float YGNodeLayoutGetLeft(YGNodeConstRef node);
|
||||||
WIN_EXPORT float YGNodeLayoutGetTop(YGNodeRef node);
|
WIN_EXPORT float YGNodeLayoutGetTop(YGNodeConstRef node);
|
||||||
WIN_EXPORT float YGNodeLayoutGetRight(YGNodeRef node);
|
WIN_EXPORT float YGNodeLayoutGetRight(YGNodeConstRef node);
|
||||||
WIN_EXPORT float YGNodeLayoutGetBottom(YGNodeRef node);
|
WIN_EXPORT float YGNodeLayoutGetBottom(YGNodeConstRef node);
|
||||||
WIN_EXPORT float YGNodeLayoutGetWidth(YGNodeRef node);
|
WIN_EXPORT float YGNodeLayoutGetWidth(YGNodeConstRef node);
|
||||||
WIN_EXPORT float YGNodeLayoutGetHeight(YGNodeRef node);
|
WIN_EXPORT float YGNodeLayoutGetHeight(YGNodeConstRef node);
|
||||||
WIN_EXPORT YGDirection YGNodeLayoutGetDirection(YGNodeRef node);
|
WIN_EXPORT YGDirection YGNodeLayoutGetDirection(YGNodeConstRef node);
|
||||||
WIN_EXPORT bool YGNodeLayoutGetHadOverflow(YGNodeRef node);
|
WIN_EXPORT bool YGNodeLayoutGetHadOverflow(YGNodeConstRef node);
|
||||||
|
|
||||||
// Get the computed values for these nodes after performing layout. If they were
|
// Get the computed values for these nodes after performing layout. If they were
|
||||||
// set using point values then the returned value will be the same as
|
// set using point values then the returned value will be the same as
|
||||||
// YGNodeStyleGetXXX. However if they were set using a percentage value then the
|
// YGNodeStyleGetXXX. However if they were set using a percentage value then the
|
||||||
// returned value is the computed value used during layout.
|
// returned value is the computed value used during layout.
|
||||||
WIN_EXPORT float YGNodeLayoutGetMargin(YGNodeRef node, YGEdge edge);
|
WIN_EXPORT float YGNodeLayoutGetMargin(YGNodeConstRef node, YGEdge edge);
|
||||||
WIN_EXPORT float YGNodeLayoutGetBorder(YGNodeRef node, YGEdge edge);
|
WIN_EXPORT float YGNodeLayoutGetBorder(YGNodeConstRef node, YGEdge edge);
|
||||||
WIN_EXPORT float YGNodeLayoutGetPadding(YGNodeRef node, YGEdge edge);
|
WIN_EXPORT float YGNodeLayoutGetPadding(YGNodeConstRef node, YGEdge edge);
|
||||||
|
|
||||||
WIN_EXPORT void YGConfigSetLogger(YGConfigRef config, YGLogger logger);
|
WIN_EXPORT void YGConfigSetLogger(YGConfigRef config, YGLogger logger);
|
||||||
// Set this to number of pixels in 1 point to round calculation results If you
|
// Set this to number of pixels in 1 point to round calculation results If you
|
||||||
@@ -303,7 +304,7 @@ WIN_EXPORT void YGConfigSetLogger(YGConfigRef config, YGLogger logger);
|
|||||||
WIN_EXPORT void YGConfigSetPointScaleFactor(
|
WIN_EXPORT void YGConfigSetPointScaleFactor(
|
||||||
YGConfigRef config,
|
YGConfigRef config,
|
||||||
float pixelsInPoint);
|
float pixelsInPoint);
|
||||||
WIN_EXPORT float YGConfigGetPointScaleFactor(YGConfigRef config);
|
WIN_EXPORT float YGConfigGetPointScaleFactor(YGConfigConstRef config);
|
||||||
|
|
||||||
// Yoga previously had an error where containers would take the maximum space
|
// Yoga previously had an error where containers would take the maximum space
|
||||||
// possible instead of the minimum like they are supposed to. In practice this
|
// possible instead of the minimum like they are supposed to. In practice this
|
||||||
@@ -312,7 +313,7 @@ WIN_EXPORT float YGConfigGetPointScaleFactor(YGConfigRef config);
|
|||||||
// this behaviour.
|
// this behaviour.
|
||||||
WIN_EXPORT YG_DEPRECATED(
|
WIN_EXPORT YG_DEPRECATED(
|
||||||
"Please use "
|
"Please use "
|
||||||
"\"YGConfigGetErrata()\"") bool YGConfigGetUseLegacyStretchBehaviour(YGConfigRef
|
"\"YGConfigGetErrata()\"") bool YGConfigGetUseLegacyStretchBehaviour(YGConfigConstRef
|
||||||
config);
|
config);
|
||||||
WIN_EXPORT
|
WIN_EXPORT
|
||||||
YG_DEPRECATED(
|
YG_DEPRECATED(
|
||||||
@@ -336,26 +337,25 @@ WIN_EXPORT void YGConfigSetExperimentalFeatureEnabled(
|
|||||||
YGExperimentalFeature feature,
|
YGExperimentalFeature feature,
|
||||||
bool enabled);
|
bool enabled);
|
||||||
WIN_EXPORT bool YGConfigIsExperimentalFeatureEnabled(
|
WIN_EXPORT bool YGConfigIsExperimentalFeatureEnabled(
|
||||||
YGConfigRef config,
|
YGConfigConstRef config,
|
||||||
YGExperimentalFeature feature);
|
YGExperimentalFeature feature);
|
||||||
|
|
||||||
// Using the web defaults is the preferred configuration for new projects. Usage
|
// Using the web defaults is the preferred configuration for new projects. Usage
|
||||||
// of non web defaults should be considered as legacy.
|
// of non web defaults should be considered as legacy.
|
||||||
WIN_EXPORT void YGConfigSetUseWebDefaults(YGConfigRef config, bool enabled);
|
WIN_EXPORT void YGConfigSetUseWebDefaults(YGConfigRef config, bool enabled);
|
||||||
WIN_EXPORT bool YGConfigGetUseWebDefaults(YGConfigRef config);
|
WIN_EXPORT bool YGConfigGetUseWebDefaults(YGConfigConstRef config);
|
||||||
|
|
||||||
WIN_EXPORT void YGConfigSetCloneNodeFunc(
|
WIN_EXPORT void YGConfigSetCloneNodeFunc(
|
||||||
YGConfigRef config,
|
YGConfigRef config,
|
||||||
YGCloneNodeFunc callback);
|
YGCloneNodeFunc callback);
|
||||||
|
|
||||||
// Export only for C#
|
|
||||||
WIN_EXPORT YGConfigRef YGConfigGetDefault(void);
|
WIN_EXPORT YGConfigRef YGConfigGetDefault(void);
|
||||||
|
|
||||||
WIN_EXPORT void YGConfigSetContext(YGConfigRef config, void* context);
|
WIN_EXPORT void YGConfigSetContext(YGConfigRef config, void* context);
|
||||||
WIN_EXPORT void* YGConfigGetContext(YGConfigRef config);
|
WIN_EXPORT void* YGConfigGetContext(YGConfigConstRef config);
|
||||||
|
|
||||||
WIN_EXPORT void YGConfigSetErrata(YGConfigRef config, YGErrata errata);
|
WIN_EXPORT void YGConfigSetErrata(YGConfigRef config, YGErrata errata);
|
||||||
WIN_EXPORT YGErrata YGConfigGetErrata(YGConfigRef config);
|
WIN_EXPORT YGErrata YGConfigGetErrata(YGConfigConstRef config);
|
||||||
|
|
||||||
WIN_EXPORT float YGRoundValueToPixelGrid(
|
WIN_EXPORT float YGRoundValueToPixelGrid(
|
||||||
double value,
|
double value,
|
||||||
|
@@ -34,8 +34,8 @@ float calculateBaseline(const yoga::Node* node, void* layoutContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
yoga::Node* baselineChild = nullptr;
|
yoga::Node* baselineChild = nullptr;
|
||||||
const uint32_t childCount = YGNodeGetChildCount(node);
|
const size_t childCount = node->getChildCount();
|
||||||
for (uint32_t i = 0; i < childCount; i++) {
|
for (size_t i = 0; i < childCount; i++) {
|
||||||
auto child = node->getChild(i);
|
auto child = node->getChild(i);
|
||||||
if (child->getLineIndex() > 0) {
|
if (child->getLineIndex() > 0) {
|
||||||
break;
|
break;
|
||||||
|
@@ -827,8 +827,10 @@ static void zeroOutLayoutRecursively(
|
|||||||
node->setLayoutDimension(0, YGDimensionHeight);
|
node->setLayoutDimension(0, YGDimensionHeight);
|
||||||
node->setHasNewLayout(true);
|
node->setHasNewLayout(true);
|
||||||
|
|
||||||
node->iterChildrenAfterCloningIfNeeded(
|
node->cloneChildrenIfNeeded(layoutContext);
|
||||||
zeroOutLayoutRecursively, layoutContext);
|
for (const auto child : node->getChildren()) {
|
||||||
|
zeroOutLayoutRecursively(child, layoutContext);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static float calculateAvailableInnerDimension(
|
static float calculateAvailableInnerDimension(
|
||||||
@@ -963,8 +965,8 @@ static CollectFlexItemsRowValues calculateCollectFlexItemsRowValues(
|
|||||||
const float mainAxisownerSize,
|
const float mainAxisownerSize,
|
||||||
const float availableInnerWidth,
|
const float availableInnerWidth,
|
||||||
const float availableInnerMainDim,
|
const float availableInnerMainDim,
|
||||||
const uint32_t startOfLineIndex,
|
const size_t startOfLineIndex,
|
||||||
const uint32_t lineCount) {
|
const size_t lineCount) {
|
||||||
CollectFlexItemsRowValues flexAlgoRowMeasurement = {};
|
CollectFlexItemsRowValues flexAlgoRowMeasurement = {};
|
||||||
flexAlgoRowMeasurement.relativeChildren.reserve(node->getChildren().size());
|
flexAlgoRowMeasurement.relativeChildren.reserve(node->getChildren().size());
|
||||||
|
|
||||||
@@ -975,7 +977,7 @@ static CollectFlexItemsRowValues calculateCollectFlexItemsRowValues(
|
|||||||
const float gap = node->getGapForAxis(mainAxis, availableInnerWidth).unwrap();
|
const float gap = node->getGapForAxis(mainAxis, availableInnerWidth).unwrap();
|
||||||
|
|
||||||
// Add items to the current line until it's full or we run out of items.
|
// Add items to the current line until it's full or we run out of items.
|
||||||
uint32_t endOfLineIndex = startOfLineIndex;
|
size_t endOfLineIndex = startOfLineIndex;
|
||||||
for (; endOfLineIndex < node->getChildren().size(); endOfLineIndex++) {
|
for (; endOfLineIndex < node->getChildren().size(); endOfLineIndex++) {
|
||||||
auto child = node->getChild(endOfLineIndex);
|
auto child = node->getChild(endOfLineIndex);
|
||||||
if (child->getStyle().display() == YGDisplayNone ||
|
if (child->getStyle().display() == YGDisplayNone ||
|
||||||
@@ -1406,7 +1408,7 @@ static void resolveFlexibleLength(
|
|||||||
static void YGJustifyMainAxis(
|
static void YGJustifyMainAxis(
|
||||||
yoga::Node* const node,
|
yoga::Node* const node,
|
||||||
CollectFlexItemsRowValues& collectedFlexItemsValues,
|
CollectFlexItemsRowValues& collectedFlexItemsValues,
|
||||||
const uint32_t startOfLineIndex,
|
const size_t startOfLineIndex,
|
||||||
const YGFlexDirection mainAxis,
|
const YGFlexDirection mainAxis,
|
||||||
const YGFlexDirection crossAxis,
|
const YGFlexDirection crossAxis,
|
||||||
const YGMeasureMode measureModeMainDim,
|
const YGMeasureMode measureModeMainDim,
|
||||||
@@ -1454,8 +1456,7 @@ static void YGJustifyMainAxis(
|
|||||||
}
|
}
|
||||||
|
|
||||||
int numberOfAutoMarginsOnCurrentLine = 0;
|
int numberOfAutoMarginsOnCurrentLine = 0;
|
||||||
for (uint32_t i = startOfLineIndex;
|
for (size_t i = startOfLineIndex; i < collectedFlexItemsValues.endOfLineIndex;
|
||||||
i < collectedFlexItemsValues.endOfLineIndex;
|
|
||||||
i++) {
|
i++) {
|
||||||
auto child = node->getChild(i);
|
auto child = node->getChild(i);
|
||||||
if (child->getStyle().positionType() != YGPositionTypeAbsolute) {
|
if (child->getStyle().positionType() != YGPositionTypeAbsolute) {
|
||||||
@@ -1515,8 +1516,7 @@ static void YGJustifyMainAxis(
|
|||||||
float maxAscentForCurrentLine = 0;
|
float maxAscentForCurrentLine = 0;
|
||||||
float maxDescentForCurrentLine = 0;
|
float maxDescentForCurrentLine = 0;
|
||||||
bool isNodeBaselineLayout = isBaselineLayout(node);
|
bool isNodeBaselineLayout = isBaselineLayout(node);
|
||||||
for (uint32_t i = startOfLineIndex;
|
for (size_t i = startOfLineIndex; i < collectedFlexItemsValues.endOfLineIndex;
|
||||||
i < collectedFlexItemsValues.endOfLineIndex;
|
|
||||||
i++) {
|
i++) {
|
||||||
const auto child = node->getChild(i);
|
const auto child = node->getChild(i);
|
||||||
const Style& childStyle = child->getStyle();
|
const Style& childStyle = child->getStyle();
|
||||||
@@ -1904,11 +1904,11 @@ static void calculateLayoutImpl(
|
|||||||
// STEP 4: COLLECT FLEX ITEMS INTO FLEX LINES
|
// STEP 4: COLLECT FLEX ITEMS INTO FLEX LINES
|
||||||
|
|
||||||
// Indexes of children that represent the first and last items in the line.
|
// Indexes of children that represent the first and last items in the line.
|
||||||
uint32_t startOfLineIndex = 0;
|
size_t startOfLineIndex = 0;
|
||||||
uint32_t endOfLineIndex = 0;
|
size_t endOfLineIndex = 0;
|
||||||
|
|
||||||
// Number of lines.
|
// Number of lines.
|
||||||
uint32_t lineCount = 0;
|
size_t lineCount = 0;
|
||||||
|
|
||||||
// Accumulated cross dimensions of all lines so far.
|
// Accumulated cross dimensions of all lines so far.
|
||||||
float totalLineCrossDim = 0;
|
float totalLineCrossDim = 0;
|
||||||
@@ -2091,7 +2091,7 @@ static void calculateLayoutImpl(
|
|||||||
// STEP 7: CROSS-AXIS ALIGNMENT
|
// STEP 7: CROSS-AXIS ALIGNMENT
|
||||||
// We can skip child alignment if we're just measuring the container.
|
// We can skip child alignment if we're just measuring the container.
|
||||||
if (performLayout) {
|
if (performLayout) {
|
||||||
for (uint32_t i = startOfLineIndex; i < endOfLineIndex; i++) {
|
for (size_t i = startOfLineIndex; i < endOfLineIndex; i++) {
|
||||||
const auto child = node->getChild(i);
|
const auto child = node->getChild(i);
|
||||||
if (child->getStyle().display() == YGDisplayNone) {
|
if (child->getStyle().display() == YGDisplayNone) {
|
||||||
continue;
|
continue;
|
||||||
@@ -2289,10 +2289,10 @@ static void calculateLayoutImpl(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
uint32_t endIndex = 0;
|
size_t endIndex = 0;
|
||||||
for (uint32_t i = 0; i < lineCount; i++) {
|
for (size_t i = 0; i < lineCount; i++) {
|
||||||
const uint32_t startIndex = endIndex;
|
const size_t startIndex = endIndex;
|
||||||
uint32_t ii;
|
size_t ii;
|
||||||
|
|
||||||
// compute the line's height and find the endIndex
|
// compute the line's height and find the endIndex
|
||||||
float lineHeight = 0;
|
float lineHeight = 0;
|
||||||
@@ -2535,7 +2535,7 @@ static void calculateLayoutImpl(
|
|||||||
// As we only wrapped in normal direction yet, we need to reverse the
|
// As we only wrapped in normal direction yet, we need to reverse the
|
||||||
// positions on wrap-reverse.
|
// positions on wrap-reverse.
|
||||||
if (performLayout && node->getStyle().flexWrap() == YGWrapWrapReverse) {
|
if (performLayout && node->getStyle().flexWrap() == YGWrapWrapReverse) {
|
||||||
for (uint32_t i = 0; i < childCount; i++) {
|
for (size_t i = 0; i < childCount; i++) {
|
||||||
const auto child = node->getChild(i);
|
const auto child = node->getChild(i);
|
||||||
if (child->getStyle().positionType() != YGPositionTypeAbsolute) {
|
if (child->getStyle().positionType() != YGPositionTypeAbsolute) {
|
||||||
child->setLayoutPosition(
|
child->setLayoutPosition(
|
||||||
@@ -2584,7 +2584,7 @@ static void calculateLayoutImpl(
|
|||||||
|
|
||||||
// Set trailing position if necessary.
|
// Set trailing position if necessary.
|
||||||
if (needsMainTrailingPos || needsCrossTrailingPos) {
|
if (needsMainTrailingPos || needsCrossTrailingPos) {
|
||||||
for (uint32_t i = 0; i < childCount; i++) {
|
for (size_t i = 0; i < childCount; i++) {
|
||||||
const auto child = node->getChild(i);
|
const auto child = node->getChild(i);
|
||||||
if (child->getStyle().display() == YGDisplayNone) {
|
if (child->getStyle().display() == YGDisplayNone) {
|
||||||
continue;
|
continue;
|
||||||
@@ -2708,7 +2708,7 @@ bool calculateLayoutInternal(
|
|||||||
cachedResults = &layout->cachedLayout;
|
cachedResults = &layout->cachedLayout;
|
||||||
} else {
|
} else {
|
||||||
// Try to use the measurement cache.
|
// Try to use the measurement cache.
|
||||||
for (uint32_t i = 0; i < layout->nextCachedMeasurementsIndex; i++) {
|
for (size_t i = 0; i < layout->nextCachedMeasurementsIndex; i++) {
|
||||||
if (canUseCachedMeasurement(
|
if (canUseCachedMeasurement(
|
||||||
widthMeasureMode,
|
widthMeasureMode,
|
||||||
availableWidth,
|
availableWidth,
|
||||||
|
@@ -39,11 +39,11 @@ namespace facebook::yoga {
|
|||||||
// and/or grow.
|
// and/or grow.
|
||||||
|
|
||||||
struct CollectFlexItemsRowValues {
|
struct CollectFlexItemsRowValues {
|
||||||
uint32_t itemsOnLine;
|
size_t itemsOnLine;
|
||||||
float sizeConsumedOnCurrentLine;
|
float sizeConsumedOnCurrentLine;
|
||||||
float totalFlexGrowFactors;
|
float totalFlexGrowFactors;
|
||||||
float totalFlexShrinkScaledFactors;
|
float totalFlexShrinkScaledFactors;
|
||||||
uint32_t endOfLineIndex;
|
size_t endOfLineIndex;
|
||||||
std::vector<yoga::Node*> relativeChildren;
|
std::vector<yoga::Node*> relativeChildren;
|
||||||
float remainingFreeSpace;
|
float remainingFreeSpace;
|
||||||
// The size of the mainDim for the row after considering size, padding, margin
|
// The size of the mainDim for the row after considering size, padding, margin
|
||||||
|
@@ -125,8 +125,8 @@ void roundLayoutResultsToPixelGrid(
|
|||||||
absoluteNodeTop, pointScaleFactor, false, textRounding),
|
absoluteNodeTop, pointScaleFactor, false, textRounding),
|
||||||
YGDimensionHeight);
|
YGDimensionHeight);
|
||||||
|
|
||||||
const uint32_t childCount = YGNodeGetChildCount(node);
|
const size_t childCount = node->getChildCount();
|
||||||
for (uint32_t i = 0; i < childCount; i++) {
|
for (size_t i = 0; i < childCount; i++) {
|
||||||
roundLayoutResultsToPixelGrid(
|
roundLayoutResultsToPixelGrid(
|
||||||
node->getChild(i), pointScaleFactor, absoluteNodeLeft, absoluteNodeTop);
|
node->getChild(i), pointScaleFactor, absoluteNodeLeft, absoluteNodeTop);
|
||||||
}
|
}
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <yoga/config/Config.h>
|
#include <yoga/config/Config.h>
|
||||||
|
#include <yoga/node/Node.h>
|
||||||
|
|
||||||
namespace facebook::yoga {
|
namespace facebook::yoga {
|
||||||
|
|
||||||
@@ -101,11 +102,11 @@ void Config::setLogger(std::nullptr_t) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Config::log(
|
void Config::log(
|
||||||
YGNodeRef node,
|
const yoga::Node* node,
|
||||||
YGLogLevel logLevel,
|
YGLogLevel logLevel,
|
||||||
void* logContext,
|
void* logContext,
|
||||||
const char* format,
|
const char* format,
|
||||||
va_list args) {
|
va_list args) const {
|
||||||
if (flags_.loggerUsesContext) {
|
if (flags_.loggerUsesContext) {
|
||||||
logger_.withContext(this, node, logLevel, logContext, format, args);
|
logger_.withContext(this, node, logLevel, logContext, format, args);
|
||||||
} else {
|
} else {
|
||||||
@@ -128,9 +129,9 @@ void Config::setCloneNodeCallback(std::nullptr_t) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
YGNodeRef Config::cloneNode(
|
YGNodeRef Config::cloneNode(
|
||||||
YGNodeRef node,
|
YGNodeConstRef node,
|
||||||
YGNodeRef owner,
|
YGNodeConstRef owner,
|
||||||
int childIndex,
|
size_t childIndex,
|
||||||
void* cloneContext) const {
|
void* cloneContext) const {
|
||||||
YGNodeRef clone = nullptr;
|
YGNodeRef clone = nullptr;
|
||||||
if (cloneNodeCallback_.noContext != nullptr) {
|
if (cloneNodeCallback_.noContext != nullptr) {
|
||||||
|
@@ -16,6 +16,7 @@ struct YGConfig {};
|
|||||||
namespace facebook::yoga {
|
namespace facebook::yoga {
|
||||||
|
|
||||||
class Config;
|
class Config;
|
||||||
|
class Node;
|
||||||
|
|
||||||
// Whether moving a node from config "a" to config "b" should dirty previously
|
// Whether moving a node from config "a" to config "b" should dirty previously
|
||||||
// calculated layout results.
|
// calculated layout results.
|
||||||
@@ -24,16 +25,16 @@ bool configUpdateInvalidatesLayout(Config* a, Config* b);
|
|||||||
// Internal variants of log functions, currently used only by JNI bindings.
|
// Internal variants of log functions, currently used only by JNI bindings.
|
||||||
// TODO: Reconcile this with the public API
|
// TODO: Reconcile this with the public API
|
||||||
using LogWithContextFn = int (*)(
|
using LogWithContextFn = int (*)(
|
||||||
YGConfigRef config,
|
YGConfigConstRef config,
|
||||||
YGNodeRef node,
|
YGNodeConstRef node,
|
||||||
YGLogLevel level,
|
YGLogLevel level,
|
||||||
void* context,
|
void* context,
|
||||||
const char* format,
|
const char* format,
|
||||||
va_list args);
|
va_list args);
|
||||||
using CloneWithContextFn = YGNodeRef (*)(
|
using CloneWithContextFn = YGNodeRef (*)(
|
||||||
YGNodeRef node,
|
YGNodeConstRef node,
|
||||||
YGNodeRef owner,
|
YGNodeConstRef owner,
|
||||||
int childIndex,
|
size_t childIndex,
|
||||||
void* cloneContext);
|
void* cloneContext);
|
||||||
|
|
||||||
#pragma pack(push)
|
#pragma pack(push)
|
||||||
@@ -78,15 +79,20 @@ public:
|
|||||||
void setLogger(YGLogger logger);
|
void setLogger(YGLogger logger);
|
||||||
void setLogger(LogWithContextFn logger);
|
void setLogger(LogWithContextFn logger);
|
||||||
void setLogger(std::nullptr_t);
|
void setLogger(std::nullptr_t);
|
||||||
void log(YGNodeRef, YGLogLevel, void*, const char*, va_list);
|
void log(
|
||||||
|
const yoga::Node* node,
|
||||||
|
YGLogLevel logLevel,
|
||||||
|
void* logContext,
|
||||||
|
const char* format,
|
||||||
|
va_list args) const;
|
||||||
|
|
||||||
void setCloneNodeCallback(YGCloneNodeFunc cloneNode);
|
void setCloneNodeCallback(YGCloneNodeFunc cloneNode);
|
||||||
void setCloneNodeCallback(CloneWithContextFn cloneNode);
|
void setCloneNodeCallback(CloneWithContextFn cloneNode);
|
||||||
void setCloneNodeCallback(std::nullptr_t);
|
void setCloneNodeCallback(std::nullptr_t);
|
||||||
YGNodeRef cloneNode(
|
YGNodeRef cloneNode(
|
||||||
YGNodeRef node,
|
YGNodeConstRef node,
|
||||||
YGNodeRef owner,
|
YGNodeConstRef owner,
|
||||||
int childIndex,
|
size_t childIndex,
|
||||||
void* cloneContext) const;
|
void* cloneContext) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -106,4 +112,12 @@ private:
|
|||||||
void* context_ = nullptr;
|
void* context_ = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline Config* resolveRef(const YGConfigRef ref) {
|
||||||
|
return static_cast<Config*>(ref);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const Config* resolveRef(const YGConfigConstRef ref) {
|
||||||
|
return static_cast<const Config*>(ref);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace facebook::yoga
|
} // namespace facebook::yoga
|
||||||
|
@@ -22,43 +22,27 @@ namespace facebook::yoga {
|
|||||||
|
|
||||||
void assertFatal(const bool condition, const char* message) {
|
void assertFatal(const bool condition, const char* message) {
|
||||||
if (!condition) {
|
if (!condition) {
|
||||||
yoga::log(
|
yoga::log(YGLogLevelFatal, nullptr, "%s\n", message);
|
||||||
static_cast<yoga::Node*>(nullptr),
|
|
||||||
YGLogLevelFatal,
|
|
||||||
nullptr,
|
|
||||||
"%s\n",
|
|
||||||
message);
|
|
||||||
fatalWithMessage(message);
|
fatalWithMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void assertFatalWithNode(
|
void assertFatalWithNode(
|
||||||
const YGNodeConstRef node,
|
const yoga::Node* const node,
|
||||||
const bool condition,
|
const bool condition,
|
||||||
const char* message) {
|
const char* message) {
|
||||||
if (!condition) {
|
if (!condition) {
|
||||||
yoga::log(
|
yoga::log(node, YGLogLevelFatal, nullptr, "%s\n", message);
|
||||||
// TODO: Break log callbacks and make them const correct
|
|
||||||
static_cast<yoga::Node*>(const_cast<YGNodeRef>(node)),
|
|
||||||
YGLogLevelFatal,
|
|
||||||
nullptr,
|
|
||||||
"%s\n",
|
|
||||||
message);
|
|
||||||
fatalWithMessage(message);
|
fatalWithMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void assertFatalWithConfig(
|
void assertFatalWithConfig(
|
||||||
YGConfigRef config,
|
const yoga::Config* const config,
|
||||||
const bool condition,
|
const bool condition,
|
||||||
const char* message) {
|
const char* message) {
|
||||||
if (!condition) {
|
if (!condition) {
|
||||||
yoga::log(
|
yoga::log(config, YGLogLevelFatal, nullptr, "%s\n", message);
|
||||||
static_cast<yoga::Config*>(config),
|
|
||||||
YGLogLevelFatal,
|
|
||||||
nullptr,
|
|
||||||
"%s\n",
|
|
||||||
message);
|
|
||||||
fatalWithMessage(message);
|
fatalWithMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,11 +17,11 @@ namespace facebook::yoga {
|
|||||||
|
|
||||||
void assertFatal(bool condition, const char* message);
|
void assertFatal(bool condition, const char* message);
|
||||||
void assertFatalWithNode(
|
void assertFatalWithNode(
|
||||||
YGNodeConstRef node,
|
const yoga::Node* node,
|
||||||
bool condition,
|
bool condition,
|
||||||
const char* message);
|
const char* message);
|
||||||
void assertFatalWithConfig(
|
void assertFatalWithConfig(
|
||||||
YGConfigRef config,
|
const yoga::Config* config,
|
||||||
bool condition,
|
bool condition,
|
||||||
const char* message);
|
const char* message);
|
||||||
|
|
||||||
|
@@ -12,21 +12,28 @@ namespace facebook::yoga {
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void vlog(
|
void vlog(
|
||||||
yoga::Config* config,
|
const yoga::Config* config,
|
||||||
yoga::Node* node,
|
const yoga::Node* node,
|
||||||
YGLogLevel level,
|
YGLogLevel level,
|
||||||
void* context,
|
void* context,
|
||||||
const char* format,
|
const char* format,
|
||||||
va_list args) {
|
va_list args) {
|
||||||
yoga::Config* logConfig = config != nullptr
|
const yoga::Config* logConfig =
|
||||||
? config
|
config != nullptr ? config : resolveRef(YGConfigGetDefault());
|
||||||
: static_cast<yoga::Config*>(YGConfigGetDefault());
|
|
||||||
logConfig->log(node, level, context, format, args);
|
logConfig->log(const_cast<yoga::Node*>(node), level, context, format, args);
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
void log(YGLogLevel level, void* context, const char* format, ...) noexcept {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, format);
|
||||||
|
vlog(nullptr, nullptr, level, context, format, args);
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
void log(
|
void log(
|
||||||
yoga::Node* node,
|
const yoga::Node* node,
|
||||||
YGLogLevel level,
|
YGLogLevel level,
|
||||||
void* context,
|
void* context,
|
||||||
const char* format,
|
const char* format,
|
||||||
@@ -44,7 +51,7 @@ void log(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void log(
|
void log(
|
||||||
yoga::Config* config,
|
const yoga::Config* config,
|
||||||
YGLogLevel level,
|
YGLogLevel level,
|
||||||
void* context,
|
void* context,
|
||||||
const char* format,
|
const char* format,
|
||||||
|
@@ -13,15 +13,17 @@
|
|||||||
|
|
||||||
namespace facebook::yoga {
|
namespace facebook::yoga {
|
||||||
|
|
||||||
|
void log(YGLogLevel level, void*, const char* format, ...) noexcept;
|
||||||
|
|
||||||
void log(
|
void log(
|
||||||
yoga::Node* node,
|
const yoga::Node* node,
|
||||||
YGLogLevel level,
|
YGLogLevel level,
|
||||||
void*,
|
void*,
|
||||||
const char* message,
|
const char* message,
|
||||||
...) noexcept;
|
...) noexcept;
|
||||||
|
|
||||||
void log(
|
void log(
|
||||||
yoga::Config* config,
|
const yoga::Config* config,
|
||||||
YGLogLevel level,
|
YGLogLevel level,
|
||||||
void*,
|
void*,
|
||||||
const char* format,
|
const char* format,
|
||||||
|
@@ -117,7 +117,7 @@ static void appendEdgeIfNotUndefined(
|
|||||||
|
|
||||||
void nodeToString(
|
void nodeToString(
|
||||||
std::string& str,
|
std::string& str,
|
||||||
yoga::Node* node,
|
const yoga::Node* node,
|
||||||
YGPrintOptions options,
|
YGPrintOptions options,
|
||||||
uint32_t level) {
|
uint32_t level) {
|
||||||
indent(str, level);
|
indent(str, level);
|
||||||
@@ -227,9 +227,9 @@ void nodeToString(
|
|||||||
}
|
}
|
||||||
appendFormattedString(str, ">");
|
appendFormattedString(str, ">");
|
||||||
|
|
||||||
const uint32_t childCount = static_cast<uint32_t>(node->getChildren().size());
|
const size_t childCount = node->getChildCount();
|
||||||
if (options & YGPrintOptionsChildren && childCount > 0) {
|
if (options & YGPrintOptionsChildren && childCount > 0) {
|
||||||
for (uint32_t i = 0; i < childCount; i++) {
|
for (size_t i = 0; i < childCount; i++) {
|
||||||
appendFormattedString(str, "\n");
|
appendFormattedString(str, "\n");
|
||||||
nodeToString(str, node->getChild(i), options, level + 1);
|
nodeToString(str, node->getChild(i), options, level + 1);
|
||||||
}
|
}
|
||||||
|
@@ -18,7 +18,7 @@ namespace facebook::yoga {
|
|||||||
|
|
||||||
void nodeToString(
|
void nodeToString(
|
||||||
std::string& str,
|
std::string& str,
|
||||||
yoga::Node* node,
|
const yoga::Node* node,
|
||||||
YGPrintOptions options,
|
YGPrintOptions options,
|
||||||
uint32_t level);
|
uint32_t level);
|
||||||
|
|
||||||
|
@@ -484,7 +484,14 @@ YOGA_EXPORT void Node::clearChildren() {
|
|||||||
// Other Methods
|
// Other Methods
|
||||||
|
|
||||||
void Node::cloneChildrenIfNeeded(void* cloneContext) {
|
void Node::cloneChildrenIfNeeded(void* cloneContext) {
|
||||||
iterChildrenAfterCloningIfNeeded([](Node*, void*) {}, cloneContext);
|
size_t i = 0;
|
||||||
|
for (Node*& child : children_) {
|
||||||
|
if (child->getOwner() != this) {
|
||||||
|
child = resolveRef(config_->cloneNode(child, this, i, cloneContext));
|
||||||
|
child->setOwner(this);
|
||||||
|
}
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::markDirtyAndPropagate() {
|
void Node::markDirtyAndPropagate() {
|
||||||
|
@@ -11,6 +11,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <yoga/Yoga.h>
|
||||||
|
|
||||||
#include <yoga/config/Config.h>
|
#include <yoga/config/Config.h>
|
||||||
#include <yoga/node/LayoutResults.h>
|
#include <yoga/node/LayoutResults.h>
|
||||||
#include <yoga/style/CompactValue.h>
|
#include <yoga/style/CompactValue.h>
|
||||||
@@ -36,10 +38,17 @@ struct NodeFlags {
|
|||||||
|
|
||||||
class YOGA_EXPORT Node : public ::YGNode {
|
class YOGA_EXPORT Node : public ::YGNode {
|
||||||
public:
|
public:
|
||||||
using MeasureWithContextFn =
|
// Internal variants of callbacks, currently used only by JNI bindings.
|
||||||
YGSize (*)(YGNode*, float, YGMeasureMode, float, YGMeasureMode, void*);
|
// TODO: Reconcile this with the public API
|
||||||
using BaselineWithContextFn = float (*)(YGNode*, float, float, void*);
|
using MeasureWithContextFn = YGSize (*)(
|
||||||
using PrintWithContextFn = void (*)(YGNode*, void*);
|
YGNodeConstRef,
|
||||||
|
float,
|
||||||
|
YGMeasureMode,
|
||||||
|
float,
|
||||||
|
YGMeasureMode,
|
||||||
|
void*);
|
||||||
|
using BaselineWithContextFn = float (*)(YGNodeConstRef, float, float, void*);
|
||||||
|
using PrintWithContextFn = void (*)(YGNodeConstRef, void*);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void* context_ = nullptr;
|
void* context_ = nullptr;
|
||||||
@@ -59,7 +68,7 @@ private:
|
|||||||
YGDirtiedFunc dirtied_ = nullptr;
|
YGDirtiedFunc dirtied_ = nullptr;
|
||||||
Style style_ = {};
|
Style style_ = {};
|
||||||
LayoutResults layout_ = {};
|
LayoutResults layout_ = {};
|
||||||
uint32_t lineIndex_ = 0;
|
size_t lineIndex_ = 0;
|
||||||
Node* owner_ = nullptr;
|
Node* owner_ = nullptr;
|
||||||
std::vector<Node*> children_ = {};
|
std::vector<Node*> children_ = {};
|
||||||
Config* config_;
|
Config* config_;
|
||||||
@@ -137,9 +146,9 @@ public:
|
|||||||
|
|
||||||
const LayoutResults& getLayout() const { return layout_; }
|
const LayoutResults& getLayout() const { return layout_; }
|
||||||
|
|
||||||
uint32_t getLineIndex() const { return lineIndex_; }
|
size_t getLineIndex() const { return lineIndex_; }
|
||||||
|
|
||||||
bool isReferenceBaseline() { return flags_.isReferenceBaseline; }
|
bool isReferenceBaseline() const { return flags_.isReferenceBaseline; }
|
||||||
|
|
||||||
// returns the Node that owns this Node. An owner is used to identify
|
// returns the Node that owns this Node. An owner is used to identify
|
||||||
// the YogaTree that a Node belongs to. This method will return the parent
|
// the YogaTree that a Node belongs to. This method will return the parent
|
||||||
@@ -152,23 +161,6 @@ public:
|
|||||||
|
|
||||||
const std::vector<Node*>& getChildren() const { return children_; }
|
const std::vector<Node*>& getChildren() const { return children_; }
|
||||||
|
|
||||||
// Applies a callback to all children, after cloning them if they are not
|
|
||||||
// owned.
|
|
||||||
template <typename T>
|
|
||||||
void iterChildrenAfterCloningIfNeeded(T callback, void* cloneContext) {
|
|
||||||
int i = 0;
|
|
||||||
for (Node*& child : children_) {
|
|
||||||
if (child->getOwner() != this) {
|
|
||||||
child = static_cast<Node*>(
|
|
||||||
config_->cloneNode(child, this, i, cloneContext));
|
|
||||||
child->setOwner(this);
|
|
||||||
}
|
|
||||||
i += 1;
|
|
||||||
|
|
||||||
callback(child, cloneContext);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Node* getChild(size_t index) const { return children_.at(index); }
|
Node* getChild(size_t index) const { return children_.at(index); }
|
||||||
|
|
||||||
size_t getChildCount() const { return children_.size(); }
|
size_t getChildCount() const { return children_.size(); }
|
||||||
@@ -284,7 +276,7 @@ public:
|
|||||||
|
|
||||||
void setLayout(const LayoutResults& layout) { layout_ = layout; }
|
void setLayout(const LayoutResults& layout) { layout_ = layout; }
|
||||||
|
|
||||||
void setLineIndex(uint32_t lineIndex) { lineIndex_ = lineIndex; }
|
void setLineIndex(size_t lineIndex) { lineIndex_ = lineIndex; }
|
||||||
|
|
||||||
void setIsReferenceBaseline(bool isReferenceBaseline) {
|
void setIsReferenceBaseline(bool isReferenceBaseline) {
|
||||||
flags_.isReferenceBaseline = isReferenceBaseline;
|
flags_.isReferenceBaseline = isReferenceBaseline;
|
||||||
@@ -343,4 +335,12 @@ public:
|
|||||||
void reset();
|
void reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline Node* resolveRef(const YGNodeRef ref) {
|
||||||
|
return static_cast<Node*>(ref);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const Node* resolveRef(const YGNodeConstRef ref) {
|
||||||
|
return static_cast<const Node*>(ref);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace facebook::yoga
|
} // namespace facebook::yoga
|
||||||
|
Reference in New Issue
Block a user