From c5edcb3d3af1b657d1496fddea05302ebf83e83c Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Tue, 19 Dec 2023 13:38:40 -0800 Subject: [PATCH] Reorder members in `Node.h` (#1529) Summary: X-link: https://github.com/facebook/react-native/pull/41994 Pull Request resolved: https://github.com/facebook/yoga/pull/1529 Reorganizes the header according to common C++ convnetions. Public first, then private. Constructors, then functions, then member variables. Reviewed By: joevilches Differential Revision: D52106056 fbshipit-source-id: 0095cf7caa58dc79c1803b3b231911e4fc66ddaf --- yoga/node/Node.h | 112 +++++++++++++++++++++-------------------------- 1 file changed, 51 insertions(+), 61 deletions(-) diff --git a/yoga/node/Node.h b/yoga/node/Node.h index acd2ec39..712f154e 100644 --- a/yoga/node/Node.h +++ b/yoga/node/Node.h @@ -29,65 +29,9 @@ struct YGNode {}; namespace facebook::yoga { class YG_EXPORT Node : public ::YGNode { - private: - bool hasNewLayout_ : 1 = true; - bool isReferenceBaseline_ : 1 = false; - bool isDirty_ : 1 = false; - NodeType nodeType_ : bitCount() = NodeType::Default; - void* context_ = nullptr; - YGMeasureFunc measureFunc_ = {nullptr}; - YGBaselineFunc baselineFunc_ = {nullptr}; - YGPrintFunc printFunc_ = {nullptr}; - YGDirtiedFunc dirtiedFunc_ = nullptr; - Style style_ = {}; - LayoutResults layout_ = {}; - size_t lineIndex_ = 0; - Node* owner_ = nullptr; - std::vector children_ = {}; - const Config* config_; - std::array resolvedDimensions_ = { - {value::undefined(), value::undefined()}}; - - float relativePosition( - FlexDirection axis, - Direction direction, - const float axisSize) const; - - Edge getInlineStartEdgeUsingErrata( - FlexDirection flexDirection, - Direction direction) const; - Edge getInlineEndEdgeUsingErrata( - FlexDirection flexDirection, - Direction direction) const; - Edge getFlexStartRelativeEdgeUsingErrata( - FlexDirection flexDirection, - Direction direction) const; - Edge getFlexEndRelativeEdgeUsingErrata( - FlexDirection flexDirection, - Direction direction) const; - - void useWebDefaults() { - style_.setFlexDirection(FlexDirection::Row); - style_.setAlignContent(Align::Stretch); - } - - template - Style::Length computeEdgeValueForColumn(Edge edge) const; - - template - Style::Length computeEdgeValueForRow(Edge rowEdge, Edge edge) const; - - // DANGER DANGER DANGER! - // If the node assigned to has children, we'd either have to deallocate - // them (potentially incorrect) or ignore them (danger of leaks). Only ever - // use this after checking that there are no children. - // DO NOT CHANGE THE VISIBILITY OF THIS METHOD! - Node& operator=(Node&&) = default; - public: Node(); explicit Node(const Config* config); - ~Node() = default; // cleanup of owner/children relationships in YGNodeFree Node(Node&&); @@ -181,11 +125,6 @@ class YG_EXPORT Node : public ::YGNode { return owner_; } - // Deprecated, use getOwner() instead. - Node* getParent() const { - return getOwner(); - } - const std::vector& getChildren() const { return children_; } @@ -393,6 +332,57 @@ class YG_EXPORT Node : public ::YGNode { float resolveFlexShrink() const; bool isNodeFlexible(); void reset(); + + private: + // Used to allow resetting the node + Node& operator=(Node&&) = default; + + float relativePosition( + FlexDirection axis, + Direction direction, + const float axisSize) const; + + Edge getInlineStartEdgeUsingErrata( + FlexDirection flexDirection, + Direction direction) const; + Edge getInlineEndEdgeUsingErrata( + FlexDirection flexDirection, + Direction direction) const; + Edge getFlexStartRelativeEdgeUsingErrata( + FlexDirection flexDirection, + Direction direction) const; + Edge getFlexEndRelativeEdgeUsingErrata( + FlexDirection flexDirection, + Direction direction) const; + + void useWebDefaults() { + style_.setFlexDirection(FlexDirection::Row); + style_.setAlignContent(Align::Stretch); + } + + template + Style::Length computeEdgeValueForColumn(Edge edge) const; + + template + Style::Length computeEdgeValueForRow(Edge rowEdge, Edge edge) const; + + bool hasNewLayout_ : 1 = true; + bool isReferenceBaseline_ : 1 = false; + bool isDirty_ : 1 = false; + NodeType nodeType_ : bitCount() = NodeType::Default; + void* context_ = nullptr; + YGMeasureFunc measureFunc_ = {nullptr}; + YGBaselineFunc baselineFunc_ = {nullptr}; + YGPrintFunc printFunc_ = {nullptr}; + YGDirtiedFunc dirtiedFunc_ = nullptr; + Style style_ = {}; + LayoutResults layout_ = {}; + size_t lineIndex_ = 0; + Node* owner_ = nullptr; + std::vector children_ = {}; + const Config* config_; + std::array resolvedDimensions_ = { + {value::undefined(), value::undefined()}}; }; inline Node* resolveRef(const YGNodeRef ref) {