Call measure and baseline fns within YGNode
Summary: @public Stricter encapsulation of baseline and measure callbacks withing `YGNode`. Instead of invoking these callbacks directly (`node->getBaseline()(...)`), they are invoked via methods on `YGNode` (`node->baseline(...)`). This change will allow us to add the concept of a *Layout Context,* where measure and baseline functions will be able to receive an additional `void *` argument if configured accordingly. This API will be used internally for Yoga’s JNI bindings, to avoid storing a weak JNI reference for each node, and avoid reference table overflows. Changed API: - `YGNodeGetMeasureFunc()` -> `YGNodeHasMeasureFunc()` - `YGNodeGetBaselineFunc()` -> `YGNodeHasBaselineFunc()` - `YGNode::getMeasure()` -> `YGNode::hasMeasureFunc()` + `YGNode::measure()` - `YGNpde::getBaseline()` -> `YGNode::hasBaselineFunc()` + `YGNode::baseline()` Reviewed By: SidharthGuglani Differential Revision: D14099550 fbshipit-source-id: 2653ab36acc252a9747986bc88d21dac22d8c91b
This commit is contained in:
committed by
Facebook Github Bot
parent
d5ad51bccc
commit
f86c74ce7e
@@ -8,45 +8,51 @@
|
||||
#include <yoga/YGNode.h>
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
static YGSize _measure(YGNodeRef node,
|
||||
float width,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode) {
|
||||
int* measureCount = (int*)node->getContext();
|
||||
static YGSize _measure(
|
||||
YGNodeRef node,
|
||||
float width,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode) {
|
||||
int* measureCount = (int*) node->getContext();
|
||||
if (measureCount) {
|
||||
(*measureCount)++;
|
||||
}
|
||||
|
||||
return YGSize{
|
||||
.width = 10, .height = 10,
|
||||
.width = 10,
|
||||
.height = 10,
|
||||
};
|
||||
}
|
||||
|
||||
static YGSize _simulate_wrapping_text(YGNodeRef node,
|
||||
float width,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode) {
|
||||
static YGSize _simulate_wrapping_text(
|
||||
YGNodeRef node,
|
||||
float width,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode) {
|
||||
if (widthMode == YGMeasureModeUndefined || width >= 68) {
|
||||
return YGSize{.width = 68, .height = 16};
|
||||
}
|
||||
|
||||
return YGSize{
|
||||
.width = 50, .height = 32,
|
||||
.width = 50,
|
||||
.height = 32,
|
||||
};
|
||||
}
|
||||
|
||||
static YGSize _measure_assert_negative(YGNodeRef node,
|
||||
float width,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode) {
|
||||
static YGSize _measure_assert_negative(
|
||||
YGNodeRef node,
|
||||
float width,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode) {
|
||||
EXPECT_GE(width, 0);
|
||||
EXPECT_GE(height, 0);
|
||||
|
||||
return YGSize{
|
||||
.width = 0, .height = 0,
|
||||
.width = 0,
|
||||
.height = 0,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -148,7 +154,6 @@ TEST(YogaTest, dont_measure_when_min_equals_max_percentages) {
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
|
||||
TEST(YogaTest, measure_nodes_with_margin_auto_and_stretch) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
YGNodeStyleSetWidth(root, 500);
|
||||
@@ -593,7 +598,7 @@ TEST(YogaTest, can_nullify_measure_func_on_any_node) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
YGNodeInsertChild(root, YGNodeNew(), 0);
|
||||
root->setMeasureFunc(nullptr);
|
||||
ASSERT_TRUE(root->getMeasure() == NULL);
|
||||
ASSERT_TRUE(!root->hasMeasureFunc());
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
@@ -635,14 +640,16 @@ TEST(YogaTest, cant_call_negative_measure_horizontal) {
|
||||
YGConfigFree(config);
|
||||
}
|
||||
|
||||
static YGSize _measure_90_10(YGNodeRef node,
|
||||
float width,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode) {
|
||||
static YGSize _measure_90_10(
|
||||
YGNodeRef node,
|
||||
float width,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode) {
|
||||
|
||||
return YGSize{
|
||||
.width = 90, .height = 10,
|
||||
.width = 90,
|
||||
.height = 10,
|
||||
};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user