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
This commit is contained in:
Nick Gerleman
2023-12-19 13:38:40 -08:00
committed by Facebook GitHub Bot
parent 1f391dfc50
commit c5edcb3d3a

View File

@@ -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>() = 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<Node*> children_ = {};
const Config* config_;
std::array<Style::Length, 2> 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 <auto Field>
Style::Length computeEdgeValueForColumn(Edge edge) const;
template <auto Field>
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<Node*>& 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 <auto Field>
Style::Length computeEdgeValueForColumn(Edge edge) const;
template <auto Field>
Style::Length computeEdgeValueForRow(Edge rowEdge, Edge edge) const;
bool hasNewLayout_ : 1 = true;
bool isReferenceBaseline_ : 1 = false;
bool isDirty_ : 1 = false;
NodeType nodeType_ : bitCount<NodeType>() = 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<Node*> children_ = {};
const Config* config_;
std::array<Style::Length, 2> resolvedDimensions_ = {
{value::undefined(), value::undefined()}};
};
inline Node* resolveRef(const YGNodeRef ref) {