diff --git a/yoga/YGNode.cpp b/yoga/YGNode.cpp index 77000b5c..dcb1b8a2 100644 --- a/yoga/YGNode.cpp +++ b/yoga/YGNode.cpp @@ -12,9 +12,13 @@ using namespace facebook; using facebook::yoga::detail::CompactValue; -void YGNode::print() { - if (print_ != nullptr) { - print_(this); +void YGNode::print(void* printContext) { + if (print_.noContext != nullptr) { + if (printUsesContext_) { + print_.withContext(this, printContext); + } else { + print_.noContext(this); + } } } @@ -304,13 +308,14 @@ YGNode& YGNode::operator=(const YGNode& node) { } context_ = node.getContext(); - print_ = node.print_; hasNewLayout_ = node.getHasNewLayout(); nodeType_ = node.getNodeType(); measureUsesContext_ = node.measureUsesContext_; baselineUsesContext_ = node.baselineUsesContext_; + printUsesContext_ = node.printUsesContext_; measure_ = node.measure_; baseline_ = node.baseline_; + print_ = node.print_; dirtied_ = node.getDirtied(); style_ = node.style_; layout_ = node.layout_; diff --git a/yoga/YGNode.h b/yoga/YGNode.h index 14bc6639..63087fe4 100644 --- a/yoga/YGNode.h +++ b/yoga/YGNode.h @@ -15,16 +15,17 @@ struct YGNode { using MeasureWithContextFn = YGSize (*)(YGNode*, float, YGMeasureMode, float, YGMeasureMode, void*); using BaselineWithContextFn = float (*)(YGNode*, float, float, void*); + using PrintWithContextFn = void (*)(YGNode*, void*); private: void* context_ = nullptr; - YGPrintFunc print_ = nullptr; bool hasNewLayout_ : 1; bool isReferenceBaseline_ : 1; bool isDirty_ : 1; YGNodeType nodeType_ : 1; bool measureUsesContext_ : 1; bool baselineUsesContext_ : 1; + bool printUsesContext_ : 1; union { YGMeasureFunc noContext; MeasureWithContextFn withContext; @@ -33,6 +34,10 @@ private: YGBaselineFunc noContext; BaselineWithContextFn withContext; } baseline_ = {nullptr}; + union { + YGPrintFunc noContext; + PrintWithContextFn withContext; + } print_ = {nullptr}; YGDirtiedFunc dirtied_ = nullptr; YGStyle style_ = {}; YGLayout layout_ = {}; @@ -57,7 +62,8 @@ public: isDirty_{false}, nodeType_{YGNodeTypeDefault}, measureUsesContext_{false}, - baselineUsesContext_{false} {} + baselineUsesContext_{false}, + printUsesContext_{false} {} ~YGNode() = default; // cleanup of owner/children relationships in YGNodeFree explicit YGNode(const YGConfigRef newConfig) : config_(newConfig){}; YGNode(const YGNode& node) = default; @@ -68,7 +74,7 @@ public: return context_; } - void print(); + void print(void*); bool getHasNewLayout() const { return hasNewLayout_; @@ -196,7 +202,15 @@ public: } void setPrintFunc(YGPrintFunc printFunc) { - print_ = printFunc; + print_.noContext = printFunc; + printUsesContext_ = false; + } + void setPrintFunc(PrintWithContextFn printFunc) { + print_.withContext = printFunc; + printUsesContext_ = true; + } + void setPrintFunc(std::nullptr_t) { + setPrintFunc(YGPrintFunc{nullptr}); } void setHasNewLayout(bool hasNewLayout) { diff --git a/yoga/YGNodePrint.cpp b/yoga/YGNodePrint.cpp index a4db36f2..5dbd214f 100644 --- a/yoga/YGNodePrint.cpp +++ b/yoga/YGNodePrint.cpp @@ -114,7 +114,6 @@ void YGNodeToString( uint32_t level) { indent(str, level); appendFormatedString(str, "
print(); if (options & YGPrintOptionsLayout) { appendFormatedString(str, "layout=\""); diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index c87f776d..93ba9851 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -3843,7 +3843,7 @@ bool YGLayoutNodeInternal( "%s%d.{[skipped] ", YGSpacer(gDepth), gDepth); - node->print(); + node->print(layoutContext); Log::log( node, YGLogLevelVerbose, @@ -3867,7 +3867,7 @@ bool YGLayoutNodeInternal( YGSpacer(gDepth), gDepth, needToVisitNode ? "*" : ""); - node->print(); + node->print(layoutContext); Log::log( node, YGLogLevelVerbose, @@ -3903,7 +3903,7 @@ bool YGLayoutNodeInternal( YGSpacer(gDepth), gDepth, needToVisitNode ? "*" : ""); - node->print(); + node->print(layoutContext); Log::log( node, YGLogLevelVerbose,