C++ style enums 10/N: Justify (#1396)
Summary: X-link: https://github.com/facebook/react-native/pull/39498 Pull Request resolved: https://github.com/facebook/yoga/pull/1396 Moves internal usages of YGJustify to Justify. bypass-github-export-checks Changelog: [Internal] Reviewed By: rshest Differential Revision: D49336538 fbshipit-source-id: 6deb2438e3cd2989c8212ee294fd0fe4819f40ab
This commit is contained in:
committed by
Facebook GitHub Bot
parent
6ec790dd1b
commit
61763e7d0a
@@ -96,11 +96,11 @@ ACCESSOR_TEST(
|
||||
|
||||
ACCESSOR_TEST(
|
||||
justifyContent,
|
||||
YGJustifyFlexStart,
|
||||
YGJustifyFlexEnd,
|
||||
YGJustifySpaceAround,
|
||||
YGJustifyFlexStart,
|
||||
YGJustifySpaceEvenly)
|
||||
Justify::FlexStart,
|
||||
Justify::FlexEnd,
|
||||
Justify::SpaceAround,
|
||||
Justify::FlexStart,
|
||||
Justify::SpaceEvenly)
|
||||
|
||||
ACCESSOR_TEST(
|
||||
alignContent,
|
||||
|
@@ -449,10 +449,10 @@ void YGNodeStyleSetJustifyContent(
|
||||
const YGNodeRef node,
|
||||
const YGJustify justifyContent) {
|
||||
updateStyle<MSVC_HINT(justifyContent)>(
|
||||
node, &Style::justifyContent, justifyContent);
|
||||
node, &Style::justifyContent, scopedEnum(justifyContent));
|
||||
}
|
||||
YGJustify YGNodeStyleGetJustifyContent(const YGNodeConstRef node) {
|
||||
return resolveRef(node)->getStyle().justifyContent();
|
||||
return unscopedEnum(resolveRef(node)->getStyle().justifyContent());
|
||||
}
|
||||
|
||||
void YGNodeStyleSetAlignContent(
|
||||
|
@@ -465,7 +465,7 @@ static void layoutAbsoluteChild(
|
||||
leadingEdge(mainAxis));
|
||||
} else if (
|
||||
!child->isLeadingPositionDefined(mainAxis) &&
|
||||
node->getStyle().justifyContent() == YGJustifyCenter) {
|
||||
node->getStyle().justifyContent() == Justify::Center) {
|
||||
child->setLayoutPosition(
|
||||
(node->getLayout().measuredDimensions[dimension(mainAxis)] -
|
||||
child->getLayout().measuredDimensions[dimension(mainAxis)]) /
|
||||
@@ -473,7 +473,7 @@ static void layoutAbsoluteChild(
|
||||
leadingEdge(mainAxis));
|
||||
} else if (
|
||||
!child->isLeadingPositionDefined(mainAxis) &&
|
||||
node->getStyle().justifyContent() == YGJustifyFlexEnd) {
|
||||
node->getStyle().justifyContent() == Justify::FlexEnd) {
|
||||
child->setLayoutPosition(
|
||||
(node->getLayout().measuredDimensions[dimension(mainAxis)] -
|
||||
child->getLayout().measuredDimensions[dimension(mainAxis)]),
|
||||
@@ -1196,7 +1196,7 @@ static void resolveFlexibleLength(
|
||||
flexLine.layout.remainingFreeSpace = originalFreeSpace - distributedFreeSpace;
|
||||
}
|
||||
|
||||
static void YGJustifyMainAxis(
|
||||
static void justifyMainAxis(
|
||||
yoga::Node* const node,
|
||||
FlexLine& flexLine,
|
||||
const size_t startOfLineIndex,
|
||||
@@ -1263,36 +1263,36 @@ static void YGJustifyMainAxis(
|
||||
// each two elements.
|
||||
float leadingMainDim = 0;
|
||||
float betweenMainDim = gap;
|
||||
const YGJustify justifyContent = node->getStyle().justifyContent();
|
||||
const Justify justifyContent = node->getStyle().justifyContent();
|
||||
|
||||
if (numberOfAutoMarginsOnCurrentLine == 0) {
|
||||
switch (justifyContent) {
|
||||
case YGJustifyCenter:
|
||||
case Justify::Center:
|
||||
leadingMainDim = flexLine.layout.remainingFreeSpace / 2;
|
||||
break;
|
||||
case YGJustifyFlexEnd:
|
||||
case Justify::FlexEnd:
|
||||
leadingMainDim = flexLine.layout.remainingFreeSpace;
|
||||
break;
|
||||
case YGJustifySpaceBetween:
|
||||
case Justify::SpaceBetween:
|
||||
if (flexLine.itemsInFlow.size() > 1) {
|
||||
betweenMainDim +=
|
||||
yoga::maxOrDefined(flexLine.layout.remainingFreeSpace, 0) /
|
||||
static_cast<float>(flexLine.itemsInFlow.size() - 1);
|
||||
}
|
||||
break;
|
||||
case YGJustifySpaceEvenly:
|
||||
case Justify::SpaceEvenly:
|
||||
// Space is distributed evenly across all elements
|
||||
leadingMainDim = flexLine.layout.remainingFreeSpace /
|
||||
static_cast<float>(flexLine.itemsInFlow.size() + 1);
|
||||
betweenMainDim += leadingMainDim;
|
||||
break;
|
||||
case YGJustifySpaceAround:
|
||||
case Justify::SpaceAround:
|
||||
// Space on the edges is half of the space between elements
|
||||
leadingMainDim = 0.5f * flexLine.layout.remainingFreeSpace /
|
||||
static_cast<float>(flexLine.itemsInFlow.size());
|
||||
betweenMainDim += leadingMainDim * 2;
|
||||
break;
|
||||
case YGJustifyFlexStart:
|
||||
case Justify::FlexStart:
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1814,7 +1814,7 @@ static void calculateLayoutImpl(
|
||||
// of items that are aligned "stretch". We need to compute these stretch
|
||||
// values and set the final positions.
|
||||
|
||||
YGJustifyMainAxis(
|
||||
justifyMainAxis(
|
||||
node,
|
||||
flexLine,
|
||||
startOfLineIndex,
|
||||
|
@@ -146,9 +146,7 @@ void nodeToString(
|
||||
}
|
||||
if (style.justifyContent() != yoga::Node{}.getStyle().justifyContent()) {
|
||||
appendFormattedString(
|
||||
str,
|
||||
"justify-content: %s; ",
|
||||
YGJustifyToString(style.justifyContent()));
|
||||
str, "justify-content: %s; ", toString(style.justifyContent()));
|
||||
}
|
||||
if (style.alignItems() != yoga::Node{}.getStyle().alignItems()) {
|
||||
appendFormattedString(
|
||||
|
@@ -17,6 +17,7 @@
|
||||
#include <yoga/bits/NumericBitfield.h>
|
||||
#include <yoga/enums/Direction.h>
|
||||
#include <yoga/enums/FlexDirection.h>
|
||||
#include <yoga/enums/Justify.h>
|
||||
#include <yoga/numeric/FloatOptional.h>
|
||||
#include <yoga/style/CompactValue.h>
|
||||
|
||||
@@ -106,7 +107,7 @@ class YG_EXPORT Style {
|
||||
static constexpr uint8_t justifyContentOffset =
|
||||
flexdirectionOffset + minimumBitCount<FlexDirection>();
|
||||
static constexpr uint8_t alignContentOffset =
|
||||
justifyContentOffset + minimumBitCount<YGJustify>();
|
||||
justifyContentOffset + minimumBitCount<Justify>();
|
||||
static constexpr uint8_t alignItemsOffset =
|
||||
alignContentOffset + minimumBitCount<YGAlign>();
|
||||
static constexpr uint8_t alignSelfOffset =
|
||||
@@ -155,10 +156,10 @@ class YG_EXPORT Style {
|
||||
return {*this, flexdirectionOffset};
|
||||
}
|
||||
|
||||
YGJustify justifyContent() const {
|
||||
return getEnumData<YGJustify>(flags, justifyContentOffset);
|
||||
Justify justifyContent() const {
|
||||
return getEnumData<Justify>(flags, justifyContentOffset);
|
||||
}
|
||||
BitfieldRef<YGJustify> justifyContent() {
|
||||
BitfieldRef<Justify> justifyContent() {
|
||||
return {*this, justifyContentOffset};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user