Replace dim and pos arrays (#1373)
Summary: X-link: https://github.com/facebook/react-native/pull/39397 Pull Request resolved: https://github.com/facebook/yoga/pull/1373 These are used to get the position origin edge from axis (same as leading edge), and dimension from axis. Replace them with function usage, so that we can call into them from other files than `CalculateLayout.cpp`, and so that we can later use scoped enums not implicitly convertible to ints. Reviewed By: rshest Differential Revision: D49134566 fbshipit-source-id: cb806539ba0733a5773c594713720d465987e469
This commit is contained in:
committed by
Facebook GitHub Bot
parent
a4f36bdb51
commit
62ba8ebb3d
@@ -50,16 +50,6 @@ bool calculateLayoutInternal(
|
|||||||
const uint32_t depth,
|
const uint32_t depth,
|
||||||
const uint32_t generationCount);
|
const uint32_t generationCount);
|
||||||
|
|
||||||
static const std::array<YGEdge, 4> pos = {{
|
|
||||||
YGEdgeTop,
|
|
||||||
YGEdgeBottom,
|
|
||||||
YGEdgeLeft,
|
|
||||||
YGEdgeRight,
|
|
||||||
}};
|
|
||||||
|
|
||||||
static const std::array<YGDimension, 4> dim = {
|
|
||||||
{YGDimensionHeight, YGDimensionHeight, YGDimensionWidth, YGDimensionWidth}};
|
|
||||||
|
|
||||||
static bool isBaselineLayout(const yoga::Node* node) {
|
static bool isBaselineLayout(const yoga::Node* node) {
|
||||||
if (isColumn(node->getStyle().flexDirection())) {
|
if (isColumn(node->getStyle().flexDirection())) {
|
||||||
return false;
|
return false;
|
||||||
@@ -83,7 +73,7 @@ static inline float dimensionWithMargin(
|
|||||||
const yoga::Node* const node,
|
const yoga::Node* const node,
|
||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float widthSize) {
|
const float widthSize) {
|
||||||
return node->getLayout().measuredDimensions[dim[axis]] +
|
return node->getLayout().measuredDimensions[dimension(axis)] +
|
||||||
(node->getLeadingMargin(axis, widthSize) +
|
(node->getLeadingMargin(axis, widthSize) +
|
||||||
node->getTrailingMargin(axis, widthSize))
|
node->getTrailingMargin(axis, widthSize))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -94,22 +84,22 @@ static inline bool styleDefinesDimension(
|
|||||||
const YGFlexDirection axis,
|
const YGFlexDirection axis,
|
||||||
const float ownerSize) {
|
const float ownerSize) {
|
||||||
bool isUndefined =
|
bool isUndefined =
|
||||||
yoga::isUndefined(node->getResolvedDimension(dim[axis]).value);
|
yoga::isUndefined(node->getResolvedDimension(dimension(axis)).value);
|
||||||
|
|
||||||
|
auto resolvedDimension = node->getResolvedDimension(dimension(axis));
|
||||||
return !(
|
return !(
|
||||||
node->getResolvedDimension(dim[axis]).unit == YGUnitAuto ||
|
resolvedDimension.unit == YGUnitAuto ||
|
||||||
node->getResolvedDimension(dim[axis]).unit == YGUnitUndefined ||
|
resolvedDimension.unit == YGUnitUndefined ||
|
||||||
(node->getResolvedDimension(dim[axis]).unit == YGUnitPoint &&
|
(resolvedDimension.unit == YGUnitPoint && !isUndefined &&
|
||||||
!isUndefined && node->getResolvedDimension(dim[axis]).value < 0.0f) ||
|
resolvedDimension.value < 0.0f) ||
|
||||||
(node->getResolvedDimension(dim[axis]).unit == YGUnitPercent &&
|
(resolvedDimension.unit == YGUnitPercent && !isUndefined &&
|
||||||
!isUndefined &&
|
(resolvedDimension.value < 0.0f || yoga::isUndefined(ownerSize))));
|
||||||
(node->getResolvedDimension(dim[axis]).value < 0.0f ||
|
|
||||||
yoga::isUndefined(ownerSize))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool isLayoutDimensionDefined(
|
static inline bool isLayoutDimensionDefined(
|
||||||
const yoga::Node* const node,
|
const yoga::Node* const node,
|
||||||
const YGFlexDirection axis) {
|
const YGFlexDirection axis) {
|
||||||
const float value = node->getLayout().measuredDimensions[dim[axis]];
|
const float value = node->getLayout().measuredDimensions[dimension(axis)];
|
||||||
return !yoga::isUndefined(value) && value >= 0.0f;
|
return !yoga::isUndefined(value) && value >= 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,10 +107,10 @@ static void setChildTrailingPosition(
|
|||||||
const yoga::Node* const node,
|
const yoga::Node* const node,
|
||||||
yoga::Node* const child,
|
yoga::Node* const child,
|
||||||
const YGFlexDirection axis) {
|
const YGFlexDirection axis) {
|
||||||
const float size = child->getLayout().measuredDimensions[dim[axis]];
|
const float size = child->getLayout().measuredDimensions[dimension(axis)];
|
||||||
child->setLayoutPosition(
|
child->setLayoutPosition(
|
||||||
node->getLayout().measuredDimensions[dim[axis]] - size -
|
node->getLayout().measuredDimensions[dimension(axis)] - size -
|
||||||
child->getLayout().position[pos[axis]],
|
child->getLayout().position[leadingEdge(axis)],
|
||||||
trailingEdge(axis));
|
trailingEdge(axis));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +123,7 @@ static void constrainMaxSizeForMode(
|
|||||||
float* size) {
|
float* size) {
|
||||||
const FloatOptional maxSize =
|
const FloatOptional maxSize =
|
||||||
yoga::resolveValue(
|
yoga::resolveValue(
|
||||||
node->getStyle().maxDimensions()[dim[axis]], ownerAxisSize) +
|
node->getStyle().maxDimensions()[dimension(axis)], ownerAxisSize) +
|
||||||
FloatOptional(node->getMarginForAxis(axis, ownerWidth));
|
FloatOptional(node->getMarginForAxis(axis, ownerWidth));
|
||||||
switch (*mode) {
|
switch (*mode) {
|
||||||
case YGMeasureModeExactly:
|
case YGMeasureModeExactly:
|
||||||
@@ -343,7 +333,7 @@ static void computeFlexBasisForChild(
|
|||||||
generationCount);
|
generationCount);
|
||||||
|
|
||||||
child->setLayoutComputedFlexBasis(FloatOptional(yoga::maxOrDefined(
|
child->setLayoutComputedFlexBasis(FloatOptional(yoga::maxOrDefined(
|
||||||
child->getLayout().measuredDimensions[dim[mainAxis]],
|
child->getLayout().measuredDimensions[dimension(mainAxis)],
|
||||||
paddingAndBorderForAxis(child, mainAxis, ownerWidth))));
|
paddingAndBorderForAxis(child, mainAxis, ownerWidth))));
|
||||||
}
|
}
|
||||||
child->setLayoutComputedFlexBasisGeneration(generationCount);
|
child->setLayoutComputedFlexBasisGeneration(generationCount);
|
||||||
@@ -495,8 +485,8 @@ static void layoutAbsoluteChild(
|
|||||||
if (child->isTrailingPosDefined(mainAxis) &&
|
if (child->isTrailingPosDefined(mainAxis) &&
|
||||||
!child->isLeadingPositionDefined(mainAxis)) {
|
!child->isLeadingPositionDefined(mainAxis)) {
|
||||||
child->setLayoutPosition(
|
child->setLayoutPosition(
|
||||||
node->getLayout().measuredDimensions[dim[mainAxis]] -
|
node->getLayout().measuredDimensions[dimension(mainAxis)] -
|
||||||
child->getLayout().measuredDimensions[dim[mainAxis]] -
|
child->getLayout().measuredDimensions[dimension(mainAxis)] -
|
||||||
node->getTrailingBorder(mainAxis) -
|
node->getTrailingBorder(mainAxis) -
|
||||||
child->getTrailingMargin(mainAxis, isMainAxisRow ? width : height)
|
child->getTrailingMargin(mainAxis, isMainAxisRow ? width : height)
|
||||||
.unwrap() -
|
.unwrap() -
|
||||||
@@ -507,16 +497,16 @@ static void layoutAbsoluteChild(
|
|||||||
!child->isLeadingPositionDefined(mainAxis) &&
|
!child->isLeadingPositionDefined(mainAxis) &&
|
||||||
node->getStyle().justifyContent() == YGJustifyCenter) {
|
node->getStyle().justifyContent() == YGJustifyCenter) {
|
||||||
child->setLayoutPosition(
|
child->setLayoutPosition(
|
||||||
(node->getLayout().measuredDimensions[dim[mainAxis]] -
|
(node->getLayout().measuredDimensions[dimension(mainAxis)] -
|
||||||
child->getLayout().measuredDimensions[dim[mainAxis]]) /
|
child->getLayout().measuredDimensions[dimension(mainAxis)]) /
|
||||||
2.0f,
|
2.0f,
|
||||||
leadingEdge(mainAxis));
|
leadingEdge(mainAxis));
|
||||||
} else if (
|
} else if (
|
||||||
!child->isLeadingPositionDefined(mainAxis) &&
|
!child->isLeadingPositionDefined(mainAxis) &&
|
||||||
node->getStyle().justifyContent() == YGJustifyFlexEnd) {
|
node->getStyle().justifyContent() == YGJustifyFlexEnd) {
|
||||||
child->setLayoutPosition(
|
child->setLayoutPosition(
|
||||||
(node->getLayout().measuredDimensions[dim[mainAxis]] -
|
(node->getLayout().measuredDimensions[dimension(mainAxis)] -
|
||||||
child->getLayout().measuredDimensions[dim[mainAxis]]),
|
child->getLayout().measuredDimensions[dimension(mainAxis)]),
|
||||||
leadingEdge(mainAxis));
|
leadingEdge(mainAxis));
|
||||||
} else if (
|
} else if (
|
||||||
node->getConfig()->isExperimentalFeatureEnabled(
|
node->getConfig()->isExperimentalFeatureEnabled(
|
||||||
@@ -524,13 +514,14 @@ static void layoutAbsoluteChild(
|
|||||||
child->isLeadingPositionDefined(mainAxis)) {
|
child->isLeadingPositionDefined(mainAxis)) {
|
||||||
child->setLayoutPosition(
|
child->setLayoutPosition(
|
||||||
child->getLeadingPosition(
|
child->getLeadingPosition(
|
||||||
mainAxis, node->getLayout().measuredDimensions[dim[mainAxis]])
|
mainAxis,
|
||||||
|
node->getLayout().measuredDimensions[dimension(mainAxis)])
|
||||||
.unwrap() +
|
.unwrap() +
|
||||||
node->getLeadingBorder(mainAxis) +
|
node->getLeadingBorder(mainAxis) +
|
||||||
child
|
child
|
||||||
->getLeadingMargin(
|
->getLeadingMargin(
|
||||||
mainAxis,
|
mainAxis,
|
||||||
node->getLayout().measuredDimensions[dim[mainAxis]])
|
node->getLayout().measuredDimensions[dimension(mainAxis)])
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
leadingEdge(mainAxis));
|
leadingEdge(mainAxis));
|
||||||
}
|
}
|
||||||
@@ -538,8 +529,8 @@ static void layoutAbsoluteChild(
|
|||||||
if (child->isTrailingPosDefined(crossAxis) &&
|
if (child->isTrailingPosDefined(crossAxis) &&
|
||||||
!child->isLeadingPositionDefined(crossAxis)) {
|
!child->isLeadingPositionDefined(crossAxis)) {
|
||||||
child->setLayoutPosition(
|
child->setLayoutPosition(
|
||||||
node->getLayout().measuredDimensions[dim[crossAxis]] -
|
node->getLayout().measuredDimensions[dimension(crossAxis)] -
|
||||||
child->getLayout().measuredDimensions[dim[crossAxis]] -
|
child->getLayout().measuredDimensions[dimension(crossAxis)] -
|
||||||
node->getTrailingBorder(crossAxis) -
|
node->getTrailingBorder(crossAxis) -
|
||||||
child->getTrailingMargin(crossAxis, isMainAxisRow ? height : width)
|
child->getTrailingMargin(crossAxis, isMainAxisRow ? height : width)
|
||||||
.unwrap() -
|
.unwrap() -
|
||||||
@@ -552,8 +543,8 @@ static void layoutAbsoluteChild(
|
|||||||
!child->isLeadingPositionDefined(crossAxis) &&
|
!child->isLeadingPositionDefined(crossAxis) &&
|
||||||
resolveChildAlignment(node, child) == YGAlignCenter) {
|
resolveChildAlignment(node, child) == YGAlignCenter) {
|
||||||
child->setLayoutPosition(
|
child->setLayoutPosition(
|
||||||
(node->getLayout().measuredDimensions[dim[crossAxis]] -
|
(node->getLayout().measuredDimensions[dimension(crossAxis)] -
|
||||||
child->getLayout().measuredDimensions[dim[crossAxis]]) /
|
child->getLayout().measuredDimensions[dimension(crossAxis)]) /
|
||||||
2.0f,
|
2.0f,
|
||||||
leadingEdge(crossAxis));
|
leadingEdge(crossAxis));
|
||||||
} else if (
|
} else if (
|
||||||
@@ -561,8 +552,8 @@ static void layoutAbsoluteChild(
|
|||||||
((resolveChildAlignment(node, child) == YGAlignFlexEnd) ^
|
((resolveChildAlignment(node, child) == YGAlignFlexEnd) ^
|
||||||
(node->getStyle().flexWrap() == YGWrapWrapReverse))) {
|
(node->getStyle().flexWrap() == YGWrapWrapReverse))) {
|
||||||
child->setLayoutPosition(
|
child->setLayoutPosition(
|
||||||
(node->getLayout().measuredDimensions[dim[crossAxis]] -
|
(node->getLayout().measuredDimensions[dimension(crossAxis)] -
|
||||||
child->getLayout().measuredDimensions[dim[crossAxis]]),
|
child->getLayout().measuredDimensions[dimension(crossAxis)]),
|
||||||
leadingEdge(crossAxis));
|
leadingEdge(crossAxis));
|
||||||
} else if (
|
} else if (
|
||||||
node->getConfig()->isExperimentalFeatureEnabled(
|
node->getConfig()->isExperimentalFeatureEnabled(
|
||||||
@@ -571,13 +562,13 @@ static void layoutAbsoluteChild(
|
|||||||
child->setLayoutPosition(
|
child->setLayoutPosition(
|
||||||
child->getLeadingPosition(
|
child->getLeadingPosition(
|
||||||
crossAxis,
|
crossAxis,
|
||||||
node->getLayout().measuredDimensions[dim[crossAxis]])
|
node->getLayout().measuredDimensions[dimension(crossAxis)])
|
||||||
.unwrap() +
|
.unwrap() +
|
||||||
node->getLeadingBorder(crossAxis) +
|
node->getLeadingBorder(crossAxis) +
|
||||||
child
|
child
|
||||||
->getLeadingMargin(
|
->getLeadingMargin(
|
||||||
crossAxis,
|
crossAxis,
|
||||||
node->getLayout().measuredDimensions[dim[crossAxis]])
|
node->getLayout().measuredDimensions[dimension(crossAxis)])
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
leadingEdge(crossAxis));
|
leadingEdge(crossAxis));
|
||||||
}
|
}
|
||||||
@@ -1026,12 +1017,12 @@ static float distributeFreeSpaceSecondPass(
|
|||||||
} else {
|
} else {
|
||||||
childCrossSize =
|
childCrossSize =
|
||||||
yoga::resolveValue(
|
yoga::resolveValue(
|
||||||
currentLineChild->getResolvedDimension(dim[crossAxis]),
|
currentLineChild->getResolvedDimension(dimension(crossAxis)),
|
||||||
availableInnerCrossDim)
|
availableInnerCrossDim)
|
||||||
.unwrap() +
|
.unwrap() +
|
||||||
marginCross;
|
marginCross;
|
||||||
const bool isLoosePercentageMeasurement =
|
const bool isLoosePercentageMeasurement =
|
||||||
currentLineChild->getResolvedDimension(dim[crossAxis]).unit ==
|
currentLineChild->getResolvedDimension(dimension(crossAxis)).unit ==
|
||||||
YGUnitPercent &&
|
YGUnitPercent &&
|
||||||
measureModeCrossDim != YGMeasureModeExactly;
|
measureModeCrossDim != YGMeasureModeExactly;
|
||||||
childCrossMeasureMode =
|
childCrossMeasureMode =
|
||||||
@@ -1280,9 +1271,9 @@ static void YGJustifyMainAxis(
|
|||||||
// remainingFreeSpace is 0 when min main dimension is not given
|
// remainingFreeSpace is 0 when min main dimension is not given
|
||||||
if (measureModeMainDim == YGMeasureModeAtMost &&
|
if (measureModeMainDim == YGMeasureModeAtMost &&
|
||||||
flexLine.layout.remainingFreeSpace > 0) {
|
flexLine.layout.remainingFreeSpace > 0) {
|
||||||
if (!style.minDimensions()[dim[mainAxis]].isUndefined() &&
|
if (!style.minDimensions()[dimension(mainAxis)].isUndefined() &&
|
||||||
!yoga::resolveValue(
|
!yoga::resolveValue(
|
||||||
style.minDimensions()[dim[mainAxis]], mainAxisownerSize)
|
style.minDimensions()[dimension(mainAxis)], mainAxisownerSize)
|
||||||
.isUndefined()) {
|
.isUndefined()) {
|
||||||
// This condition makes sure that if the size of main dimension(after
|
// This condition makes sure that if the size of main dimension(after
|
||||||
// considering child nodes main dim, leading and trailing padding etc)
|
// considering child nodes main dim, leading and trailing padding etc)
|
||||||
@@ -1293,7 +1284,7 @@ static void YGJustifyMainAxis(
|
|||||||
// can be laid out, it will exclude space consumed by padding and border.
|
// can be laid out, it will exclude space consumed by padding and border.
|
||||||
const float minAvailableMainDim =
|
const float minAvailableMainDim =
|
||||||
yoga::resolveValue(
|
yoga::resolveValue(
|
||||||
style.minDimensions()[dim[mainAxis]], mainAxisownerSize)
|
style.minDimensions()[dimension(mainAxis)], mainAxisownerSize)
|
||||||
.unwrap() -
|
.unwrap() -
|
||||||
leadingPaddingAndBorderMain - trailingPaddingAndBorderMain;
|
leadingPaddingAndBorderMain - trailingPaddingAndBorderMain;
|
||||||
const float occupiedSpaceByChildNodes =
|
const float occupiedSpaceByChildNodes =
|
||||||
@@ -1386,7 +1377,7 @@ static void YGJustifyMainAxis(
|
|||||||
.unwrap() +
|
.unwrap() +
|
||||||
node->getLeadingBorder(mainAxis) +
|
node->getLeadingBorder(mainAxis) +
|
||||||
child->getLeadingMargin(mainAxis, availableInnerWidth).unwrap(),
|
child->getLeadingMargin(mainAxis, availableInnerWidth).unwrap(),
|
||||||
pos[mainAxis]);
|
leadingEdge(mainAxis));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Now that we placed the element, we need to update the variables.
|
// Now that we placed the element, we need to update the variables.
|
||||||
@@ -1400,8 +1391,9 @@ static void YGJustifyMainAxis(
|
|||||||
|
|
||||||
if (performLayout) {
|
if (performLayout) {
|
||||||
child->setLayoutPosition(
|
child->setLayoutPosition(
|
||||||
childLayout.position[pos[mainAxis]] + flexLine.layout.mainDim,
|
childLayout.position[leadingEdge(mainAxis)] +
|
||||||
pos[mainAxis]);
|
flexLine.layout.mainDim,
|
||||||
|
leadingEdge(mainAxis));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (child->marginTrailingValue(mainAxis).unit == YGUnitAuto) {
|
if (child->marginTrailingValue(mainAxis).unit == YGUnitAuto) {
|
||||||
@@ -1455,9 +1447,9 @@ static void YGJustifyMainAxis(
|
|||||||
}
|
}
|
||||||
} else if (performLayout) {
|
} else if (performLayout) {
|
||||||
child->setLayoutPosition(
|
child->setLayoutPosition(
|
||||||
childLayout.position[pos[mainAxis]] +
|
childLayout.position[leadingEdge(mainAxis)] +
|
||||||
node->getLeadingBorder(mainAxis) + leadingMainDim,
|
node->getLeadingBorder(mainAxis) + leadingMainDim,
|
||||||
pos[mainAxis]);
|
leadingEdge(mainAxis));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1947,17 +1939,18 @@ static void calculateLayoutImpl(
|
|||||||
node->getLeadingBorder(crossAxis) +
|
node->getLeadingBorder(crossAxis) +
|
||||||
child->getLeadingMargin(crossAxis, availableInnerWidth)
|
child->getLeadingMargin(crossAxis, availableInnerWidth)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
pos[crossAxis]);
|
leadingEdge(crossAxis));
|
||||||
}
|
}
|
||||||
// If leading position is not defined or calculations result in Nan,
|
// If leading position is not defined or calculations result in Nan,
|
||||||
// default to border + margin
|
// default to border + margin
|
||||||
if (!isChildLeadingPosDefined ||
|
if (!isChildLeadingPosDefined ||
|
||||||
yoga::isUndefined(child->getLayout().position[pos[crossAxis]])) {
|
yoga::isUndefined(
|
||||||
|
child->getLayout().position[leadingEdge(crossAxis)])) {
|
||||||
child->setLayoutPosition(
|
child->setLayoutPosition(
|
||||||
node->getLeadingBorder(crossAxis) +
|
node->getLeadingBorder(crossAxis) +
|
||||||
child->getLeadingMargin(crossAxis, availableInnerWidth)
|
child->getLeadingMargin(crossAxis, availableInnerWidth)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
pos[crossAxis]);
|
leadingEdge(crossAxis));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
float leadingCrossDim = leadingPaddingAndBorderCross;
|
float leadingCrossDim = leadingPaddingAndBorderCross;
|
||||||
@@ -1978,7 +1971,7 @@ static void calculateLayoutImpl(
|
|||||||
if (!styleDefinesDimension(
|
if (!styleDefinesDimension(
|
||||||
child, crossAxis, availableInnerCrossDim)) {
|
child, crossAxis, availableInnerCrossDim)) {
|
||||||
float childMainSize =
|
float childMainSize =
|
||||||
child->getLayout().measuredDimensions[dim[mainAxis]];
|
child->getLayout().measuredDimensions[dimension(mainAxis)];
|
||||||
const auto& childStyle = child->getStyle();
|
const auto& childStyle = child->getStyle();
|
||||||
float childCrossSize = !childStyle.aspectRatio().isUndefined()
|
float childCrossSize = !childStyle.aspectRatio().isUndefined()
|
||||||
? child->getMarginForAxis(crossAxis, availableInnerWidth)
|
? child->getMarginForAxis(crossAxis, availableInnerWidth)
|
||||||
@@ -2069,9 +2062,9 @@ static void calculateLayoutImpl(
|
|||||||
}
|
}
|
||||||
// And we apply the position
|
// And we apply the position
|
||||||
child->setLayoutPosition(
|
child->setLayoutPosition(
|
||||||
child->getLayout().position[pos[crossAxis]] + totalLineCrossDim +
|
child->getLayout().position[leadingEdge(crossAxis)] +
|
||||||
leadingCrossDim,
|
totalLineCrossDim + leadingCrossDim,
|
||||||
pos[crossAxis]);
|
leadingEdge(crossAxis));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2148,7 +2141,7 @@ static void calculateLayoutImpl(
|
|||||||
if (isLayoutDimensionDefined(child, crossAxis)) {
|
if (isLayoutDimensionDefined(child, crossAxis)) {
|
||||||
lineHeight = yoga::maxOrDefined(
|
lineHeight = yoga::maxOrDefined(
|
||||||
lineHeight,
|
lineHeight,
|
||||||
child->getLayout().measuredDimensions[dim[crossAxis]] +
|
child->getLayout().measuredDimensions[dimension(crossAxis)] +
|
||||||
child->getMarginForAxis(crossAxis, availableInnerWidth)
|
child->getMarginForAxis(crossAxis, availableInnerWidth)
|
||||||
.unwrap());
|
.unwrap());
|
||||||
}
|
}
|
||||||
@@ -2191,7 +2184,7 @@ static void calculateLayoutImpl(
|
|||||||
currentLead +
|
currentLead +
|
||||||
child->getLeadingMargin(crossAxis, availableInnerWidth)
|
child->getLeadingMargin(crossAxis, availableInnerWidth)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
pos[crossAxis]);
|
leadingEdge(crossAxis));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case YGAlignFlexEnd: {
|
case YGAlignFlexEnd: {
|
||||||
@@ -2199,17 +2192,18 @@ static void calculateLayoutImpl(
|
|||||||
currentLead + lineHeight -
|
currentLead + lineHeight -
|
||||||
child->getTrailingMargin(crossAxis, availableInnerWidth)
|
child->getTrailingMargin(crossAxis, availableInnerWidth)
|
||||||
.unwrap() -
|
.unwrap() -
|
||||||
child->getLayout().measuredDimensions[dim[crossAxis]],
|
child->getLayout()
|
||||||
pos[crossAxis]);
|
.measuredDimensions[dimension(crossAxis)],
|
||||||
|
leadingEdge(crossAxis));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case YGAlignCenter: {
|
case YGAlignCenter: {
|
||||||
float childHeight =
|
float childHeight =
|
||||||
child->getLayout().measuredDimensions[dim[crossAxis]];
|
child->getLayout().measuredDimensions[dimension(crossAxis)];
|
||||||
|
|
||||||
child->setLayoutPosition(
|
child->setLayoutPosition(
|
||||||
currentLead + (lineHeight - childHeight) / 2,
|
currentLead + (lineHeight - childHeight) / 2,
|
||||||
pos[crossAxis]);
|
leadingEdge(crossAxis));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case YGAlignStretch: {
|
case YGAlignStretch: {
|
||||||
@@ -2217,7 +2211,7 @@ static void calculateLayoutImpl(
|
|||||||
currentLead +
|
currentLead +
|
||||||
child->getLeadingMargin(crossAxis, availableInnerWidth)
|
child->getLeadingMargin(crossAxis, availableInnerWidth)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
pos[crossAxis]);
|
leadingEdge(crossAxis));
|
||||||
|
|
||||||
// Remeasure child with the line height as it as been only
|
// Remeasure child with the line height as it as been only
|
||||||
// measured with the owners height yet.
|
// measured with the owners height yet.
|
||||||
@@ -2319,7 +2313,7 @@ static void calculateLayoutImpl(
|
|||||||
node->setLayoutMeasuredDimension(
|
node->setLayoutMeasuredDimension(
|
||||||
boundAxis(
|
boundAxis(
|
||||||
node, mainAxis, maxLineMainDim, mainAxisownerSize, ownerWidth),
|
node, mainAxis, maxLineMainDim, mainAxisownerSize, ownerWidth),
|
||||||
dim[mainAxis]);
|
dimension(mainAxis));
|
||||||
|
|
||||||
} else if (
|
} else if (
|
||||||
measureModeMainDim == YGMeasureModeAtMost &&
|
measureModeMainDim == YGMeasureModeAtMost &&
|
||||||
@@ -2335,7 +2329,7 @@ static void calculateLayoutImpl(
|
|||||||
mainAxisownerSize)
|
mainAxisownerSize)
|
||||||
.unwrap()),
|
.unwrap()),
|
||||||
paddingAndBorderAxisMain),
|
paddingAndBorderAxisMain),
|
||||||
dim[mainAxis]);
|
dimension(mainAxis));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (measureModeCrossDim == YGMeasureModeUndefined ||
|
if (measureModeCrossDim == YGMeasureModeUndefined ||
|
||||||
@@ -2350,7 +2344,7 @@ static void calculateLayoutImpl(
|
|||||||
totalLineCrossDim + paddingAndBorderAxisCross,
|
totalLineCrossDim + paddingAndBorderAxisCross,
|
||||||
crossAxisownerSize,
|
crossAxisownerSize,
|
||||||
ownerWidth),
|
ownerWidth),
|
||||||
dim[crossAxis]);
|
dimension(crossAxis));
|
||||||
|
|
||||||
} else if (
|
} else if (
|
||||||
measureModeCrossDim == YGMeasureModeAtMost &&
|
measureModeCrossDim == YGMeasureModeAtMost &&
|
||||||
@@ -2367,7 +2361,7 @@ static void calculateLayoutImpl(
|
|||||||
crossAxisownerSize)
|
crossAxisownerSize)
|
||||||
.unwrap()),
|
.unwrap()),
|
||||||
paddingAndBorderAxisCross),
|
paddingAndBorderAxisCross),
|
||||||
dim[crossAxis]);
|
dimension(crossAxis));
|
||||||
}
|
}
|
||||||
|
|
||||||
// As we only wrapped in normal direction yet, we need to reverse the
|
// As we only wrapped in normal direction yet, we need to reverse the
|
||||||
@@ -2377,10 +2371,10 @@ static void calculateLayoutImpl(
|
|||||||
const auto child = node->getChild(i);
|
const auto child = node->getChild(i);
|
||||||
if (child->getStyle().positionType() != YGPositionTypeAbsolute) {
|
if (child->getStyle().positionType() != YGPositionTypeAbsolute) {
|
||||||
child->setLayoutPosition(
|
child->setLayoutPosition(
|
||||||
node->getLayout().measuredDimensions[dim[crossAxis]] -
|
node->getLayout().measuredDimensions[dimension(crossAxis)] -
|
||||||
child->getLayout().position[pos[crossAxis]] -
|
child->getLayout().position[leadingEdge(crossAxis)] -
|
||||||
child->getLayout().measuredDimensions[dim[crossAxis]],
|
child->getLayout().measuredDimensions[dimension(crossAxis)],
|
||||||
pos[crossAxis]);
|
leadingEdge(crossAxis));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2767,9 +2761,9 @@ void calculateLayout(
|
|||||||
YGMeasureMode widthMeasureMode = YGMeasureModeUndefined;
|
YGMeasureMode widthMeasureMode = YGMeasureModeUndefined;
|
||||||
const auto& maxDimensions = node->getStyle().maxDimensions();
|
const auto& maxDimensions = node->getStyle().maxDimensions();
|
||||||
if (styleDefinesDimension(node, YGFlexDirectionRow, ownerWidth)) {
|
if (styleDefinesDimension(node, YGFlexDirectionRow, ownerWidth)) {
|
||||||
width =
|
width = (yoga::resolveValue(
|
||||||
(yoga::resolveValue(
|
node->getResolvedDimension(dimension(YGFlexDirectionRow)),
|
||||||
node->getResolvedDimension(dim[YGFlexDirectionRow]), ownerWidth) +
|
ownerWidth) +
|
||||||
node->getMarginForAxis(YGFlexDirectionRow, ownerWidth))
|
node->getMarginForAxis(YGFlexDirectionRow, ownerWidth))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
widthMeasureMode = YGMeasureModeExactly;
|
widthMeasureMode = YGMeasureModeExactly;
|
||||||
@@ -2788,7 +2782,7 @@ void calculateLayout(
|
|||||||
YGMeasureMode heightMeasureMode = YGMeasureModeUndefined;
|
YGMeasureMode heightMeasureMode = YGMeasureModeUndefined;
|
||||||
if (styleDefinesDimension(node, YGFlexDirectionColumn, ownerHeight)) {
|
if (styleDefinesDimension(node, YGFlexDirectionColumn, ownerHeight)) {
|
||||||
height = (yoga::resolveValue(
|
height = (yoga::resolveValue(
|
||||||
node->getResolvedDimension(dim[YGFlexDirectionColumn]),
|
node->getResolvedDimension(dimension(YGFlexDirectionColumn)),
|
||||||
ownerHeight) +
|
ownerHeight) +
|
||||||
node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth))
|
node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@@ -75,4 +75,19 @@ inline YGEdge trailingEdge(const YGFlexDirection flexDirection) {
|
|||||||
fatalWithMessage("Invalid YGFlexDirection");
|
fatalWithMessage("Invalid YGFlexDirection");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline YGDimension dimension(const YGFlexDirection flexDirection) {
|
||||||
|
switch (flexDirection) {
|
||||||
|
case YGFlexDirectionColumn:
|
||||||
|
return YGDimensionHeight;
|
||||||
|
case YGFlexDirectionColumnReverse:
|
||||||
|
return YGDimensionHeight;
|
||||||
|
case YGFlexDirectionRow:
|
||||||
|
return YGDimensionWidth;
|
||||||
|
case YGFlexDirectionRowReverse:
|
||||||
|
return YGDimensionWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
fatalWithMessage("Invalid YGFlexDirection");
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace facebook::yoga
|
} // namespace facebook::yoga
|
||||||
|
Reference in New Issue
Block a user