C++ style enums 11/N: Align (#1395)
Summary: X-link: https://github.com/facebook/react-native/pull/39497 Pull Request resolved: https://github.com/facebook/yoga/pull/1395 Moves internal usages of YGAlign to Align bypass-github-export-checks Changelog: [Internal] Reviewed By: rshest Differential Revision: D49337511 fbshipit-source-id: bb9906fcd22780d2cfd8d1360ef69f66b9701bb6
This commit is contained in:
committed by
Facebook GitHub Bot
parent
61763e7d0a
commit
5bf81b1ef8
@@ -104,30 +104,30 @@ ACCESSOR_TEST(
|
||||
|
||||
ACCESSOR_TEST(
|
||||
alignContent,
|
||||
YGAlignFlexStart,
|
||||
YGAlignAuto,
|
||||
YGAlignFlexStart,
|
||||
YGAlignCenter,
|
||||
YGAlignFlexEnd,
|
||||
YGAlignStretch)
|
||||
Align::FlexStart,
|
||||
Align::Auto,
|
||||
Align::FlexStart,
|
||||
Align::Center,
|
||||
Align::FlexEnd,
|
||||
Align::Stretch)
|
||||
|
||||
ACCESSOR_TEST(
|
||||
alignItems,
|
||||
YGAlignStretch,
|
||||
YGAlignFlexStart,
|
||||
YGAlignFlexEnd,
|
||||
YGAlignBaseline,
|
||||
YGAlignSpaceBetween,
|
||||
YGAlignSpaceAround)
|
||||
Align::Stretch,
|
||||
Align::FlexStart,
|
||||
Align::FlexEnd,
|
||||
Align::Baseline,
|
||||
Align::SpaceBetween,
|
||||
Align::SpaceAround)
|
||||
|
||||
ACCESSOR_TEST(
|
||||
alignSelf,
|
||||
YGAlignAuto,
|
||||
YGAlignFlexStart,
|
||||
YGAlignCenter,
|
||||
YGAlignAuto,
|
||||
YGAlignFlexEnd,
|
||||
YGAlignStretch)
|
||||
Align::Auto,
|
||||
Align::FlexStart,
|
||||
Align::Center,
|
||||
Align::Auto,
|
||||
Align::FlexEnd,
|
||||
Align::Stretch)
|
||||
|
||||
ACCESSOR_TEST(
|
||||
positionType,
|
||||
|
@@ -459,24 +459,26 @@ void YGNodeStyleSetAlignContent(
|
||||
const YGNodeRef node,
|
||||
const YGAlign alignContent) {
|
||||
updateStyle<MSVC_HINT(alignContent)>(
|
||||
node, &Style::alignContent, alignContent);
|
||||
node, &Style::alignContent, scopedEnum(alignContent));
|
||||
}
|
||||
YGAlign YGNodeStyleGetAlignContent(const YGNodeConstRef node) {
|
||||
return resolveRef(node)->getStyle().alignContent();
|
||||
return unscopedEnum(resolveRef(node)->getStyle().alignContent());
|
||||
}
|
||||
|
||||
void YGNodeStyleSetAlignItems(const YGNodeRef node, const YGAlign alignItems) {
|
||||
updateStyle<MSVC_HINT(alignItems)>(node, &Style::alignItems, alignItems);
|
||||
updateStyle<MSVC_HINT(alignItems)>(
|
||||
node, &Style::alignItems, scopedEnum(alignItems));
|
||||
}
|
||||
YGAlign YGNodeStyleGetAlignItems(const YGNodeConstRef node) {
|
||||
return resolveRef(node)->getStyle().alignItems();
|
||||
return unscopedEnum(resolveRef(node)->getStyle().alignItems());
|
||||
}
|
||||
|
||||
void YGNodeStyleSetAlignSelf(const YGNodeRef node, const YGAlign alignSelf) {
|
||||
updateStyle<MSVC_HINT(alignSelf)>(node, &Style::alignSelf, alignSelf);
|
||||
updateStyle<MSVC_HINT(alignSelf)>(
|
||||
node, &Style::alignSelf, scopedEnum(alignSelf));
|
||||
}
|
||||
YGAlign YGNodeStyleGetAlignSelf(const YGNodeConstRef node) {
|
||||
return resolveRef(node)->getStyle().alignSelf();
|
||||
return unscopedEnum(resolveRef(node)->getStyle().alignSelf());
|
||||
}
|
||||
|
||||
void YGNodeStyleSetPositionType(
|
||||
|
@@ -14,14 +14,14 @@
|
||||
|
||||
namespace facebook::yoga {
|
||||
|
||||
inline YGAlign resolveChildAlignment(
|
||||
inline Align resolveChildAlignment(
|
||||
const yoga::Node* node,
|
||||
const yoga::Node* child) {
|
||||
const YGAlign align = child->getStyle().alignSelf() == YGAlignAuto
|
||||
const Align align = child->getStyle().alignSelf() == Align::Auto
|
||||
? node->getStyle().alignItems()
|
||||
: child->getStyle().alignSelf();
|
||||
if (align == YGAlignBaseline && isColumn(node->getStyle().flexDirection())) {
|
||||
return YGAlignFlexStart;
|
||||
if (align == Align::Baseline && isColumn(node->getStyle().flexDirection())) {
|
||||
return Align::FlexStart;
|
||||
}
|
||||
return align;
|
||||
}
|
||||
|
@@ -41,7 +41,7 @@ float calculateBaseline(const yoga::Node* node) {
|
||||
if (child->getStyle().positionType() == YGPositionTypeAbsolute) {
|
||||
continue;
|
||||
}
|
||||
if (resolveChildAlignment(node, child) == YGAlignBaseline ||
|
||||
if (resolveChildAlignment(node, child) == Align::Baseline ||
|
||||
child->isReferenceBaseline()) {
|
||||
baselineChild = child;
|
||||
break;
|
||||
@@ -64,14 +64,14 @@ bool isBaselineLayout(const yoga::Node* node) {
|
||||
if (isColumn(node->getStyle().flexDirection())) {
|
||||
return false;
|
||||
}
|
||||
if (node->getStyle().alignItems() == YGAlignBaseline) {
|
||||
if (node->getStyle().alignItems() == Align::Baseline) {
|
||||
return true;
|
||||
}
|
||||
const auto childCount = node->getChildCount();
|
||||
for (size_t i = 0; i < childCount; i++) {
|
||||
auto child = node->getChild(i);
|
||||
if (child->getStyle().positionType() != YGPositionTypeAbsolute &&
|
||||
child->getStyle().alignSelf() == YGAlignBaseline) {
|
||||
child->getStyle().alignSelf() == Align::Baseline) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -247,7 +247,7 @@ static void computeFlexBasisForChild(
|
||||
const bool hasExactWidth =
|
||||
!yoga::isUndefined(width) && widthMode == MeasureMode::Exactly;
|
||||
const bool childWidthStretch =
|
||||
resolveChildAlignment(node, child) == YGAlignStretch &&
|
||||
resolveChildAlignment(node, child) == Align::Stretch &&
|
||||
childWidthMeasureMode != MeasureMode::Exactly;
|
||||
if (!isMainAxisRow && !isRowStyleDimDefined && hasExactWidth &&
|
||||
childWidthStretch) {
|
||||
@@ -263,7 +263,7 @@ static void computeFlexBasisForChild(
|
||||
const bool hasExactHeight =
|
||||
!yoga::isUndefined(height) && heightMode == MeasureMode::Exactly;
|
||||
const bool childHeightStretch =
|
||||
resolveChildAlignment(node, child) == YGAlignStretch &&
|
||||
resolveChildAlignment(node, child) == Align::Stretch &&
|
||||
childHeightMeasureMode != MeasureMode::Exactly;
|
||||
if (isMainAxisRow && !isColumnStyleDimDefined && hasExactHeight &&
|
||||
childHeightStretch) {
|
||||
@@ -511,7 +511,7 @@ static void layoutAbsoluteChild(
|
||||
|
||||
} else if (
|
||||
!child->isLeadingPositionDefined(crossAxis) &&
|
||||
resolveChildAlignment(node, child) == YGAlignCenter) {
|
||||
resolveChildAlignment(node, child) == Align::Center) {
|
||||
child->setLayoutPosition(
|
||||
(node->getLayout().measuredDimensions[dimension(crossAxis)] -
|
||||
child->getLayout().measuredDimensions[dimension(crossAxis)]) /
|
||||
@@ -519,7 +519,7 @@ static void layoutAbsoluteChild(
|
||||
leadingEdge(crossAxis));
|
||||
} else if (
|
||||
!child->isLeadingPositionDefined(crossAxis) &&
|
||||
((resolveChildAlignment(node, child) == YGAlignFlexEnd) ^
|
||||
((resolveChildAlignment(node, child) == Align::FlexEnd) ^
|
||||
(node->getStyle().flexWrap() == YGWrapWrapReverse))) {
|
||||
child->setLayoutPosition(
|
||||
(node->getLayout().measuredDimensions[dimension(crossAxis)] -
|
||||
@@ -959,7 +959,7 @@ static float distributeFreeSpaceSecondPass(
|
||||
currentLineChild, crossAxis, availableInnerCrossDim) &&
|
||||
measureModeCrossDim == MeasureMode::Exactly &&
|
||||
!(isNodeFlexWrap && mainAxisOverflows) &&
|
||||
resolveChildAlignment(node, currentLineChild) == YGAlignStretch &&
|
||||
resolveChildAlignment(node, currentLineChild) == Align::Stretch &&
|
||||
currentLineChild->marginLeadingValue(crossAxis).unit != YGUnitAuto &&
|
||||
currentLineChild->marginTrailingValue(crossAxis).unit != YGUnitAuto) {
|
||||
childCrossSize = availableInnerCrossDim;
|
||||
@@ -1005,7 +1005,7 @@ static float distributeFreeSpaceSecondPass(
|
||||
const bool requiresStretchLayout =
|
||||
!styleDefinesDimension(
|
||||
currentLineChild, crossAxis, availableInnerCrossDim) &&
|
||||
resolveChildAlignment(node, currentLineChild) == YGAlignStretch &&
|
||||
resolveChildAlignment(node, currentLineChild) == Align::Stretch &&
|
||||
currentLineChild->marginLeadingValue(crossAxis).unit != YGUnitAuto &&
|
||||
currentLineChild->marginTrailingValue(crossAxis).unit != YGUnitAuto;
|
||||
|
||||
@@ -1898,12 +1898,12 @@ static void calculateLayoutImpl(
|
||||
// For a relative children, we're either using alignItems (owner) or
|
||||
// alignSelf (child) in order to determine the position in the cross
|
||||
// axis
|
||||
const YGAlign alignItem = resolveChildAlignment(node, child);
|
||||
const Align alignItem = resolveChildAlignment(node, child);
|
||||
|
||||
// If the child uses align stretch, we need to lay it out one more
|
||||
// time, this time forcing the cross-axis size to be the computed
|
||||
// cross size for the current line.
|
||||
if (alignItem == YGAlignStretch &&
|
||||
if (alignItem == Align::Stretch &&
|
||||
child->marginLeadingValue(crossAxis).unit != YGUnitAuto &&
|
||||
child->marginTrailingValue(crossAxis).unit != YGUnitAuto) {
|
||||
// If the child defines a definite size for its cross axis, there's
|
||||
@@ -1949,7 +1949,7 @@ static void calculateLayoutImpl(
|
||||
|
||||
auto alignContent = node->getStyle().alignContent();
|
||||
auto crossAxisDoesNotGrow =
|
||||
alignContent != YGAlignStretch && isNodeFlexWrap;
|
||||
alignContent != Align::Stretch && isNodeFlexWrap;
|
||||
const MeasureMode childWidthMeasureMode =
|
||||
yoga::isUndefined(childWidth) ||
|
||||
(!isMainAxisRow && crossAxisDoesNotGrow)
|
||||
@@ -1990,9 +1990,9 @@ static void calculateLayoutImpl(
|
||||
} else if (
|
||||
child->marginLeadingValue(crossAxis).unit == YGUnitAuto) {
|
||||
leadingCrossDim += yoga::maxOrDefined(0.0f, remainingCrossDim);
|
||||
} else if (alignItem == YGAlignFlexStart) {
|
||||
} else if (alignItem == Align::FlexStart) {
|
||||
// No-Op
|
||||
} else if (alignItem == YGAlignCenter) {
|
||||
} else if (alignItem == Align::Center) {
|
||||
leadingCrossDim += remainingCrossDim / 2;
|
||||
} else {
|
||||
leadingCrossDim += remainingCrossDim;
|
||||
@@ -2022,19 +2022,19 @@ static void calculateLayoutImpl(
|
||||
const float remainingAlignContentDim =
|
||||
availableInnerCrossDim - totalLineCrossDim;
|
||||
switch (node->getStyle().alignContent()) {
|
||||
case YGAlignFlexEnd:
|
||||
case Align::FlexEnd:
|
||||
currentLead += remainingAlignContentDim;
|
||||
break;
|
||||
case YGAlignCenter:
|
||||
case Align::Center:
|
||||
currentLead += remainingAlignContentDim / 2;
|
||||
break;
|
||||
case YGAlignStretch:
|
||||
case Align::Stretch:
|
||||
if (availableInnerCrossDim > totalLineCrossDim) {
|
||||
crossDimLead =
|
||||
remainingAlignContentDim / static_cast<float>(lineCount);
|
||||
}
|
||||
break;
|
||||
case YGAlignSpaceAround:
|
||||
case Align::SpaceAround:
|
||||
if (availableInnerCrossDim > totalLineCrossDim) {
|
||||
currentLead +=
|
||||
remainingAlignContentDim / (2 * static_cast<float>(lineCount));
|
||||
@@ -2046,15 +2046,15 @@ static void calculateLayoutImpl(
|
||||
currentLead += remainingAlignContentDim / 2;
|
||||
}
|
||||
break;
|
||||
case YGAlignSpaceBetween:
|
||||
case Align::SpaceBetween:
|
||||
if (availableInnerCrossDim > totalLineCrossDim && lineCount > 1) {
|
||||
crossDimLead =
|
||||
remainingAlignContentDim / static_cast<float>(lineCount - 1);
|
||||
}
|
||||
break;
|
||||
case YGAlignAuto:
|
||||
case YGAlignFlexStart:
|
||||
case YGAlignBaseline:
|
||||
case Align::Auto:
|
||||
case Align::FlexStart:
|
||||
case Align::Baseline:
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -2083,7 +2083,7 @@ static void calculateLayoutImpl(
|
||||
child->getMarginForAxis(crossAxis, availableInnerWidth)
|
||||
.unwrap());
|
||||
}
|
||||
if (resolveChildAlignment(node, child) == YGAlignBaseline) {
|
||||
if (resolveChildAlignment(node, child) == Align::Baseline) {
|
||||
const float ascent = calculateBaseline(child) +
|
||||
child
|
||||
->getLeadingMargin(
|
||||
@@ -2117,7 +2117,7 @@ static void calculateLayoutImpl(
|
||||
}
|
||||
if (child->getStyle().positionType() != YGPositionTypeAbsolute) {
|
||||
switch (resolveChildAlignment(node, child)) {
|
||||
case YGAlignFlexStart: {
|
||||
case Align::FlexStart: {
|
||||
child->setLayoutPosition(
|
||||
currentLead +
|
||||
child->getLeadingMargin(crossAxis, availableInnerWidth)
|
||||
@@ -2125,7 +2125,7 @@ static void calculateLayoutImpl(
|
||||
leadingEdge(crossAxis));
|
||||
break;
|
||||
}
|
||||
case YGAlignFlexEnd: {
|
||||
case Align::FlexEnd: {
|
||||
child->setLayoutPosition(
|
||||
currentLead + lineHeight -
|
||||
child->getTrailingMargin(crossAxis, availableInnerWidth)
|
||||
@@ -2135,7 +2135,7 @@ static void calculateLayoutImpl(
|
||||
leadingEdge(crossAxis));
|
||||
break;
|
||||
}
|
||||
case YGAlignCenter: {
|
||||
case Align::Center: {
|
||||
float childHeight =
|
||||
child->getLayout().measuredDimensions[dimension(crossAxis)];
|
||||
|
||||
@@ -2144,7 +2144,7 @@ static void calculateLayoutImpl(
|
||||
leadingEdge(crossAxis));
|
||||
break;
|
||||
}
|
||||
case YGAlignStretch: {
|
||||
case Align::Stretch: {
|
||||
child->setLayoutPosition(
|
||||
currentLead +
|
||||
child->getLeadingMargin(crossAxis, availableInnerWidth)
|
||||
@@ -2195,7 +2195,7 @@ static void calculateLayoutImpl(
|
||||
}
|
||||
break;
|
||||
}
|
||||
case YGAlignBaseline: {
|
||||
case Align::Baseline: {
|
||||
child->setLayoutPosition(
|
||||
currentLead + maxAscentForCurrentLine -
|
||||
calculateBaseline(child) +
|
||||
@@ -2207,9 +2207,9 @@ static void calculateLayoutImpl(
|
||||
|
||||
break;
|
||||
}
|
||||
case YGAlignAuto:
|
||||
case YGAlignSpaceBetween:
|
||||
case YGAlignSpaceAround:
|
||||
case Align::Auto:
|
||||
case Align::SpaceBetween:
|
||||
case Align::SpaceAround:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -150,15 +150,15 @@ void nodeToString(
|
||||
}
|
||||
if (style.alignItems() != yoga::Node{}.getStyle().alignItems()) {
|
||||
appendFormattedString(
|
||||
str, "align-items: %s; ", YGAlignToString(style.alignItems()));
|
||||
str, "align-items: %s; ", toString(style.alignItems()));
|
||||
}
|
||||
if (style.alignContent() != yoga::Node{}.getStyle().alignContent()) {
|
||||
appendFormattedString(
|
||||
str, "align-content: %s; ", YGAlignToString(style.alignContent()));
|
||||
str, "align-content: %s; ", toString(style.alignContent()));
|
||||
}
|
||||
if (style.alignSelf() != yoga::Node{}.getStyle().alignSelf()) {
|
||||
appendFormattedString(
|
||||
str, "align-self: %s; ", YGAlignToString(style.alignSelf()));
|
||||
str, "align-self: %s; ", toString(style.alignSelf()));
|
||||
}
|
||||
appendFloatOptionalIfDefined(str, "flex-grow", style.flexGrow());
|
||||
appendFloatOptionalIfDefined(str, "flex-shrink", style.flexShrink());
|
||||
|
@@ -52,7 +52,7 @@ class YG_EXPORT Node : public ::YGNode {
|
||||
|
||||
void useWebDefaults() {
|
||||
style_.flexDirection() = FlexDirection::Row;
|
||||
style_.alignContent() = YGAlignStretch;
|
||||
style_.alignContent() = Align::Stretch;
|
||||
}
|
||||
|
||||
// DANGER DANGER DANGER!
|
||||
|
@@ -15,6 +15,7 @@
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
#include <yoga/bits/NumericBitfield.h>
|
||||
#include <yoga/enums/Align.h>
|
||||
#include <yoga/enums/Direction.h>
|
||||
#include <yoga/enums/FlexDirection.h>
|
||||
#include <yoga/enums/Justify.h>
|
||||
@@ -95,8 +96,8 @@ class YG_EXPORT Style {
|
||||
};
|
||||
|
||||
Style() {
|
||||
alignContent() = YGAlignFlexStart;
|
||||
alignItems() = YGAlignStretch;
|
||||
alignContent() = Align::FlexStart;
|
||||
alignItems() = Align::Stretch;
|
||||
}
|
||||
~Style() = default;
|
||||
|
||||
@@ -109,11 +110,11 @@ class YG_EXPORT Style {
|
||||
static constexpr uint8_t alignContentOffset =
|
||||
justifyContentOffset + minimumBitCount<Justify>();
|
||||
static constexpr uint8_t alignItemsOffset =
|
||||
alignContentOffset + minimumBitCount<YGAlign>();
|
||||
alignContentOffset + minimumBitCount<Align>();
|
||||
static constexpr uint8_t alignSelfOffset =
|
||||
alignItemsOffset + minimumBitCount<YGAlign>();
|
||||
alignItemsOffset + minimumBitCount<Align>();
|
||||
static constexpr uint8_t positionTypeOffset =
|
||||
alignSelfOffset + minimumBitCount<YGAlign>();
|
||||
alignSelfOffset + minimumBitCount<Align>();
|
||||
static constexpr uint8_t flexWrapOffset =
|
||||
positionTypeOffset + minimumBitCount<YGPositionType>();
|
||||
static constexpr uint8_t overflowOffset =
|
||||
@@ -163,24 +164,24 @@ class YG_EXPORT Style {
|
||||
return {*this, justifyContentOffset};
|
||||
}
|
||||
|
||||
YGAlign alignContent() const {
|
||||
return getEnumData<YGAlign>(flags, alignContentOffset);
|
||||
Align alignContent() const {
|
||||
return getEnumData<Align>(flags, alignContentOffset);
|
||||
}
|
||||
BitfieldRef<YGAlign> alignContent() {
|
||||
BitfieldRef<Align> alignContent() {
|
||||
return {*this, alignContentOffset};
|
||||
}
|
||||
|
||||
YGAlign alignItems() const {
|
||||
return getEnumData<YGAlign>(flags, alignItemsOffset);
|
||||
Align alignItems() const {
|
||||
return getEnumData<Align>(flags, alignItemsOffset);
|
||||
}
|
||||
BitfieldRef<YGAlign> alignItems() {
|
||||
BitfieldRef<Align> alignItems() {
|
||||
return {*this, alignItemsOffset};
|
||||
}
|
||||
|
||||
YGAlign alignSelf() const {
|
||||
return getEnumData<YGAlign>(flags, alignSelfOffset);
|
||||
Align alignSelf() const {
|
||||
return getEnumData<Align>(flags, alignSelfOffset);
|
||||
}
|
||||
BitfieldRef<YGAlign> alignSelf() {
|
||||
BitfieldRef<Align> alignSelf() {
|
||||
return {*this, alignSelfOffset};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user