Remove layoutContext Drilling (#1376)

Summary:
X-link: https://github.com/facebook/react-native/pull/39401

Pull Request resolved: https://github.com/facebook/yoga/pull/1376

kill_with_fire_flamethrower

Reviewed By: rshest

Differential Revision: D49179244

fbshipit-source-id: 9a827e1bd29205254fee5725449191726d6bcf5a
This commit is contained in:
Nick Gerleman
2023-09-12 19:08:55 -07:00
committed by Facebook GitHub Bot
parent b1e0140aaa
commit 0a90b16ac6
17 changed files with 83 additions and 370 deletions

View File

@@ -24,7 +24,6 @@ struct TypedEventTestData {};
template <> template <>
struct TypedEventTestData<Event::LayoutPassEnd> { struct TypedEventTestData<Event::LayoutPassEnd> {
void* layoutContext;
LayoutData layoutData; LayoutData layoutData;
}; };
@@ -329,7 +328,7 @@ void EventTest::listen(
case Event::LayoutPassEnd: { case Event::LayoutPassEnd: {
auto& eventData = data.get<Event::LayoutPassEnd>(); auto& eventData = data.get<Event::LayoutPassEnd>();
events.push_back(createArgs<Event::LayoutPassEnd>( events.push_back(createArgs<Event::LayoutPassEnd>(
node, data, {eventData.layoutContext, *eventData.layoutData})); node, data, {*eventData.layoutData}));
break; break;
} }

View File

@@ -33,7 +33,7 @@ TEST_F(ConfigCloningTest, uses_values_provided_by_cloning_callback) {
config->setCloneNodeCallback(cloneNode); config->setCloneNodeCallback(cloneNode);
yoga::Node node{}, owner{}; yoga::Node node{}, owner{};
auto clone = config->cloneNode(&node, &owner, 0, nullptr); auto clone = config->cloneNode(&node, &owner, 0);
ASSERT_EQ(clone, &clonedNode); ASSERT_EQ(clone, &clonedNode);
} }
@@ -44,22 +44,12 @@ TEST_F(
config->setCloneNodeCallback(doNotClone); config->setCloneNodeCallback(doNotClone);
yoga::Node node{}, owner{}; yoga::Node node{}, owner{};
auto clone = config->cloneNode(&node, &owner, 0, nullptr); auto clone = config->cloneNode(&node, &owner, 0);
ASSERT_NE(clone, nullptr); ASSERT_NE(clone, nullptr);
YGNodeFree(clone); YGNodeFree(clone);
} }
TEST_F(ConfigCloningTest, can_clone_with_context) {
config->setCloneNodeCallback(
[](YGNodeConstRef, YGNodeConstRef, size_t, void* context) {
return (YGNodeRef) context;
});
yoga::Node node{}, owner{}, clone{};
ASSERT_EQ(config->cloneNode(&node, &owner, 0, &clone), &clone);
}
void ConfigCloningTest::SetUp() { void ConfigCloningTest::SetUp() {
config = {static_cast<yoga::Config*>(YGConfigNew()), YGConfigFree}; config = {static_cast<yoga::Config*>(YGConfigNew()), YGConfigFree};
} }

View File

