Breaking: Fix callback const-correctness (#1369)
Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1369 X-link: https://github.com/facebook/react-native/pull/39370 This fixes const-correctness of callbacks (e.g. not letting a logger function modify nodes during layout). This helps us to continue to fix const-correctness issues inside of Yoga. This change is breaking to the public API, since it requires a change in signature passed to Yoga. Changelog: [Internal] Reviewed By: rshest Differential Revision: D49130714 fbshipit-source-id: 4305f8882d89f296e45b78497a51716a0dbb3b2d
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b12a6a340c
commit
26f2b28eca
@@ -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,
|
||||||
@@ -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);
|
||||||
|
@@ -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,
|
||||||
|
@@ -23,8 +23,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, int) {
|
||||||
static YGNodeRef doNotClone(YGNodeRef, YGNodeRef, int) { return nullptr; }
|
return &clonedNode;
|
||||||
|
}
|
||||||
|
static YGNodeRef doNotClone(YGNodeConstRef, YGNodeConstRef, int) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(ConfigCloningTest, uses_values_provided_by_cloning_callback) {
|
TEST_F(ConfigCloningTest, uses_values_provided_by_cloning_callback) {
|
||||||
@@ -49,7 +53,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, int, void* context) {
|
||||||
return (YGNodeRef) context;
|
return (YGNodeRef) context;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -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,8 +87,6 @@ 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) {
|
||||||
@@ -202,7 +196,7 @@ 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 = resolveRef(oldNodeRef);
|
auto oldNode = resolveRef(oldNodeRef);
|
||||||
const auto node = new yoga::Node(*oldNode);
|
const auto node = new yoga::Node(*oldNode);
|
||||||
yoga::assertFatalWithConfig(
|
yoga::assertFatalWithConfig(
|
||||||
|
22
yoga/Yoga.h
22
yoga/Yoga.h
@@ -29,28 +29,30 @@ 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,
|
||||||
|
int 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,
|
||||||
|
@@ -107,23 +107,10 @@ void Config::log(
|
|||||||
void* logContext,
|
void* logContext,
|
||||||
const char* format,
|
const char* format,
|
||||||
va_list args) const {
|
va_list args) const {
|
||||||
// TODO: Break log callback signatures to make them const correct
|
|
||||||
|
|
||||||
if (flags_.loggerUsesContext) {
|
if (flags_.loggerUsesContext) {
|
||||||
logger_.withContext(
|
logger_.withContext(this, node, logLevel, logContext, format, args);
|
||||||
const_cast<yoga::Config*>(this),
|
|
||||||
const_cast<yoga::Node*>(node),
|
|
||||||
logLevel,
|
|
||||||
logContext,
|
|
||||||
format,
|
|
||||||
args);
|
|
||||||
} else {
|
} else {
|
||||||
logger_.noContext(
|
logger_.noContext(this, node, logLevel, format, args);
|
||||||
const_cast<yoga::Config*>(this),
|
|
||||||
const_cast<yoga::Node*>(node),
|
|
||||||
logLevel,
|
|
||||||
format,
|
|
||||||
args);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,8 +129,8 @@ void Config::setCloneNodeCallback(std::nullptr_t) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
YGNodeRef Config::cloneNode(
|
YGNodeRef Config::cloneNode(
|
||||||
YGNodeRef node,
|
YGNodeConstRef node,
|
||||||
YGNodeRef owner,
|
YGNodeConstRef owner,
|
||||||
int childIndex,
|
int childIndex,
|
||||||
void* cloneContext) const {
|
void* cloneContext) const {
|
||||||
YGNodeRef clone = nullptr;
|
YGNodeRef clone = nullptr;
|
||||||
|
@@ -25,15 +25,15 @@ 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,
|
int childIndex,
|
||||||
void* cloneContext);
|
void* cloneContext);
|
||||||
|
|
||||||
@@ -90,8 +90,8 @@ public:
|
|||||||
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,
|
int childIndex,
|
||||||
void* cloneContext) const;
|
void* cloneContext) const;
|
||||||
|
|
||||||
|
@@ -38,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;
|
||||||
|
Reference in New Issue
Block a user