diff --git a/csharp/Facebook.Yoga/YogaAlign.cs b/csharp/Facebook.Yoga/YogaAlign.cs index 7a47e81b..b80987bb 100644 --- a/csharp/Facebook.Yoga/YogaAlign.cs +++ b/csharp/Facebook.Yoga/YogaAlign.cs @@ -1,10 +1,12 @@ /* - * Copyright (c) Facebook, Inc. and its affiliates. + * 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 YogaAlign diff --git a/csharp/Facebook.Yoga/YogaDimension.cs b/csharp/Facebook.Yoga/YogaDimension.cs index db2fba3f..33ac99bd 100644 --- a/csharp/Facebook.Yoga/YogaDimension.cs +++ b/csharp/Facebook.Yoga/YogaDimension.cs @@ -1,10 +1,12 @@ /* - * Copyright (c) Facebook, Inc. and its affiliates. + * 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 YogaDimension diff --git a/csharp/Facebook.Yoga/YogaDirection.cs b/csharp/Facebook.Yoga/YogaDirection.cs index 81797bf4..de31a0bd 100644 --- a/csharp/Facebook.Yoga/YogaDirection.cs +++ b/csharp/Facebook.Yoga/YogaDirection.cs @@ -1,10 +1,12 @@ /* - * Copyright (c) Facebook, Inc. and its affiliates. + * 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 YogaDirection diff --git a/csharp/Facebook.Yoga/YogaDisplay.cs b/csharp/Facebook.Yoga/YogaDisplay.cs index 065c3fe9..6e7ee6e2 100644 --- a/csharp/Facebook.Yoga/YogaDisplay.cs +++ b/csharp/Facebook.Yoga/YogaDisplay.cs @@ -1,10 +1,12 @@ /* - * Copyright (c) Facebook, Inc. and its affiliates. + * 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 YogaDisplay diff --git a/csharp/Facebook.Yoga/YogaEdge.cs b/csharp/Facebook.Yoga/YogaEdge.cs index d3e0ad9d..2d1937d0 100644 --- a/csharp/Facebook.Yoga/YogaEdge.cs +++ b/csharp/Facebook.Yoga/YogaEdge.cs @@ -1,10 +1,12 @@ /* - * Copyright (c) Facebook, Inc. and its affiliates. + * 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 YogaEdge diff --git a/csharp/Facebook.Yoga/YogaExperimentalFeature.cs b/csharp/Facebook.Yoga/YogaExperimentalFeature.cs index 0e7879a6..c78a77ba 100644 --- a/csharp/Facebook.Yoga/YogaExperimentalFeature.cs +++ b/csharp/Facebook.Yoga/YogaExperimentalFeature.cs @@ -1,10 +1,12 @@ /* - * Copyright (c) Facebook, Inc. and its affiliates. + * 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 YogaExperimentalFeature diff --git a/csharp/Facebook.Yoga/YogaFlexDirection.cs b/csharp/Facebook.Yoga/YogaFlexDirection.cs index 1d4f9c12..38d75ffb 100644 --- a/csharp/Facebook.Yoga/YogaFlexDirection.cs +++ b/csharp/Facebook.Yoga/YogaFlexDirection.cs @@ -1,10 +1,12 @@ /* - * Copyright (c) Facebook, Inc. and its affiliates. + * 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 YogaFlexDirection diff --git a/csharp/Facebook.Yoga/YogaJustify.cs b/csharp/Facebook.Yoga/YogaJustify.cs index 09f4d5cc..696325b6 100644 --- a/csharp/Facebook.Yoga/YogaJustify.cs +++ b/csharp/Facebook.Yoga/YogaJustify.cs @@ -1,10 +1,12 @@ /* - * Copyright (c) Facebook, Inc. and its affiliates. + * 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 YogaJustify diff --git a/csharp/Facebook.Yoga/YogaLogLevel.cs b/csharp/Facebook.Yoga/YogaLogLevel.cs index 9f587ab7..b1236e63 100644 --- a/csharp/Facebook.Yoga/YogaLogLevel.cs +++ b/csharp/Facebook.Yoga/YogaLogLevel.cs @@ -1,10 +1,12 @@ /* - * Copyright (c) Facebook, Inc. and its affiliates. + * 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 YogaLogLevel diff --git a/csharp/Facebook.Yoga/YogaMeasureMode.cs b/csharp/Facebook.Yoga/YogaMeasureMode.cs index 457f1fd7..6c9b8c3b 100644 --- a/csharp/Facebook.Yoga/YogaMeasureMode.cs +++ b/csharp/Facebook.Yoga/YogaMeasureMode.cs @@ -1,10 +1,12 @@ /* - * Copyright (c) Facebook, Inc. and its affiliates. + * 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 YogaMeasureMode diff --git a/csharp/Facebook.Yoga/YogaNodeType.cs b/csharp/Facebook.Yoga/YogaNodeType.cs index 9a17c4d1..8834589b 100644 --- a/csharp/Facebook.Yoga/YogaNodeType.cs +++ b/csharp/Facebook.Yoga/YogaNodeType.cs @@ -1,10 +1,12 @@ /* - * Copyright (c) Facebook, Inc. and its affiliates. + * 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 YogaNodeType diff --git a/csharp/Facebook.Yoga/YogaOverflow.cs b/csharp/Facebook.Yoga/YogaOverflow.cs index b2a99e5c..02b1f805 100644 --- a/csharp/Facebook.Yoga/YogaOverflow.cs +++ b/csharp/Facebook.Yoga/YogaOverflow.cs @@ -1,10 +1,12 @@ /* - * Copyright (c) Facebook, Inc. and its affiliates. + * 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 YogaOverflow diff --git a/csharp/Facebook.Yoga/YogaPositionType.cs b/csharp/Facebook.Yoga/YogaPositionType.cs index d63b7eab..f1ac93ad 100644 --- a/csharp/Facebook.Yoga/YogaPositionType.cs +++ b/csharp/Facebook.Yoga/YogaPositionType.cs @@ -1,14 +1,17 @@ /* - * Copyright (c) Facebook, Inc. and its affiliates. + * 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 YogaPositionType { + Static, Relative, Absolute, } diff --git a/csharp/Facebook.Yoga/YogaPrintOptions.cs b/csharp/Facebook.Yoga/YogaPrintOptions.cs index 82183db2..a268f7b4 100644 --- a/csharp/Facebook.Yoga/YogaPrintOptions.cs +++ b/csharp/Facebook.Yoga/YogaPrintOptions.cs @@ -1,10 +1,12 @@ /* - * Copyright (c) Facebook, Inc. and its affiliates. + * 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 { [System.Flags] diff --git a/csharp/Facebook.Yoga/YogaUnit.cs b/csharp/Facebook.Yoga/YogaUnit.cs index bb424be1..0b62efc0 100644 --- a/csharp/Facebook.Yoga/YogaUnit.cs +++ b/csharp/Facebook.Yoga/YogaUnit.cs @@ -1,10 +1,12 @@ /* - * Copyright (c) Facebook, Inc. and its affiliates. + * 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 YogaUnit diff --git a/csharp/Facebook.Yoga/YogaWrap.cs b/csharp/Facebook.Yoga/YogaWrap.cs index 541e06f9..a1835777 100644 --- a/csharp/Facebook.Yoga/YogaWrap.cs +++ b/csharp/Facebook.Yoga/YogaWrap.cs @@ -1,10 +1,12 @@ /* - * Copyright (c) Facebook, Inc. and its affiliates. + * 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 YogaWrap diff --git a/enums.py b/enums.py index 4fe43f7b..81966bee 100644 --- a/enums.py +++ b/enums.py @@ -1,4 +1,4 @@ -# Copyright (c) Facebook, Inc. and its affiliates. +# 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. @@ -31,7 +31,7 @@ ENUMS = { "SpaceBetween", "SpaceAround", ], - "PositionType": ["Relative", "Absolute"], + "PositionType": ["Static", "Relative", "Absolute"], "Display": ["Flex", "None"], "Wrap": ["NoWrap", "Wrap", "WrapReverse"], "MeasureMode": ["Undefined", "Exactly", "AtMost"], @@ -56,14 +56,26 @@ ENUMS = { "PrintOptions": [("Layout", 1), ("Style", 2), ("Children", 4)], } -LICENSE = """/** - * Copyright (c) Facebook, Inc. and its affiliates. +# Generated Java enums used to emit @DoNotStrip, but D17519844 removed them +# manually from all but YogaLogLevel. TODO: Is it safe to remove from it as +# well? +DO_NOT_STRIP = ["LogLevel"] + + +def get_license(ext): + prologue = "/**" if ext == "js" else "/*" + return """{} + * 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 + +""".format( + prologue + ) def to_java_upper(symbol): @@ -92,32 +104,40 @@ root = os.path.dirname(os.path.abspath(__file__)) # write out C & Objective-C headers with open(root + "/yoga/YGEnums.h", "w") as f: - f.write(LICENSE) - f.write("#pragma once\n\n") + f.write(get_license("cpp")) + f.write("#pragma once\n") + f.write("// clang-format: off\n\n") f.write('#include "YGMacros.h"\n\n') - f.write("YG_EXTERN_C_BEGIN\n\n") - for name, values in sorted(ENUMS.items()): - f.write("#define YG%sCount %s\n" % (name, len(values))) - f.write("typedef YG_ENUM_BEGIN(YG%s) {\n" % name) + + f.write('YG_EXTERN_C_BEGIN\n\n') + items = sorted(ENUMS.items()) + for name, values in items: + if (isinstance(values[0], tuple)): + f.write("YG_ENUM_DECL(\n") + else: + f.write("YG_ENUM_SEQ_DECL(\n") + + f.write(" YG%s,\n" % name) for value in values: if isinstance(value, tuple): - f.write(" YG%s%s = %d,\n" % (name, value[0], value[1])) + f.write(" YG%s%s = %d" % (name, value[0], value[1])) else: - f.write(" YG%s%s,\n" % (name, value)) - f.write("} YG_ENUM_END(YG%s);\n" % name) - f.write( - "WIN_EXPORT const char *YG%sToString(const YG%s value);\n" % (name, name) - ) + f.write(" YG%s%s" % (name, value)) + if value == values[-1]: + f.write(")\n") + else: + f.write(",\n") f.write("\n") f.write("YG_EXTERN_C_END\n") # write out C body for printing with open(root + "/yoga/YGEnums.cpp", "w") as f: - f.write(LICENSE) + f.write(get_license("cpp")) f.write('#include "YGEnums.h"\n\n') - for name, values in sorted(ENUMS.items()): - f.write("const char *YG%sToString(const YG%s value){\n" % (name, name)) - f.write(" switch(value){\n") + items = sorted(ENUMS.items()) + for name, values in items: + f.write("const char* YG%sToString(const YG%s value) {\n" % (name, name)) + f.write(" switch (value) {\n") for value in values: if isinstance(value, tuple): f.write(" case YG%s%s:\n" % (name, value[0])) @@ -127,15 +147,18 @@ with open(root + "/yoga/YGEnums.cpp", "w") as f: f.write(' return "%s";\n' % to_log_lower(value)) f.write(" }\n") f.write(' return "unknown";\n') - f.write("}\n\n") + f.write("}\n") + if name != items[-1][0]: + f.write("\n") # write out java files for name, values in sorted(ENUMS.items()): with open(root + "/java/com/facebook/yoga/Yoga%s.java" % name, "w") as f: - f.write(LICENSE.replace("/**", "/*", 1)) + f.write(get_license("java")) f.write("package com.facebook.yoga;\n\n") - f.write("import com.facebook.proguard.annotations.DoNotStrip;\n\n") - f.write("@DoNotStrip\n") + if name in DO_NOT_STRIP: + f.write("import com.facebook.proguard.annotations.DoNotStrip;\n\n") + f.write("@DoNotStrip\n") f.write("public enum Yoga%s {\n" % name) if len(values) > 0: for value in values: @@ -150,7 +173,7 @@ for name, values in sorted(ENUMS.items()): else: f.write("__EMPTY(-1);") f.write("\n") - f.write(" private int mIntValue;\n") + f.write(" private final int mIntValue;\n") f.write("\n") f.write(" Yoga%s(int intValue) {\n" % name) f.write(" mIntValue = intValue;\n") @@ -160,6 +183,8 @@ for name, values in sorted(ENUMS.items()): f.write(" return mIntValue;\n") f.write(" }\n") f.write("\n") + if name in DO_NOT_STRIP: + f.write(" @DoNotStrip\n") f.write(" public static Yoga%s fromInt(int value) {\n" % name) f.write(" switch (value) {\n") for value in values: @@ -182,7 +207,7 @@ for name, values in sorted(ENUMS.items()): # write out csharp files for name, values in sorted(ENUMS.items()): with open(root + "/csharp/Facebook.Yoga/Yoga%s.cs" % name, "w") as f: - f.write(LICENSE) + f.write(get_license("cs")) f.write("namespace Facebook.Yoga\n{\n") if isinstance(next(iter(values or []), None), tuple): f.write(" [System.Flags]\n") @@ -197,9 +222,12 @@ for name, values in sorted(ENUMS.items()): # write out javascript file with open(root + "/javascript/sources/YGEnums.js", "w") as f: - f.write(LICENSE) - f.write("module.exports = {\n\n") - for name, values in sorted(ENUMS.items()): + f.write(get_license("js")) + f.write("// @flow\n") + f.write("// @format\n") + f.write("const CONSTANTS = {\n") + items = sorted(ENUMS.items()) + for name, values in items: f.write(" %s_COUNT: %s,\n" % (to_java_upper(name), len(values))) base = 0 for value in values: @@ -214,5 +242,24 @@ with open(root + "/javascript/sources/YGEnums.js", "w") as f: " %s_%s: %d,\n" % (to_java_upper(name), to_java_upper(value), base) ) base += 1 - f.write("\n") + + if name != items[-1][0]: + f.write("\n") f.write("};\n") + + for name, values in sorted(ENUMS.items()): + f.write("export type Yoga${} =\n".format(name)) + for value in values: + unpackedValue = value[0] if isinstance(value, tuple) else value + f.write( + " | typeof CONSTANTS.{}_{}".format( + to_java_upper(name), to_java_upper(unpackedValue) + ) + ) + if values[-1] == value: + f.write(";\n") + else: + f.write("\n") + + f.write("\n") + f.write("module.exports = CONSTANTS;\n") diff --git a/java/com/facebook/yoga/YogaAlign.java b/java/com/facebook/yoga/YogaAlign.java index 5411e39f..a60d77e0 100644 --- a/java/com/facebook/yoga/YogaAlign.java +++ b/java/com/facebook/yoga/YogaAlign.java @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +// @generated by enums.py + package com.facebook.yoga; public enum YogaAlign { diff --git a/java/com/facebook/yoga/YogaDimension.java b/java/com/facebook/yoga/YogaDimension.java index eeecd85e..a949ddc3 100644 --- a/java/com/facebook/yoga/YogaDimension.java +++ b/java/com/facebook/yoga/YogaDimension.java @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +// @generated by enums.py + package com.facebook.yoga; public enum YogaDimension { diff --git a/java/com/facebook/yoga/YogaDirection.java b/java/com/facebook/yoga/YogaDirection.java index 344c0f80..7cedba3a 100644 --- a/java/com/facebook/yoga/YogaDirection.java +++ b/java/com/facebook/yoga/YogaDirection.java @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +// @generated by enums.py + package com.facebook.yoga; public enum YogaDirection { diff --git a/java/com/facebook/yoga/YogaDisplay.java b/java/com/facebook/yoga/YogaDisplay.java index aa94b053..d4c4685f 100644 --- a/java/com/facebook/yoga/YogaDisplay.java +++ b/java/com/facebook/yoga/YogaDisplay.java @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +// @generated by enums.py + package com.facebook.yoga; public enum YogaDisplay { diff --git a/java/com/facebook/yoga/YogaEdge.java b/java/com/facebook/yoga/YogaEdge.java index 929b3315..6b915348 100644 --- a/java/com/facebook/yoga/YogaEdge.java +++ b/java/com/facebook/yoga/YogaEdge.java @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +// @generated by enums.py + package com.facebook.yoga; public enum YogaEdge { diff --git a/java/com/facebook/yoga/YogaExperimentalFeature.java b/java/com/facebook/yoga/YogaExperimentalFeature.java index f54c7b6e..3fabbb91 100644 --- a/java/com/facebook/yoga/YogaExperimentalFeature.java +++ b/java/com/facebook/yoga/YogaExperimentalFeature.java @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +// @generated by enums.py + package com.facebook.yoga; public enum YogaExperimentalFeature { diff --git a/java/com/facebook/yoga/YogaFlexDirection.java b/java/com/facebook/yoga/YogaFlexDirection.java index c314c0cf..719888a1 100644 --- a/java/com/facebook/yoga/YogaFlexDirection.java +++ b/java/com/facebook/yoga/YogaFlexDirection.java @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +// @generated by enums.py + package com.facebook.yoga; public enum YogaFlexDirection { diff --git a/java/com/facebook/yoga/YogaJustify.java b/java/com/facebook/yoga/YogaJustify.java index e19213f7..4be1ed71 100644 --- a/java/com/facebook/yoga/YogaJustify.java +++ b/java/com/facebook/yoga/YogaJustify.java @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +// @generated by enums.py + package com.facebook.yoga; public enum YogaJustify { @@ -32,8 +34,7 @@ public enum YogaJustify { case 2: return FLEX_END; case 3: return SPACE_BETWEEN; case 4: return SPACE_AROUND; - case 5: - return SPACE_EVENLY; + case 5: return SPACE_EVENLY; default: throw new IllegalArgumentException("Unknown enum value: " + value); } } diff --git a/java/com/facebook/yoga/YogaLogLevel.java b/java/com/facebook/yoga/YogaLogLevel.java index f105145a..85076706 100644 --- a/java/com/facebook/yoga/YogaLogLevel.java +++ b/java/com/facebook/yoga/YogaLogLevel.java @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +// @generated by enums.py + package com.facebook.yoga; import com.facebook.proguard.annotations.DoNotStrip; diff --git a/java/com/facebook/yoga/YogaMeasureMode.java b/java/com/facebook/yoga/YogaMeasureMode.java index 1750d2a1..0c77c238 100644 --- a/java/com/facebook/yoga/YogaMeasureMode.java +++ b/java/com/facebook/yoga/YogaMeasureMode.java @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +// @generated by enums.py + package com.facebook.yoga; public enum YogaMeasureMode { diff --git a/java/com/facebook/yoga/YogaNodeType.java b/java/com/facebook/yoga/YogaNodeType.java index 1d90eec3..b8828014 100644 --- a/java/com/facebook/yoga/YogaNodeType.java +++ b/java/com/facebook/yoga/YogaNodeType.java @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +// @generated by enums.py + package com.facebook.yoga; public enum YogaNodeType { diff --git a/java/com/facebook/yoga/YogaOverflow.java b/java/com/facebook/yoga/YogaOverflow.java index 321d4e00..8e59966b 100644 --- a/java/com/facebook/yoga/YogaOverflow.java +++ b/java/com/facebook/yoga/YogaOverflow.java @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +// @generated by enums.py + package com.facebook.yoga; public enum YogaOverflow { diff --git a/java/com/facebook/yoga/YogaPositionType.java b/java/com/facebook/yoga/YogaPositionType.java index 6663a0ee..cf735fbe 100644 --- a/java/com/facebook/yoga/YogaPositionType.java +++ b/java/com/facebook/yoga/YogaPositionType.java @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +// @generated by enums.py + package com.facebook.yoga; public enum YogaPositionType { diff --git a/java/com/facebook/yoga/YogaPrintOptions.java b/java/com/facebook/yoga/YogaPrintOptions.java index 8c1a34d9..54eacc51 100644 --- a/java/com/facebook/yoga/YogaPrintOptions.java +++ b/java/com/facebook/yoga/YogaPrintOptions.java @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +// @generated by enums.py + package com.facebook.yoga; public enum YogaPrintOptions { diff --git a/java/com/facebook/yoga/YogaUnit.java b/java/com/facebook/yoga/YogaUnit.java index e2ab8bff..3614ec10 100644 --- a/java/com/facebook/yoga/YogaUnit.java +++ b/java/com/facebook/yoga/YogaUnit.java @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +// @generated by enums.py + package com.facebook.yoga; public enum YogaUnit { diff --git a/java/com/facebook/yoga/YogaWrap.java b/java/com/facebook/yoga/YogaWrap.java index e7e60143..cf87e9ef 100644 --- a/java/com/facebook/yoga/YogaWrap.java +++ b/java/com/facebook/yoga/YogaWrap.java @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +// @generated by enums.py + package com.facebook.yoga; public enum YogaWrap { diff --git a/javascript/sources/YGEnums.js b/javascript/sources/YGEnums.js index 4fd232b3..c3d4cb3c 100644 --- a/javascript/sources/YGEnums.js +++ b/javascript/sources/YGEnums.js @@ -1,13 +1,14 @@ /** - * Copyright (c) Facebook, Inc. and its affiliates. + * 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. - * - * @flow - * @format */ +// @generated by enums.py + +// @flow +// @format const CONSTANTS = { ALIGN_COUNT: 8, ALIGN_AUTO: 0, @@ -82,9 +83,10 @@ const CONSTANTS = { OVERFLOW_HIDDEN: 1, OVERFLOW_SCROLL: 2, - POSITION_TYPE_COUNT: 2, - POSITION_TYPE_RELATIVE: 0, - POSITION_TYPE_ABSOLUTE: 1, + POSITION_TYPE_COUNT: 3, + POSITION_TYPE_STATIC: 0, + POSITION_TYPE_RELATIVE: 1, + POSITION_TYPE_ABSOLUTE: 2, PRINT_OPTIONS_COUNT: 3, PRINT_OPTIONS_LAYOUT: 1, @@ -102,41 +104,28 @@ const CONSTANTS = { WRAP_WRAP: 1, WRAP_WRAP_REVERSE: 2, }; - -export type Yoga$JustifyContent = - | typeof CONSTANTS.JUSTIFY_CENTER - | typeof CONSTANTS.JUSTIFY_FLEX_END - | typeof CONSTANTS.JUSTIFY_FLEX_START - | typeof CONSTANTS.JUSTIFY_SPACE_AROUND - | typeof CONSTANTS.JUSTIFY_SPACE_BETWEEN - | typeof CONSTANTS.JUSTIFY_SPACE_EVENLY; - export type Yoga$Align = | typeof CONSTANTS.ALIGN_AUTO - | typeof CONSTANTS.ALIGN_BASELINE + | typeof CONSTANTS.ALIGN_FLEX_START | typeof CONSTANTS.ALIGN_CENTER | typeof CONSTANTS.ALIGN_FLEX_END - | typeof CONSTANTS.ALIGN_FLEX_START - | typeof CONSTANTS.ALIGN_SPACE_AROUND + | typeof CONSTANTS.ALIGN_STRETCH + | typeof CONSTANTS.ALIGN_BASELINE | typeof CONSTANTS.ALIGN_SPACE_BETWEEN - | typeof CONSTANTS.ALIGN_STRETCH; + | typeof CONSTANTS.ALIGN_SPACE_AROUND; -export type Yoga$FlexDirection = - | typeof CONSTANTS.FLEX_DIRECTION_COLUMN - | typeof CONSTANTS.FLEX_DIRECTION_COLUMN_REVERSE - | typeof CONSTANTS.FLEX_DIRECTION_COUNT - | typeof CONSTANTS.FLEX_DIRECTION_ROW - | typeof CONSTANTS.FLEX_DIRECTION_ROW_REVERSE; +export type Yoga$Dimension = + | typeof CONSTANTS.DIMENSION_WIDTH + | typeof CONSTANTS.DIMENSION_HEIGHT; export type Yoga$Direction = | typeof CONSTANTS.DIRECTION_INHERIT | typeof CONSTANTS.DIRECTION_LTR | typeof CONSTANTS.DIRECTION_RTL; -export type Yoga$FlexWrap = - | typeof CONSTANTS.WRAP_NO_WRAP - | typeof CONSTANTS.WRAP_WRAP - | typeof CONSTANTS.WRAP_WRAP_REVERSE; +export type Yoga$Display = + | typeof CONSTANTS.DISPLAY_FLEX + | typeof CONSTANTS.DISPLAY_NONE; export type Yoga$Edge = | typeof CONSTANTS.EDGE_LEFT @@ -149,25 +138,64 @@ export type Yoga$Edge = | typeof CONSTANTS.EDGE_VERTICAL | typeof CONSTANTS.EDGE_ALL; -export type Yoga$Display = - | typeof CONSTANTS.DISPLAY_FLEX - | typeof CONSTANTS.DISPLAY_NONE; +export type Yoga$ExperimentalFeature = + | typeof CONSTANTS.EXPERIMENTAL_FEATURE_WEB_FLEX_BASIS; -export type Yoga$Unit = - | typeof CONSTANTS.UNIT_AUTO - | typeof CONSTANTS.UNIT_PERCENT - | typeof CONSTANTS.UNIT_POINT - | typeof CONSTANTS.UNIT_UNDEFINED; +export type Yoga$FlexDirection = + | typeof CONSTANTS.FLEX_DIRECTION_COLUMN + | typeof CONSTANTS.FLEX_DIRECTION_COLUMN_REVERSE + | typeof CONSTANTS.FLEX_DIRECTION_ROW + | typeof CONSTANTS.FLEX_DIRECTION_ROW_REVERSE; + +export type Yoga$Justify = + | typeof CONSTANTS.JUSTIFY_FLEX_START + | typeof CONSTANTS.JUSTIFY_CENTER + | typeof CONSTANTS.JUSTIFY_FLEX_END + | typeof CONSTANTS.JUSTIFY_SPACE_BETWEEN + | typeof CONSTANTS.JUSTIFY_SPACE_AROUND + | typeof CONSTANTS.JUSTIFY_SPACE_EVENLY; + +export type Yoga$LogLevel = + | typeof CONSTANTS.LOG_LEVEL_ERROR + | typeof CONSTANTS.LOG_LEVEL_WARN + | typeof CONSTANTS.LOG_LEVEL_INFO + | typeof CONSTANTS.LOG_LEVEL_DEBUG + | typeof CONSTANTS.LOG_LEVEL_VERBOSE + | typeof CONSTANTS.LOG_LEVEL_FATAL; + +export type Yoga$MeasureMode = + | typeof CONSTANTS.MEASURE_MODE_UNDEFINED + | typeof CONSTANTS.MEASURE_MODE_EXACTLY + | typeof CONSTANTS.MEASURE_MODE_AT_MOST; + +export type Yoga$NodeType = + | typeof CONSTANTS.NODE_TYPE_DEFAULT + | typeof CONSTANTS.NODE_TYPE_TEXT; export type Yoga$Overflow = + | typeof CONSTANTS.OVERFLOW_VISIBLE | typeof CONSTANTS.OVERFLOW_HIDDEN - | typeof CONSTANTS.OVERFLOW_SCROLL - | typeof CONSTANTS.OVERFLOW_VISIBLE; + | typeof CONSTANTS.OVERFLOW_SCROLL; export type Yoga$PositionType = - | typeof CONSTANTS.POSITION_TYPE_ABSOLUTE - | typeof CONSTANTS.POSITION_TYPE_RELATIVE; + | typeof CONSTANTS.POSITION_TYPE_STATIC + | typeof CONSTANTS.POSITION_TYPE_RELATIVE + | typeof CONSTANTS.POSITION_TYPE_ABSOLUTE; -export type Yoga$ExperimentalFeature = typeof CONSTANTS.EXPERIMENTAL_FEATURE_WEB_FLEX_BASIS; +export type Yoga$PrintOptions = + | typeof CONSTANTS.PRINT_OPTIONS_LAYOUT + | typeof CONSTANTS.PRINT_OPTIONS_STYLE + | typeof CONSTANTS.PRINT_OPTIONS_CHILDREN; + +export type Yoga$Unit = + | typeof CONSTANTS.UNIT_UNDEFINED + | typeof CONSTANTS.UNIT_POINT + | typeof CONSTANTS.UNIT_PERCENT + | typeof CONSTANTS.UNIT_AUTO; + +export type Yoga$Wrap = + | typeof CONSTANTS.WRAP_NO_WRAP + | typeof CONSTANTS.WRAP_WRAP + | typeof CONSTANTS.WRAP_WRAP_REVERSE; module.exports = CONSTANTS; diff --git a/javascript/sources/entry-browser.js b/javascript/sources/entry-browser.js index cd162ed5..5007b9f2 100644 --- a/javascript/sources/entry-browser.js +++ b/javascript/sources/entry-browser.js @@ -1,5 +1,5 @@ /** - * Copyright (c) Facebook, Inc. and its affiliates. + * 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. @@ -38,11 +38,11 @@ if (!ran) { module.exports = Yoga(ret.bind, ret.lib); export type { - Yoga$JustifyContent, + Yoga$Justify, Yoga$Align, Yoga$FlexDirection, Yoga$Direction, - Yoga$FlexWrap, + Yoga$Wrap, Yoga$Edge, Yoga$Display, Yoga$Unit, diff --git a/javascript/sources/entry-common.js b/javascript/sources/entry-common.js index b9ade022..1f885e6e 100644 --- a/javascript/sources/entry-common.js +++ b/javascript/sources/entry-common.js @@ -1,5 +1,5 @@ /** - * Copyright (c) Facebook, Inc. and its affiliates. + * 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. @@ -8,16 +8,17 @@ * @format */ + const CONSTANTS = require('./YGEnums'); import type { Yoga$Edge, - Yoga$FlexWrap, + Yoga$Wrap, Yoga$Align, Yoga$FlexDirection, Yoga$Direction, Yoga$PositionType, Yoga$Overflow, - Yoga$JustifyContent, + Yoga$Justify, Yoga$Display, Yoga$ExperimentalFeature, } from './YGEnums'; @@ -151,9 +152,9 @@ export type Yoga$Node = { getFlexDirection(): Yoga$FlexDirection, getFlexGrow(): number, getFlexShrink(): number, - getFlexWrap(): Yoga$FlexWrap, + getFlexWrap(): Yoga$Wrap, getHeight(): Value, - getJustifyContent(): Yoga$JustifyContent, + getJustifyContent(): Yoga$Justify, getMargin(edge: Yoga$Edge): Value, getMaxHeight(): Value, getMaxWidth(): Value, @@ -182,11 +183,11 @@ export type Yoga$Node = { setFlexDirection(flexDirection: Yoga$FlexDirection): void, setFlexGrow(flexGrow: number): void, setFlexShrink(flexShrink: number): void, - setFlexWrap(flexWrap: Yoga$FlexWrap): void, + setFlexWrap(flexWrap: Yoga$Wrap): void, setHeight(height: number | string): void, setHeightAuto(): void, setHeightPercent(height: number): void, - setJustifyContent(justifyContent: Yoga$JustifyContent): void, + setJustifyContent(justifyContent: Yoga$Justify): void, setMargin(edge: Yoga$Edge, margin: number): void, setMarginAuto(edge: Yoga$Edge): void, setMarginPercent(edge: Yoga$Edge, margin: number): void, diff --git a/javascript/sources/entry-node.js b/javascript/sources/entry-node.js index 3cd67643..c9243be6 100644 --- a/javascript/sources/entry-node.js +++ b/javascript/sources/entry-node.js @@ -1,5 +1,5 @@ /** - * Copyright (c) Facebook, Inc. and its affiliates. + * 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. @@ -13,11 +13,11 @@ const nbind = require('nbind'); const {bind, lib} = nbind.init(__dirname + '/../'); module.exports = Yoga(bind, lib); export type { - Yoga$JustifyContent, + Yoga$Justify, Yoga$Align, Yoga$FlexDirection, Yoga$Direction, - Yoga$FlexWrap, + Yoga$Wrap, Yoga$Edge, Yoga$Display, Yoga$Unit, diff --git a/website/src/components/Playground/src/LayoutRecord.js b/website/src/components/Playground/src/LayoutRecord.js index 2574f546..3113a313 100644 --- a/website/src/components/Playground/src/LayoutRecord.js +++ b/website/src/components/Playground/src/LayoutRecord.js @@ -1,5 +1,5 @@ /** - * Copyright (c) Facebook, Inc. and its affiliates. + * 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. @@ -8,6 +8,7 @@ * @format */ + import {Record, List} from 'immutable'; import type {RecordOf} from 'immutable'; import PositionRecord from './PositionRecord'; @@ -16,9 +17,9 @@ import yoga from 'yoga-layout/dist/entry-browser'; import type { Yoga$Align, - Yoga$JustifyContent, + Yoga$Justify, Yoga$FlexDirection, - Yoga$FlexWrap, + Yoga$Wrap, Yoga$PositionType, } from 'yoga-layout'; @@ -29,7 +30,7 @@ export type LayoutRecordT = RecordOf<{ minHeight?: ?number, maxWidth?: ?number, maxHeight?: ?number, - justifyContent?: Yoga$JustifyContent, + justifyContent?: Yoga$Justify, padding: PositionRecordT, border: PositionRecordT, margin: PositionRecordT, @@ -43,7 +44,7 @@ export type LayoutRecordT = RecordOf<{ flexGrow?: number, flexShrink?: number, padding?: number, - flexWrap?: Yoga$FlexWrap, + flexWrap?: Yoga$Wrap, aspectRatio?: number, children?: List, minWidth?: number, diff --git a/yoga/YGEnums.cpp b/yoga/YGEnums.cpp index b97342d8..b67b0dac 100644 --- a/yoga/YGEnums.cpp +++ b/yoga/YGEnums.cpp @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +// @generated by enums.py + #include "YGEnums.h" const char* YGAlignToString(const YGAlign value) { diff --git a/yoga/YGEnums.h b/yoga/YGEnums.h index c14daaa1..9d6abfb1 100644 --- a/yoga/YGEnums.h +++ b/yoga/YGEnums.h @@ -5,53 +5,13 @@ * LICENSE file in the root directory of this source tree. */ +// @generated by enums.py + #pragma once +// clang-format: off #include "YGMacros.h" -#ifdef __cplusplus -namespace facebook { -namespace yoga { -namespace enums { - -template -constexpr int count(); // can't use `= delete` due to a defect in clang < 3.9 - -namespace detail { -template -constexpr int n() { - return sizeof...(xs); -} -} // namespace detail - -} // namespace enums -} // namespace yoga -} // namespace facebook -#endif - -#define YG_ENUM_DECL(NAME, ...) \ - typedef YG_ENUM_BEGIN(NAME){__VA_ARGS__} YG_ENUM_END(NAME); \ - WIN_EXPORT const char* NAME##ToString(NAME); - -#ifdef __cplusplus -#define YG_ENUM_SEQ_DECL(NAME, ...) \ - YG_ENUM_DECL(NAME, __VA_ARGS__) \ - YG_EXTERN_C_END \ - namespace facebook { \ - namespace yoga { \ - namespace enums { \ - template <> \ - constexpr int count() { \ - return detail::n<__VA_ARGS__>(); \ - } \ - } \ - } \ - } \ - YG_EXTERN_C_BEGIN -#else -#define YG_ENUM_SEQ_DECL YG_ENUM_DECL -#endif - YG_EXTERN_C_BEGIN YG_ENUM_SEQ_DECL( @@ -63,9 +23,12 @@ YG_ENUM_SEQ_DECL( YGAlignStretch, YGAlignBaseline, YGAlignSpaceBetween, - YGAlignSpaceAround); + YGAlignSpaceAround) -YG_ENUM_SEQ_DECL(YGDimension, YGDimensionWidth, YGDimensionHeight) +YG_ENUM_SEQ_DECL( + YGDimension, + YGDimensionWidth, + YGDimensionHeight) YG_ENUM_SEQ_DECL( YGDirection, @@ -73,7 +36,10 @@ YG_ENUM_SEQ_DECL( YGDirectionLTR, YGDirectionRTL) -YG_ENUM_SEQ_DECL(YGDisplay, YGDisplayFlex, YGDisplayNone) +YG_ENUM_SEQ_DECL( + YGDisplay, + YGDisplayFlex, + YGDisplayNone) YG_ENUM_SEQ_DECL( YGEdge, @@ -87,7 +53,9 @@ YG_ENUM_SEQ_DECL( YGEdgeVertical, YGEdgeAll) -YG_ENUM_SEQ_DECL(YGExperimentalFeature, YGExperimentalFeatureWebFlexBasis) +YG_ENUM_SEQ_DECL( + YGExperimentalFeature, + YGExperimentalFeatureWebFlexBasis) YG_ENUM_SEQ_DECL( YGFlexDirection, @@ -120,7 +88,10 @@ YG_ENUM_SEQ_DECL( YGMeasureModeExactly, YGMeasureModeAtMost) -YG_ENUM_SEQ_DECL(YGNodeType, YGNodeTypeDefault, YGNodeTypeText) +YG_ENUM_SEQ_DECL( + YGNodeType, + YGNodeTypeDefault, + YGNodeTypeText) YG_ENUM_SEQ_DECL( YGOverflow, @@ -147,9 +118,10 @@ YG_ENUM_SEQ_DECL( YGUnitPercent, YGUnitAuto) -YG_ENUM_SEQ_DECL(YGWrap, YGWrapNoWrap, YGWrapWrap, YGWrapWrapReverse) +YG_ENUM_SEQ_DECL( + YGWrap, + YGWrapNoWrap, + YGWrapWrap, + YGWrapWrapReverse) YG_EXTERN_C_END - -#undef YG_ENUM_DECL -#undef YG_ENUM_SEQ_DECL diff --git a/yoga/YGMacros.h b/yoga/YGMacros.h index 9211c87b..ee143c29 100644 --- a/yoga/YGMacros.h +++ b/yoga/YGMacros.h @@ -40,6 +40,49 @@ #define YG_ENUM_END(name) name #endif +#ifdef __cplusplus +namespace facebook { +namespace yoga { +namespace enums { + +template +constexpr int count(); // can't use `= delete` due to a defect in clang < 3.9 + +namespace detail { +template +constexpr int n() { + return sizeof...(xs); +} +} // namespace detail + +} // namespace enums +} // namespace yoga +} // namespace facebook +#endif + +#define YG_ENUM_DECL(NAME, ...) \ + typedef YG_ENUM_BEGIN(NAME){__VA_ARGS__} YG_ENUM_END(NAME); \ + WIN_EXPORT const char* NAME##ToString(NAME); + +#ifdef __cplusplus +#define YG_ENUM_SEQ_DECL(NAME, ...) \ + YG_ENUM_DECL(NAME, __VA_ARGS__) \ + YG_EXTERN_C_END \ + namespace facebook { \ + namespace yoga { \ + namespace enums { \ + template <> \ + constexpr int count() { \ + return detail::n<__VA_ARGS__>(); \ + } \ + } \ + } \ + } \ + YG_EXTERN_C_BEGIN +#else +#define YG_ENUM_SEQ_DECL YG_ENUM_DECL +#endif + #ifdef __GNUC__ #define YG_DEPRECATED __attribute__((deprecated)) #elif defined(_MSC_VER)