C++ style enums 8/N: Direction (#1392)

Summary:
X-link: https://github.com/facebook/react-native/pull/39483

Pull Request resolved: https://github.com/facebook/yoga/pull/1392

Moves internal usages of YGDirection to Direction.

bypass-github-export-checks

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D49335231

fbshipit-source-id: 459fe820c91be88734cebaa8655cd3f0afda83bf
This commit is contained in:
Nick Gerleman
2023-09-19 16:30:02 -07:00
committed by Facebook GitHub Bot
parent ea3869fe9f
commit 9b99e4fc22
13 changed files with 146 additions and 108 deletions

View File

@@ -82,10 +82,10 @@ namespace facebook::yoga {
ACCESSOR_TEST( ACCESSOR_TEST(
direction, direction,
YGDirectionInherit, Direction::Inherit,
YGDirectionLTR, Direction::LTR,
YGDirectionRTL, Direction::RTL,
YGDirectionInherit); Direction::Inherit);
ACCESSOR_TEST( ACCESSOR_TEST(
flexDirection, flexDirection,

View File

@@ -90,10 +90,11 @@
#ifdef __cplusplus #ifdef __cplusplus
namespace facebook::yoga::enums { namespace facebook::yoga {
template <typename T> template <typename T>
constexpr int count(); // can't use `= delete` due to a defect in clang < 3.9 constexpr int
ordinalCount(); // can't use `= delete` due to a defect in clang < 3.9
namespace detail { namespace detail {
template <int... xs> template <int... xs>
@@ -102,7 +103,7 @@ constexpr int n() {
} }
} // namespace detail } // namespace detail
} // namespace facebook::yoga::enums } // namespace facebook::yoga
#endif #endif
#define YG_ENUM_DECL(NAME, ...) \ #define YG_ENUM_DECL(NAME, ...) \
@@ -110,16 +111,16 @@ constexpr int n() {
YG_EXPORT const char* NAME##ToString(NAME); YG_EXPORT const char* NAME##ToString(NAME);
#ifdef __cplusplus #ifdef __cplusplus
#define YG_ENUM_SEQ_DECL(NAME, ...) \ #define YG_ENUM_SEQ_DECL(NAME, ...) \
YG_ENUM_DECL(NAME, __VA_ARGS__) \ YG_ENUM_DECL(NAME, __VA_ARGS__) \
YG_EXTERN_C_END \ YG_EXTERN_C_END \
\ \
namespace facebook::yoga::enums { \ namespace facebook::yoga { \
template <> \ template <> \
constexpr int count<NAME>() { \ constexpr int ordinalCount<NAME>() { \
return detail::n<__VA_ARGS__>(); \ return detail::n<__VA_ARGS__>(); \
} \ } \
} \ } \
YG_EXTERN_C_BEGIN YG_EXTERN_C_BEGIN
#else #else
#define YG_ENUM_SEQ_DECL YG_ENUM_DECL #define YG_ENUM_SEQ_DECL YG_ENUM_DECL

View File

@@ -429,10 +429,10 @@ void updateIndexedStyleProp(
#define MSVC_HINT(PROP) decltype(Style{}.PROP()) #define MSVC_HINT(PROP) decltype(Style{}.PROP())
void YGNodeStyleSetDirection(const YGNodeRef node, const YGDirection value) { void YGNodeStyleSetDirection(const YGNodeRef node, const YGDirection value) {
updateStyle<MSVC_HINT(direction)>(node, &Style::direction, value); updateStyle<MSVC_HINT(direction)>(node, &Style::direction, scopedEnum(value));
} }
YGDirection YGNodeStyleGetDirection(const YGNodeConstRef node) { YGDirection YGNodeStyleGetDirection(const YGNodeConstRef node) {
return resolveRef(node)->getStyle().direction(); return unscopedEnum(resolveRef(node)->getStyle().direction());
} }
void YGNodeStyleSetFlexDirection( void YGNodeStyleSetFlexDirection(
@@ -754,51 +754,82 @@ YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) {
return resolveRef(node)->getStyle().maxDimensions()[YGDimensionHeight]; return resolveRef(node)->getStyle().maxDimensions()[YGDimensionHeight];
} }
#define YG_NODE_LAYOUT_PROPERTY_IMPL(type, name, instanceName) \ namespace {
type YGNodeLayoutGet##name(const YGNodeConstRef node) { \
return resolveRef(node)->getLayout().instanceName; \ template <auto LayoutMember>
float getResolvedLayoutProperty(
const YGNodeConstRef nodeRef,
const YGEdge edge) {
const auto node = resolveRef(nodeRef);
yoga::assertFatalWithNode(
node,
edge <= YGEdgeEnd,
"Cannot get layout properties of multi-edge shorthands");
if (edge == YGEdgeStart) {
if (node->getLayout().direction() == Direction::RTL) {
return (node->getLayout().*LayoutMember)[YGEdgeRight];
} else {
return (node->getLayout().*LayoutMember)[YGEdgeLeft];
}
} }
#define YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(type, name, instanceName) \ if (edge == YGEdgeEnd) {
type YGNodeLayoutGet##name( \ if (node->getLayout().direction() == Direction::RTL) {
const YGNodeConstRef nodeRef, const YGEdge edge) { \ return (node->getLayout().*LayoutMember)[YGEdgeLeft];
const auto node = resolveRef(nodeRef); \ } else {
yoga::assertFatalWithNode( \ return (node->getLayout().*LayoutMember)[YGEdgeRight];
node, \ }
edge <= YGEdgeEnd, \
"Cannot get layout properties of multi-edge shorthands"); \
\
if (edge == YGEdgeStart) { \
if (node->getLayout().direction() == YGDirectionRTL) { \
return node->getLayout().instanceName[YGEdgeRight]; \
} else { \
return node->getLayout().instanceName[YGEdgeLeft]; \
} \
} \
\
if (edge == YGEdgeEnd) { \
if (node->getLayout().direction() == YGDirectionRTL) { \
return node->getLayout().instanceName[YGEdgeLeft]; \
} else { \
return node->getLayout().instanceName[YGEdgeRight]; \
} \
} \
\
return node->getLayout().instanceName[edge]; \
} }
YG_NODE_LAYOUT_PROPERTY_IMPL(float, Left, position[YGEdgeLeft]) return (node->getLayout().*LayoutMember)[edge];
YG_NODE_LAYOUT_PROPERTY_IMPL(float, Top, position[YGEdgeTop]) }
YG_NODE_LAYOUT_PROPERTY_IMPL(float, Right, position[YGEdgeRight])
YG_NODE_LAYOUT_PROPERTY_IMPL(float, Bottom, position[YGEdgeBottom])
YG_NODE_LAYOUT_PROPERTY_IMPL(float, Width, dimensions[YGDimensionWidth])
YG_NODE_LAYOUT_PROPERTY_IMPL(float, Height, dimensions[YGDimensionHeight])
YG_NODE_LAYOUT_PROPERTY_IMPL(YGDirection, Direction, direction())
YG_NODE_LAYOUT_PROPERTY_IMPL(bool, HadOverflow, hadOverflow())
YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Margin, margin) } // namespace
YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Border, border)
YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Padding, padding) float YGNodeLayoutGetLeft(const YGNodeConstRef node) {
return resolveRef(node)->getLayout().position[YGEdgeLeft];
}
float YGNodeLayoutGetTop(const YGNodeConstRef node) {
return resolveRef(node)->getLayout().position[YGEdgeTop];
}
float YGNodeLayoutGetRight(const YGNodeConstRef node) {
return resolveRef(node)->getLayout().position[YGEdgeRight];
}
float YGNodeLayoutGetBottom(const YGNodeConstRef node) {
return resolveRef(node)->getLayout().position[YGEdgeBottom];
}
float YGNodeLayoutGetWidth(const YGNodeConstRef node) {
return resolveRef(node)->getLayout().dimensions[YGDimensionWidth];
}
float YGNodeLayoutGetHeight(const YGNodeConstRef node) {
return resolveRef(node)->getLayout().dimensions[YGDimensionHeight];
}
YGDirection YGNodeLayoutGetDirection(const YGNodeConstRef node) {
return unscopedEnum(resolveRef(node)->getLayout().direction());
}
bool YGNodeLayoutGetHadOverflow(const YGNodeConstRef node) {
return resolveRef(node)->getLayout().hadOverflow();
}
float YGNodeLayoutGetMargin(YGNodeConstRef node, YGEdge edge) {
return getResolvedLayoutProperty<&LayoutResults::margin>(node, edge);
}
float YGNodeLayoutGetBorder(YGNodeConstRef node, YGEdge edge) {
return getResolvedLayoutProperty<&LayoutResults::border>(node, edge);
}
float YGNodeLayoutGetPadding(YGNodeConstRef node, YGEdge edge) {
return getResolvedLayoutProperty<&LayoutResults::padding>(node, edge);
}
#ifdef DEBUG #ifdef DEBUG
void YGNodePrint(const YGNodeConstRef node, const YGPrintOptions options) { void YGNodePrint(const YGNodeConstRef node, const YGPrintOptions options) {
@@ -926,5 +957,5 @@ void YGNodeCalculateLayout(
const float ownerHeight, const float ownerHeight,
const YGDirection ownerDirection) { const YGDirection ownerDirection) {
yoga::calculateLayout( yoga::calculateLayout(
resolveRef(node), ownerWidth, ownerHeight, ownerDirection); resolveRef(node), ownerWidth, ownerHeight, scopedEnum(ownerDirection));
} }

View File

@@ -38,7 +38,7 @@ bool calculateLayoutInternal(
yoga::Node* const node, yoga::Node* const node,
const float availableWidth, const float availableWidth,
const float availableHeight, const float availableHeight,
const YGDirection ownerDirection, const Direction ownerDirection,
const MeasureMode widthMeasureMode, const MeasureMode widthMeasureMode,
const MeasureMode heightMeasureMode, const MeasureMode heightMeasureMode,
const float ownerWidth, const float ownerWidth,
@@ -130,7 +130,7 @@ static void computeFlexBasisForChild(
const float ownerWidth, const float ownerWidth,
const float ownerHeight, const float ownerHeight,
const MeasureMode heightMode, const MeasureMode heightMode,
const YGDirection direction, const Direction direction,
LayoutData& layoutMarkerData, LayoutData& layoutMarkerData,
const uint32_t depth, const uint32_t depth,
const uint32_t generationCount) { const uint32_t generationCount) {
@@ -321,7 +321,7 @@ static void layoutAbsoluteChild(
const float width, const float width,
const MeasureMode widthMode, const MeasureMode widthMode,
const float height, const float height,
const YGDirection direction, const Direction direction,
LayoutData& layoutMarkerData, LayoutData& layoutMarkerData,
const uint32_t depth, const uint32_t depth,
const uint32_t generationCount) { const uint32_t generationCount) {
@@ -771,7 +771,7 @@ static float computeFlexBasisForChildren(
const float availableInnerHeight, const float availableInnerHeight,
MeasureMode widthMeasureMode, MeasureMode widthMeasureMode,
MeasureMode heightMeasureMode, MeasureMode heightMeasureMode,
YGDirection direction, Direction direction,
YGFlexDirection mainAxis, YGFlexDirection mainAxis,
bool performLayout, bool performLayout,
LayoutData& layoutMarkerData, LayoutData& layoutMarkerData,
@@ -812,7 +812,7 @@ static float computeFlexBasisForChildren(
} }
if (performLayout) { if (performLayout) {
// Set the initial position (relative to the owner). // Set the initial position (relative to the owner).
const YGDirection childDirection = child->resolveDirection(direction); const Direction childDirection = child->resolveDirection(direction);
const float mainDim = const float mainDim =
isRow(mainAxis) ? availableInnerWidth : availableInnerHeight; isRow(mainAxis) ? availableInnerWidth : availableInnerHeight;
const float crossDim = const float crossDim =
@@ -1478,7 +1478,7 @@ static void calculateLayoutImpl(
yoga::Node* const node, yoga::Node* const node,
const float availableWidth, const float availableWidth,
const float availableHeight, const float availableHeight,
const YGDirection ownerDirection, const Direction ownerDirection,
const MeasureMode widthMeasureMode, const MeasureMode widthMeasureMode,
const MeasureMode heightMeasureMode, const MeasureMode heightMeasureMode,
const float ownerWidth, const float ownerWidth,
@@ -1506,7 +1506,7 @@ static void calculateLayoutImpl(
(performLayout ? layoutMarkerData.layouts : layoutMarkerData.measures) += 1; (performLayout ? layoutMarkerData.layouts : layoutMarkerData.measures) += 1;
// Set the resolved resolution in the node's layout. // Set the resolved resolution in the node's layout.
const YGDirection direction = node->resolveDirection(ownerDirection); const Direction direction = node->resolveDirection(ownerDirection);
node->setLayoutDirection(direction); node->setLayoutDirection(direction);
const YGFlexDirection flexRowDirection = const YGFlexDirection flexRowDirection =
@@ -1515,8 +1515,8 @@ static void calculateLayoutImpl(
resolveDirection(YGFlexDirectionColumn, direction); resolveDirection(YGFlexDirectionColumn, direction);
const YGEdge startEdge = const YGEdge startEdge =
direction == YGDirectionLTR ? YGEdgeLeft : YGEdgeRight; direction == Direction::LTR ? YGEdgeLeft : YGEdgeRight;
const YGEdge endEdge = direction == YGDirectionLTR ? YGEdgeRight : YGEdgeLeft; const YGEdge endEdge = direction == Direction::LTR ? YGEdgeRight : YGEdgeLeft;
const float marginRowLeading = const float marginRowLeading =
node->getLeadingMargin(flexRowDirection, ownerWidth).unwrap(); node->getLeadingMargin(flexRowDirection, ownerWidth).unwrap();
@@ -2408,7 +2408,7 @@ bool calculateLayoutInternal(
yoga::Node* const node, yoga::Node* const node,
const float availableWidth, const float availableWidth,
const float availableHeight, const float availableHeight,
const YGDirection ownerDirection, const Direction ownerDirection,
const MeasureMode widthMeasureMode, const MeasureMode widthMeasureMode,
const MeasureMode heightMeasureMode, const MeasureMode heightMeasureMode,
const float ownerWidth, const float ownerWidth,
@@ -2668,7 +2668,7 @@ void calculateLayout(
yoga::Node* const node, yoga::Node* const node,
const float ownerWidth, const float ownerWidth,
const float ownerHeight, const float ownerHeight,
const YGDirection ownerDirection) { const Direction ownerDirection) {
Event::publish<Event::LayoutPassStart>(node); Event::publish<Event::LayoutPassStart>(node);
LayoutData markerData = {}; LayoutData markerData = {};

View File

@@ -16,6 +16,6 @@ void calculateLayout(
yoga::Node* const node, yoga::Node* const node,
const float ownerWidth, const float ownerWidth,
const float ownerHeight, const float ownerHeight,
const YGDirection ownerDirection); const Direction ownerDirection);
} // namespace facebook::yoga } // namespace facebook::yoga

View File

@@ -25,8 +25,8 @@ inline bool isColumn(const YGFlexDirection flexDirection) {
inline YGFlexDirection resolveDirection( inline YGFlexDirection resolveDirection(
const YGFlexDirection flexDirection, const YGFlexDirection flexDirection,
const YGDirection direction) { const Direction direction) {
if (direction == YGDirectionRTL) { if (direction == Direction::RTL) {
if (flexDirection == YGFlexDirectionRow) { if (flexDirection == YGFlexDirectionRow) {
return YGFlexDirectionRowReverse; return YGFlexDirectionRowReverse;
} else if (flexDirection == YGFlexDirectionRowReverse) { } else if (flexDirection == YGFlexDirectionRowReverse) {
@@ -39,7 +39,7 @@ inline YGFlexDirection resolveDirection(
inline YGFlexDirection resolveCrossDirection( inline YGFlexDirection resolveCrossDirection(
const YGFlexDirection flexDirection, const YGFlexDirection flexDirection,
const YGDirection direction) { const Direction direction) {
return isColumn(flexDirection) return isColumn(flexDirection)
? resolveDirection(YGFlexDirectionRow, direction) ? resolveDirection(YGFlexDirectionRow, direction)
: YGFlexDirectionColumn; : YGFlexDirectionColumn;

View File

@@ -15,7 +15,7 @@ namespace facebook::yoga {
FlexLine calculateFlexLine( FlexLine calculateFlexLine(
yoga::Node* const node, yoga::Node* const node,
const YGDirection ownerDirection, const Direction ownerDirection,
const float mainAxisownerSize, const float mainAxisownerSize,
const float availableInnerWidth, const float availableInnerWidth,
const float availableInnerMainDim, const float availableInnerMainDim,

View File

@@ -64,7 +64,7 @@ struct FlexLine {
// computeFlexBasisForChildren function). // computeFlexBasisForChildren function).
FlexLine calculateFlexLine( FlexLine calculateFlexLine(
yoga::Node* const node, yoga::Node* const node,
YGDirection ownerDirection, Direction ownerDirection,
float mainAxisownerSize, float mainAxisownerSize,
float availableInnerWidth, float availableInnerWidth,
float availableInnerMainDim, float availableInnerMainDim,

View File

@@ -10,8 +10,10 @@
#include <bitset> #include <bitset>
#include <cstdint> #include <cstdint>
#include <cstdio> #include <cstdio>
#include <type_traits>
#include <yoga/YGEnums.h> #include <yoga/YGEnums.h>
#include <yoga/enums/YogaEnums.h>
namespace facebook::yoga::details { namespace facebook::yoga::details {
@@ -28,11 +30,11 @@ constexpr uint32_t mask(uint8_t bitWidth, uint8_t index) {
namespace facebook::yoga { namespace facebook::yoga {
// The number of bits necessary to represent enums defined with YG_ENUM_SEQ_DECL // The number of bits necessary to represent enums defined with YG_ENUM_SEQ_DECL
template <typename Enum> template <
typename Enum,
std::enable_if_t<(ordinalCount<Enum>() > 0), bool> = true>
constexpr uint8_t minimumBitCount() { constexpr uint8_t minimumBitCount() {
static_assert( return details::log2ceilFn(ordinalCount<Enum>() - 1);
enums::count<Enum>() > 0, "Enums must have at least one entries");
return details::log2ceilFn(enums::count<Enum>() - 1);
} }
template <typename Enum> template <typename Enum>
@@ -41,12 +43,13 @@ constexpr Enum getEnumData(uint32_t flags, uint8_t index) {
(flags & details::mask(minimumBitCount<Enum>(), index)) >> index); (flags & details::mask(minimumBitCount<Enum>(), index)) >> index);
} }
template <typename Enum> template <typename Enum, typename Value>
void setEnumData(uint32_t& flags, uint8_t index, uint32_t newValue) { void setEnumData(uint32_t& flags, uint8_t index, Value newValue) {
flags = flags =
(flags & (flags &
~static_cast<uint32_t>(details::mask(minimumBitCount<Enum>(), index))) | ~static_cast<uint32_t>(details::mask(minimumBitCount<Enum>(), index))) |
((newValue << index) & (details::mask(minimumBitCount<Enum>(), index))); ((static_cast<uint32_t>(newValue) << index) &
(details::mask(minimumBitCount<Enum>(), index)));
} }
constexpr bool getBooleanData(uint32_t flags, uint8_t index) { constexpr bool getBooleanData(uint32_t flags, uint8_t index) {

View File

@@ -10,6 +10,7 @@
#include <array> #include <array>
#include <yoga/bits/NumericBitfield.h> #include <yoga/bits/NumericBitfield.h>
#include <yoga/enums/Direction.h>
#include <yoga/node/CachedMeasurement.h> #include <yoga/node/CachedMeasurement.h>
#include <yoga/numeric/FloatOptional.h> #include <yoga/numeric/FloatOptional.h>
@@ -27,7 +28,7 @@ struct LayoutResults {
std::array<float, 4> padding = {}; std::array<float, 4> padding = {};
private: private:
uint32_t direction_ : 2 = static_cast<uint32_t>(YGDirectionInherit) & 0x03; Direction direction_ : bitCount<Direction>() = Direction::Inherit;
bool hadOverflow_ : 1 = false; bool hadOverflow_ : 1 = false;
public: public:
@@ -37,7 +38,7 @@ struct LayoutResults {
// Instead of recomputing the entire layout every single time, we cache some // Instead of recomputing the entire layout every single time, we cache some
// information to break early when nothing changed // information to break early when nothing changed
uint32_t generationCount = 0; uint32_t generationCount = 0;
YGDirection lastOwnerDirection = YGDirectionInherit; Direction lastOwnerDirection = Direction::Inherit;
uint32_t nextCachedMeasurementsIndex = 0; uint32_t nextCachedMeasurementsIndex = 0;
std::array<CachedMeasurement, MaxCachedMeasurements> cachedMeasurements = {}; std::array<CachedMeasurement, MaxCachedMeasurements> cachedMeasurements = {};
@@ -45,12 +46,12 @@ struct LayoutResults {
CachedMeasurement cachedLayout{}; CachedMeasurement cachedLayout{};
YGDirection direction() const { Direction direction() const {
return static_cast<YGDirection>(direction_); return direction_;
} }
void setDirection(YGDirection direction) { void setDirection(Direction direction) {
direction_ = static_cast<uint32_t>(direction) & 0x03; direction_ = direction;
} }
bool hadOverflow() const { bool hadOverflow() const {

View File

@@ -296,7 +296,7 @@ void Node::removeChild(size_t index) {
children_.erase(children_.begin() + static_cast<ptrdiff_t>(index)); children_.erase(children_.begin() + static_cast<ptrdiff_t>(index));
} }
void Node::setLayoutDirection(YGDirection direction) { void Node::setLayoutDirection(Direction direction) {
layout_.setDirection(direction); layout_.setDirection(direction);
} }
@@ -318,7 +318,7 @@ void Node::setLayoutPadding(float padding, YGEdge edge) {
layout_.padding[edge] = padding; layout_.padding[edge] = padding;
} }
void Node::setLayoutLastOwnerDirection(YGDirection direction) { void Node::setLayoutLastOwnerDirection(Direction direction) {
layout_.lastOwnerDirection = direction; layout_.lastOwnerDirection = direction;
} }
@@ -369,14 +369,14 @@ FloatOptional Node::relativePosition(
} }
void Node::setPosition( void Node::setPosition(
const YGDirection direction, const Direction direction,
const float mainSize, const float mainSize,
const float crossSize, const float crossSize,
const float ownerWidth) { const float ownerWidth) {
/* Root nodes should be always layouted as LTR, so we don't return negative /* Root nodes should be always layouted as LTR, so we don't return negative
* values. */ * values. */
const YGDirection directionRespectingRoot = const Direction directionRespectingRoot =
owner_ != nullptr ? direction : YGDirectionLTR; owner_ != nullptr ? direction : Direction::LTR;
const YGFlexDirection mainAxis = const YGFlexDirection mainAxis =
yoga::resolveDirection(style_.flexDirection(), directionRespectingRoot); yoga::resolveDirection(style_.flexDirection(), directionRespectingRoot);
const YGFlexDirection crossAxis = const YGFlexDirection crossAxis =
@@ -447,10 +447,10 @@ void Node::resolveDimension() {
} }
} }
YGDirection Node::resolveDirection(const YGDirection ownerDirection) { Direction Node::resolveDirection(const Direction ownerDirection) {
if (style_.direction() == YGDirectionInherit) { if (style_.direction() == Direction::Inherit) {
return ownerDirection > YGDirectionInherit ? ownerDirection return ownerDirection != Direction::Inherit ? ownerDirection
: YGDirectionLTR; : Direction::LTR;
} else { } else {
return style_.direction(); return style_.direction();
} }

View File

@@ -14,6 +14,7 @@
#include <yoga/Yoga.h> #include <yoga/Yoga.h>
#include <yoga/config/Config.h> #include <yoga/config/Config.h>
#include <yoga/enums/Direction.h>
#include <yoga/enums/Errata.h> #include <yoga/enums/Errata.h>
#include <yoga/enums/MeasureMode.h> #include <yoga/enums/MeasureMode.h>
#include <yoga/enums/NodeType.h> #include <yoga/enums/NodeType.h>
@@ -289,7 +290,7 @@ class YG_EXPORT Node : public ::YGNode {
void setConfig(Config* config); void setConfig(Config* config);
void setDirty(bool isDirty); void setDirty(bool isDirty);
void setLayoutLastOwnerDirection(YGDirection direction); void setLayoutLastOwnerDirection(Direction direction);
void setLayoutComputedFlexBasis(const FloatOptional computedFlexBasis); void setLayoutComputedFlexBasis(const FloatOptional computedFlexBasis);
void setLayoutComputedFlexBasisGeneration( void setLayoutComputedFlexBasisGeneration(
uint32_t computedFlexBasisGeneration); uint32_t computedFlexBasisGeneration);
@@ -298,13 +299,13 @@ class YG_EXPORT Node : public ::YGNode {
YGDimension dimension); YGDimension dimension);
void setLayoutHadOverflow(bool hadOverflow); void setLayoutHadOverflow(bool hadOverflow);
void setLayoutDimension(float dimensionValue, YGDimension dimension); void setLayoutDimension(float dimensionValue, YGDimension dimension);
void setLayoutDirection(YGDirection direction); void setLayoutDirection(Direction direction);
void setLayoutMargin(float margin, YGEdge edge); void setLayoutMargin(float margin, YGEdge edge);
void setLayoutBorder(float border, YGEdge edge); void setLayoutBorder(float border, YGEdge edge);
void setLayoutPadding(float padding, YGEdge edge); void setLayoutPadding(float padding, YGEdge edge);
void setLayoutPosition(float position, YGEdge edge); void setLayoutPosition(float position, YGEdge edge);
void setPosition( void setPosition(
const YGDirection direction, const Direction direction,
const float mainSize, const float mainSize,
const float crossSize, const float crossSize,
const float ownerWidth); const float ownerWidth);
@@ -315,7 +316,7 @@ class YG_EXPORT Node : public ::YGNode {
YGValue marginTrailingValue(const YGFlexDirection axis) const; YGValue marginTrailingValue(const YGFlexDirection axis) const;
YGValue resolveFlexBasisPtr() const; YGValue resolveFlexBasisPtr() const;
void resolveDimension(); void resolveDimension();
YGDirection resolveDirection(const YGDirection ownerDirection); Direction resolveDirection(const Direction ownerDirection);
void clearChildren(); void clearChildren();
/// Replaces the occurrences of oldChild with newChild /// Replaces the occurrences of oldChild with newChild
void replaceChild(Node* oldChild, Node* newChild); void replaceChild(Node* oldChild, Node* newChild);

View File

@@ -15,6 +15,7 @@
#include <yoga/Yoga.h> #include <yoga/Yoga.h>
#include <yoga/bits/NumericBitfield.h> #include <yoga/bits/NumericBitfield.h>
#include <yoga/enums/Direction.h>
#include <yoga/numeric/FloatOptional.h> #include <yoga/numeric/FloatOptional.h>
#include <yoga/style/CompactValue.h> #include <yoga/style/CompactValue.h>
@@ -22,7 +23,7 @@ namespace facebook::yoga {
class YG_EXPORT Style { class YG_EXPORT Style {
template <typename Enum> template <typename Enum>
using Values = std::array<CompactValue, enums::count<Enum>()>; using Values = std::array<CompactValue, ordinalCount<Enum>()>;
public: public:
using Dimensions = Values<YGDimension>; using Dimensions = Values<YGDimension>;
@@ -100,7 +101,7 @@ class YG_EXPORT Style {
private: private:
static constexpr uint8_t directionOffset = 0; static constexpr uint8_t directionOffset = 0;
static constexpr uint8_t flexdirectionOffset = static constexpr uint8_t flexdirectionOffset =
directionOffset + minimumBitCount<YGDirection>(); directionOffset + minimumBitCount<Direction>();
static constexpr uint8_t justifyContentOffset = static constexpr uint8_t justifyContentOffset =
flexdirectionOffset + minimumBitCount<YGFlexDirection>(); flexdirectionOffset + minimumBitCount<YGFlexDirection>();
static constexpr uint8_t alignContentOffset = static constexpr uint8_t alignContentOffset =
@@ -139,10 +140,10 @@ class YG_EXPORT Style {
// for library users needing a type // for library users needing a type
using ValueRepr = std::remove_reference<decltype(margin_[0])>::type; using ValueRepr = std::remove_reference<decltype(margin_[0])>::type;
YGDirection direction() const { Direction direction() const {
return getEnumData<YGDirection>(flags, directionOffset); return getEnumData<Direction>(flags, directionOffset);
} }
BitfieldRef<YGDirection> direction() { BitfieldRef<Direction> direction() {
return {*this, directionOffset}; return {*this, directionOffset};
} }