YGEdge -> yoga::Edge (#1461)
Summary: X-link: https://github.com/facebook/react-native/pull/41391 Pull Request resolved: https://github.com/facebook/yoga/pull/1461 Converts usages of `YGEdge` within internal APIs to `yoga::Edge` scoped enum. With the exception of YGUnit which is in its own state of transition, this is the last public yoga enum to need to be moved to scoped enum form for usages internal to the Yoga public API. Changelog: [internal] Reviewed By: rshest Differential Revision: D51152779 fbshipit-source-id: 06554f67bfd7709cbc24fdd9a5474e897e9e95d8
This commit is contained in:
committed by
Facebook GitHub Bot
parent
a121483e81
commit
325ccea068
@@ -57,7 +57,7 @@ float calculateBaseline(const yoga::Node* node) {
|
||||
}
|
||||
|
||||
const float baseline = calculateBaseline(baselineChild);
|
||||
return baseline + baselineChild->getLayout().position[YGEdgeTop];
|
||||
return baseline + baselineChild->getLayout().position(Edge::Top);
|
||||
}
|
||||
|
||||
bool isBaselineLayout(const yoga::Node* node) {
|
||||
|
@@ -89,7 +89,7 @@ static void setChildTrailingPosition(
|
||||
const float size = child->getLayout().measuredDimension(dimension(axis));
|
||||
child->setLayoutPosition(
|
||||
node->getLayout().measuredDimension(dimension(axis)) - size -
|
||||
child->getLayout().position[flexStartEdge(axis)],
|
||||
child->getLayout().position(flexStartEdge(axis)),
|
||||
flexEndEdge(axis));
|
||||
}
|
||||
|
||||
@@ -553,12 +553,13 @@ static void measureNodeWithMeasureFunc(
|
||||
availableHeight = YGUndefined;
|
||||
}
|
||||
|
||||
const auto& padding = node->getLayout().padding;
|
||||
const auto& border = node->getLayout().border;
|
||||
const float paddingAndBorderAxisRow = padding[YGEdgeLeft] +
|
||||
padding[YGEdgeRight] + border[YGEdgeLeft] + border[YGEdgeRight];
|
||||
const float paddingAndBorderAxisColumn = padding[YGEdgeTop] +
|
||||
padding[YGEdgeBottom] + border[YGEdgeTop] + border[YGEdgeBottom];
|
||||
const auto& layout = node->getLayout();
|
||||
const float paddingAndBorderAxisRow = layout.padding(Edge::Left) +
|
||||
layout.padding(Edge::Right) + layout.border(Edge::Left) +
|
||||
layout.border(Edge::Right);
|
||||
const float paddingAndBorderAxisColumn = layout.padding(Edge::Top) +
|
||||
layout.padding(Edge::Bottom) + layout.border(Edge::Top) +
|
||||
layout.border(Edge::Bottom);
|
||||
|
||||
// We want to make sure we don't call measure with negative size
|
||||
const float innerWidth = yoga::isUndefined(availableWidth)
|
||||
@@ -643,14 +644,13 @@ static void measureNodeWithoutChildren(
|
||||
const SizingMode heightSizingMode,
|
||||
const float ownerWidth,
|
||||
const float ownerHeight) {
|
||||
const auto& padding = node->getLayout().padding;
|
||||
const auto& border = node->getLayout().border;
|
||||
const auto& layout = node->getLayout();
|
||||
|
||||
float width = availableWidth;
|
||||
if (widthSizingMode == SizingMode::MaxContent ||
|
||||
widthSizingMode == SizingMode::FitContent) {
|
||||
width = padding[YGEdgeLeft] + padding[YGEdgeRight] + border[YGEdgeLeft] +
|
||||
border[YGEdgeRight];
|
||||
width = layout.padding(Edge::Left) + layout.padding(Edge::Right) +
|
||||
layout.border(Edge::Left) + layout.border(Edge::Right);
|
||||
}
|
||||
node->setLayoutMeasuredDimension(
|
||||
boundAxis(node, FlexDirection::Row, width, ownerWidth, ownerWidth),
|
||||
@@ -659,8 +659,8 @@ static void measureNodeWithoutChildren(
|
||||
float height = availableHeight;
|
||||
if (heightSizingMode == SizingMode::MaxContent ||
|
||||
heightSizingMode == SizingMode::FitContent) {
|
||||
height = padding[YGEdgeTop] + padding[YGEdgeBottom] + border[YGEdgeTop] +
|
||||
border[YGEdgeBottom];
|
||||
height = layout.padding(Edge::Top) + layout.padding(Edge::Bottom) +
|
||||
layout.border(Edge::Top) + layout.border(Edge::Bottom);
|
||||
}
|
||||
node->setLayoutMeasuredDimension(
|
||||
boundAxis(node, FlexDirection::Column, height, ownerHeight, ownerWidth),
|
||||
@@ -1330,7 +1330,7 @@ static void justifyMainAxis(
|
||||
|
||||
if (performLayout) {
|
||||
child->setLayoutPosition(
|
||||
childLayout.position[flexStartEdge(mainAxis)] +
|
||||
childLayout.position(flexStartEdge(mainAxis)) +
|
||||
flexLine.layout.mainDim,
|
||||
flexStartEdge(mainAxis));
|
||||
}
|
||||
@@ -1386,7 +1386,7 @@ static void justifyMainAxis(
|
||||
}
|
||||
} else if (performLayout) {
|
||||
child->setLayoutPosition(
|
||||
childLayout.position[flexStartEdge(mainAxis)] +
|
||||
childLayout.position(flexStartEdge(mainAxis)) +
|
||||
node->getInlineStartBorder(mainAxis, direction) +
|
||||
leadingMainDim,
|
||||
flexStartEdge(mainAxis));
|
||||
@@ -1497,9 +1497,8 @@ static void calculateLayoutImpl(
|
||||
const FlexDirection flexColumnDirection =
|
||||
resolveDirection(FlexDirection::Column, direction);
|
||||
|
||||
const YGEdge startEdge =
|
||||
direction == Direction::LTR ? YGEdgeLeft : YGEdgeRight;
|
||||
const YGEdge endEdge = direction == Direction::LTR ? YGEdgeRight : YGEdgeLeft;
|
||||
const Edge startEdge = direction == Direction::LTR ? Edge::Left : Edge::Right;
|
||||
const Edge endEdge = direction == Direction::LTR ? Edge::Right : Edge::Left;
|
||||
|
||||
const float marginRowLeading =
|
||||
node->getInlineStartMargin(flexRowDirection, direction, ownerWidth);
|
||||
@@ -1509,10 +1508,10 @@ static void calculateLayoutImpl(
|
||||
node->setLayoutMargin(marginRowTrailing, endEdge);
|
||||
const float marginColumnLeading =
|
||||
node->getInlineStartMargin(flexColumnDirection, direction, ownerWidth);
|
||||
node->setLayoutMargin(marginColumnLeading, YGEdgeTop);
|
||||
node->setLayoutMargin(marginColumnLeading, Edge::Top);
|
||||
const float marginColumnTrailing =
|
||||
node->getInlineEndMargin(flexColumnDirection, direction, ownerWidth);
|
||||
node->setLayoutMargin(marginColumnTrailing, YGEdgeBottom);
|
||||
node->setLayoutMargin(marginColumnTrailing, Edge::Bottom);
|
||||
|
||||
const float marginAxisRow = marginRowLeading + marginRowTrailing;
|
||||
const float marginAxisColumn = marginColumnLeading + marginColumnTrailing;
|
||||
@@ -1522,9 +1521,9 @@ static void calculateLayoutImpl(
|
||||
node->setLayoutBorder(
|
||||
node->getInlineEndBorder(flexRowDirection, direction), endEdge);
|
||||
node->setLayoutBorder(
|
||||
node->getInlineStartBorder(flexColumnDirection, direction), YGEdgeTop);
|
||||
node->getInlineStartBorder(flexColumnDirection, direction), Edge::Top);
|
||||
node->setLayoutBorder(
|
||||
node->getInlineEndBorder(flexColumnDirection, direction), YGEdgeBottom);
|
||||
node->getInlineEndBorder(flexColumnDirection, direction), Edge::Bottom);
|
||||
|
||||
node->setLayoutPadding(
|
||||
node->getInlineStartPadding(flexRowDirection, direction, ownerWidth),
|
||||
@@ -1534,10 +1533,10 @@ static void calculateLayoutImpl(
|
||||
endEdge);
|
||||
node->setLayoutPadding(
|
||||
node->getInlineStartPadding(flexColumnDirection, direction, ownerWidth),
|
||||
YGEdgeTop);
|
||||
Edge::Top);
|
||||
node->setLayoutPadding(
|
||||
node->getInlineEndPadding(flexColumnDirection, direction, ownerWidth),
|
||||
YGEdgeBottom);
|
||||
Edge::Bottom);
|
||||
|
||||
if (node->hasMeasureFunc()) {
|
||||
measureNodeWithMeasureFunc(
|
||||
@@ -1868,7 +1867,7 @@ static void calculateLayoutImpl(
|
||||
// default to border + margin
|
||||
if (!isChildLeadingPosDefined ||
|
||||
yoga::isUndefined(
|
||||
child->getLayout().position[flexStartEdge(crossAxis)])) {
|
||||
child->getLayout().position(flexStartEdge(crossAxis)))) {
|
||||
child->setLayoutPosition(
|
||||
node->getInlineStartBorder(crossAxis, direction) +
|
||||
child->getInlineStartMargin(
|
||||
@@ -1981,7 +1980,7 @@ static void calculateLayoutImpl(
|
||||
}
|
||||
// And we apply the position
|
||||
child->setLayoutPosition(
|
||||
child->getLayout().position[flexStartEdge(crossAxis)] +
|
||||
child->getLayout().position(flexStartEdge(crossAxis)) +
|
||||
totalLineCrossDim + leadingCrossDim,
|
||||
flexStartEdge(crossAxis));
|
||||
}
|
||||
@@ -2190,7 +2189,7 @@ static void calculateLayoutImpl(
|
||||
FlexDirection::Column,
|
||||
direction,
|
||||
availableInnerCrossDim),
|
||||
YGEdgeTop);
|
||||
Edge::Top);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -2296,7 +2295,7 @@ static void calculateLayoutImpl(
|
||||
if (child->getStyle().positionType() != PositionType::Absolute) {
|
||||
child->setLayoutPosition(
|
||||
node->getLayout().measuredDimension(dimension(crossAxis)) -
|
||||
child->getLayout().position[flexStartEdge(crossAxis)] -
|
||||
child->getLayout().position(flexStartEdge(crossAxis)) -
|
||||
child->getLayout().measuredDimension(dimension(crossAxis)),
|
||||
flexStartEdge(crossAxis));
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@
|
||||
#include <yoga/debug/AssertFatal.h>
|
||||
#include <yoga/enums/Dimension.h>
|
||||
#include <yoga/enums/Direction.h>
|
||||
#include <yoga/enums/Edge.h>
|
||||
#include <yoga/enums/FlexDirection.h>
|
||||
|
||||
namespace facebook::yoga {
|
||||
@@ -48,80 +49,80 @@ inline FlexDirection resolveCrossDirection(
|
||||
: FlexDirection::Column;
|
||||
}
|
||||
|
||||
inline YGEdge flexStartEdge(const FlexDirection flexDirection) {
|
||||
inline Edge flexStartEdge(const FlexDirection flexDirection) {
|
||||
switch (flexDirection) {
|
||||
case FlexDirection::Column:
|
||||
return YGEdgeTop;
|
||||
return Edge::Top;
|
||||
case FlexDirection::ColumnReverse:
|
||||
return YGEdgeBottom;
|
||||
return Edge::Bottom;
|
||||
case FlexDirection::Row:
|
||||
return YGEdgeLeft;
|
||||
return Edge::Left;
|
||||
case FlexDirection::RowReverse:
|
||||
return YGEdgeRight;
|
||||
return Edge::Right;
|
||||
}
|
||||
|
||||
fatalWithMessage("Invalid FlexDirection");
|
||||
}
|
||||
|
||||
inline YGEdge flexEndEdge(const FlexDirection flexDirection) {
|
||||
inline Edge flexEndEdge(const FlexDirection flexDirection) {
|
||||
switch (flexDirection) {
|
||||
case FlexDirection::Column:
|
||||
return YGEdgeBottom;
|
||||
return Edge::Bottom;
|
||||
case FlexDirection::ColumnReverse:
|
||||
return YGEdgeTop;
|
||||
return Edge::Top;
|
||||
case FlexDirection::Row:
|
||||
return YGEdgeRight;
|
||||
return Edge::Right;
|
||||
case FlexDirection::RowReverse:
|
||||
return YGEdgeLeft;
|
||||
return Edge::Left;
|
||||
}
|
||||
|
||||
fatalWithMessage("Invalid FlexDirection");
|
||||
}
|
||||
|
||||
inline YGEdge inlineStartEdge(
|
||||
inline Edge inlineStartEdge(
|
||||
const FlexDirection flexDirection,
|
||||
const Direction direction) {
|
||||
if (isRow(flexDirection)) {
|
||||
return direction == Direction::RTL ? YGEdgeRight : YGEdgeLeft;
|
||||
return direction == Direction::RTL ? Edge::Right : Edge::Left;
|
||||
}
|
||||
|
||||
return YGEdgeTop;
|
||||
return Edge::Top;
|
||||
}
|
||||
|
||||
inline YGEdge inlineEndEdge(
|
||||
inline Edge inlineEndEdge(
|
||||
const FlexDirection flexDirection,
|
||||
const Direction direction) {
|
||||
if (isRow(flexDirection)) {
|
||||
return direction == Direction::RTL ? YGEdgeLeft : YGEdgeRight;
|
||||
return direction == Direction::RTL ? Edge::Left : Edge::Right;
|
||||
}
|
||||
|
||||
return YGEdgeBottom;
|
||||
return Edge::Bottom;
|
||||
}
|
||||
|
||||
/**
|
||||
* The physical edges that YGEdgeStart and YGEdgeEnd correspond to (e.g.
|
||||
* The physical edges that Edge::Start and Edge::End correspond to (e.g.
|
||||
* left/right) are soley dependent on the direction. However, there are cases
|
||||
* where we want the flex start/end edge (i.e. which edge is the start/end
|
||||
* for laying out flex items), which can be distinct from the corresponding
|
||||
* inline edge. In these cases we need to know which "relative edge"
|
||||
* (YGEdgeStart/YGEdgeEnd) corresponds to the said flex start/end edge as these
|
||||
* (Edge::Start/Edge::End) corresponds to the said flex start/end edge as these
|
||||
* relative edges can be used instead of physical ones when defining certain
|
||||
* attributes like border or padding.
|
||||
*/
|
||||
inline YGEdge flexStartRelativeEdge(
|
||||
inline Edge flexStartRelativeEdge(
|
||||
FlexDirection flexDirection,
|
||||
Direction direction) {
|
||||
const YGEdge leadLayoutEdge = inlineStartEdge(flexDirection, direction);
|
||||
const YGEdge leadFlexItemEdge = flexStartEdge(flexDirection);
|
||||
return leadLayoutEdge == leadFlexItemEdge ? YGEdgeStart : YGEdgeEnd;
|
||||
const Edge leadLayoutEdge = inlineStartEdge(flexDirection, direction);
|
||||
const Edge leadFlexItemEdge = flexStartEdge(flexDirection);
|
||||
return leadLayoutEdge == leadFlexItemEdge ? Edge::Start : Edge::End;
|
||||
}
|
||||
|
||||
inline YGEdge flexEndRelativeEdge(
|
||||
inline Edge flexEndRelativeEdge(
|
||||
FlexDirection flexDirection,
|
||||
Direction direction) {
|
||||
const YGEdge trailLayoutEdge = inlineEndEdge(flexDirection, direction);
|
||||
const YGEdge trailFlexItemEdge = flexEndEdge(flexDirection);
|
||||
return trailLayoutEdge == trailFlexItemEdge ? YGEdgeEnd : YGEdgeStart;
|
||||
const Edge trailLayoutEdge = inlineEndEdge(flexDirection, direction);
|
||||
const Edge trailFlexItemEdge = flexEndEdge(flexDirection);
|
||||
return trailLayoutEdge == trailFlexItemEdge ? Edge::End : Edge::Start;
|
||||
}
|
||||
|
||||
inline Dimension dimension(const FlexDirection flexDirection) {
|
||||
|
@@ -68,8 +68,8 @@ void roundLayoutResultsToPixelGrid(
|
||||
const double absoluteTop) {
|
||||
const auto pointScaleFactor = node->getConfig()->getPointScaleFactor();
|
||||
|
||||
const double nodeLeft = node->getLayout().position[YGEdgeLeft];
|
||||
const double nodeTop = node->getLayout().position[YGEdgeTop];
|
||||
const double nodeLeft = node->getLayout().position(Edge::Left);
|
||||
const double nodeTop = node->getLayout().position(Edge::Top);
|
||||
|
||||
const double nodeWidth = node->getLayout().dimension(Dimension::Width);
|
||||
const double nodeHeight = node->getLayout().dimension(Dimension::Height);
|
||||
@@ -87,11 +87,11 @@ void roundLayoutResultsToPixelGrid(
|
||||
|
||||
node->setLayoutPosition(
|
||||
roundValueToPixelGrid(nodeLeft, pointScaleFactor, false, textRounding),
|
||||
YGEdgeLeft);
|
||||
Edge::Left);
|
||||
|
||||
node->setLayoutPosition(
|
||||
roundValueToPixelGrid(nodeTop, pointScaleFactor, false, textRounding),
|
||||
YGEdgeTop);
|
||||
Edge::Top);
|
||||
|
||||
// We multiply dimension by scale factor and if the result is close to the
|
||||
// whole number, we don't have any fraction To verify if the result is close
|
||||
|
Reference in New Issue
Block a user