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(
|
ACCESSOR_TEST(
|
||||||
justifyContent,
|
justifyContent,
|
||||||
YGJustifyFlexStart,
|
Justify::FlexStart,
|
||||||
YGJustifyFlexEnd,
|
Justify::FlexEnd,
|
||||||
YGJustifySpaceAround,
|
Justify::SpaceAround,
|
||||||
YGJustifyFlexStart,
|
Justify::FlexStart,
|
||||||
YGJustifySpaceEvenly)
|
Justify::SpaceEvenly)
|
||||||
|
|
||||||
ACCESSOR_TEST(
|
ACCESSOR_TEST(
|
||||||
alignContent,
|
alignContent,
|
||||||
|
@@ -449,10 +449,10 @@ void YGNodeStyleSetJustifyContent(
|
|||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const YGJustify justifyContent) {
|
const YGJustify justifyContent) {
|
||||||
updateStyle<MSVC_HINT(justifyContent)>(
|
updateStyle<MSVC_HINT(justifyContent)>(
|
||||||
node, &Style::justifyContent, justifyContent);
|
node, &Style::justifyContent, scopedEnum(justifyContent));
|
||||||
}
|
}
|
||||||
YGJustify YGNodeStyleGetJustifyContent(const YGNodeConstRef node) {
|
YGJustify YGNodeStyleGetJustifyContent(const YGNodeConstRef node) {
|
||||||
return resolveRef(node)->getStyle().justifyContent();
|
return unscopedEnum(resolveRef(node)->getStyle().justifyContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGNodeStyleSetAlignContent(
|
void YGNodeStyleSetAlignContent(
|
||||||
|
@@ -465,7 +465,7 @@ static void layoutAbsoluteChild(
|
|||||||
leadingEdge(mainAxis));
|
leadingEdge(mainAxis));
|
||||||
} else if (
|
} else if (
|
||||||
!child->isLeadingPositionDefined(mainAxis) &&
|
!child->isLeadingPositionDefined(mainAxis) &&
|
||||||
node->getStyle().justifyContent() == YGJustifyCenter) {
|
node->getStyle().justifyContent() == Justify::Center) {
|
||||||
child->setLayoutPosition(
|
child->setLayoutPosition(
|
||||||
(node->getLayout().measuredDimensions[dimension(mainAxis)] -
|
(node->getLayout().measuredDimensions[dimension(mainAxis)] -
|
||||||
child->getLayout().measuredDimensions[dimension(mainAxis)]) /
|
child->getLayout().measuredDimensions[dimension(mainAxis)]) /
|
||||||
@@ -473,7 +473,7 @@ static void layoutAbsoluteChild(
|
|||||||
leadingEdge(mainAxis));
|
leadingEdge(mainAxis));
|
||||||
} else if (
|
} else if (
|
||||||
!child->isLeadingPositionDefined(mainAxis) &&
|
!child->isLeadingPositionDefined(mainAxis) &&
|
||||||
node->getStyle().justifyContent() == YGJustifyFlexEnd) {
|
node->getStyle().justifyContent() == Justify::FlexEnd) {
|
||||||
child->setLayoutPosition(
|
child->setLayoutPosition(
|
||||||
(node->getLayout().measuredDimensions[dimension(mainAxis)] -
|
(node->getLayout().measuredDimensions[dimension(mainAxis)] -
|
||||||
child->getLayout().measuredDimensions[dimension(mainAxis)]),
|
child->getLayout().measuredDimensions[dimension(mainAxis)]),
|
||||||
@@ -1196,7 +1196,7 @@ static void resolveFlexibleLength(
|
|||||||
flexLine.layout.remainingFreeSpace = originalFreeSpace - distributedFreeSpace;
|
flexLine.layout.remainingFreeSpace = originalFreeSpace - distributedFreeSpace;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void YGJustifyMainAxis(
|
static void justifyMainAxis(
|
||||||
yoga::Node* const node,
|
yoga::Node* const node,
|
||||||
FlexLine& flexLine,
|
FlexLine& flexLine,
|
||||||
const size_t startOfLineIndex,
|
const size_t startOfLineIndex,
|
||||||
@@ -1263,36 +1263,36 @@ static void YGJustifyMainAxis(
|
|||||||
// each two elements.
|
// each two elements.
|
||||||
float leadingMainDim = 0;
|
float leadingMainDim = 0;
|
||||||
float betweenMainDim = gap;
|
float betweenMainDim = gap;
|
||||||
const YGJustify justifyContent = node->getStyle().justifyContent();
|
const Justify justifyContent = node->getStyle().justifyContent();
|
||||||
|
|
||||||
if (numberOfAutoMarginsOnCurrentLine == 0) {
|
if (numberOfAutoMarginsOnCurrentLine == 0) {
|
||||||
switch (justifyContent) {
|
switch (justifyContent) {
|
||||||
case YGJustifyCenter:
|
case Justify::Center:
|
||||||
leadingMainDim = flexLine.layout.remainingFreeSpace / 2;
|
leadingMainDim = flexLine.layout.remainingFreeSpace / 2;
|
||||||
break;
|
break;
|
||||||
case YGJustifyFlexEnd:
|
case Justify::FlexEnd:
|
||||||
leadingMainDim = flexLine.layout.remainingFreeSpace;
|
leadingMainDim = flexLine.layout.remainingFreeSpace;
|
||||||
break;
|
break;
|
||||||
case YGJustifySpaceBetween:
|
case Justify::SpaceBetween:
|
||||||
if (flexLine.itemsInFlow.size() > 1) {
|
if (flexLine.itemsInFlow.size() > 1) {
|
||||||
betweenMainDim +=
|
betweenMainDim +=
|
||||||
yoga::maxOrDefined(flexLine.layout.remainingFreeSpace, 0) /
|
yoga::maxOrDefined(flexLine.layout.remainingFreeSpace, 0) /
|
||||||
static_cast<float>(flexLine.itemsInFlow.size() - 1);
|
static_cast<float>(flexLine.itemsInFlow.size() - 1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case YGJustifySpaceEvenly:
|
case Justify::SpaceEvenly:
|
||||||
// Space is distributed evenly across all elements
|
// Space is distributed evenly across all elements
|
||||||
leadingMainDim = flexLine.layout.remainingFreeSpace /
|
leadingMainDim = flexLine.layout.remainingFreeSpace /
|
||||||
static_cast<float>(flexLine.itemsInFlow.size() + 1);
|
static_cast<float>(flexLine.itemsInFlow.size() + 1);
|
||||||
betweenMainDim += leadingMainDim;
|
betweenMainDim += leadingMainDim;
|
||||||
break;
|
break;
|
||||||
case YGJustifySpaceAround:
|
case Justify::SpaceAround:
|
||||||
// Space on the edges is half of the space between elements
|
// Space on the edges is half of the space between elements
|
||||||
leadingMainDim = 0.5f * flexLine.layout.remainingFreeSpace /
|
leadingMainDim = 0.5f * flexLine.layout.remainingFreeSpace /
|
||||||
static_cast<float>(flexLine.itemsInFlow.size());
|
static_cast<float>(flexLine.itemsInFlow.size());
|
||||||
betweenMainDim += leadingMainDim * 2;
|
betweenMainDim += leadingMainDim * 2;
|
||||||
break;
|
break;
|
||||||
case YGJustifyFlexStart:
|
case Justify::FlexStart:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1814,7 +1814,7 @@ static void calculateLayoutImpl(
|
|||||||
// of items that are aligned "stretch". We need to compute these stretch
|
// of items that are aligned "stretch". We need to compute these stretch
|
||||||
// values and set the final positions.
|
// values and set the final positions.
|
||||||
|
|
||||||
YGJustifyMainAxis(
|
justifyMainAxis(
|
||||||
node,
|
node,
|
||||||
flexLine,
|
flexLine,
|
||||||
startOfLineIndex,
|
startOfLineIndex,
|
||||||
|
@@ -146,9 +146,7 @@ void nodeToString(
|
|||||||
}
|
}
|
||||||
if (style.justifyContent() != yoga::Node{}.getStyle().justifyContent()) {
|
if (style.justifyContent() != yoga::Node{}.getStyle().justifyContent()) {
|
||||||
appendFormattedString(
|
appendFormattedString(
|
||||||
str,
|
str, "justify-content: %s; ", toString(style.justifyContent()));
|
||||||
"justify-content: %s; ",
|
|
||||||
YGJustifyToString(style.justifyContent()));
|
|
||||||
}
|
}
|
||||||
if (style.alignItems() != yoga::Node{}.getStyle().alignItems()) {
|
if (style.alignItems() != yoga::Node{}.getStyle().alignItems()) {
|
||||||
appendFormattedString(
|
appendFormattedString(
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
#include <yoga/bits/NumericBitfield.h>
|
#include <yoga/bits/NumericBitfield.h>
|
||||||
#include <yoga/enums/Direction.h>
|
#include <yoga/enums/Direction.h>
|
||||||
#include <yoga/enums/FlexDirection.h>
|
#include <yoga/enums/FlexDirection.h>
|
||||||
|
#include <yoga/enums/Justify.h>
|
||||||
#include <yoga/numeric/FloatOptional.h>
|
#include <yoga/numeric/FloatOptional.h>
|
||||||
#include <yoga/style/CompactValue.h>
|
#include <yoga/style/CompactValue.h>
|
||||||
|
|
||||||
@@ -106,7 +107,7 @@ class YG_EXPORT Style {
|
|||||||
static constexpr uint8_t justifyContentOffset =
|
static constexpr uint8_t justifyContentOffset =
|
||||||
flexdirectionOffset + minimumBitCount<FlexDirection>();
|
flexdirectionOffset + minimumBitCount<FlexDirection>();
|
||||||
static constexpr uint8_t alignContentOffset =
|
static constexpr uint8_t alignContentOffset =
|
||||||
justifyContentOffset + minimumBitCount<YGJustify>();
|
justifyContentOffset + minimumBitCount<Justify>();
|
||||||
static constexpr uint8_t alignItemsOffset =
|
static constexpr uint8_t alignItemsOffset =
|
||||||
alignContentOffset + minimumBitCount<YGAlign>();
|
alignContentOffset + minimumBitCount<YGAlign>();
|
||||||
static constexpr uint8_t alignSelfOffset =
|
static constexpr uint8_t alignSelfOffset =
|
||||||
@@ -155,10 +156,10 @@ class YG_EXPORT Style {
|
|||||||
return {*this, flexdirectionOffset};
|
return {*this, flexdirectionOffset};
|
||||||
}
|
}
|
||||||
|
|
||||||
YGJustify justifyContent() const {
|
Justify justifyContent() const {
|
||||||
return getEnumData<YGJustify>(flags, justifyContentOffset);
|
return getEnumData<Justify>(flags, justifyContentOffset);
|
||||||
}
|
}
|
||||||
BitfieldRef<YGJustify> justifyContent() {
|
BitfieldRef<Justify> justifyContent() {
|
||||||
return {*this, justifyContentOffset};
|
return {*this, justifyContentOffset};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user