Revert D13597449: [Yoga][cleanup] Remove enum count macros
Differential Revision: D13597449 Original commit changeset: edcee225ada4 fbshipit-source-id: 1afc24833c8657a8a198bc4529d98c8f605b7fbd
This commit is contained in:
parent
c458242d87
commit
1feda5e5c8
|
@ -12,7 +12,6 @@
|
|||
#include <react/components/view/primitives.h>
|
||||
#include <react/core/LayoutMetrics.h>
|
||||
#include <react/graphics/Geometry.h>
|
||||
#include <yoga/YGEnums.h>
|
||||
#include <yoga/YGNode.h>
|
||||
#include <yoga/Yoga.h>
|
||||
#include <cmath>
|
||||
|
@ -446,7 +445,7 @@ inline void fromDynamic(const folly::dynamic &value, BorderStyle &result) {
|
|||
}
|
||||
|
||||
inline std::string toString(
|
||||
const std::array<float, yoga::enums::count<YGDimension>()> &dimensions) {
|
||||
const std::array<float, YGDimensionCount> &dimensions) {
|
||||
return "{" + folly::to<std::string>(dimensions[0]) + ", " +
|
||||
folly::to<std::string>(dimensions[1]) + "}";
|
||||
}
|
||||
|
@ -456,8 +455,7 @@ inline std::string toString(const std::array<float, 4> &position) {
|
|||
folly::to<std::string>(position[1]) + "}";
|
||||
}
|
||||
|
||||
inline std::string toString(
|
||||
const std::array<float, yoga::enums::count<YGEdge>()> &edges) {
|
||||
inline std::string toString(const std::array<float, YGEdgeCount> &edges) {
|
||||
return "{" + folly::to<std::string>(edges[0]) + ", " +
|
||||
folly::to<std::string>(edges[1]) + ", " +
|
||||
folly::to<std::string>(edges[2]) + ", " +
|
||||
|
@ -592,21 +590,20 @@ inline std::string toString(const YGStyle::Dimensions &value) {
|
|||
}
|
||||
|
||||
inline std::string toString(const YGStyle::Edges &value) {
|
||||
static std::array<std::string, yoga::enums::count<YGEdge>()> names = {
|
||||
{"left",
|
||||
"top",
|
||||
"right",
|
||||
"bottom",
|
||||
"start",
|
||||
"end",
|
||||
"horizontal",
|
||||
"vertical",
|
||||
"all"}};
|
||||
static std::array<std::string, YGEdgeCount> names = {{"left",
|
||||
"top",
|
||||
"right",
|
||||
"bottom",
|
||||
"start",
|
||||
"end",
|
||||
"horizontal",
|
||||
"vertical",
|
||||
"all"}};
|
||||
|
||||
auto result = std::string{};
|
||||
auto separator = std::string{", "};
|
||||
|
||||
for (auto i = 0; i < yoga::enums::count<YGEdge>(); i++) {
|
||||
for (auto i = 0; i < YGEdgeCount; i++) {
|
||||
YGValue v = value[i];
|
||||
if (v.unit == YGUnitUndefined) {
|
||||
continue;
|
||||
|
|
|
@ -10,8 +10,7 @@
|
|||
#include "Yoga.h"
|
||||
|
||||
struct YGConfig {
|
||||
std::array<bool, facebook::yoga::enums::count<YGExperimentalFeature>()>
|
||||
experimentalFeatures = {};
|
||||
std::array<bool, YGExperimentalFeatureCount> experimentalFeatures = {};
|
||||
bool useWebDefaults = false;
|
||||
bool useLegacyStretchBehaviour = false;
|
||||
bool shouldDiffLayoutWithoutLegacyStretchBehaviour = false;
|
||||
|
|
|
@ -8,52 +8,14 @@
|
|||
|
||||
#include "YGMacros.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace facebook {
|
||||
namespace yoga {
|
||||
namespace enums {
|
||||
|
||||
template <typename T>
|
||||
constexpr int count() = delete;
|
||||
|
||||
namespace detail {
|
||||
template <int... xs>
|
||||
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<NAME>() { \
|
||||
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(
|
||||
#define YGAlignCount 8
|
||||
YG_ENUM_DECL(
|
||||
YGAlign,
|
||||
YGAlignAuto,
|
||||
YGAlignFlexStart,
|
||||
|
@ -64,17 +26,17 @@ YG_ENUM_SEQ_DECL(
|
|||
YGAlignSpaceBetween,
|
||||
YGAlignSpaceAround);
|
||||
|
||||
YG_ENUM_SEQ_DECL(YGDimension, YGDimensionWidth, YGDimensionHeight)
|
||||
#define YGDimensionCount 2
|
||||
YG_ENUM_DECL(YGDimension, YGDimensionWidth, YGDimensionHeight)
|
||||
|
||||
YG_ENUM_SEQ_DECL(
|
||||
YGDirection,
|
||||
YGDirectionInherit,
|
||||
YGDirectionLTR,
|
||||
YGDirectionRTL)
|
||||
#define YGDirectionCount 3
|
||||
YG_ENUM_DECL(YGDirection, YGDirectionInherit, YGDirectionLTR, YGDirectionRTL)
|
||||
|
||||
YG_ENUM_SEQ_DECL(YGDisplay, YGDisplayFlex, YGDisplayNone)
|
||||
#define YGDisplayCount 2
|
||||
YG_ENUM_DECL(YGDisplay, YGDisplayFlex, YGDisplayNone)
|
||||
|
||||
YG_ENUM_SEQ_DECL(
|
||||
#define YGEdgeCount 9
|
||||
YG_ENUM_DECL(
|
||||
YGEdge,
|
||||
YGEdgeLeft,
|
||||
YGEdgeTop,
|
||||
|
@ -86,16 +48,19 @@ YG_ENUM_SEQ_DECL(
|
|||
YGEdgeVertical,
|
||||
YGEdgeAll)
|
||||
|
||||
YG_ENUM_SEQ_DECL(YGExperimentalFeature, YGExperimentalFeatureWebFlexBasis)
|
||||
#define YGExperimentalFeatureCount 1
|
||||
YG_ENUM_DECL(YGExperimentalFeature, YGExperimentalFeatureWebFlexBasis)
|
||||
|
||||
YG_ENUM_SEQ_DECL(
|
||||
#define YGFlexDirectionCount 4
|
||||
YG_ENUM_DECL(
|
||||
YGFlexDirection,
|
||||
YGFlexDirectionColumn,
|
||||
YGFlexDirectionColumnReverse,
|
||||
YGFlexDirectionRow,
|
||||
YGFlexDirectionRowReverse)
|
||||
|
||||
YG_ENUM_SEQ_DECL(
|
||||
#define YGJustifyCount 6
|
||||
YG_ENUM_DECL(
|
||||
YGJustify,
|
||||
YGJustifyFlexStart,
|
||||
YGJustifyCenter,
|
||||
|
@ -104,7 +69,8 @@ YG_ENUM_SEQ_DECL(
|
|||
YGJustifySpaceAround,
|
||||
YGJustifySpaceEvenly)
|
||||
|
||||
YG_ENUM_SEQ_DECL(
|
||||
#define YGLogLevelCount 6
|
||||
YG_ENUM_DECL(
|
||||
YGLogLevel,
|
||||
YGLogLevelError,
|
||||
YGLogLevelWarn,
|
||||
|
@ -113,38 +79,35 @@ YG_ENUM_SEQ_DECL(
|
|||
YGLogLevelVerbose,
|
||||
YGLogLevelFatal)
|
||||
|
||||
YG_ENUM_SEQ_DECL(
|
||||
#define YGMeasureModeCount 3
|
||||
YG_ENUM_DECL(
|
||||
YGMeasureMode,
|
||||
YGMeasureModeUndefined,
|
||||
YGMeasureModeExactly,
|
||||
YGMeasureModeAtMost)
|
||||
|
||||
YG_ENUM_SEQ_DECL(YGNodeType, YGNodeTypeDefault, YGNodeTypeText)
|
||||
#define YGNodeTypeCount 2
|
||||
YG_ENUM_DECL(YGNodeType, YGNodeTypeDefault, YGNodeTypeText)
|
||||
|
||||
YG_ENUM_SEQ_DECL(
|
||||
YGOverflow,
|
||||
YGOverflowVisible,
|
||||
YGOverflowHidden,
|
||||
YGOverflowScroll)
|
||||
#define YGOverflowCount 3
|
||||
YG_ENUM_DECL(YGOverflow, YGOverflowVisible, YGOverflowHidden, YGOverflowScroll)
|
||||
|
||||
YG_ENUM_SEQ_DECL(YGPositionType, YGPositionTypeRelative, YGPositionTypeAbsolute)
|
||||
#define YGPositionTypeCount 2
|
||||
YG_ENUM_DECL(YGPositionType, YGPositionTypeRelative, YGPositionTypeAbsolute)
|
||||
|
||||
#define YGPrintOptionsCount 3
|
||||
YG_ENUM_DECL(
|
||||
YGPrintOptions,
|
||||
YGPrintOptionsLayout = 1,
|
||||
YGPrintOptionsStyle = 2,
|
||||
YGPrintOptionsChildren = 4)
|
||||
|
||||
YG_ENUM_SEQ_DECL(
|
||||
YGUnit,
|
||||
YGUnitUndefined,
|
||||
YGUnitPoint,
|
||||
YGUnitPercent,
|
||||
YGUnitAuto)
|
||||
#define YGUnitCount 4
|
||||
YG_ENUM_DECL(YGUnit, YGUnitUndefined, YGUnitPoint, YGUnitPercent, YGUnitAuto)
|
||||
|
||||
YG_ENUM_SEQ_DECL(YGWrap, YGWrapNoWrap, YGWrapWrap, YGWrapWrapReverse)
|
||||
#define YGWrapCount 3
|
||||
YG_ENUM_DECL(YGWrap, YGWrapNoWrap, YGWrapWrap, YGWrapWrapReverse)
|
||||
|
||||
YG_EXTERN_C_END
|
||||
|
||||
#undef YG_ENUM_DECL
|
||||
#undef YG_ENUM_SEQ_DECL
|
||||
|
|
|
@ -313,8 +313,7 @@ YGValue YGNode::resolveFlexBasisPtr() const {
|
|||
}
|
||||
|
||||
void YGNode::resolveDimension() {
|
||||
using namespace yoga;
|
||||
for (int dim = YGDimensionWidth; dim < enums::count<YGDimension>(); dim++) {
|
||||
for (uint32_t dim = YGDimensionWidth; dim < YGDimensionCount; dim++) {
|
||||
if (!getStyle().maxDimensions[dim].isUndefined() &&
|
||||
YGValueEqual(
|
||||
getStyle().maxDimensions[dim], style_.minDimensions[dim])) {
|
||||
|
|
|
@ -20,7 +20,8 @@ static void indent(string& base, uint32_t level) {
|
|||
}
|
||||
}
|
||||
|
||||
static bool areFourValuesEqual(const YGStyle::Edges& four) {
|
||||
static bool areFourValuesEqual(
|
||||
const facebook::yoga::detail::Values<YGEdgeCount>& four) {
|
||||
return YGValueEqual(four[0], four[1]) && YGValueEqual(four[0], four[2]) &&
|
||||
YGValueEqual(four[0], four[3]);
|
||||
}
|
||||
|
@ -85,7 +86,7 @@ static void appendNumberIfNotZero(
|
|||
static void appendEdges(
|
||||
string& base,
|
||||
const string& key,
|
||||
const YGStyle::Edges& edges) {
|
||||
const facebook::yoga::detail::Values<YGEdgeCount>& edges) {
|
||||
if (areFourValuesEqual(edges)) {
|
||||
appendNumberIfNotZero(base, key, edges[YGEdgeLeft]);
|
||||
} else {
|
||||
|
@ -99,7 +100,7 @@ static void appendEdges(
|
|||
static void appendEdgeIfNotUndefined(
|
||||
string& base,
|
||||
const string& str,
|
||||
const YGStyle::Edges& edges,
|
||||
const facebook::yoga::detail::Values<YGEdgeCount>& edges,
|
||||
const YGEdge edge) {
|
||||
appendNumberIfNotUndefined(
|
||||
base,
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#include <array>
|
||||
#include <initializer_list>
|
||||
#include "CompactValue.h"
|
||||
#include "YGEnums.h"
|
||||
#include "YGFloatOptional.h"
|
||||
#include "Yoga-internal.h"
|
||||
#include "Yoga.h"
|
||||
|
@ -30,8 +29,7 @@ private:
|
|||
|
||||
public:
|
||||
using Dimensions = facebook::yoga::detail::Values<2>;
|
||||
using Edges =
|
||||
facebook::yoga::detail::Values<facebook::yoga::enums::count<YGEdge>()>;
|
||||
using Edges = facebook::yoga::detail::Values<YGEdgeCount>;
|
||||
|
||||
/* Some platforms don't support enum bitfields,
|
||||
so please use BITFIELD_ENUM_SIZED(BITS_COUNT) */
|
||||
|
|
|
@ -149,7 +149,6 @@ static const float kWebDefaultFlexShrink = 1.0f;
|
|||
extern bool YGFloatsEqual(const float a, const float b);
|
||||
extern bool YGValueEqual(const YGValue a, const YGValue b);
|
||||
extern facebook::yoga::detail::CompactValue YGComputedEdgeValue(
|
||||
const facebook::yoga::detail::Values<
|
||||
facebook::yoga::enums::count<YGEdge>()>& edges,
|
||||
const facebook::yoga::detail::Values<YGEdgeCount>& edges,
|
||||
YGEdge edge,
|
||||
facebook::yoga::detail::CompactValue defaultValue);
|
||||
|
|
|
@ -105,7 +105,7 @@ bool YGFloatIsUndefined(const float value) {
|
|||
}
|
||||
|
||||
detail::CompactValue YGComputedEdgeValue(
|
||||
const YGStyle::Edges& edges,
|
||||
const facebook::yoga::detail::Values<YGEdgeCount>& edges,
|
||||
YGEdge edge,
|
||||
detail::CompactValue defaultValue) {
|
||||
if (!edges[edge].isUndefined()) {
|
||||
|
@ -3546,12 +3546,14 @@ static const char* YGSpacer(const unsigned long level) {
|
|||
static const char* YGMeasureModeName(
|
||||
const YGMeasureMode mode,
|
||||
const bool performLayout) {
|
||||
constexpr auto N = enums::count<YGMeasureMode>();
|
||||
const char* kMeasureModeNames[N] = {"UNDEFINED", "EXACTLY", "AT_MOST"};
|
||||
const char* kLayoutModeNames[N] = {
|
||||
"LAY_UNDEFINED", "LAY_EXACTLY", "LAY_AT_MOST"};
|
||||
const char* kMeasureModeNames[YGMeasureModeCount] = {
|
||||
"UNDEFINED", "EXACTLY", "AT_MOST"};
|
||||
const char* kLayoutModeNames[YGMeasureModeCount] = {"LAY_UNDEFINED",
|
||||
"LAY_EXACTLY",
|
||||
"LAY_AT_"
|
||||
"MOST"};
|
||||
|
||||
if (mode >= N) {
|
||||
if (mode >= YGMeasureModeCount) {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue