From 206bf414ec6ce5e41b6fb923e871e143522ddd06 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Thu, 29 Sep 2022 22:25:24 -0700 Subject: [PATCH] Add YGGutter Enum Summary: This adds the YGGutter enum, used to choose between row/column gap variants (row-gap, column-gap, gap). This used later in changes from https://github.com/facebook/yoga/pull/1116, in the APIs which deal with setting gap on style on yoga node. Note the original PR called this `YGGap`, but this ending up leading to a couple public method signatures that could appear ambiguous: 1. `SetGap(YGGap gap, float gapLength)`: Enums like `YGAlign` are the vaues for an `align` prop. `YGGap` controls the variant of the gap (like `YGEdge` does for left/right/top/bottom variants). So the enum reads as if it is the `gapValue`, and it looks like we have two of the same parameter. 2. `SetGap(YGGap gapDirection, float gap)`: This is misleading, because the direction gaps flow is the cross-axis of flex-direction. 3. `GetGap(YGGap gap)`: `gap` is the variant, but looks like an out param. The [CSS Box Alignment](https://www.w3.org/TR/css-align-3/#column-row-gap) spec refers to these gaps as "Gutters", which removes the ambiguity. Changelog: [General][Added] - Add YGGutter Enum Reviewed By: yungsters Differential Revision: D39922412 fbshipit-source-id: 4b0baf800fecb3d03560a4267c7fb4c4330fd39e --- csharp/Facebook.Yoga/YogaGutter.cs | 18 +++++++++++++ enums.py | 1 + java/com/facebook/yoga/YogaGutter.java | 35 ++++++++++++++++++++++++++ javascript/sources/YGEnums.js | 10 ++++++++ yoga/YGEnums.cpp | 12 +++++++++ yoga/YGEnums.h | 6 +++++ 6 files changed, 82 insertions(+) create mode 100644 csharp/Facebook.Yoga/YogaGutter.cs create mode 100644 java/com/facebook/yoga/YogaGutter.java diff --git a/csharp/Facebook.Yoga/YogaGutter.cs b/csharp/Facebook.Yoga/YogaGutter.cs new file mode 100644 index 00000000..3a16d796 --- /dev/null +++ b/csharp/Facebook.Yoga/YogaGutter.cs @@ -0,0 +1,18 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// @generated by enums.py + +namespace Facebook.Yoga +{ + public enum YogaGutter + { + Column, + Row, + All, + } +} diff --git a/enums.py b/enums.py index 81966bee..8e37c7c7 100644 --- a/enums.py +++ b/enums.py @@ -54,6 +54,7 @@ ENUMS = { "WebFlexBasis" ], "PrintOptions": [("Layout", 1), ("Style", 2), ("Children", 4)], + "Gutter": ["Column", "Row", "All"], } # Generated Java enums used to emit @DoNotStrip, but D17519844 removed them diff --git a/java/com/facebook/yoga/YogaGutter.java b/java/com/facebook/yoga/YogaGutter.java new file mode 100644 index 00000000..2b4be1c0 --- /dev/null +++ b/java/com/facebook/yoga/YogaGutter.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// @generated by enums.py + +package com.facebook.yoga; + +public enum YogaGutter { + COLUMN(0), + ROW(1), + ALL(2); + + private final int mIntValue; + + YogaGutter(int intValue) { + mIntValue = intValue; + } + + public int intValue() { + return mIntValue; + } + + public static YogaGutter fromInt(int value) { + switch (value) { + case 0: return COLUMN; + case 1: return ROW; + case 2: return ALL; + default: throw new IllegalArgumentException("Unknown enum value: " + value); + } + } +} diff --git a/javascript/sources/YGEnums.js b/javascript/sources/YGEnums.js index c3d4cb3c..96905ce4 100644 --- a/javascript/sources/YGEnums.js +++ b/javascript/sources/YGEnums.js @@ -53,6 +53,11 @@ const CONSTANTS = { FLEX_DIRECTION_ROW: 2, FLEX_DIRECTION_ROW_REVERSE: 3, + GUTTER_COUNT: 3, + GUTTER_COLUMN: 0, + GUTTER_ROW: 1, + GUTTER_ALL: 2, + JUSTIFY_COUNT: 6, JUSTIFY_FLEX_START: 0, JUSTIFY_CENTER: 1, @@ -147,6 +152,11 @@ export type Yoga$FlexDirection = | typeof CONSTANTS.FLEX_DIRECTION_ROW | typeof CONSTANTS.FLEX_DIRECTION_ROW_REVERSE; +export type Yoga$Gutter = + | typeof CONSTANTS.GUTTER_COLUMN + | typeof CONSTANTS.GUTTER_ROW + | typeof CONSTANTS.GUTTER_ALL; + export type Yoga$Justify = | typeof CONSTANTS.JUSTIFY_FLEX_START | typeof CONSTANTS.JUSTIFY_CENTER diff --git a/yoga/YGEnums.cpp b/yoga/YGEnums.cpp index b67b0dac..3c3c0929 100644 --- a/yoga/YGEnums.cpp +++ b/yoga/YGEnums.cpp @@ -109,6 +109,18 @@ const char* YGFlexDirectionToString(const YGFlexDirection value) { return "unknown"; } +const char* YGGutterToString(const YGGutter value) { + switch (value) { + case YGGutterColumn: + return "column"; + case YGGutterRow: + return "row"; + case YGGutterAll: + return "all"; + } + return "unknown"; +} + const char* YGJustifyToString(const YGJustify value) { switch (value) { case YGJustifyFlexStart: diff --git a/yoga/YGEnums.h b/yoga/YGEnums.h index 9d6abfb1..8faec2eb 100644 --- a/yoga/YGEnums.h +++ b/yoga/YGEnums.h @@ -64,6 +64,12 @@ YG_ENUM_SEQ_DECL( YGFlexDirectionRow, YGFlexDirectionRowReverse) +YG_ENUM_SEQ_DECL( + YGGutter, + YGGutterColumn, + YGGutterRow, + YGGutterAll) + YG_ENUM_SEQ_DECL( YGJustify, YGJustifyFlexStart,