yoga::resolveValue -> Length::resolve (#1520)
Summary: X-link: https://github.com/facebook/react-native/pull/41939 Pull Request resolved: https://github.com/facebook/yoga/pull/1520 This code originates as `YGValueResolve`, used to compute a YGValue to a length in points, using a reference for 100%. This moves it to `Style::Length`, so we can encapsulate parts of it (for style value functions), and make the API more cohesive now that we can do C++ style OOP with it. Changelog: [Internal] Reviewed By: joevilches Differential Revision: D51796973 fbshipit-source-id: a7c359c7544f4bd2066a80d976dde67a0d16f1dd
This commit is contained in:
committed by
Facebook GitHub Bot
parent
192016a0a8
commit
ca4ecc044d
@@ -9,7 +9,6 @@
|
|||||||
#include <yoga/algorithm/Align.h>
|
#include <yoga/algorithm/Align.h>
|
||||||
#include <yoga/algorithm/BoundAxis.h>
|
#include <yoga/algorithm/BoundAxis.h>
|
||||||
#include <yoga/algorithm/CalculateLayout.h>
|
#include <yoga/algorithm/CalculateLayout.h>
|
||||||
#include <yoga/algorithm/ResolveValue.h>
|
|
||||||
|
|
||||||
namespace facebook::yoga {
|
namespace facebook::yoga {
|
||||||
|
|
||||||
@@ -323,9 +322,8 @@ void layoutAbsoluteChild(
|
|||||||
child->getMarginForAxis(FlexDirection::Column, containingBlockWidth);
|
child->getMarginForAxis(FlexDirection::Column, containingBlockWidth);
|
||||||
|
|
||||||
if (child->styleDefinesDimension(FlexDirection::Row, containingBlockWidth)) {
|
if (child->styleDefinesDimension(FlexDirection::Row, containingBlockWidth)) {
|
||||||
childWidth =
|
childWidth = child->getResolvedDimension(Dimension::Width)
|
||||||
yoga::resolveValue(
|
.resolve(containingBlockWidth)
|
||||||
child->getResolvedDimension(Dimension::Width), containingBlockWidth)
|
|
||||||
.unwrap() +
|
.unwrap() +
|
||||||
marginRow;
|
marginRow;
|
||||||
} else {
|
} else {
|
||||||
@@ -352,9 +350,8 @@ void layoutAbsoluteChild(
|
|||||||
|
|
||||||
if (child->styleDefinesDimension(
|
if (child->styleDefinesDimension(
|
||||||
FlexDirection::Column, containingBlockHeight)) {
|
FlexDirection::Column, containingBlockHeight)) {
|
||||||
childHeight = yoga::resolveValue(
|
childHeight = child->getResolvedDimension(Dimension::Height)
|
||||||
child->getResolvedDimension(Dimension::Height),
|
.resolve(containingBlockHeight)
|
||||||
containingBlockHeight)
|
|
||||||
.unwrap() +
|
.unwrap() +
|
||||||
marginColumn;
|
marginColumn;
|
||||||
} else {
|
} else {
|
||||||
|
@@ -8,7 +8,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <yoga/algorithm/FlexDirection.h>
|
#include <yoga/algorithm/FlexDirection.h>
|
||||||
#include <yoga/algorithm/ResolveValue.h>
|
|
||||||
#include <yoga/enums/Dimension.h>
|
#include <yoga/enums/Dimension.h>
|
||||||
#include <yoga/enums/FlexDirection.h>
|
#include <yoga/enums/FlexDirection.h>
|
||||||
#include <yoga/node/Node.h>
|
#include <yoga/node/Node.h>
|
||||||
@@ -36,15 +35,11 @@ inline FloatOptional boundAxisWithinMinAndMax(
|
|||||||
FloatOptional max;
|
FloatOptional max;
|
||||||
|
|
||||||
if (isColumn(axis)) {
|
if (isColumn(axis)) {
|
||||||
min = yoga::resolveValue(
|
min = node->getStyle().minDimension(Dimension::Height).resolve(axisSize);
|
||||||
node->getStyle().minDimension(Dimension::Height), axisSize);
|
max = node->getStyle().maxDimension(Dimension::Height).resolve(axisSize);
|
||||||
max = yoga::resolveValue(
|
|
||||||
node->getStyle().maxDimension(Dimension::Height), axisSize);
|
|
||||||
} else if (isRow(axis)) {
|
} else if (isRow(axis)) {
|
||||||
min = yoga::resolveValue(
|
min = node->getStyle().minDimension(Dimension::Width).resolve(axisSize);
|
||||||
node->getStyle().minDimension(Dimension::Width), axisSize);
|
max = node->getStyle().maxDimension(Dimension::Width).resolve(axisSize);
|
||||||
max = yoga::resolveValue(
|
|
||||||
node->getStyle().maxDimension(Dimension::Width), axisSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (max >= FloatOptional{0} && value > max) {
|
if (max >= FloatOptional{0} && value > max) {
|
||||||
|
@@ -22,7 +22,6 @@
|
|||||||
#include <yoga/algorithm/FlexDirection.h>
|
#include <yoga/algorithm/FlexDirection.h>
|
||||||
#include <yoga/algorithm/FlexLine.h>
|
#include <yoga/algorithm/FlexLine.h>
|
||||||
#include <yoga/algorithm/PixelGrid.h>
|
#include <yoga/algorithm/PixelGrid.h>
|
||||||
#include <yoga/algorithm/ResolveValue.h>
|
|
||||||
#include <yoga/algorithm/SizingMode.h>
|
#include <yoga/algorithm/SizingMode.h>
|
||||||
#include <yoga/debug/AssertFatal.h>
|
#include <yoga/debug/AssertFatal.h>
|
||||||
#include <yoga/debug/Log.h>
|
#include <yoga/debug/Log.h>
|
||||||
@@ -52,15 +51,14 @@ bool calculateLayoutInternal(
|
|||||||
const uint32_t generationCount);
|
const uint32_t generationCount);
|
||||||
|
|
||||||
static void constrainMaxSizeForMode(
|
static void constrainMaxSizeForMode(
|
||||||
const yoga::Node* const node,
|
const yoga::Node* node,
|
||||||
const enum FlexDirection axis,
|
FlexDirection axis,
|
||||||
const float ownerAxisSize,
|
float ownerAxisSize,
|
||||||
const float ownerWidth,
|
float ownerWidth,
|
||||||
SizingMode* mode,
|
/*in_out*/ SizingMode* mode,
|
||||||
float* size) {
|
/*in_out*/ float* size) {
|
||||||
const FloatOptional maxSize =
|
const FloatOptional maxSize =
|
||||||
yoga::resolveValue(
|
node->getStyle().maxDimension(dimension(axis)).resolve(ownerAxisSize) +
|
||||||
node->getStyle().maxDimension(dimension(axis)), ownerAxisSize) +
|
|
||||||
FloatOptional(node->getMarginForAxis(axis, ownerWidth));
|
FloatOptional(node->getMarginForAxis(axis, ownerWidth));
|
||||||
switch (*mode) {
|
switch (*mode) {
|
||||||
case SizingMode::StretchFit:
|
case SizingMode::StretchFit:
|
||||||
@@ -103,7 +101,7 @@ static void computeFlexBasisForChild(
|
|||||||
SizingMode childHeightSizingMode;
|
SizingMode childHeightSizingMode;
|
||||||
|
|
||||||
const FloatOptional resolvedFlexBasis =
|
const FloatOptional resolvedFlexBasis =
|
||||||
yoga::resolveValue(child->resolveFlexBasisPtr(), mainAxisownerSize);
|
child->resolveFlexBasisPtr().resolve(mainAxisownerSize);
|
||||||
const bool isRowStyleDimDefined =
|
const bool isRowStyleDimDefined =
|
||||||
child->styleDefinesDimension(FlexDirection::Row, ownerWidth);
|
child->styleDefinesDimension(FlexDirection::Row, ownerWidth);
|
||||||
const bool isColumnStyleDimDefined =
|
const bool isColumnStyleDimDefined =
|
||||||
@@ -125,16 +123,14 @@ static void computeFlexBasisForChild(
|
|||||||
paddingAndBorderForAxis(child, FlexDirection::Row, ownerWidth));
|
paddingAndBorderForAxis(child, FlexDirection::Row, ownerWidth));
|
||||||
|
|
||||||
child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
|
child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
|
||||||
yoga::resolveValue(
|
child->getResolvedDimension(Dimension::Width).resolve(ownerWidth),
|
||||||
child->getResolvedDimension(Dimension::Width), ownerWidth),
|
|
||||||
paddingAndBorder));
|
paddingAndBorder));
|
||||||
} else if (!isMainAxisRow && isColumnStyleDimDefined) {
|
} else if (!isMainAxisRow && isColumnStyleDimDefined) {
|
||||||
// The height is definite, so use that as the flex basis.
|
// The height is definite, so use that as the flex basis.
|
||||||
const FloatOptional paddingAndBorder = FloatOptional(
|
const FloatOptional paddingAndBorder = FloatOptional(
|
||||||
paddingAndBorderForAxis(child, FlexDirection::Column, ownerWidth));
|
paddingAndBorderForAxis(child, FlexDirection::Column, ownerWidth));
|
||||||
child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
|
child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
|
||||||
yoga::resolveValue(
|
child->getResolvedDimension(Dimension::Height).resolve(ownerHeight),
|
||||||
child->getResolvedDimension(Dimension::Height), ownerHeight),
|
|
||||||
paddingAndBorder));
|
paddingAndBorder));
|
||||||
} else {
|
} else {
|
||||||
// Compute the flex basis and hypothetical main size (i.e. the clamped flex
|
// Compute the flex basis and hypothetical main size (i.e. the clamped flex
|
||||||
@@ -149,17 +145,15 @@ static void computeFlexBasisForChild(
|
|||||||
child->getMarginForAxis(FlexDirection::Column, ownerWidth);
|
child->getMarginForAxis(FlexDirection::Column, ownerWidth);
|
||||||
|
|
||||||
if (isRowStyleDimDefined) {
|
if (isRowStyleDimDefined) {
|
||||||
childWidth =
|
childWidth = child->getResolvedDimension(Dimension::Width)
|
||||||
yoga::resolveValue(
|
.resolve(ownerWidth)
|
||||||
child->getResolvedDimension(Dimension::Width), ownerWidth)
|
|
||||||
.unwrap() +
|
.unwrap() +
|
||||||
marginRow;
|
marginRow;
|
||||||
childWidthSizingMode = SizingMode::StretchFit;
|
childWidthSizingMode = SizingMode::StretchFit;
|
||||||
}
|
}
|
||||||
if (isColumnStyleDimDefined) {
|
if (isColumnStyleDimDefined) {
|
||||||
childHeight =
|
childHeight = child->getResolvedDimension(Dimension::Height)
|
||||||
yoga::resolveValue(
|
.resolve(ownerHeight)
|
||||||
child->getResolvedDimension(Dimension::Height), ownerHeight)
|
|
||||||
.unwrap() +
|
.unwrap() +
|
||||||
marginColumn;
|
marginColumn;
|
||||||
childHeightSizingMode = SizingMode::StretchFit;
|
childHeightSizingMode = SizingMode::StretchFit;
|
||||||
@@ -477,13 +471,13 @@ static float calculateAvailableInnerDimension(
|
|||||||
// We want to make sure our available height does not violate min and max
|
// We want to make sure our available height does not violate min and max
|
||||||
// constraints
|
// constraints
|
||||||
const FloatOptional minDimensionOptional =
|
const FloatOptional minDimensionOptional =
|
||||||
yoga::resolveValue(node->getStyle().minDimension(dimension), ownerDim);
|
node->getStyle().minDimension(dimension).resolve(ownerDim);
|
||||||
const float minInnerDim = minDimensionOptional.isUndefined()
|
const float minInnerDim = minDimensionOptional.isUndefined()
|
||||||
? 0.0f
|
? 0.0f
|
||||||
: minDimensionOptional.unwrap() - paddingAndBorder;
|
: minDimensionOptional.unwrap() - paddingAndBorder;
|
||||||
|
|
||||||
const FloatOptional maxDimensionOptional =
|
const FloatOptional maxDimensionOptional =
|
||||||
yoga::resolveValue(node->getStyle().maxDimension(dimension), ownerDim);
|
node->getStyle().maxDimension(dimension).resolve(ownerDim);
|
||||||
|
|
||||||
const float maxInnerDim = maxDimensionOptional.isUndefined()
|
const float maxInnerDim = maxDimensionOptional.isUndefined()
|
||||||
? FLT_MAX
|
? FLT_MAX
|
||||||
@@ -700,9 +694,8 @@ static float distributeFreeSpaceSecondPass(
|
|||||||
: SizingMode::FitContent;
|
: SizingMode::FitContent;
|
||||||
} else {
|
} else {
|
||||||
childCrossSize =
|
childCrossSize =
|
||||||
yoga::resolveValue(
|
currentLineChild->getResolvedDimension(dimension(crossAxis))
|
||||||
currentLineChild->getResolvedDimension(dimension(crossAxis)),
|
.resolve(availableInnerCrossDim)
|
||||||
availableInnerCrossDim)
|
|
||||||
.unwrap() +
|
.unwrap() +
|
||||||
marginCross;
|
marginCross;
|
||||||
const bool isLoosePercentageMeasurement =
|
const bool isLoosePercentageMeasurement =
|
||||||
@@ -954,8 +947,8 @@ static void justifyMainAxis(
|
|||||||
if (sizingModeMainDim == SizingMode::FitContent &&
|
if (sizingModeMainDim == SizingMode::FitContent &&
|
||||||
flexLine.layout.remainingFreeSpace > 0) {
|
flexLine.layout.remainingFreeSpace > 0) {
|
||||||
if (style.minDimension(dimension(mainAxis)).isDefined() &&
|
if (style.minDimension(dimension(mainAxis)).isDefined() &&
|
||||||
yoga::resolveValue(
|
style.minDimension(dimension(mainAxis))
|
||||||
style.minDimension(dimension(mainAxis)), mainAxisownerSize)
|
.resolve(mainAxisownerSize)
|
||||||
.isDefined()) {
|
.isDefined()) {
|
||||||
// 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)
|
||||||
@@ -964,9 +957,8 @@ static void justifyMainAxis(
|
|||||||
|
|
||||||
// `minAvailableMainDim` denotes minimum available space in which child
|
// `minAvailableMainDim` denotes minimum available space in which child
|
||||||
// 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 = style.minDimension(dimension(mainAxis))
|
||||||
yoga::resolveValue(
|
.resolve(mainAxisownerSize)
|
||||||
style.minDimension(dimension(mainAxis)), mainAxisownerSize)
|
|
||||||
.unwrap() -
|
.unwrap() -
|
||||||
leadingPaddingAndBorderMain - trailingPaddingAndBorderMain;
|
leadingPaddingAndBorderMain - trailingPaddingAndBorderMain;
|
||||||
const float occupiedSpaceByChildNodes =
|
const float occupiedSpaceByChildNodes =
|
||||||
@@ -1446,20 +1438,16 @@ static void calculateLayoutImpl(
|
|||||||
if (sizingModeMainDim != SizingMode::StretchFit) {
|
if (sizingModeMainDim != SizingMode::StretchFit) {
|
||||||
const auto& style = node->getStyle();
|
const auto& style = node->getStyle();
|
||||||
const float minInnerWidth =
|
const float minInnerWidth =
|
||||||
yoga::resolveValue(style.minDimension(Dimension::Width), ownerWidth)
|
style.minDimension(Dimension::Width).resolve(ownerWidth).unwrap() -
|
||||||
.unwrap() -
|
|
||||||
paddingAndBorderAxisRow;
|
paddingAndBorderAxisRow;
|
||||||
const float maxInnerWidth =
|
const float maxInnerWidth =
|
||||||
yoga::resolveValue(style.maxDimension(Dimension::Width), ownerWidth)
|
style.maxDimension(Dimension::Width).resolve(ownerWidth).unwrap() -
|
||||||
.unwrap() -
|
|
||||||
paddingAndBorderAxisRow;
|
paddingAndBorderAxisRow;
|
||||||
const float minInnerHeight =
|
const float minInnerHeight =
|
||||||
yoga::resolveValue(style.minDimension(Dimension::Height), ownerHeight)
|
style.minDimension(Dimension::Height).resolve(ownerHeight).unwrap() -
|
||||||
.unwrap() -
|
|
||||||
paddingAndBorderAxisColumn;
|
paddingAndBorderAxisColumn;
|
||||||
const float maxInnerHeight =
|
const float maxInnerHeight =
|
||||||
yoga::resolveValue(style.maxDimension(Dimension::Height), ownerHeight)
|
style.maxDimension(Dimension::Height).resolve(ownerHeight).unwrap() -
|
||||||
.unwrap() -
|
|
||||||
paddingAndBorderAxisColumn;
|
paddingAndBorderAxisColumn;
|
||||||
|
|
||||||
const float minInnerMainDim =
|
const float minInnerMainDim =
|
||||||
@@ -1748,9 +1736,8 @@ static void calculateLayoutImpl(
|
|||||||
const float unclampedCrossDim = sizingModeCrossDim == SizingMode::StretchFit
|
const float unclampedCrossDim = sizingModeCrossDim == SizingMode::StretchFit
|
||||||
? availableInnerCrossDim + paddingAndBorderAxisCross
|
? availableInnerCrossDim + paddingAndBorderAxisCross
|
||||||
: node->styleDefinesDimension(crossAxis, crossAxisownerSize)
|
: node->styleDefinesDimension(crossAxis, crossAxisownerSize)
|
||||||
? yoga::resolveValue(
|
? node->getResolvedDimension(dimension(crossAxis))
|
||||||
node->getResolvedDimension(dimension(crossAxis)),
|
.resolve(crossAxisownerSize)
|
||||||
crossAxisownerSize)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
: totalLineCrossDim + paddingAndBorderAxisCross;
|
: totalLineCrossDim + paddingAndBorderAxisCross;
|
||||||
|
|
||||||
@@ -2442,17 +2429,15 @@ void calculateLayout(
|
|||||||
const auto& style = node->getStyle();
|
const auto& style = node->getStyle();
|
||||||
if (node->styleDefinesDimension(FlexDirection::Row, ownerWidth)) {
|
if (node->styleDefinesDimension(FlexDirection::Row, ownerWidth)) {
|
||||||
width =
|
width =
|
||||||
(yoga::resolveValue(
|
(node->getResolvedDimension(dimension(FlexDirection::Row))
|
||||||
node->getResolvedDimension(dimension(FlexDirection::Row)),
|
.resolve(ownerWidth)
|
||||||
ownerWidth)
|
|
||||||
.unwrap() +
|
.unwrap() +
|
||||||
node->getMarginForAxis(FlexDirection::Row, ownerWidth));
|
node->getMarginForAxis(FlexDirection::Row, ownerWidth));
|
||||||
widthSizingMode = SizingMode::StretchFit;
|
widthSizingMode = SizingMode::StretchFit;
|
||||||
} else if (yoga::resolveValue(
|
} else if (style.maxDimension(Dimension::Width)
|
||||||
style.maxDimension(Dimension::Width), ownerWidth)
|
.resolve(ownerWidth)
|
||||||
.isDefined()) {
|
.isDefined()) {
|
||||||
width = yoga::resolveValue(style.maxDimension(Dimension::Width), ownerWidth)
|
width = style.maxDimension(Dimension::Width).resolve(ownerWidth).unwrap();
|
||||||
.unwrap();
|
|
||||||
widthSizingMode = SizingMode::FitContent;
|
widthSizingMode = SizingMode::FitContent;
|
||||||
} else {
|
} else {
|
||||||
width = ownerWidth;
|
width = ownerWidth;
|
||||||
@@ -2464,18 +2449,16 @@ void calculateLayout(
|
|||||||
SizingMode heightSizingMode = SizingMode::MaxContent;
|
SizingMode heightSizingMode = SizingMode::MaxContent;
|
||||||
if (node->styleDefinesDimension(FlexDirection::Column, ownerHeight)) {
|
if (node->styleDefinesDimension(FlexDirection::Column, ownerHeight)) {
|
||||||
height =
|
height =
|
||||||
(yoga::resolveValue(
|
(node->getResolvedDimension(dimension(FlexDirection::Column))
|
||||||
node->getResolvedDimension(dimension(FlexDirection::Column)),
|
.resolve(ownerHeight)
|
||||||
ownerHeight)
|
|
||||||
.unwrap() +
|
.unwrap() +
|
||||||
node->getMarginForAxis(FlexDirection::Column, ownerWidth));
|
node->getMarginForAxis(FlexDirection::Column, ownerWidth));
|
||||||
heightSizingMode = SizingMode::StretchFit;
|
heightSizingMode = SizingMode::StretchFit;
|
||||||
} else if (yoga::resolveValue(
|
} else if (style.maxDimension(Dimension::Height)
|
||||||
style.maxDimension(Dimension::Height), ownerHeight)
|
.resolve(ownerHeight)
|
||||||
.isDefined()) {
|
.isDefined()) {
|
||||||
height =
|
height =
|
||||||
yoga::resolveValue(style.maxDimension(Dimension::Height), ownerHeight)
|
style.maxDimension(Dimension::Height).resolve(ownerHeight).unwrap();
|
||||||
.unwrap();
|
|
||||||
heightSizingMode = SizingMode::FitContent;
|
heightSizingMode = SizingMode::FitContent;
|
||||||
} else {
|
} else {
|
||||||
height = ownerHeight;
|
height = ownerHeight;
|
||||||
|
@@ -1,28 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
||||||
*
|
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <yoga/Yoga.h>
|
|
||||||
|
|
||||||
#include <yoga/numeric/FloatOptional.h>
|
|
||||||
#include <yoga/style/Style.h>
|
|
||||||
|
|
||||||
namespace facebook::yoga {
|
|
||||||
|
|
||||||
inline FloatOptional resolveValue(Style::Length length, float ownerSize) {
|
|
||||||
switch (length.unit()) {
|
|
||||||
case Unit::Point:
|
|
||||||
return length.value();
|
|
||||||
case Unit::Percent:
|
|
||||||
return FloatOptional{length.value().unwrap() * ownerSize * 0.01f};
|
|
||||||
default:
|
|
||||||
return FloatOptional{};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace facebook::yoga
|
|
@@ -10,7 +10,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <yoga/algorithm/FlexDirection.h>
|
#include <yoga/algorithm/FlexDirection.h>
|
||||||
#include <yoga/algorithm/ResolveValue.h>
|
|
||||||
#include <yoga/debug/AssertFatal.h>
|
#include <yoga/debug/AssertFatal.h>
|
||||||
#include <yoga/node/Node.h>
|
#include <yoga/node/Node.h>
|
||||||
#include <yoga/numeric/Comparison.h>
|
#include <yoga/numeric/Comparison.h>
|
||||||
@@ -166,7 +165,7 @@ float Node::getFlexStartPosition(
|
|||||||
flexStartEdge(axis))
|
flexStartEdge(axis))
|
||||||
: computeEdgeValueForColumn<&Style::position>(flexStartEdge(axis));
|
: computeEdgeValueForColumn<&Style::position>(flexStartEdge(axis));
|
||||||
|
|
||||||
return resolveValue(leadingPosition, axisSize).unwrapOrDefault(0.0f);
|
return leadingPosition.resolve(axisSize).unwrapOrDefault(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Node::getInlineStartPosition(
|
float Node::getInlineStartPosition(
|
||||||
@@ -178,7 +177,7 @@ float Node::getInlineStartPosition(
|
|||||||
? computeEdgeValueForRow<&Style::position>(Edge::Start, startEdge)
|
? computeEdgeValueForRow<&Style::position>(Edge::Start, startEdge)
|
||||||
: computeEdgeValueForColumn<&Style::position>(startEdge);
|
: computeEdgeValueForColumn<&Style::position>(startEdge);
|
||||||
|
|
||||||
return resolveValue(leadingPosition, axisSize).unwrapOrDefault(0.0f);
|
return leadingPosition.resolve(axisSize).unwrapOrDefault(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Node::getFlexEndPosition(
|
float Node::getFlexEndPosition(
|
||||||
@@ -191,7 +190,7 @@ float Node::getFlexEndPosition(
|
|||||||
flexEndEdge(axis))
|
flexEndEdge(axis))
|
||||||
: computeEdgeValueForColumn<&Style::position>(flexEndEdge(axis));
|
: computeEdgeValueForColumn<&Style::position>(flexEndEdge(axis));
|
||||||
|
|
||||||
return resolveValue(trailingPosition, axisSize).unwrapOrDefault(0.0f);
|
return trailingPosition.resolve(axisSize).unwrapOrDefault(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Node::getInlineEndPosition(
|
float Node::getInlineEndPosition(
|
||||||
@@ -203,7 +202,7 @@ float Node::getInlineEndPosition(
|
|||||||
? computeEdgeValueForRow<&Style::position>(Edge::End, endEdge)
|
? computeEdgeValueForRow<&Style::position>(Edge::End, endEdge)
|
||||||
: computeEdgeValueForColumn<&Style::position>(endEdge);
|
: computeEdgeValueForColumn<&Style::position>(endEdge);
|
||||||
|
|
||||||
return resolveValue(trailingPosition, axisSize).unwrapOrDefault(0.0f);
|
return trailingPosition.resolve(axisSize).unwrapOrDefault(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Node::getFlexStartMargin(
|
float Node::getFlexStartMargin(
|
||||||
@@ -216,7 +215,7 @@ float Node::getFlexStartMargin(
|
|||||||
flexStartEdge(axis))
|
flexStartEdge(axis))
|
||||||
: computeEdgeValueForColumn<&Style::margin>(flexStartEdge(axis));
|
: computeEdgeValueForColumn<&Style::margin>(flexStartEdge(axis));
|
||||||
|
|
||||||
return resolveValue(leadingMargin, widthSize).unwrapOrDefault(0.0f);
|
return leadingMargin.resolve(widthSize).unwrapOrDefault(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Node::getInlineStartMargin(
|
float Node::getInlineStartMargin(
|
||||||
@@ -228,7 +227,7 @@ float Node::getInlineStartMargin(
|
|||||||
? computeEdgeValueForRow<&Style::margin>(Edge::Start, startEdge)
|
? computeEdgeValueForRow<&Style::margin>(Edge::Start, startEdge)
|
||||||
: computeEdgeValueForColumn<&Style::margin>(startEdge);
|
: computeEdgeValueForColumn<&Style::margin>(startEdge);
|
||||||
|
|
||||||
return resolveValue(leadingMargin, widthSize).unwrapOrDefault(0.0f);
|
return leadingMargin.resolve(widthSize).unwrapOrDefault(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Node::getFlexEndMargin(
|
float Node::getFlexEndMargin(
|
||||||
@@ -241,7 +240,7 @@ float Node::getFlexEndMargin(
|
|||||||
flexEndEdge(axis))
|
flexEndEdge(axis))
|
||||||
: computeEdgeValueForColumn<&Style::margin>(flexEndEdge(axis));
|
: computeEdgeValueForColumn<&Style::margin>(flexEndEdge(axis));
|
||||||
|
|
||||||
return resolveValue(trailingMargin, widthSize).unwrapOrDefault(0.0f);
|
return trailingMargin.resolve(widthSize).unwrapOrDefault(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Node::getInlineEndMargin(
|
float Node::getInlineEndMargin(
|
||||||
@@ -253,7 +252,7 @@ float Node::getInlineEndMargin(
|
|||||||
? computeEdgeValueForRow<&Style::margin>(Edge::End, endEdge)
|
? computeEdgeValueForRow<&Style::margin>(Edge::End, endEdge)
|
||||||
: computeEdgeValueForColumn<&Style::margin>(endEdge);
|
: computeEdgeValueForColumn<&Style::margin>(endEdge);
|
||||||
|
|
||||||
return resolveValue(trailingMargin, widthSize).unwrapOrDefault(0.0f);
|
return trailingMargin.resolve(widthSize).unwrapOrDefault(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Node::getInlineStartBorder(FlexDirection axis, Direction direction)
|
float Node::getInlineStartBorder(FlexDirection axis, Direction direction)
|
||||||
@@ -304,7 +303,7 @@ float Node::getInlineStartPadding(
|
|||||||
? computeEdgeValueForRow<&Style::padding>(Edge::Start, startEdge)
|
? computeEdgeValueForRow<&Style::padding>(Edge::Start, startEdge)
|
||||||
: computeEdgeValueForColumn<&Style::padding>(startEdge);
|
: computeEdgeValueForColumn<&Style::padding>(startEdge);
|
||||||
|
|
||||||
return maxOrDefined(resolveValue(leadingPadding, widthSize).unwrap(), 0.0f);
|
return maxOrDefined(leadingPadding.resolve(widthSize).unwrap(), 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Node::getFlexStartPadding(
|
float Node::getFlexStartPadding(
|
||||||
@@ -317,7 +316,7 @@ float Node::getFlexStartPadding(
|
|||||||
flexStartEdge(axis))
|
flexStartEdge(axis))
|
||||||
: computeEdgeValueForColumn<&Style::padding>(flexStartEdge(axis));
|
: computeEdgeValueForColumn<&Style::padding>(flexStartEdge(axis));
|
||||||
|
|
||||||
return maxOrDefined(resolveValue(leadingPadding, widthSize).unwrap(), 0.0f);
|
return maxOrDefined(leadingPadding.resolve(widthSize).unwrap(), 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Node::getInlineEndPadding(
|
float Node::getInlineEndPadding(
|
||||||
@@ -329,7 +328,7 @@ float Node::getInlineEndPadding(
|
|||||||
? computeEdgeValueForRow<&Style::padding>(Edge::End, endEdge)
|
? computeEdgeValueForRow<&Style::padding>(Edge::End, endEdge)
|
||||||
: computeEdgeValueForColumn<&Style::padding>(endEdge);
|
: computeEdgeValueForColumn<&Style::padding>(endEdge);
|
||||||
|
|
||||||
return maxOrDefined(resolveValue(trailingPadding, widthSize).unwrap(), 0.0f);
|
return maxOrDefined(trailingPadding.resolve(widthSize).unwrap(), 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Node::getFlexEndPadding(
|
float Node::getFlexEndPadding(
|
||||||
@@ -342,7 +341,7 @@ float Node::getFlexEndPadding(
|
|||||||
flexEndEdge(axis))
|
flexEndEdge(axis))
|
||||||
: computeEdgeValueForColumn<&Style::padding>(flexEndEdge(axis));
|
: computeEdgeValueForColumn<&Style::padding>(flexEndEdge(axis));
|
||||||
|
|
||||||
return maxOrDefined(resolveValue(trailingPadding, widthSize).unwrap(), 0.0f);
|
return maxOrDefined(trailingPadding.resolve(widthSize).unwrap(), 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Node::getInlineStartPaddingAndBorder(
|
float Node::getInlineStartPaddingAndBorder(
|
||||||
@@ -393,7 +392,7 @@ float Node::getGapForAxis(FlexDirection axis) const {
|
|||||||
auto gap = isRow(axis) ? style_.resolveColumnGap() : style_.resolveRowGap();
|
auto gap = isRow(axis) ? style_.resolveColumnGap() : style_.resolveRowGap();
|
||||||
// TODO: Validate percentage gap, and expose ability to set percentage to
|
// TODO: Validate percentage gap, and expose ability to set percentage to
|
||||||
// public API
|
// public API
|
||||||
return maxOrDefined(resolveValue(gap, 0.0f /*ownerSize*/).unwrap(), 0.0f);
|
return maxOrDefined(gap.resolve(0.0f /*ownerSize*/).unwrap(), 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
YGSize Node::measure(
|
YGSize Node::measure(
|
||||||
|
@@ -71,6 +71,17 @@ class StyleLength {
|
|||||||
return unit_;
|
return unit_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr FloatOptional resolve(float referenceLength) {
|
||||||
|
switch (unit_) {
|
||||||
|
case Unit::Point:
|
||||||
|
return value_;
|
||||||
|
case Unit::Percent:
|
||||||
|
return FloatOptional{value_.unwrap() * referenceLength * 0.01f};
|
||||||
|
default:
|
||||||
|
return FloatOptional{};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
explicit constexpr operator YGValue() const {
|
explicit constexpr operator YGValue() const {
|
||||||
return YGValue{value_.unwrap(), unscopedEnum(unit_)};
|
return YGValue{value_.unwrap(), unscopedEnum(unit_)};
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user