From 485f63372414d4d303bc4d34b62b759f391f6a20 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Mon, 25 Sep 2023 20:27:27 -0700 Subject: [PATCH] C++ style enums 17/N: Gutter (#1407) Summary: X-link: https://github.com/facebook/react-native/pull/39599 Pull Request resolved: https://github.com/facebook/yoga/pull/1407 Replaces internal usages of YGGutter with Gutter. Changelog: [Internal] Differential Revision: D49532100 fbshipit-source-id: 2404e2b52781489a957a026eb8bc4ae0551c7f12 --- yoga/Yoga.cpp | 5 +++-- yoga/debug/NodeToString.cpp | 8 ++++---- yoga/style/Style.h | 23 ++++++++++++----------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 865a984e58..ee14372bf1 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -635,11 +635,12 @@ void YGNodeStyleSetGap( const YGGutter gutter, const float gapLength) { auto length = CompactValue::ofMaybe(gapLength); - updateIndexedStyleProp<&Style::gap, &Style::setGap>(node, gutter, length); + updateIndexedStyleProp<&Style::gap, &Style::setGap>( + node, scopedEnum(gutter), length); } float YGNodeStyleGetGap(const YGNodeConstRef node, const YGGutter gutter) { - auto gapLength = resolveRef(node)->getStyle().gap(gutter); + auto gapLength = resolveRef(node)->getStyle().gap(scopedEnum(gutter)); if (gapLength.isUndefined() || gapLength.isAuto()) { return YGUndefined; } diff --git a/yoga/debug/NodeToString.cpp b/yoga/debug/NodeToString.cpp index 0b8e180d96..d944b3a51d 100644 --- a/yoga/debug/NodeToString.cpp +++ b/yoga/debug/NodeToString.cpp @@ -177,11 +177,11 @@ void nodeToString( appendEdges(str, "padding", style.padding()); appendEdges(str, "border", style.border()); - if (!style.gap(YGGutterAll).isUndefined()) { - appendNumberIfNotUndefined(str, "gap", style.gap(YGGutterAll)); + if (!style.gap(Gutter::All).isUndefined()) { + appendNumberIfNotUndefined(str, "gap", style.gap(Gutter::All)); } else { - appendNumberIfNotUndefined(str, "column-gap", style.gap(YGGutterColumn)); - appendNumberIfNotUndefined(str, "row-gap", style.gap(YGGutterRow)); + appendNumberIfNotUndefined(str, "column-gap", style.gap(Gutter::Column)); + appendNumberIfNotUndefined(str, "row-gap", style.gap(Gutter::Row)); } appendNumberIfNotAuto(str, "width", style.dimension(Dimension::Width)); diff --git a/yoga/style/Style.h b/yoga/style/Style.h index 3cc1508ad3..f02710d3e0 100644 --- a/yoga/style/Style.h +++ b/yoga/style/Style.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -36,7 +37,7 @@ class YG_EXPORT Style { public: using Dimensions = Values; using Edges = Values; - using Gutters = Values; + using Gutters = Values; static constexpr float DefaultFlexGrow = 0.0f; static constexpr float DefaultFlexShrink = 0.0f; @@ -274,11 +275,11 @@ class YG_EXPORT Style { return {*this}; } - CompactValue gap(YGGutter gutter) const { - return gap_[gutter]; + CompactValue gap(Gutter gutter) const { + return gap_[yoga::to_underlying(gutter)]; } - void setGap(YGGutter gutter, CompactValue value) { - gap_[gutter] = value; + void setGap(Gutter gutter, CompactValue value) { + gap_[yoga::to_underlying(gutter)] = value; } CompactValue dimension(Dimension axis) const { @@ -311,18 +312,18 @@ class YG_EXPORT Style { } CompactValue resolveColumnGap() const { - if (!gap_[YGGutterColumn].isUndefined()) { - return gap_[YGGutterColumn]; + if (!gap_[yoga::to_underlying(Gutter::Column)].isUndefined()) { + return gap_[yoga::to_underlying(Gutter::Column)]; } else { - return gap_[YGGutterAll]; + return gap_[yoga::to_underlying(Gutter::All)]; } } CompactValue resolveRowGap() const { - if (!gap_[YGGutterRow].isUndefined()) { - return gap_[YGGutterRow]; + if (!gap_[yoga::to_underlying(Gutter::Row)].isUndefined()) { + return gap_[yoga::to_underlying(Gutter::Row)]; } else { - return gap_[YGGutterAll]; + return gap_[yoga::to_underlying(Gutter::All)]; } }