@@ -38,38 +38,7 @@ TEST(Node, measure_with_measure_fn) {
}); });
ASSERT_EQ( ASSERT_EQ(
n.measure(23, YGMeasureModeExactly, 24, YGMeasureModeAtMost, nullptr), n.measure(23, YGMeasureModeExactly, 24, YGMeasureModeAtMost),
(YGSize{23, 12}));
}
TEST(Node, measure_with_context_measure_fn) {
auto n = Node{};
n.setMeasureFunc([](YGNodeConstRef,
float,
YGMeasureMode,
float,
YGMeasureMode,
void* ctx) { return *(YGSize*) ctx; });
auto result = YGSize{123.4f, -56.7f};
ASSERT_EQ(
n.measure(0, YGMeasureModeUndefined, 0, YGMeasureModeUndefined, &result),
result);
}
TEST(Node, switching_measure_fn_types) {
auto n = Node{};
n.setMeasureFunc(
[](YGNodeConstRef, float, YGMeasureMode, float, YGMeasureMode, void*) {
return YGSize{};
});
n.setMeasureFunc(
[](YGNodeConstRef, float w, YGMeasureMode wm, float h, YGMeasureMode hm) {
return YGSize{w * static_cast<float>(wm), h / static_cast<float>(hm)};
});
ASSERT_EQ(
n.measure(23, YGMeasureModeExactly, 24, YGMeasureModeAtMost, nullptr),
(YGSize{23, 12})); (YGSize{23, 12}));
} }
@@ -84,17 +53,6 @@ TEST(Node, hasMeasureFunc_after_unset) {
ASSERT_FALSE(n.hasMeasureFunc()); ASSERT_FALSE(n.hasMeasureFunc());
} }
TEST(Node, hasMeasureFunc_after_unset_context) {
auto n = Node{};
n.setMeasureFunc(
[](YGNodeConstRef, float, YGMeasureMode, float, YGMeasureMode, void*) {
return YGSize{};
});
n.setMeasureFunc(nullptr);
ASSERT_FALSE(n.hasMeasureFunc());
}
TEST(Node, hasBaselineFunc_initial) { TEST(Node, hasBaselineFunc_initial) {
auto n = Node{}; auto n = Node{};
ASSERT_FALSE(n.hasBaselineFunc()); ASSERT_FALSE(n.hasBaselineFunc());
@@ -110,17 +68,7 @@ TEST(Node, baseline_with_baseline_fn) {
auto n = Node{}; auto n = Node{};
n.setBaselineFunc([](YGNodeConstRef, 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), 3.75f);
}
TEST(Node, baseline_with_context_baseline_fn) {
auto n = Node{};
n.setBaselineFunc([](YGNodeConstRef, float w, float h, void* ctx) {
return w + h + *(float*) ctx;
});
auto ctx = -10.0f;
ASSERT_EQ(n.baseline(1.25f, 2.5f, &ctx), -6.25f);
} }
TEST(Node, hasBaselineFunc_after_unset) { TEST(Node, hasBaselineFunc_after_unset) {
@@ -130,18 +78,3 @@ TEST(Node, hasBaselineFunc_after_unset) {
n.setBaselineFunc(nullptr); n.setBaselineFunc(nullptr);
ASSERT_FALSE(n.hasBaselineFunc()); ASSERT_FALSE(n.hasBaselineFunc());
} }
TEST(Node, hasBaselineFunc_after_unset_context) {
auto n = Node{};
n.setBaselineFunc([](YGNodeConstRef, float, float, void*) { return 0.0f; });
n.setMeasureFunc(nullptr);
ASSERT_FALSE(n.hasMeasureFunc());
}
TEST(Node, switching_baseline_fn_types) {
auto n = Node{};
n.setBaselineFunc([](YGNodeConstRef, float, float, void*) { return 0.0f; });
n.setBaselineFunc([](YGNodeConstRef, float, float) { return 1.0f; });
ASSERT_EQ(n.baseline(1, 2, nullptr), 1.0f);
}

View File

@@ -15,13 +15,6 @@
YG_EXTERN_C_BEGIN YG_EXTERN_C_BEGIN
YG_EXPORT void YGNodeCalculateLayoutWithContext(
YGNodeRef node,
float availableWidth,
float availableHeight,
YGDirection ownerDirection,
void* layoutContext);
// Deallocates a Yoga Node. Unlike YGNodeFree, does not remove the node from // Deallocates a Yoga Node. Unlike YGNodeFree, does not remove the node from
// its parent or children. // its parent or children.
YG_EXPORT void YGNodeDeallocate(YGNodeRef node); YG_EXPORT void YGNodeDeallocate(YGNodeRef node);

View File

@@ -57,7 +57,7 @@ void YGNodeSetBaselineFunc(YGNodeRef node, YGBaselineFunc baselineFunc) {
} }
YGDirtiedFunc YGNodeGetDirtiedFunc(YGNodeConstRef node) { YGDirtiedFunc YGNodeGetDirtiedFunc(YGNodeConstRef node) {
return resolveRef(node)->getDirtied(); return resolveRef(node)->getDirtiedFunc();
} }
void YGNodeSetDirtiedFunc(YGNodeRef node, YGDirtiedFunc dirtiedFunc) { void YGNodeSetDirtiedFunc(YGNodeRef node, YGDirtiedFunc dirtiedFunc) {
@@ -805,7 +805,7 @@ void YGNodePrint(const YGNodeConstRef nodeRef, const YGPrintOptions options) {
const auto node = resolveRef(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, str.c_str());
} }
#endif #endif
@@ -927,16 +927,6 @@ void YGNodeCalculateLayout(
const float ownerWidth, const float ownerWidth,
const float ownerHeight, const float ownerHeight,
const YGDirection ownerDirection) { const YGDirection ownerDirection) {
YGNodeCalculateLayoutWithContext(
node, ownerWidth, ownerHeight, ownerDirection, nullptr);
}
void YGNodeCalculateLayoutWithContext(
const YGNodeRef node,
const float ownerWidth,
const float ownerHeight,
const YGDirection ownerDirection,
void* layoutContext) {
yoga::calculateLayout( yoga::calculateLayout(
resolveRef(node), ownerWidth, ownerHeight, ownerDirection, layoutContext); resolveRef(node), ownerWidth, ownerHeight, ownerDirection);
} }

View File

@@ -14,15 +14,14 @@
namespace facebook::yoga { namespace facebook::yoga {
float calculateBaseline(const yoga::Node* node, void* layoutContext) { float calculateBaseline(const yoga::Node* node) {
if (node->hasBaselineFunc()) { if (node->hasBaselineFunc()) {
Event::publish<Event::NodeBaselineStart>(node); Event::publish<Event::NodeBaselineStart>(node);
const float baseline = node->baseline( const float baseline = node->baseline(
node->getLayout().measuredDimensions[YGDimensionWidth], node->getLayout().measuredDimensions[YGDimensionWidth],
node->getLayout().measuredDimensions[YGDimensionHeight], node->getLayout().measuredDimensions[YGDimensionHeight]);
layoutContext);
Event::publish<Event::NodeBaselineEnd>(node); Event::publish<Event::NodeBaselineEnd>(node);
@@ -58,7 +57,7 @@ float calculateBaseline(const yoga::Node* node, void* layoutContext) {
return node->getLayout().measuredDimensions[YGDimensionHeight]; return node->getLayout().measuredDimensions[YGDimensionHeight];
} }
const float baseline = calculateBaseline(baselineChild, layoutContext); const float baseline = calculateBaseline(baselineChild);
return baseline + baselineChild->getLayout().position[YGEdgeTop]; return baseline + baselineChild->getLayout().position[YGEdgeTop];
} }

View File

@@ -13,7 +13,7 @@
namespace facebook::yoga { namespace facebook::yoga {
// Calculate baseline represented as an offset from the top edge of the node. // Calculate baseline represented as an offset from the top edge of the node.
float calculateBaseline(const yoga::Node* node, void* layoutContext); float calculateBaseline(const yoga::Node* node);
// Whether any of the children of this node participate in baseline alignment // Whether any of the children of this node participate in baseline alignment
bool isBaselineLayout(const yoga::Node* node); bool isBaselineLayout(const yoga::Node* node);

View File

@@ -46,7 +46,6 @@ bool calculateLayoutInternal(
const LayoutPassReason reason, const LayoutPassReason reason,
const yoga::Config* const config, const yoga::Config* const config,
LayoutData& layoutMarkerData, LayoutData& layoutMarkerData,
void* const layoutContext,
const uint32_t depth, const uint32_t depth,
const uint32_t generationCount); const uint32_t generationCount);
@@ -134,7 +133,6 @@ static void computeFlexBasisForChild(
const YGDirection direction, const YGDirection direction,
const yoga::Config* const config, const yoga::Config* const config,
LayoutData& layoutMarkerData, LayoutData& layoutMarkerData,
void* const layoutContext,
const uint32_t depth, const uint32_t depth,
const uint32_t generationCount) { const uint32_t generationCount) {
const YGFlexDirection mainAxis = const YGFlexDirection mainAxis =
@@ -309,7 +307,6 @@ static void computeFlexBasisForChild(
LayoutPassReason::kMeasureChild, LayoutPassReason::kMeasureChild,
config, config,
layoutMarkerData, layoutMarkerData,
layoutContext,
depth, depth,
generationCount); generationCount);
@@ -329,7 +326,6 @@ static void layoutAbsoluteChild(
const YGDirection direction, const YGDirection direction,
const yoga::Config* const config, const yoga::Config* const config,
LayoutData& layoutMarkerData, LayoutData& layoutMarkerData,
void* const layoutContext,
const uint32_t depth, const uint32_t depth,
const uint32_t generationCount) { const uint32_t generationCount) {
const YGFlexDirection mainAxis = const YGFlexDirection mainAxis =
@@ -437,7 +433,6 @@ static void layoutAbsoluteChild(
LayoutPassReason::kAbsMeasureChild, LayoutPassReason::kAbsMeasureChild,
config, config,
layoutMarkerData, layoutMarkerData,
layoutContext,
depth, depth,
generationCount); generationCount);
childWidth = child->getLayout().measuredDimensions[YGDimensionWidth] + childWidth = child->getLayout().measuredDimensions[YGDimensionWidth] +
@@ -459,7 +454,6 @@ static void layoutAbsoluteChild(
LayoutPassReason::kAbsLayout, LayoutPassReason::kAbsLayout,
config, config,
layoutMarkerData, layoutMarkerData,
layoutContext,
depth, depth,
generationCount); generationCount);
@@ -564,7 +558,6 @@ static void measureNodeWithMeasureFunc(
const float ownerWidth, const float ownerWidth,
const float ownerHeight, const float ownerHeight,
LayoutData& layoutMarkerData, LayoutData& layoutMarkerData,
void* const layoutContext,
const LayoutPassReason reason) { const LayoutPassReason reason) {
yoga::assertFatalWithNode( yoga::assertFatalWithNode(
node, node,
@@ -613,11 +606,7 @@ static void measureNodeWithMeasureFunc(
// Measure the text under the current constraints. // Measure the text under the current constraints.
const YGSize measuredSize = node->measure( const YGSize measuredSize = node->measure(
innerWidth, innerWidth, widthMeasureMode, innerHeight, heightMeasureMode);
widthMeasureMode,
innerHeight,
heightMeasureMode,
layoutContext);
layoutMarkerData.measureCallbacks += 1; layoutMarkerData.measureCallbacks += 1;
layoutMarkerData.measureCallbackReasonsCount[static_cast<size_t>(reason)] += layoutMarkerData.measureCallbackReasonsCount[static_cast<size_t>(reason)] +=
@@ -625,8 +614,7 @@ static void measureNodeWithMeasureFunc(
Event::publish<Event::MeasureCallbackEnd>( Event::publish<Event::MeasureCallbackEnd>(
node, node,
{layoutContext, {innerWidth,
innerWidth,
widthMeasureMode, widthMeasureMode,
innerHeight, innerHeight,
heightMeasureMode, heightMeasureMode,
@@ -739,17 +727,15 @@ static bool measureNodeWithFixedSize(
return false; return false;
} }
static void zeroOutLayoutRecursively( static void zeroOutLayoutRecursively(yoga::Node* const node) {
yoga::Node* const node,
void* layoutContext) {
node->getLayout() = {}; node->getLayout() = {};
node->setLayoutDimension(0, YGDimensionWidth); node->setLayoutDimension(0, YGDimensionWidth);
node->setLayoutDimension(0, YGDimensionHeight); node->setLayoutDimension(0, YGDimensionHeight);
node->setHasNewLayout(true); node->setHasNewLayout(true);
node->cloneChildrenIfNeeded(layoutContext); node->cloneChildrenIfNeeded();
for (const auto child : node->getChildren()) { for (const auto child : node->getChildren()) {
zeroOutLayoutRecursively(child, layoutContext); zeroOutLayoutRecursively(child);
} }
} }
@@ -795,7 +781,6 @@ static float computeFlexBasisForChildren(
const yoga::Config* const config, const yoga::Config* const config,
bool performLayout, bool performLayout,
LayoutData& layoutMarkerData, LayoutData& layoutMarkerData,
void* const layoutContext,
const uint32_t depth, const uint32_t depth,
const uint32_t generationCount) { const uint32_t generationCount) {
float totalOuterFlexBasis = 0.0f; float totalOuterFlexBasis = 0.0f;
@@ -826,7 +811,7 @@ static float computeFlexBasisForChildren(
for (auto child : children) { for (auto child : children) {
child->resolveDimension(); child->resolveDimension();
if (child->getStyle().display() == YGDisplayNone) { if (child->getStyle().display() == YGDisplayNone) {
zeroOutLayoutRecursively(child, layoutContext); zeroOutLayoutRecursively(child);
child->setHasNewLayout(true); child->setHasNewLayout(true);
child->setDirty(false); child->setDirty(false);
continue; continue;
@@ -861,7 +846,6 @@ static float computeFlexBasisForChildren(
direction, direction,
config, config,
layoutMarkerData, layoutMarkerData,
layoutContext,
depth, depth,
generationCount); generationCount);
} }
@@ -894,7 +878,6 @@ static float distributeFreeSpaceSecondPass(
const bool performLayout, const bool performLayout,
const yoga::Config* const config, const yoga::Config* const config,
LayoutData& layoutMarkerData, LayoutData& layoutMarkerData,
void* const layoutContext,
const uint32_t depth, const uint32_t depth,
const uint32_t generationCount) { const uint32_t generationCount) {
float childFlexBasis = 0; float childFlexBasis = 0;
@@ -1059,7 +1042,6 @@ static float distributeFreeSpaceSecondPass(
: LayoutPassReason::kFlexMeasure, : LayoutPassReason::kFlexMeasure,
config, config,
layoutMarkerData, layoutMarkerData,
layoutContext,
depth, depth,
generationCount); generationCount);
node->setLayoutHadOverflow( node->setLayoutHadOverflow(
@@ -1192,7 +1174,6 @@ static void resolveFlexibleLength(
const bool performLayout, const bool performLayout,
const yoga::Config* const config, const yoga::Config* const config,
LayoutData& layoutMarkerData, LayoutData& layoutMarkerData,
void* const layoutContext,
const uint32_t depth, const uint32_t depth,
const uint32_t generationCount) { const uint32_t generationCount) {
const float originalFreeSpace = flexLine.layout.remainingFreeSpace; const float originalFreeSpace = flexLine.layout.remainingFreeSpace;
@@ -1220,7 +1201,6 @@ static void resolveFlexibleLength(
performLayout, performLayout,
config, config,
layoutMarkerData, layoutMarkerData,
layoutContext,
depth, depth,
generationCount); generationCount);
@@ -1240,8 +1220,7 @@ static void YGJustifyMainAxis(
const float availableInnerMainDim, const float availableInnerMainDim,
const float availableInnerCrossDim, const float availableInnerCrossDim,
const float availableInnerWidth, const float availableInnerWidth,
const bool performLayout, const bool performLayout) {
void* const layoutContext) {
const auto& style = node->getStyle(); const auto& style = node->getStyle();
const float leadingPaddingAndBorderMain = const float leadingPaddingAndBorderMain =
node->getLeadingPaddingAndBorder(mainAxis, ownerWidth).unwrap(); node->getLeadingPaddingAndBorder(mainAxis, ownerWidth).unwrap();
@@ -1400,7 +1379,7 @@ static void YGJustifyMainAxis(
if (isNodeBaselineLayout) { if (isNodeBaselineLayout) {
// If the child is baseline aligned then the cross dimension is // If the child is baseline aligned then the cross dimension is
// calculated by adding maxAscent and maxDescent from the baseline. // calculated by adding maxAscent and maxDescent from the baseline.
const float ascent = calculateBaseline(child, layoutContext) + const float ascent = calculateBaseline(child) +
child child
->getLeadingMargin( ->getLeadingMargin(
YGFlexDirectionColumn, availableInnerWidth) YGFlexDirectionColumn, availableInnerWidth)
@@ -1519,7 +1498,6 @@ static void calculateLayoutImpl(
const bool performLayout, const bool performLayout,
const yoga::Config* const config, const yoga::Config* const config,
LayoutData& layoutMarkerData, LayoutData& layoutMarkerData,
void* const layoutContext,
const uint32_t depth, const uint32_t depth,
const uint32_t generationCount, const uint32_t generationCount,
const LayoutPassReason reason) { const LayoutPassReason reason) {
@@ -1597,7 +1575,6 @@ static void calculateLayoutImpl(
ownerWidth, ownerWidth,
ownerHeight, ownerHeight,
layoutMarkerData, layoutMarkerData,
layoutContext,
reason); reason);
return; return;
} }
@@ -1631,7 +1608,7 @@ static void calculateLayoutImpl(
// At this point we know we're going to perform work. Ensure that each child // At this point we know we're going to perform work. Ensure that each child
// has a mutable copy. // has a mutable copy.
node->cloneChildrenIfNeeded(layoutContext); node->cloneChildrenIfNeeded();
// Reset layout flags, as they could have changed. // Reset layout flags, as they could have changed.
node->setLayoutHadOverflow(false); node->setLayoutHadOverflow(false);
@@ -1699,7 +1676,6 @@ static void calculateLayoutImpl(
config, config,
performLayout, performLayout,
layoutMarkerData, layoutMarkerData,
layoutContext,
depth, depth,
generationCount); generationCount);
@@ -1838,7 +1814,6 @@ static void calculateLayoutImpl(
performLayout, performLayout,
config, config,
layoutMarkerData, layoutMarkerData,
layoutContext,
depth, depth,
generationCount); generationCount);
} }
@@ -1867,8 +1842,7 @@ static void calculateLayoutImpl(
availableInnerMainDim, availableInnerMainDim,
availableInnerCrossDim, availableInnerCrossDim,
availableInnerWidth, availableInnerWidth,
performLayout, performLayout);
layoutContext);
float containerCrossAxis = availableInnerCrossDim; float containerCrossAxis = availableInnerCrossDim;
if (measureModeCrossDim == YGMeasureModeUndefined || if (measureModeCrossDim == YGMeasureModeUndefined ||
@@ -2015,7 +1989,6 @@ static void calculateLayoutImpl(
LayoutPassReason::kStretch, LayoutPassReason::kStretch,
config, config,
layoutMarkerData, layoutMarkerData,
layoutContext,
depth, depth,
generationCount); generationCount);
} }
@@ -2127,7 +2100,7 @@ static void calculateLayoutImpl(
.unwrap()); .unwrap());
} }
if (resolveChildAlignment(node, child) == YGAlignBaseline) { if (resolveChildAlignment(node, child) == YGAlignBaseline) {
const float ascent = calculateBaseline(child, layoutContext) + const float ascent = calculateBaseline(child) +
child child
->getLeadingMargin( ->getLeadingMargin(
YGFlexDirectionColumn, availableInnerWidth) YGFlexDirectionColumn, availableInnerWidth)
@@ -2233,7 +2206,6 @@ static void calculateLayoutImpl(
LayoutPassReason::kMultilineStretch, LayoutPassReason::kMultilineStretch,
config, config,
layoutMarkerData, layoutMarkerData,
layoutContext,
depth, depth,
generationCount); generationCount);
} }
@@ -2243,7 +2215,7 @@ static void calculateLayoutImpl(
case YGAlignBaseline: { case YGAlignBaseline: {
child->setLayoutPosition( child->setLayoutPosition(
currentLead + maxAscentForCurrentLine - currentLead + maxAscentForCurrentLine -
calculateBaseline(child, layoutContext) + calculateBaseline(child) +
child child
->getLeadingPosition( ->getLeadingPosition(
YGFlexDirectionColumn, availableInnerCrossDim) YGFlexDirectionColumn, availableInnerCrossDim)
@@ -2384,7 +2356,6 @@ static void calculateLayoutImpl(
direction, direction,
config, config,
layoutMarkerData, layoutMarkerData,
layoutContext,
depth, depth,
generationCount); generationCount);
} }
@@ -2465,7 +2436,6 @@ bool calculateLayoutInternal(
const LayoutPassReason reason, const LayoutPassReason reason,
const yoga::Config* const config, const yoga::Config* const config,
LayoutData& layoutMarkerData, LayoutData& layoutMarkerData,
void* const layoutContext,
uint32_t depth, uint32_t depth,
const uint32_t generationCount) { const uint32_t generationCount) {
LayoutResults* layout = &node->getLayout(); LayoutResults* layout = &node->getLayout();
@@ -2577,15 +2547,13 @@ bool calculateLayoutInternal(
yoga::log( yoga::log(
node, node,
YGLogLevelVerbose, YGLogLevelVerbose,
nullptr,
"%s%d.{[skipped] ", "%s%d.{[skipped] ",
spacerWithLength(depth), spacerWithLength(depth),
depth); depth);
node->print(layoutContext); node->print();
yoga::log( yoga::log(
node, node,
YGLogLevelVerbose, YGLogLevelVerbose,
nullptr,
"wm: %s, hm: %s, aw: %f ah: %f => d: (%f, %f) %s\n", "wm: %s, hm: %s, aw: %f ah: %f => d: (%f, %f) %s\n",
measureModeName(widthMeasureMode, performLayout), measureModeName(widthMeasureMode, performLayout),
measureModeName(heightMeasureMode, performLayout), measureModeName(heightMeasureMode, performLayout),
@@ -2600,16 +2568,14 @@ bool calculateLayoutInternal(
yoga::log( yoga::log(
node, node,
YGLogLevelVerbose, YGLogLevelVerbose,
nullptr,
"%s%d.{%s", "%s%d.{%s",
spacerWithLength(depth), spacerWithLength(depth),
depth, depth,
needToVisitNode ? "*" : ""); needToVisitNode ? "*" : "");
node->print(layoutContext); node->print();
yoga::log( yoga::log(
node, node,
YGLogLevelVerbose, YGLogLevelVerbose,
nullptr,
"wm: %s, hm: %s, aw: %f ah: %f %s\n", "wm: %s, hm: %s, aw: %f ah: %f %s\n",
measureModeName(widthMeasureMode, performLayout), measureModeName(widthMeasureMode, performLayout),
measureModeName(heightMeasureMode, performLayout), measureModeName(heightMeasureMode, performLayout),
@@ -2630,7 +2596,6 @@ bool calculateLayoutInternal(
performLayout, performLayout,
config, config,
layoutMarkerData, layoutMarkerData,
layoutContext,
depth, depth,
generationCount, generationCount,
reason); reason);
@@ -2639,16 +2604,14 @@ bool calculateLayoutInternal(
yoga::log( yoga::log(
node, node,
YGLogLevelVerbose, YGLogLevelVerbose,
nullptr,
"%s%d.}%s", "%s%d.}%s",
spacerWithLength(depth), spacerWithLength(depth),
depth, depth,
needToVisitNode ? "*" : ""); needToVisitNode ? "*" : "");
node->print(layoutContext); node->print();
yoga::log( yoga::log(
node, node,
YGLogLevelVerbose, YGLogLevelVerbose,
nullptr,
"wm: %s, hm: %s, d: (%f, %f) %s\n", "wm: %s, hm: %s, d: (%f, %f) %s\n",
measureModeName(widthMeasureMode, performLayout), measureModeName(widthMeasureMode, performLayout),
measureModeName(heightMeasureMode, performLayout), measureModeName(heightMeasureMode, performLayout),
@@ -2668,8 +2631,7 @@ bool calculateLayoutInternal(
if (layout->nextCachedMeasurementsIndex == if (layout->nextCachedMeasurementsIndex ==
LayoutResults::MaxCachedMeasurements) { LayoutResults::MaxCachedMeasurements) {
if (gPrintChanges) { if (gPrintChanges) {
yoga::log( yoga::log(node, YGLogLevelVerbose, "Out of cache entries!\n");
node, YGLogLevelVerbose, nullptr, "Out of cache entries!\n");
} }
layout->nextCachedMeasurementsIndex = 0; layout->nextCachedMeasurementsIndex = 0;
} }
@@ -2719,7 +2681,7 @@ bool calculateLayoutInternal(
layoutType = cachedResults != nullptr ? LayoutType::kCachedMeasure layoutType = cachedResults != nullptr ? LayoutType::kCachedMeasure
: LayoutType::kMeasure; : LayoutType::kMeasure;
} }
Event::publish<Event::NodeLayout>(node, {layoutType, layoutContext}); Event::publish<Event::NodeLayout>(node, {layoutType});
return (needToVisitNode || cachedResults == nullptr); return (needToVisitNode || cachedResults == nullptr);
} }
@@ -2728,9 +2690,8 @@ void calculateLayout(
yoga::Node* const node, yoga::Node* const node,
const float ownerWidth, const float ownerWidth,
const float ownerHeight, const float ownerHeight,
const YGDirection ownerDirection, const YGDirection ownerDirection) {
void* layoutContext) { Event::publish<Event::LayoutPassStart>(node);
Event::publish<Event::LayoutPassStart>(node, {layoutContext});
LayoutData markerData = {}; LayoutData markerData = {};
// Increment the generation count. This will force the recursive routine to // Increment the generation count. This will force the recursive routine to
@@ -2791,7 +2752,6 @@ void calculateLayout(
LayoutPassReason::kInitial, LayoutPassReason::kInitial,
node->getConfig(), node->getConfig(),
markerData, markerData,
layoutContext,
0, // tree root 0, // tree root
gCurrentGenerationCount.load(std::memory_order_relaxed))) { gCurrentGenerationCount.load(std::memory_order_relaxed))) {
node->setPosition( node->setPosition(
@@ -2808,7 +2768,7 @@ void calculateLayout(
#endif #endif
} }
Event::publish<Event::LayoutPassEnd>(node, {layoutContext, &markerData}); Event::publish<Event::LayoutPassEnd>(node, {&markerData});
} }
} // namespace facebook::yoga } // namespace facebook::yoga

View File

@@ -16,7 +16,6 @@ void calculateLayout(
yoga::Node* const node, yoga::Node* const node,
const float ownerWidth, const float ownerWidth,
const float ownerHeight, const float ownerHeight,
const YGDirection ownerDirection, const YGDirection ownerDirection);
void* layoutContext);
} // namespace facebook::yoga } // namespace facebook::yoga

View File

@@ -91,56 +91,28 @@ void* Config::getContext() const {
} }
void Config::setLogger(YGLogger logger) { void Config::setLogger(YGLogger logger) {
logger_.noContext = logger; logger_ = logger;
flags_.loggerUsesContext = false;
}
void Config::setLogger(LogWithContextFn logger) {
logger_.withContext = logger;
flags_.loggerUsesContext = true;
}
void Config::setLogger(std::nullptr_t) {
setLogger(YGLogger{nullptr});
} }
void Config::log( void Config::log(
const yoga::Node* node, const yoga::Node* node,
YGLogLevel logLevel, YGLogLevel logLevel,
void* logContext,
const char* format, const char* format,
va_list args) const { va_list args) const {
if (flags_.loggerUsesContext) { logger_(this, node, logLevel, format, args);
logger_.withContext(this, node, logLevel, logContext, format, args);
} else {
logger_.noContext(this, node, logLevel, format, args);
}
} }
void Config::setCloneNodeCallback(YGCloneNodeFunc cloneNode) { void Config::setCloneNodeCallback(YGCloneNodeFunc cloneNode) {
cloneNodeCallback_.noContext = cloneNode; cloneNodeCallback_ = cloneNode;
flags_.cloneNodeUsesContext = false;
}
void Config::setCloneNodeCallback(CloneWithContextFn cloneNode) {
cloneNodeCallback_.withContext = cloneNode;
flags_.cloneNodeUsesContext = true;
}
void Config::setCloneNodeCallback(std::nullptr_t) {
setCloneNodeCallback(YGCloneNodeFunc{nullptr});
} }
YGNodeRef Config::cloneNode( YGNodeRef Config::cloneNode(
YGNodeConstRef node, YGNodeConstRef node,
YGNodeConstRef owner, YGNodeConstRef owner,
size_t childIndex, size_t childIndex) const {
void* cloneContext) const {
YGNodeRef clone = nullptr; YGNodeRef clone = nullptr;
if (cloneNodeCallback_.noContext != nullptr) { if (cloneNodeCallback_ != nullptr) {
clone = flags_.cloneNodeUsesContext clone = cloneNodeCallback_(node, owner, childIndex);
? cloneNodeCallback_.withContext(node, owner, childIndex, cloneContext)
: cloneNodeCallback_.noContext(node, owner, childIndex);
} }
if (clone == nullptr) { if (clone == nullptr) {
clone = YGNodeClone(node); clone = YGNodeClone(node);

View File

@@ -24,29 +24,12 @@ bool configUpdateInvalidatesLayout(
const Config& oldConfig, const Config& oldConfig,
const Config& newConfig); const Config& newConfig);
// Internal variants of log functions, currently used only by JNI bindings.
// TODO: Reconcile this with the public API
using LogWithContextFn = int (*)(
YGConfigConstRef config,
YGNodeConstRef node,
YGLogLevel level,
void* context,
const char* format,
va_list args);
using CloneWithContextFn = YGNodeRef (*)(
YGNodeConstRef node,
YGNodeConstRef owner,
size_t childIndex,
void* cloneContext);
#pragma pack(push) #pragma pack(push)
#pragma pack(1) #pragma pack(1)
// Packed structure of <32-bit options to miminize size per node. // Packed structure of <32-bit options to miminize size per node.
struct ConfigFlags { struct ConfigFlags {
bool useWebDefaults : 1; bool useWebDefaults : 1;
bool printTree : 1; bool printTree : 1;
bool cloneNodeUsesContext : 1;
bool loggerUsesContext : 1;
}; };
#pragma pack(pop) #pragma pack(pop)
@@ -79,35 +62,23 @@ public:
void* getContext() const; void* getContext() const;
void setLogger(YGLogger logger); void setLogger(YGLogger logger);
void setLogger(LogWithContextFn logger);
void setLogger(std::nullptr_t);
void log( void log(
const yoga::Node* node, const yoga::Node* node,
YGLogLevel logLevel, YGLogLevel logLevel,
void* logContext,
const char* format, const char* format,
va_list args) const; va_list args) const;
void setCloneNodeCallback(YGCloneNodeFunc cloneNode); void setCloneNodeCallback(YGCloneNodeFunc cloneNode);
void setCloneNodeCallback(CloneWithContextFn cloneNode);
void setCloneNodeCallback(std::nullptr_t);
YGNodeRef cloneNode( YGNodeRef cloneNode(
YGNodeConstRef node, YGNodeConstRef node,
YGNodeConstRef owner, YGNodeConstRef owner,
size_t childIndex, size_t childIndex) const;
void* cloneContext) const;
static const Config& getDefault(); static const Config& getDefault();
private: private:
union { YGCloneNodeFunc cloneNodeCallback_;
CloneWithContextFn withContext; YGLogger logger_;
YGCloneNodeFunc noContext;
} cloneNodeCallback_;
union {
LogWithContextFn withContext;
YGLogger noContext;
} logger_;
ConfigFlags flags_{}; ConfigFlags flags_{};
EnumBitset<YGExperimentalFeature> experimentalFeatures_{}; EnumBitset<YGExperimentalFeature> experimentalFeatures_{};

View File

@@ -22,7 +22,7 @@ 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(YGLogLevelFatal, nullptr, "%s\n", message); yoga::log(YGLogLevelFatal, "%s\n", message);
fatalWithMessage(message); fatalWithMessage(message);
} }
} }
@@ -32,7 +32,7 @@ void assertFatalWithNode(
const bool condition, const bool condition,
const char* message) { const char* message) {
if (!condition) { if (!condition) {
yoga::log(node, YGLogLevelFatal, nullptr, "%s\n", message); yoga::log(node, YGLogLevelFatal, "%s\n", message);
fatalWithMessage(message); fatalWithMessage(message);
} }
} }
@@ -42,7 +42,7 @@ void assertFatalWithConfig(
const bool condition, const bool condition,
const char* message) { const char* message) {
if (!condition) { if (!condition) {
yoga::log(config, YGLogLevelFatal, nullptr, "%s\n", message); yoga::log(config, YGLogLevelFatal, "%s\n", message);
fatalWithMessage(message); fatalWithMessage(message);
} }
} }

View File

@@ -19,51 +19,43 @@ void vlog(
const yoga::Config* config, const yoga::Config* config,
const yoga::Node* node, const yoga::Node* node,
YGLogLevel level, YGLogLevel level,
void* context,
const char* format, const char* format,
va_list args) { va_list args) {
if (config == nullptr) { if (config == nullptr) {
getDefaultLogger()(nullptr, node, level, format, args); getDefaultLogger()(nullptr, node, level, format, args);
} else { } else {
config->log(node, level, context, format, args); config->log(node, level, format, args);
} }
} }
} // namespace } // namespace
void log(YGLogLevel level, void* context, const char* format, ...) noexcept { void log(YGLogLevel level, const char* format, ...) noexcept {
va_list args; va_list args;
va_start(args, format); va_start(args, format);
vlog(nullptr, nullptr, level, context, format, args); vlog(nullptr, nullptr, level, format, args);
va_end(args); va_end(args);
} }
void log( void log(
const yoga::Node* node, const yoga::Node* node,
YGLogLevel level, YGLogLevel level,
void* context,
const char* format, const char* format,
...) noexcept { ...) noexcept {
va_list args; va_list args;
va_start(args, format); va_start(args, format);
vlog( vlog(
node == nullptr ? nullptr : node->getConfig(), node == nullptr ? nullptr : node->getConfig(), node, level, format, args);
node,
level,
context,
format,
args);
va_end(args); va_end(args);
} }
void log( void log(
const yoga::Config* config, const yoga::Config* config,
YGLogLevel level, YGLogLevel level,
void* context,
const char* format, const char* format,
...) noexcept { ...) noexcept {
va_list args; va_list args;
va_start(args, format); va_start(args, format);
vlog(config, nullptr, level, context, format, args); vlog(config, nullptr, level, format, args);
va_end(args); va_end(args);
} }

View File

@@ -15,19 +15,17 @@
namespace facebook::yoga { namespace facebook::yoga {
void log(YGLogLevel level, void*, const char* format, ...) noexcept; void log(YGLogLevel level, const char* format, ...) noexcept;
void log( void log(
const yoga::Node* node, const yoga::Node* node,
YGLogLevel level, YGLogLevel level,
void*,
const char* message, const char* message,
...) noexcept; ...) noexcept;
void log( void log(
const yoga::Config* config, const yoga::Config* config,
YGLogLevel level, YGLogLevel level,
void*,
const char* format, const char* format,
...) noexcept; ...) noexcept;

View File

@@ -103,20 +103,13 @@ struct Event::TypedData<Event::NodeDeallocation> {
YGConfigConstRef config; YGConfigConstRef config;
}; };
template <>
struct Event::TypedData<Event::LayoutPassStart> {
void* layoutContext;
};
template <> template <>
struct Event::TypedData<Event::LayoutPassEnd> { struct Event::TypedData<Event::LayoutPassEnd> {
void* layoutContext;
LayoutData* layoutData; LayoutData* layoutData;
}; };
template <> template <>
struct Event::TypedData<Event::MeasureCallbackEnd> { struct Event::TypedData<Event::MeasureCallbackEnd> {
void* layoutContext;
float width; float width;
YGMeasureMode widthMeasureMode; YGMeasureMode widthMeasureMode;
float height; float height;
@@ -129,7 +122,6 @@ struct Event::TypedData<Event::MeasureCallbackEnd> {
template <> template <>
struct Event::TypedData<Event::NodeLayout> { struct Event::TypedData<Event::NodeLayout> {
LayoutType layoutType; LayoutType layoutType;
void* layoutContext;
}; };
} // namespace facebook::yoga } // namespace facebook::yoga

View File

@@ -32,10 +32,10 @@ Node::Node(const yoga::Config* config) : config_{config} {
Node::Node(Node&& node) { Node::Node(Node&& node) {
context_ = node.context_; context_ = node.context_;
flags_ = node.flags_; flags_ = node.flags_;
measure_ = node.measure_; measureFunc_ = node.measureFunc_;
baseline_ = node.baseline_; baselineFunc_ = node.baselineFunc_;
print_ = node.print_; printFunc_ = node.printFunc_;
dirtied_ = node.dirtied_; dirtiedFunc_ = node.dirtiedFunc_;
style_ = node.style_; style_ = node.style_;
layout_ = node.layout_; layout_ = node.layout_;
lineIndex_ = node.lineIndex_; lineIndex_ = node.lineIndex_;
@@ -48,13 +48,9 @@ Node::Node(Node&& node) {
} }
} }
void Node::print(void* printContext) { void Node::print() {
if (print_.noContext != nullptr) { if (printFunc_ != nullptr) {
if (flags_.printUsesContext) { printFunc_(this);
print_.withContext(this, printContext);
} else {
print_.noContext(this);
}
} }
} }
@@ -217,25 +213,18 @@ YGSize Node::measure(
float width, float width,
YGMeasureMode widthMode, YGMeasureMode widthMode,
float height, float height,
YGMeasureMode heightMode, YGMeasureMode heightMode) {
void* layoutContext) { return measureFunc_(this, width, widthMode, height, heightMode);
return flags_.measureUsesContext
? measure_.withContext(
this, width, widthMode, height, heightMode, layoutContext)
: measure_.noContext(this, width, widthMode, height, heightMode);
} }
float Node::baseline(float width, float height, void* layoutContext) const { float Node::baseline(float width, float height) const {
return flags_.baselineUsesContext return baselineFunc_(this, width, height);
? baseline_.withContext(
const_cast<Node*>(this), width, height, layoutContext)
: baseline_.noContext(const_cast<Node*>(this), width, height);
} }
// Setters // Setters
void Node::setMeasureFunc(decltype(Node::measure_) measureFunc) { void Node::setMeasureFunc(YGMeasureFunc measureFunc) {
if (measureFunc.noContext == nullptr) { if (measureFunc == nullptr) {
// TODO: t18095186 Move nodeType to opt-in function and mark appropriate // TODO: t18095186 Move nodeType to opt-in function and mark appropriate
// places in Litho // places in Litho
setNodeType(YGNodeTypeDefault); setNodeType(YGNodeTypeDefault);
@@ -250,21 +239,7 @@ void Node::setMeasureFunc(decltype(Node::measure_) measureFunc) {
setNodeType(YGNodeTypeText); setNodeType(YGNodeTypeText);
} }
measure_ = measureFunc; measureFunc_ = measureFunc;
}
void Node::setMeasureFunc(YGMeasureFunc measureFunc) {
flags_.measureUsesContext = false;
decltype(Node::measure_) m;
m.noContext = measureFunc;
setMeasureFunc(m);
}
void Node::setMeasureFunc(MeasureWithContextFn measureFunc) {
flags_.measureUsesContext = true;
decltype(Node::measure_) m;
m.withContext = measureFunc;
setMeasureFunc(m);
} }
void Node::replaceChild(Node* child, size_t index) { void Node::replaceChild(Node* child, size_t index) {
@@ -299,8 +274,8 @@ void Node::setDirty(bool isDirty) {
return; return;
} }
flags_.isDirty = isDirty; flags_.isDirty = isDirty;
if (isDirty && dirtied_) { if (isDirty && dirtiedFunc_) {
dirtied_(this); dirtiedFunc_(this);
} }
} }
@@ -485,11 +460,11 @@ void Node::clearChildren() {
// Other Methods // Other Methods
void Node::cloneChildrenIfNeeded(void* cloneContext) { void Node::cloneChildrenIfNeeded() {
size_t i = 0; size_t i = 0;
for (Node*& child : children_) { for (Node*& child : children_) {
if (child->getOwner() != this) { if (child->getOwner() != this) {
child = resolveRef(config_->cloneNode(child, this, i, cloneContext)); child = resolveRef(config_->cloneNode(child, this, i));
child->setOwner(this); child->setOwner(this);
} }
i += 1; i += 1;

View File

@@ -30,42 +30,17 @@ struct NodeFlags {
bool isReferenceBaseline : 1; bool isReferenceBaseline : 1;
bool isDirty : 1; bool isDirty : 1;
uint32_t nodeType : 1; uint32_t nodeType : 1;
bool measureUsesContext : 1;
bool baselineUsesContext : 1;
bool printUsesContext : 1;
}; };
#pragma pack(pop) #pragma pack(pop)
class YG_EXPORT Node : public ::YGNode { class YG_EXPORT Node : public ::YGNode {
public:
// Internal variants of callbacks, currently used only by JNI bindings.
// TODO: Reconcile this with the public API
using MeasureWithContextFn = YGSize (*)(
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;
NodeFlags flags_ = {}; NodeFlags flags_ = {};
union { YGMeasureFunc measureFunc_ = {nullptr};
YGMeasureFunc noContext; YGBaselineFunc baselineFunc_ = {nullptr};
MeasureWithContextFn withContext; YGPrintFunc printFunc_ = {nullptr};
} measure_ = {nullptr}; YGDirtiedFunc dirtiedFunc_ = nullptr;
union {
YGBaselineFunc noContext;
BaselineWithContextFn withContext;
} baseline_ = {nullptr};
union {
YGPrintFunc noContext;
PrintWithContextFn withContext;
} print_ = {nullptr};
YGDirtiedFunc dirtied_ = nullptr;
Style style_ = {}; Style style_ = {};
LayoutResults layout_ = {}; LayoutResults layout_ = {};
size_t lineIndex_ = 0; size_t lineIndex_ = 0;
@@ -79,9 +54,6 @@ private:
const YGFlexDirection axis, const YGFlexDirection axis,
const float axisSize) const; const float axisSize) const;
void setMeasureFunc(decltype(measure_));
void setBaselineFunc(decltype(baseline_));
void useWebDefaults() { void useWebDefaults() {
style_.flexDirection() = YGFlexDirectionRow; style_.flexDirection() = YGFlexDirectionRow;
style_.alignContent() = YGAlignStretch; style_.alignContent() = YGAlignStretch;
@@ -112,7 +84,7 @@ public:
// Getters // Getters
void* getContext() const { return context_; } void* getContext() const { return context_; }
void print(void*); void print();
bool getHasNewLayout() const { return flags_.hasNewLayout; } bool getHasNewLayout() const { return flags_.hasNewLayout; }
@@ -120,19 +92,17 @@ public:
return static_cast<YGNodeType>(flags_.nodeType); return static_cast<YGNodeType>(flags_.nodeType);
} }
bool hasMeasureFunc() const noexcept { return measure_.noContext != nullptr; } bool hasMeasureFunc() const noexcept { return measureFunc_ != nullptr; }
YGSize measure(float, YGMeasureMode, float, YGMeasureMode, void*); YGSize measure(float, YGMeasureMode, float, YGMeasureMode);
bool hasBaselineFunc() const noexcept { bool hasBaselineFunc() const noexcept { return baselineFunc_ != nullptr; }
return baseline_.noContext != nullptr;
}
float baseline(float width, float height, void* layoutContext) const; float baseline(float width, float height) const;
bool hasErrata(YGErrata errata) const { return config_->hasErrata(errata); } bool hasErrata(YGErrata errata) const { return config_->hasErrata(errata); }
YGDirtiedFunc getDirtied() const { return dirtied_; } YGDirtiedFunc getDirtiedFunc() const { return dirtiedFunc_; }
// For Performance reasons passing as reference. // For Performance reasons passing as reference.
Style& getStyle() { return style_; } Style& getStyle() { return style_; }
@@ -232,15 +202,7 @@ public:
void setContext(void* context) { context_ = context; } void setContext(void* context) { context_ = context; }
void setPrintFunc(YGPrintFunc printFunc) { void setPrintFunc(YGPrintFunc printFunc) { printFunc_ = printFunc; }
print_.noContext = printFunc;
flags_.printUsesContext = false;
}
void setPrintFunc(PrintWithContextFn printFunc) {
print_.withContext = printFunc;
flags_.printUsesContext = true;
}
void setPrintFunc(std::nullptr_t) { setPrintFunc(YGPrintFunc{nullptr}); }
void setHasNewLayout(bool hasNewLayout) { void setHasNewLayout(bool hasNewLayout) {
flags_.hasNewLayout = hasNewLayout; flags_.hasNewLayout = hasNewLayout;
@@ -251,24 +213,12 @@ public:
} }
void setMeasureFunc(YGMeasureFunc measureFunc); void setMeasureFunc(YGMeasureFunc measureFunc);
void setMeasureFunc(MeasureWithContextFn);
void setMeasureFunc(std::nullptr_t) {
return setMeasureFunc(YGMeasureFunc{nullptr});
}
void setBaselineFunc(YGBaselineFunc baseLineFunc) { void setBaselineFunc(YGBaselineFunc baseLineFunc) {
flags_.baselineUsesContext = false; baselineFunc_ = baseLineFunc;
baseline_.noContext = baseLineFunc;
}
void setBaselineFunc(BaselineWithContextFn baseLineFunc) {
flags_.baselineUsesContext = true;
baseline_.withContext = baseLineFunc;
}
void setBaselineFunc(std::nullptr_t) {
return setBaselineFunc(YGBaselineFunc{nullptr});
} }
void setDirtiedFunc(YGDirtiedFunc dirtiedFunc) { dirtied_ = dirtiedFunc; } void setDirtiedFunc(YGDirtiedFunc dirtiedFunc) { dirtiedFunc_ = dirtiedFunc; }
void setStyle(const Style& style) { style_ = style; } void setStyle(const Style& style) { style_ = style; }
@@ -325,7 +275,7 @@ public:
bool removeChild(Node* child); bool removeChild(Node* child);
void removeChild(size_t index); void removeChild(size_t index);
void cloneChildrenIfNeeded(void*); void cloneChildrenIfNeeded();
void markDirtyAndPropagate(); void markDirtyAndPropagate();
float resolveFlexGrow() const; float resolveFlexGrow() const;
float resolveFlexShrink() const; float resolveFlexShrink() const;