Skip to content

Commit

Permalink
C++ Style enums 12/N: PositionType
Browse files Browse the repository at this point in the history
Summary:
Moves internal usages of YGPositionType to PositionType

Changelog: [Internal]

Differential Revision: D49361677

fbshipit-source-id: 958c5146f76d4d3362c2bcf53d27a57e422189c7
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Sep 19, 2023
1 parent 9b63bfd commit f7d8f11
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
7 changes: 3 additions & 4 deletions tests/YGStyleAccessorsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,9 @@ ACCESSOR_TEST(

ACCESSOR_TEST(
positionType,
YGPositionTypeStatic,
YGPositionTypeAbsolute,
YGPositionTypeRelative,
YGPositionTypeStatic)
PositionType::Static,
PositionType::Absolute,
PositionType::Relative)

ACCESSOR_TEST(
flexWrap,
Expand Down
4 changes: 2 additions & 2 deletions yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,10 @@ void YGNodeStyleSetPositionType(
const YGNodeRef node,
const YGPositionType positionType) {
updateStyle<MSVC_HINT(positionType)>(
node, &Style::positionType, positionType);
node, &Style::positionType, scopedEnum(positionType));
}
YGPositionType YGNodeStyleGetPositionType(const YGNodeConstRef node) {
return resolveRef(node)->getStyle().positionType();
return unscopedEnum(resolveRef(node)->getStyle().positionType());
}

