Skip to content

Commit

Permalink
C++ style enums 15/N: Display (facebook#1397)
Browse files Browse the repository at this point in the history
Summary:
X-link: facebook/react-native#39541

Pull Request resolved: facebook#1397

Moves internal usages of YGDisplay to Display
Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D49361952

fbshipit-source-id: 3d407e6ce1c1000f7a15b7211ea20dc52f2143b1
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Sep 19, 2023
1 parent 67f46dc commit d847691
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion tests/YGStyleAccessorsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ ACCESSOR_TEST(flexWrap, Wrap::NoWrap, Wrap::Wrap, Wrap::WrapReverse)

ACCESSOR_TEST(overflow, Overflow::Visible, Overflow::Hidden, Overflow::Scroll)

ACCESSOR_TEST(display, YGDisplayFlex, YGDisplayNone, YGDisplayFlex)
ACCESSOR_TEST(display, Display::Flex, Display::None, Display::Flex)

ACCESSOR_TEST(
flex,
Expand Down
4 changes: 2 additions & 2 deletions yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,10 @@ YGOverflow YGNodeStyleGetOverflow(const YGNodeConstRef node) {
}

void YGNodeStyleSetDisplay(const YGNodeRef node, const YGDisplay display) {
updateStyle<MSVC_HINT(display)>(node, &Style::display, display);
updateStyle<MSVC_HINT(display)>(node, &Style::display, scopedEnum(display));
}
YGDisplay YGNodeStyleGetDisplay(const YGNodeConstRef node) {
return resolveRef(node)->getStyle().display();
return unscopedEnum(resolveRef(node)->getStyle().display());
}

// TODO(T26792433): Change the API to accept FloatOptional.
Expand Down
14 changes: 7 additions & 7 deletions yoga/algorithm/CalculateLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ static float computeFlexBasisForChildren(

for (auto child : children) {
child->resolveDimension();
if (child->getStyle().display() == YGDisplayNone) {
if (child->getStyle().display() == Display::None) {
zeroOutLayoutRecursively(child);
child->setHasNewLayout(true);
child->setDirty(false);
Expand Down Expand Up @@ -1307,7 +1307,7 @@ static void justifyMainAxis(
const auto child = node->getChild(i);
const Style& childStyle = child->getStyle();
const LayoutResults& childLayout = child->getLayout();
if (childStyle.display() == YGDisplayNone) {
if (childStyle.display() == Display::None) {
continue;
}
if (childStyle.positionType() == PositionType::Absolute &&
Expand Down Expand Up @@ -1863,7 +1863,7 @@ static void calculateLayoutImpl(
if (performLayout) {
for (size_t i = startOfLineIndex; i < endOfLineIndex; i++) {
const auto child = node->getChild(i);
if (child->getStyle().display() == YGDisplayNone) {
if (child->getStyle().display() == Display::None) {
continue;
}
if (child->getStyle().positionType() == PositionType::Absolute) {
Expand Down Expand Up @@ -2069,7 +2069,7 @@ static void calculateLayoutImpl(
float maxDescentForCurrentLine = 0;
for (ii = startIndex; ii < childCount; ii++) {
const auto child = node->getChild(ii);
if (child->getStyle().display() == YGDisplayNone) {
if (child->getStyle().display() == Display::None) {
continue;
}
if (child->getStyle().positionType() != PositionType::Absolute) {
Expand Down Expand Up @@ -2112,7 +2112,7 @@ static void calculateLayoutImpl(
if (performLayout) {
for (ii = startIndex; ii < endIndex; ii++) {
const auto child = node->getChild(ii);
if (child->getStyle().display() == YGDisplayNone) {
if (child->getStyle().display() == Display::None) {
continue;
}
if (child->getStyle().positionType() != PositionType::Absolute) {
Expand Down Expand Up @@ -2318,7 +2318,7 @@ static void calculateLayoutImpl(
if (performLayout) {
// STEP 10: SIZING AND POSITIONING ABSOLUTE CHILDREN
for (auto child : node->getChildren()) {
if (child->getStyle().display() == YGDisplayNone ||
if (child->getStyle().display() == Display::None ||
child->getStyle().positionType() != PositionType::Absolute) {
continue;
}
Expand Down Expand Up @@ -2352,7 +2352,7 @@ static void calculateLayoutImpl(
if (needsMainTrailingPos || needsCrossTrailingPos) {
for (size_t i = 0; i < childCount; i++) {
const auto child = node->getChild(i);
if (child->getStyle().display() == YGDisplayNone) {
if (child->getStyle().display() == Display::None) {
continue;
}
if (needsMainTrailingPos) {
Expand Down
2 changes: 1 addition & 1 deletion yoga/algorithm/FlexLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ FlexLine calculateFlexLine(
// Add items to the current line until it's full or we run out of items.
for (; endOfLineIndex < node->getChildren().size(); endOfLineIndex++) {
auto child = node->getChild(endOfLineIndex);
if (child->getStyle().display() == YGDisplayNone ||
if (child->getStyle().display() == Display::None ||
child->getStyle().positionType() == PositionType::Absolute) {
continue;
}
Expand Down
3 changes: 1 addition & 2 deletions yoga/debug/NodeToString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ void nodeToString(
}

if (style.display() != yoga::Node{}.getStyle().display()) {
appendFormattedString(
str, "display: %s; ", YGDisplayToString(style.display()));
appendFormattedString(str, "display: %s; ", toString(style.display()));
}
appendEdges(str, "margin", style.margin());
appendEdges(str, "padding", style.padding());
Expand Down
7 changes: 4 additions & 3 deletions yoga/style/Style.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <yoga/bits/NumericBitfield.h>
#include <yoga/enums/Align.h>
#include <yoga/enums/Direction.h>
#include <yoga/enums/Display.h>
#include <yoga/enums/FlexDirection.h>
#include <yoga/enums/Justify.h>
#include <yoga/enums/Overflow.h>
Expand Down Expand Up @@ -209,10 +210,10 @@ class YG_EXPORT Style {
return {*this, overflowOffset};
}

YGDisplay display() const {
return getEnumData<YGDisplay>(flags, displayOffset);
Display display() const {
return getEnumData<Display>(flags, displayOffset);
}
BitfieldRef<YGDisplay> display() {
BitfieldRef<Display> display() {
return {*this, displayOffset};
}

Expand Down

0 comments on commit d847691

Please sign in to comment.