Skip to content

Commit

Permalink
C++ style enums 14/N: Overflow (facebook#1398)
Browse files Browse the repository at this point in the history
Summary:
X-link: facebook/react-native#39537

Pull Request resolved: facebook#1398

Moves internal usages of YGOverflow to Overflow
Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D49361843

fbshipit-source-id: 966b690bd43c315f58e153c591e055780cb6bd66
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Sep 19, 2023
1 parent 7f7ffbd commit c4265a1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 22 deletions.
7 changes: 1 addition & 6 deletions tests/YGStyleAccessorsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 3 additions & 2 deletions yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,11 @@ YGWrap YGNodeStyleGetFlexWrap(const YGNodeConstRef node) {
}

void YGNodeStyleSetOverflow(const YGNodeRef node, const YGOverflow overflow) {
updateStyle<MSVC_HINT(overflow)>(node, &Style::overflow, overflow);
updateStyle<MSVC_HINT(overflow)>(
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) {
Expand Down
16 changes: 8 additions & 8 deletions yoga/algorithm/CalculateLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -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(
Expand All @@ -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.
Expand All @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions yoga/debug/NodeToString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
9 changes: 5 additions & 4 deletions yoga/style/Style.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <yoga/enums/Direction.h>
#include <yoga/enums/FlexDirection.h>
#include <yoga/enums/Justify.h>
#include <yoga/enums/Overflow.h>
#include <yoga/enums/PositionType.h>
#include <yoga/enums/Wrap.h>
#include <yoga/numeric/FloatOptional.h>
Expand Down Expand Up @@ -122,7 +123,7 @@ class YG_EXPORT Style {
static constexpr uint8_t overflowOffset =
flexWrapOffset + minimumBitCount<Wrap>();
static constexpr uint8_t displayOffset =
overflowOffset + minimumBitCount<YGOverflow>();
overflowOffset + minimumBitCount<Overflow>();

uint32_t flags = 0;

Expand Down Expand Up @@ -201,10 +202,10 @@ class YG_EXPORT Style {
return {*this, flexWrapOffset};
}

YGOverflow overflow() const {
return getEnumData<YGOverflow>(flags, overflowOffset);
Overflow overflow() const {
return getEnumData<Overflow>(flags, overflowOffset);
}
BitfieldRef<YGOverflow> overflow() {
BitfieldRef<Overflow> overflow() {
return {*this, overflowOffset};
}

Expand Down

0 comments on commit c4265a1

Please sign in to comment.