void YGNodeStyleSetFlexWrap(const YGNodeRef node, const YGWrap flexWrap) {
Expand Down
4 changes: 2 additions & 2 deletions yoga/algorithm/Baseline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ float calculateBaseline(const yoga::Node* node) {
if (child->getLineIndex() > 0) {
break;
}
if (child->getStyle().positionType() == YGPositionTypeAbsolute) {
if (child->getStyle().positionType() == PositionType::Absolute) {
continue;
}
if (resolveChildAlignment(node, child) == Align::Baseline ||
Expand Down Expand Up @@ -70,7 +70,7 @@ bool isBaselineLayout(const yoga::Node* node) {
const auto childCount = node->getChildCount();
for (size_t i = 0; i < childCount; i++) {
auto child = node->getChild(i);
if (child->getStyle().positionType() != YGPositionTypeAbsolute &&
if (child->getStyle().positionType() != PositionType::Absolute &&
child->getStyle().alignSelf() == Align::Baseline) {
return true;
}
Expand Down
18 changes: 9 additions & 9 deletions yoga/algorithm/CalculateLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ static float computeFlexBasisForChildren(
childDirection, mainDim, crossDim, availableInnerWidth);
}

if (child->getStyle().positionType() == YGPositionTypeAbsolute) {
if (child->getStyle().positionType() == PositionType::Absolute) {
continue;
}
if (child == singleFlexChild) {
Expand Down Expand Up @@ -1248,7 +1248,7 @@ static void justifyMainAxis(
int numberOfAutoMarginsOnCurrentLine = 0;
for (size_t i = startOfLineIndex; i < flexLine.endOfLineIndex; i++) {
auto child = node->getChild(i);
if (child->getStyle().positionType() != YGPositionTypeAbsolute) {
if (child->getStyle().positionType() != PositionType::Absolute) {
if (child->marginLeadingValue(mainAxis).unit == YGUnitAuto) {
numberOfAutoMarginsOnCurrentLine++;
}
Expand Down Expand Up @@ -1310,7 +1310,7 @@ static void justifyMainAxis(
if (childStyle.display() == YGDisplayNone) {
continue;
}
if (childStyle.positionType() == YGPositionTypeAbsolute &&
if (childStyle.positionType() == PositionType::Absolute &&
child->isLeadingPositionDefined(mainAxis)) {
if (performLayout) {
// In case the child is position absolute and has left/top being
Expand All @@ -1327,7 +1327,7 @@ static void justifyMainAxis(
// Now that we placed the element, we need to update the variables.
// We need to do that only for relative elements. Absolute elements do not
// take part in that phase.
if (childStyle.positionType() != YGPositionTypeAbsolute) {
if (childStyle.positionType() != PositionType::Absolute) {
if (child->marginLeadingValue(mainAxis).unit == YGUnitAuto) {
flexLine.layout.mainDim += flexLine.layout.remainingFreeSpace /
static_cast<float>(numberOfAutoMarginsOnCurrentLine);
Expand Down Expand Up @@ -1866,7 +1866,7 @@ static void calculateLayoutImpl(
if (child->getStyle().display() == YGDisplayNone) {
continue;
}
if (child->getStyle().positionType() == YGPositionTypeAbsolute) {
if (child->getStyle().positionType() == PositionType::Absolute) {
// If the child is absolutely positioned and has a
// top/left/bottom/right set, override all the previously computed
// positions to set it correctly.
Expand Down Expand Up @@ -2072,7 +2072,7 @@ static void calculateLayoutImpl(
if (child->getStyle().display() == YGDisplayNone) {
continue;
}
if (child->getStyle().positionType() != YGPositionTypeAbsolute) {
if (child->getStyle().positionType() != PositionType::Absolute) {
if (child->getLineIndex() != i) {
break;
}
Expand Down Expand Up @@ -2115,7 +2115,7 @@ static void calculateLayoutImpl(
if (child->getStyle().display() == YGDisplayNone) {
continue;
}
if (child->getStyle().positionType() != YGPositionTypeAbsolute) {
if (child->getStyle().positionType() != PositionType::Absolute) {
switch (resolveChildAlignment(node, child)) {
case Align::FlexStart: {
child->setLayoutPosition(
Expand Down Expand Up @@ -2305,7 +2305,7 @@ static void calculateLayoutImpl(
if (performLayout && node->getStyle().flexWrap() == YGWrapWrapReverse) {
for (size_t i = 0; i < childCount; i++) {
const auto child = node->getChild(i);
if (child->getStyle().positionType() != YGPositionTypeAbsolute) {
if (child->getStyle().positionType() != PositionType::Absolute) {
child->setLayoutPosition(
node->getLayout().measuredDimensions[dimension(crossAxis)] -
child->getLayout().position[leadingEdge(crossAxis)] -
Expand All @@ -2319,7 +2319,7 @@ static void calculateLayoutImpl(
// STEP 10: SIZING AND POSITIONING ABSOLUTE CHILDREN
for (auto child : node->getChildren()) {
if (child->getStyle().display() == YGDisplayNone ||
child->getStyle().positionType() != YGPositionTypeAbsolute) {
child->getStyle().positionType() != PositionType::Absolute) {
continue;
}
const bool absolutePercentageAgainstPaddingEdge =
Expand Down
2 changes: 1 addition & 1 deletion yoga/algorithm/FlexLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ FlexLine calculateFlexLine(
for (; endOfLineIndex < node->getChildren().size(); endOfLineIndex++) {
auto child = node->getChild(endOfLineIndex);
if (child->getStyle().display() == YGDisplayNone ||
child->getStyle().positionType() == YGPositionTypeAbsolute) {
child->getStyle().positionType() == PositionType::Absolute) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion yoga/debug/NodeToString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ void nodeToString(

if (style.positionType() != yoga::Node{}.getStyle().positionType()) {
appendFormattedString(
str, "position: %s; ", YGPositionTypeToString(style.positionType()));
str, "position: %s; ", toString(style.positionType()));
}

appendEdgeIfNotUndefined(str, "left", style.position(), YGEdgeLeft);
Expand Down
4 changes: 2 additions & 2 deletions yoga/node/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ void Node::setPosition(
const FlexDirection crossAxis =
yoga::resolveCrossDirection(mainAxis, directionRespectingRoot);

// Here we should check for `YGPositionTypeStatic` and in this case zero inset
// Here we should check for `PositionType::Static` and in this case zero inset
// properties (left, right, top, bottom, begin, end).
// https://www.w3.org/TR/css-position-3/#valdef-position-static
const FloatOptional relativePositionMain =
Expand Down Expand Up @@ -522,7 +522,7 @@ float Node::resolveFlexShrink() const {

bool Node::isNodeFlexible() {
return (
(style_.positionType() != YGPositionTypeAbsolute) &&
(style_.positionType() != PositionType::Absolute) &&
(resolveFlexGrow() != 0 || resolveFlexShrink() != 0));
}

Expand Down
9 changes: 5 additions & 4 deletions yoga/style/Style.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <yoga/enums/Direction.h>
#include <yoga/enums/FlexDirection.h>
#include <yoga/enums/Justify.h>
#include <yoga/enums/PositionType.h>
#include <yoga/numeric/FloatOptional.h>
#include <yoga/style/CompactValue.h>

Expand Down Expand Up @@ -116,7 +117,7 @@ class YG_EXPORT Style {
static constexpr uint8_t positionTypeOffset =
alignSelfOffset + minimumBitCount<Align>();
static constexpr uint8_t flexWrapOffset =
positionTypeOffset + minimumBitCount<YGPositionType>();
positionTypeOffset + minimumBitCount<PositionType>();
static constexpr uint8_t overflowOffset =
flexWrapOffset + minimumBitCount<YGWrap>();
static constexpr uint8_t displayOffset =
Expand Down Expand Up @@ -185,10 +186,10 @@ class YG_EXPORT Style {
return {*this, alignSelfOffset};
}

YGPositionType positionType() const {
return getEnumData<YGPositionType>(flags, positionTypeOffset);
PositionType positionType() const {
return getEnumData<PositionType>(flags, positionTypeOffset);
}
BitfieldRef<YGPositionType> positionType() {
BitfieldRef<PositionType> positionType() {
return {*this, positionTypeOffset};
}

Expand Down

0 comments on commit f7d8f11

Please sign in to comment.