From 03d052399643510985d4af521a2c9846baaf3b37 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Tue, 19 Sep 2023 16:30:02 -0700 Subject: [PATCH] C++ style enums 13/N: Wrap (#1400) Summary: X-link: https://github.com/facebook/react-native/pull/39539 Pull Request resolved: https://github.com/facebook/yoga/pull/1400 Moves internal usages of YGPositionType to PositionType bypass-github-export-checks Changelog: [Internal] Reviewed By: rshest Differential Revision: D49361746 fbshipit-source-id: ccc77b4c77753b5f41e11f1849d4c02153c190b7 --- tests/YGStyleAccessorsTest.cpp | 7 +------ yoga/Yoga.cpp | 5 +++-- yoga/algorithm/CalculateLayout.cpp | 8 ++++---- yoga/algorithm/FlexLine.cpp | 2 +- yoga/debug/NodeToString.cpp | 3 +-- yoga/style/Style.h | 9 +++++---- 6 files changed, 15 insertions(+), 19 deletions(-) diff --git a/tests/YGStyleAccessorsTest.cpp b/tests/YGStyleAccessorsTest.cpp index bf48ee31..a0b9affe 100644 --- a/tests/YGStyleAccessorsTest.cpp +++ b/tests/YGStyleAccessorsTest.cpp @@ -135,12 +135,7 @@ ACCESSOR_TEST( PositionType::Absolute, PositionType::Relative) -ACCESSOR_TEST( - flexWrap, - YGWrapNoWrap, - YGWrapWrap, - YGWrapWrapReverse, - YGWrapNoWrap) +ACCESSOR_TEST(flexWrap, Wrap::NoWrap, Wrap::Wrap, Wrap::WrapReverse) ACCESSOR_TEST( overflow, diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index cb4d96c2..79bc2610 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -492,10 +492,11 @@ YGPositionType YGNodeStyleGetPositionType(const YGNodeConstRef node) { } void YGNodeStyleSetFlexWrap(const YGNodeRef node, const YGWrap flexWrap) { - updateStyle(node, &Style::flexWrap, flexWrap); + updateStyle( + node, &Style::flexWrap, scopedEnum(flexWrap)); } YGWrap YGNodeStyleGetFlexWrap(const YGNodeConstRef node) { - return resolveRef(node)->getStyle().flexWrap(); + return unscopedEnum(resolveRef(node)->getStyle().flexWrap()); } void YGNodeStyleSetOverflow(const YGNodeRef node, const YGOverflow overflow) { diff --git a/yoga/algorithm/CalculateLayout.cpp b/yoga/algorithm/CalculateLayout.cpp index c997679e..4eaa2c1d 100644 --- a/yoga/algorithm/CalculateLayout.cpp +++ b/yoga/algorithm/CalculateLayout.cpp @@ -520,7 +520,7 @@ static void layoutAbsoluteChild( } else if ( !child->isLeadingPositionDefined(crossAxis) && ((resolveChildAlignment(node, child) == Align::FlexEnd) ^ - (node->getStyle().flexWrap() == YGWrapWrapReverse))) { + (node->getStyle().flexWrap() == Wrap::WrapReverse))) { child->setLayoutPosition( (node->getLayout().measuredDimensions[dimension(crossAxis)] - child->getLayout().measuredDimensions[dimension(crossAxis)]), @@ -877,7 +877,7 @@ static float distributeFreeSpaceSecondPass( float flexGrowFactor = 0; float deltaFreeSpace = 0; const bool isMainAxisRow = isRow(mainAxis); - const bool isNodeFlexWrap = node->getStyle().flexWrap() != YGWrapNoWrap; + const bool isNodeFlexWrap = node->getStyle().flexWrap() != Wrap::NoWrap; for (auto currentLineChild : flexLine.itemsInFlow) { childFlexBasis = boundAxisWithinMinAndMax( @@ -1604,7 +1604,7 @@ static void calculateLayoutImpl( resolveDirection(node->getStyle().flexDirection(), direction); const FlexDirection crossAxis = resolveCrossDirection(mainAxis, direction); const bool isMainAxisRow = isRow(mainAxis); - const bool isNodeFlexWrap = node->getStyle().flexWrap() != YGWrapNoWrap; + const bool isNodeFlexWrap = node->getStyle().flexWrap() != Wrap::NoWrap; const float mainAxisownerSize = isMainAxisRow ? ownerWidth : ownerHeight; const float crossAxisownerSize = isMainAxisRow ? ownerHeight : ownerWidth; @@ -2302,7 +2302,7 @@ static void calculateLayoutImpl( // As we only wrapped in normal direction yet, we need to reverse the // positions on wrap-reverse. - if (performLayout && node->getStyle().flexWrap() == YGWrapWrapReverse) { + if (performLayout && node->getStyle().flexWrap() == Wrap::WrapReverse) { for (size_t i = 0; i < childCount; i++) { const auto child = node->getChild(i); if (child->getStyle().positionType() != PositionType::Absolute) { diff --git a/yoga/algorithm/FlexLine.cpp b/yoga/algorithm/FlexLine.cpp index 2a5220c6..07219419 100644 --- a/yoga/algorithm/FlexLine.cpp +++ b/yoga/algorithm/FlexLine.cpp @@ -32,7 +32,7 @@ FlexLine calculateFlexLine( float sizeConsumedIncludingMinConstraint = 0; const FlexDirection mainAxis = resolveDirection( node->getStyle().flexDirection(), node->resolveDirection(ownerDirection)); - const bool isNodeFlexWrap = node->getStyle().flexWrap() != YGWrapNoWrap; + const bool isNodeFlexWrap = node->getStyle().flexWrap() != Wrap::NoWrap; const float gap = node->getGapForAxis(mainAxis, availableInnerWidth).unwrap(); // Add items to the current line until it's full or we run out of items. diff --git a/yoga/debug/NodeToString.cpp b/yoga/debug/NodeToString.cpp index f7f6cb11..72feed65 100644 --- a/yoga/debug/NodeToString.cpp +++ b/yoga/debug/NodeToString.cpp @@ -166,8 +166,7 @@ void nodeToString( appendFloatOptionalIfDefined(str, "flex", style.flex()); if (style.flexWrap() != yoga::Node{}.getStyle().flexWrap()) { - appendFormattedString( - str, "flex-wrap: %s; ", YGWrapToString(style.flexWrap())); + appendFormattedString(str, "flex-wrap: %s; ", toString(style.flexWrap())); } if (style.overflow() != yoga::Node{}.getStyle().overflow()) { diff --git a/yoga/style/Style.h b/yoga/style/Style.h index 12b54dca..7928b031 100644 --- a/yoga/style/Style.h +++ b/yoga/style/Style.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -119,7 +120,7 @@ class YG_EXPORT Style { static constexpr uint8_t flexWrapOffset = positionTypeOffset + minimumBitCount(); static constexpr uint8_t overflowOffset = - flexWrapOffset + minimumBitCount(); + flexWrapOffset + minimumBitCount(); static constexpr uint8_t displayOffset = overflowOffset + minimumBitCount(); @@ -193,10 +194,10 @@ class YG_EXPORT Style { return {*this, positionTypeOffset}; } - YGWrap flexWrap() const { - return getEnumData(flags, flexWrapOffset); + Wrap flexWrap() const { + return getEnumData(flags, flexWrapOffset); } - BitfieldRef flexWrap() { + BitfieldRef flexWrap() { return {*this, flexWrapOffset}; }