From 75bbfb0b710e769b5a26a0e2bd5e4bc6833ed31a Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Tue, 19 Sep 2023 16:30:02 -0700 Subject: [PATCH] C++ style enums 14/N: Overflow (#1398) Summary: X-link: https://github.com/facebook/react-native/pull/39537 Pull Request resolved: https://github.com/facebook/yoga/pull/1398 Moves internal usages of YGOverflow to Overflow bypass-github-export-checks Changelog: [Internal] Reviewed By: rshest Differential Revision: D49361843 fbshipit-source-id: 42161aa8a26f64f052587b861120cdad0290ae46 --- tests/YGStyleAccessorsTest.cpp | 7 +------ yoga/Yoga.cpp | 5 +++-- yoga/algorithm/CalculateLayout.cpp | 16 ++++++++-------- yoga/debug/NodeToString.cpp | 3 +-- yoga/style/Style.h | 9 +++++---- 5 files changed, 18 insertions(+), 22 deletions(-) diff --git a/tests/YGStyleAccessorsTest.cpp b/tests/YGStyleAccessorsTest.cpp index a0b9affe..2b935e7b 100644 --- a/tests/YGStyleAccessorsTest.cpp +++ b/tests/YGStyleAccessorsTest.cpp @@ -137,12 +137,7 @@ ACCESSOR_TEST( ACCESSOR_TEST(flexWrap, Wrap::NoWrap, Wrap::Wrap, Wrap::WrapReverse) -ACCESSOR_TEST( - overflow, - YGOverflowVisible, - YGOverflowHidden, - YGOverflowScroll, - YGOverflowVisible) +ACCESSOR_TEST(overflow, Overflow::Visible, Overflow::Hidden, Overflow::Scroll) ACCESSOR_TEST(display, YGDisplayFlex, YGDisplayNone, YGDisplayFlex) diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 79bc2610..039dc3fb 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -500,10 +500,11 @@ YGWrap YGNodeStyleGetFlexWrap(const YGNodeConstRef node) { } void YGNodeStyleSetOverflow(const YGNodeRef node, const YGOverflow overflow) { - updateStyle(node, &Style::overflow, overflow); + updateStyle( + node, &Style::overflow, scopedEnum(overflow)); } YGOverflow YGNodeStyleGetOverflow(const YGNodeConstRef node) { - return resolveRef(node)->getStyle().overflow(); + return unscopedEnum(resolveRef(node)->getStyle().overflow()); } void YGNodeStyleSetDisplay(const YGNodeRef node, const YGDisplay display) { diff --git a/yoga/algorithm/CalculateLayout.cpp b/yoga/algorithm/CalculateLayout.cpp index 4eaa2c1d..6b303b61 100644 --- a/yoga/algorithm/CalculateLayout.cpp +++ b/yoga/algorithm/CalculateLayout.cpp @@ -211,16 +211,16 @@ static void computeFlexBasisForChild( // The W3C spec doesn't say anything about the 'overflow' property, but all // major browsers appear to implement the following logic. - if ((!isMainAxisRow && node->getStyle().overflow() == YGOverflowScroll) || - node->getStyle().overflow() != YGOverflowScroll) { + if ((!isMainAxisRow && node->getStyle().overflow() == Overflow::Scroll) || + node->getStyle().overflow() != Overflow::Scroll) { if (yoga::isUndefined(childWidth) && !yoga::isUndefined(width)) { childWidth = width; childWidthMeasureMode = MeasureMode::AtMost; } } - if ((isMainAxisRow && node->getStyle().overflow() == YGOverflowScroll) || - node->getStyle().overflow() != YGOverflowScroll) { + if ((isMainAxisRow && node->getStyle().overflow() == Overflow::Scroll) || + node->getStyle().overflow() != Overflow::Scroll) { if (yoga::isUndefined(childHeight) && !yoga::isUndefined(height)) { childHeight = height; childHeightMeasureMode = MeasureMode::AtMost; @@ -2242,7 +2242,7 @@ static void calculateLayoutImpl( // If the user didn't specify a width or height for the node, set the // dimensions based on the children. if (measureModeMainDim == MeasureMode::Undefined || - (node->getStyle().overflow() != YGOverflowScroll && + (node->getStyle().overflow() != Overflow::Scroll && measureModeMainDim == MeasureMode::AtMost)) { // Clamp the size to the min/max size, if specified, and make sure it // doesn't go below the padding and border amount. @@ -2253,7 +2253,7 @@ static void calculateLayoutImpl( } else if ( measureModeMainDim == MeasureMode::AtMost && - node->getStyle().overflow() == YGOverflowScroll) { + node->getStyle().overflow() == Overflow::Scroll) { node->setLayoutMeasuredDimension( yoga::maxOrDefined( yoga::minOrDefined( @@ -2269,7 +2269,7 @@ static void calculateLayoutImpl( } if (measureModeCrossDim == MeasureMode::Undefined || - (node->getStyle().overflow() != YGOverflowScroll && + (node->getStyle().overflow() != Overflow::Scroll && measureModeCrossDim == MeasureMode::AtMost)) { // Clamp the size to the min/max size, if specified, and make sure it // doesn't go below the padding and border amount. @@ -2284,7 +2284,7 @@ static void calculateLayoutImpl( } else if ( measureModeCrossDim == MeasureMode::AtMost && - node->getStyle().overflow() == YGOverflowScroll) { + node->getStyle().overflow() == Overflow::Scroll) { node->setLayoutMeasuredDimension( yoga::maxOrDefined( yoga::minOrDefined( diff --git a/yoga/debug/NodeToString.cpp b/yoga/debug/NodeToString.cpp index 72feed65..225be915 100644 --- a/yoga/debug/NodeToString.cpp +++ b/yoga/debug/NodeToString.cpp @@ -170,8 +170,7 @@ void nodeToString( } if (style.overflow() != yoga::Node{}.getStyle().overflow()) { - appendFormattedString( - str, "overflow: %s; ", YGOverflowToString(style.overflow())); + appendFormattedString(str, "overflow: %s; ", toString(style.overflow())); } if (style.display() != yoga::Node{}.getStyle().display()) { diff --git a/yoga/style/Style.h b/yoga/style/Style.h index 7928b031..6a382823 100644 --- a/yoga/style/Style.h +++ b/yoga/style/Style.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -122,7 +123,7 @@ class YG_EXPORT Style { static constexpr uint8_t overflowOffset = flexWrapOffset + minimumBitCount(); static constexpr uint8_t displayOffset = - overflowOffset + minimumBitCount(); + overflowOffset + minimumBitCount(); uint32_t flags = 0; @@ -201,10 +202,10 @@ class YG_EXPORT Style { return {*this, flexWrapOffset}; } - YGOverflow overflow() const { - return getEnumData(flags, overflowOffset); + Overflow overflow() const { + return getEnumData(flags, overflowOffset); } - BitfieldRef overflow() { + BitfieldRef overflow() { return {*this, overflowOffset}; }