Skip to content

Commit

Permalink
C++ style enums 2/N: NodeType (facebook#1383)
Browse files Browse the repository at this point in the history
Summary:
X-link: facebook/react-native#39450

Pull Request resolved: facebook#1383

This converts usages of YGNodeType to NodeType

Reviewed By: rozele

Differential Revision: D49269117

fbshipit-source-id: 55c71143f9dca14bc92ceec5c9acc68f70cb108c
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Sep 15, 2023
1 parent 7bd7bb5 commit 48f28a2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout) {
}

YGNodeType YGNodeGetNodeType(YGNodeConstRef node) {
return resolveRef(node)->getNodeType();
return unscopedEnum(resolveRef(node)->getNodeType());
}

void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType) {
return resolveRef(node)->setNodeType(nodeType);
return resolveRef(node)->setNodeType(scopedEnum(nodeType));
}

bool YGNodeIsDirty(YGNodeConstRef node) {
Expand Down
2 changes: 1 addition & 1 deletion yoga/algorithm/PixelGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void roundLayoutResultsToPixelGrid(
if (pointScaleFactor != 0.0f) {
// If a node has a custom measure function we never want to round down its
// size as this could lead to unwanted text truncation.
const bool textRounding = node->getNodeType() == YGNodeTypeText;
const bool textRounding = node->getNodeType() == NodeType::Text;

node->setLayoutPosition(
roundValueToPixelGrid(nodeLeft, pointScaleFactor, false, textRounding),
Expand Down
4 changes: 2 additions & 2 deletions yoga/node/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void Node::setMeasureFunc(YGMeasureFunc measureFunc) {
if (measureFunc == nullptr) {
// TODO: t18095186 Move nodeType to opt-in function and mark appropriate
// places in Litho
setNodeType(YGNodeTypeDefault);
setNodeType(NodeType::Default);
} else {
yoga::assertFatalWithNode(
this,
Expand All @@ -236,7 +236,7 @@ void Node::setMeasureFunc(YGMeasureFunc measureFunc) {
"children.");
// TODO: t18095186 Move nodeType to opt-in function and mark appropriate
// places in Litho
setNodeType(YGNodeTypeText);
setNodeType(NodeType::Text);
}

measureFunc_ = measureFunc;
Expand Down
11 changes: 6 additions & 5 deletions yoga/node/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <yoga/Yoga.h>

#include <yoga/config/Config.h>
#include <yoga/enums/NodeType.h>
#include <yoga/node/LayoutResults.h>
#include <yoga/style/CompactValue.h>
#include <yoga/style/Style.h>
Expand All @@ -29,7 +30,7 @@ struct NodeFlags {
bool hasNewLayout : 1;
bool isReferenceBaseline : 1;
bool isDirty : 1;
uint32_t nodeType : 1;
NodeType nodeType : bitCount<NodeType>();
};
#pragma pack(pop)

Expand Down Expand Up @@ -92,8 +93,8 @@ class YG_EXPORT Node : public ::YGNode {
return flags_.hasNewLayout;
}

YGNodeType getNodeType() const {
return static_cast<YGNodeType>(flags_.nodeType);
NodeType getNodeType() const {
return flags_.nodeType;
}

bool hasMeasureFunc() const noexcept {
Expand Down Expand Up @@ -250,8 +251,8 @@ class YG_EXPORT Node : public ::YGNode {
flags_.hasNewLayout = hasNewLayout;
}

void setNodeType(YGNodeType nodeType) {
flags_.nodeType = static_cast<uint32_t>(nodeType) & 0x01;
void setNodeType(NodeType nodeType) {
flags_.nodeType = nodeType;
}

void setMeasureFunc(YGMeasureFunc measureFunc);
Expand Down

0 comments on commit 48f28a2

Please sign in to comment.