C++ style enums 7/N: MeasureMode (#1389)

Summary:
X-link: https://github.com/facebook/react-native/pull/39452

Pull Request resolved: https://github.com/facebook/yoga/pull/1389

This converts usages of YGMeasureMode to MeasureMode

Reviewed By: rozele

Differential Revision: D49271165

fbshipit-source-id: 273c9ed0a61c3965e469548d29d37e4566c974dc
This commit is contained in:
Nick Gerleman
2023-09-14 23:06:34 -07:00
committed by Facebook GitHub Bot
parent 383b325d06
commit ed406f0b55
8 changed files with 181 additions and 180 deletions

View File

@@ -38,7 +38,7 @@ TEST(Node, measure_with_measure_fn) {
}); });
ASSERT_EQ( ASSERT_EQ(
n.measure(23, YGMeasureModeExactly, 24, YGMeasureModeAtMost), n.measure(23, MeasureMode::Exactly, 24, MeasureMode::AtMost),
(YGSize{23, 12})); (YGSize{23, 12}));
} }

View File

@@ -905,13 +905,13 @@ bool YGNodeCanUseCachedMeasurement(
float marginColumn, float marginColumn,
YGConfigRef config) { YGConfigRef config) {
return yoga::canUseCachedMeasurement( return yoga::canUseCachedMeasurement(
widthMode, scopedEnum(widthMode),
availableWidth, availableWidth,
heightMode, scopedEnum(heightMode),
availableHeight, availableHeight,
lastWidthMode, scopedEnum(lastWidthMode),
lastAvailableWidth, lastAvailableWidth,
lastHeightMode, scopedEnum(lastHeightMode),
lastAvailableHeight, lastAvailableHeight,
lastComputedWidth, lastComputedWidth,
lastComputedHeight, lastComputedHeight,

View File

@@ -5,8 +5,6 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
#include <yoga/Yoga.h>
#include <yoga/algorithm/Cache.h> #include <yoga/algorithm/Cache.h>
#include <yoga/algorithm/PixelGrid.h> #include <yoga/algorithm/PixelGrid.h>
#include <yoga/numeric/Comparison.h> #include <yoga/numeric/Comparison.h>
@@ -14,43 +12,43 @@
namespace facebook::yoga { namespace facebook::yoga {
static inline bool sizeIsExactAndMatchesOldMeasuredSize( static inline bool sizeIsExactAndMatchesOldMeasuredSize(
YGMeasureMode sizeMode, MeasureMode sizeMode,
float size, float size,
float lastComputedSize) { float lastComputedSize) {
return sizeMode == YGMeasureModeExactly && return sizeMode == MeasureMode::Exactly &&
yoga::inexactEquals(size, lastComputedSize); yoga::inexactEquals(size, lastComputedSize);
} }
static inline bool oldSizeIsUnspecifiedAndStillFits( static inline bool oldSizeIsUnspecifiedAndStillFits(
YGMeasureMode sizeMode, MeasureMode sizeMode,
float size, float size,
YGMeasureMode lastSizeMode, MeasureMode lastSizeMode,
float lastComputedSize) { float lastComputedSize) {
return sizeMode == YGMeasureModeAtMost && return sizeMode == MeasureMode::AtMost &&
lastSizeMode == YGMeasureModeUndefined && lastSizeMode == MeasureMode::Undefined &&
(size >= lastComputedSize || yoga::inexactEquals(size, lastComputedSize)); (size >= lastComputedSize || yoga::inexactEquals(size, lastComputedSize));
} }
static inline bool newMeasureSizeIsStricterAndStillValid( static inline bool newMeasureSizeIsStricterAndStillValid(
YGMeasureMode sizeMode, MeasureMode sizeMode,
float size, float size,
YGMeasureMode lastSizeMode, MeasureMode lastSizeMode,
float lastSize, float lastSize,
float lastComputedSize) { float lastComputedSize) {
return lastSizeMode == YGMeasureModeAtMost && return lastSizeMode == MeasureMode::AtMost &&
sizeMode == YGMeasureModeAtMost && !std::isnan(lastSize) && sizeMode == MeasureMode::AtMost && !std::isnan(lastSize) &&
!std::isnan(size) && !std::isnan(lastComputedSize) && lastSize > size && !std::isnan(size) && !std::isnan(lastComputedSize) && lastSize > size &&
(lastComputedSize <= size || yoga::inexactEquals(size, lastComputedSize)); (lastComputedSize <= size || yoga::inexactEquals(size, lastComputedSize));
} }
bool canUseCachedMeasurement( bool canUseCachedMeasurement(
const YGMeasureMode widthMode, const MeasureMode widthMode,
const float availableWidth, const float availableWidth,
const YGMeasureMode heightMode, const MeasureMode heightMode,
const float availableHeight, const float availableHeight,
const YGMeasureMode lastWidthMode, const MeasureMode lastWidthMode,
const float lastAvailableWidth, const float lastAvailableWidth,
const YGMeasureMode lastHeightMode, const MeasureMode lastHeightMode,
const float lastAvailableHeight, const float lastAvailableHeight,
const float lastComputedWidth, const float lastComputedWidth,
const float lastComputedHeight, const float lastComputedHeight,

View File

@@ -7,19 +7,19 @@
#pragma once #pragma once
#include <yoga/Yoga.h>
#include <yoga/config/Config.h> #include <yoga/config/Config.h>
#include <yoga/enums/MeasureMode.h>
namespace facebook::yoga { namespace facebook::yoga {
bool canUseCachedMeasurement( bool canUseCachedMeasurement(
YGMeasureMode widthMode, MeasureMode widthMode,
float availableWidth, float availableWidth,
YGMeasureMode heightMode, MeasureMode heightMode,
float availableHeight, float availableHeight,
YGMeasureMode lastWidthMode, MeasureMode lastWidthMode,
float lastAvailableWidth, float lastAvailableWidth,
YGMeasureMode lastHeightMode, MeasureMode lastHeightMode,
float lastAvailableHeight, float lastAvailableHeight,
float lastComputedWidth, float lastComputedWidth,
float lastComputedHeight, float lastComputedHeight,

View File

@@ -39,8 +39,8 @@ bool calculateLayoutInternal(
const float availableWidth, const float availableWidth,
const float availableHeight, const float availableHeight,
const YGDirection ownerDirection, const YGDirection ownerDirection,
const YGMeasureMode widthMeasureMode, const MeasureMode widthMeasureMode,
const YGMeasureMode heightMeasureMode, const MeasureMode heightMeasureMode,
const float ownerWidth, const float ownerWidth,
const float ownerHeight, const float ownerHeight,
const bool performLayout, const bool performLayout,
@@ -99,22 +99,22 @@ static void constrainMaxSizeForMode(
const enum YGFlexDirection axis, const enum YGFlexDirection axis,
const float ownerAxisSize, const float ownerAxisSize,
const float ownerWidth, const float ownerWidth,
YGMeasureMode* mode, MeasureMode* mode,
float* size) { float* size) {
const FloatOptional maxSize = const FloatOptional maxSize =
yoga::resolveValue( yoga::resolveValue(
node->getStyle().maxDimensions()[dimension(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 MeasureMode::Exactly:
case YGMeasureModeAtMost: case MeasureMode::AtMost:
*size = (maxSize.isUndefined() || *size < maxSize.unwrap()) *size = (maxSize.isUndefined() || *size < maxSize.unwrap())
? *size ? *size
: maxSize.unwrap(); : maxSize.unwrap();
break; break;
case YGMeasureModeUndefined: case MeasureMode::Undefined:
if (!maxSize.isUndefined()) { if (!maxSize.isUndefined()) {
*mode = YGMeasureModeAtMost; *mode = MeasureMode::AtMost;
*size = maxSize.unwrap(); *size = maxSize.unwrap();
} }
break; break;
@@ -125,11 +125,11 @@ static void computeFlexBasisForChild(
const yoga::Node* const node, const yoga::Node* const node,
yoga::Node* const child, yoga::Node* const child,
const float width, const float width,
const YGMeasureMode widthMode, const MeasureMode widthMode,
const float height, const float height,
const float ownerWidth, const float ownerWidth,
const float ownerHeight, const float ownerHeight,
const YGMeasureMode heightMode, const MeasureMode heightMode,
const YGDirection direction, const YGDirection direction,
LayoutData& layoutMarkerData, LayoutData& layoutMarkerData,
const uint32_t depth, const uint32_t depth,
@@ -142,8 +142,8 @@ static void computeFlexBasisForChild(
float childWidth; float childWidth;
float childHeight; float childHeight;
YGMeasureMode childWidthMeasureMode; MeasureMode childWidthMeasureMode;
YGMeasureMode childHeightMeasureMode; MeasureMode childHeightMeasureMode;
const FloatOptional resolvedFlexBasis = const FloatOptional resolvedFlexBasis =
yoga::resolveValue(child->resolveFlexBasisPtr(), mainAxisownerSize); yoga::resolveValue(child->resolveFlexBasisPtr(), mainAxisownerSize);
@@ -184,8 +184,8 @@ static void computeFlexBasisForChild(
// basis). // basis).
childWidth = YGUndefined; childWidth = YGUndefined;
childHeight = YGUndefined; childHeight = YGUndefined;
childWidthMeasureMode = YGMeasureModeUndefined; childWidthMeasureMode = MeasureMode::Undefined;
childHeightMeasureMode = YGMeasureModeUndefined; childHeightMeasureMode = MeasureMode::Undefined;
auto marginRow = auto marginRow =
child->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap(); child->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap();
@@ -198,7 +198,7 @@ static void computeFlexBasisForChild(
child->getResolvedDimensions()[YGDimensionWidth], ownerWidth) child->getResolvedDimensions()[YGDimensionWidth], ownerWidth)
.unwrap() + .unwrap() +
marginRow; marginRow;
childWidthMeasureMode = YGMeasureModeExactly; childWidthMeasureMode = MeasureMode::Exactly;
} }
if (isColumnStyleDimDefined) { if (isColumnStyleDimDefined) {
childHeight = childHeight =
@@ -206,7 +206,7 @@ static void computeFlexBasisForChild(
child->getResolvedDimensions()[YGDimensionHeight], ownerHeight) child->getResolvedDimensions()[YGDimensionHeight], ownerHeight)
.unwrap() + .unwrap() +
marginColumn; marginColumn;
childHeightMeasureMode = YGMeasureModeExactly; childHeightMeasureMode = MeasureMode::Exactly;
} }
// The W3C spec doesn't say anything about the 'overflow' property, but all // The W3C spec doesn't say anything about the 'overflow' property, but all
@@ -215,7 +215,7 @@ static void computeFlexBasisForChild(
node->getStyle().overflow() != YGOverflowScroll) { node->getStyle().overflow() != YGOverflowScroll) {
if (yoga::isUndefined(childWidth) && !yoga::isUndefined(width)) { if (yoga::isUndefined(childWidth) && !yoga::isUndefined(width)) {
childWidth = width; childWidth = width;
childWidthMeasureMode = YGMeasureModeAtMost; childWidthMeasureMode = MeasureMode::AtMost;
} }
} }
@@ -223,21 +223,21 @@ static void computeFlexBasisForChild(
node->getStyle().overflow() != YGOverflowScroll) { node->getStyle().overflow() != YGOverflowScroll) {
if (yoga::isUndefined(childHeight) && !yoga::isUndefined(height)) { if (yoga::isUndefined(childHeight) && !yoga::isUndefined(height)) {
childHeight = height; childHeight = height;
childHeightMeasureMode = YGMeasureModeAtMost; childHeightMeasureMode = MeasureMode::AtMost;
} }
} }
const auto& childStyle = child->getStyle(); const auto& childStyle = child->getStyle();
if (!childStyle.aspectRatio().isUndefined()) { if (!childStyle.aspectRatio().isUndefined()) {
if (!isMainAxisRow && childWidthMeasureMode == YGMeasureModeExactly) { if (!isMainAxisRow && childWidthMeasureMode == MeasureMode::Exactly) {
childHeight = marginColumn + childHeight = marginColumn +
(childWidth - marginRow) / childStyle.aspectRatio().unwrap(); (childWidth - marginRow) / childStyle.aspectRatio().unwrap();
childHeightMeasureMode = YGMeasureModeExactly; childHeightMeasureMode = MeasureMode::Exactly;
} else if ( } else if (
isMainAxisRow && childHeightMeasureMode == YGMeasureModeExactly) { isMainAxisRow && childHeightMeasureMode == MeasureMode::Exactly) {
childWidth = marginRow + childWidth = marginRow +
(childHeight - marginColumn) * childStyle.aspectRatio().unwrap(); (childHeight - marginColumn) * childStyle.aspectRatio().unwrap();
childWidthMeasureMode = YGMeasureModeExactly; childWidthMeasureMode = MeasureMode::Exactly;
} }
} }
@@ -245,35 +245,35 @@ static void computeFlexBasisForChild(
// the cross axis to be measured exactly with the available inner width // the cross axis to be measured exactly with the available inner width
const bool hasExactWidth = const bool hasExactWidth =
!yoga::isUndefined(width) && widthMode == YGMeasureModeExactly; !yoga::isUndefined(width) && widthMode == MeasureMode::Exactly;
const bool childWidthStretch = const bool childWidthStretch =
resolveChildAlignment(node, child) == YGAlignStretch && resolveChildAlignment(node, child) == YGAlignStretch &&
childWidthMeasureMode != YGMeasureModeExactly; childWidthMeasureMode != MeasureMode::Exactly;
if (!isMainAxisRow && !isRowStyleDimDefined && hasExactWidth && if (!isMainAxisRow && !isRowStyleDimDefined && hasExactWidth &&
childWidthStretch) { childWidthStretch) {
childWidth = width; childWidth = width;
childWidthMeasureMode = YGMeasureModeExactly; childWidthMeasureMode = MeasureMode::Exactly;
if (!childStyle.aspectRatio().isUndefined()) { if (!childStyle.aspectRatio().isUndefined()) {
childHeight = childHeight =
(childWidth - marginRow) / childStyle.aspectRatio().unwrap(); (childWidth - marginRow) / childStyle.aspectRatio().unwrap();
childHeightMeasureMode = YGMeasureModeExactly; childHeightMeasureMode = MeasureMode::Exactly;
} }
} }
const bool hasExactHeight = const bool hasExactHeight =
!yoga::isUndefined(height) && heightMode == YGMeasureModeExactly; !yoga::isUndefined(height) && heightMode == MeasureMode::Exactly;
const bool childHeightStretch = const bool childHeightStretch =
resolveChildAlignment(node, child) == YGAlignStretch && resolveChildAlignment(node, child) == YGAlignStretch &&
childHeightMeasureMode != YGMeasureModeExactly; childHeightMeasureMode != MeasureMode::Exactly;
if (isMainAxisRow && !isColumnStyleDimDefined && hasExactHeight && if (isMainAxisRow && !isColumnStyleDimDefined && hasExactHeight &&
childHeightStretch) { childHeightStretch) {
childHeight = height; childHeight = height;
childHeightMeasureMode = YGMeasureModeExactly; childHeightMeasureMode = MeasureMode::Exactly;
if (!childStyle.aspectRatio().isUndefined()) { if (!childStyle.aspectRatio().isUndefined()) {
childWidth = childWidth =
(childHeight - marginColumn) * childStyle.aspectRatio().unwrap(); (childHeight - marginColumn) * childStyle.aspectRatio().unwrap();
childWidthMeasureMode = YGMeasureModeExactly; childWidthMeasureMode = MeasureMode::Exactly;
} }
} }
@@ -319,7 +319,7 @@ static void layoutAbsoluteChild(
const yoga::Node* const node, const yoga::Node* const node,
yoga::Node* const child, yoga::Node* const child,
const float width, const float width,
const YGMeasureMode widthMode, const MeasureMode widthMode,
const float height, const float height,
const YGDirection direction, const YGDirection direction,
LayoutData& layoutMarkerData, LayoutData& layoutMarkerData,
@@ -332,8 +332,8 @@ static void layoutAbsoluteChild(
float childWidth = YGUndefined; float childWidth = YGUndefined;
float childHeight = YGUndefined; float childHeight = YGUndefined;
YGMeasureMode childWidthMeasureMode = YGMeasureModeUndefined; MeasureMode childWidthMeasureMode = MeasureMode::Undefined;
YGMeasureMode childHeightMeasureMode = YGMeasureModeUndefined; MeasureMode childHeightMeasureMode = MeasureMode::Undefined;
auto marginRow = child->getMarginForAxis(YGFlexDirectionRow, width).unwrap(); auto marginRow = child->getMarginForAxis(YGFlexDirectionRow, width).unwrap();
auto marginColumn = auto marginColumn =
@@ -400,21 +400,21 @@ static void layoutAbsoluteChild(
// If we're still missing one or the other dimension, measure the content. // If we're still missing one or the other dimension, measure the content.
if (yoga::isUndefined(childWidth) || yoga::isUndefined(childHeight)) { if (yoga::isUndefined(childWidth) || yoga::isUndefined(childHeight)) {
childWidthMeasureMode = yoga::isUndefined(childWidth) childWidthMeasureMode = yoga::isUndefined(childWidth)
? YGMeasureModeUndefined ? MeasureMode::Undefined
: YGMeasureModeExactly; : MeasureMode::Exactly;
childHeightMeasureMode = yoga::isUndefined(childHeight) childHeightMeasureMode = yoga::isUndefined(childHeight)
? YGMeasureModeUndefined ? MeasureMode::Undefined
: YGMeasureModeExactly; : MeasureMode::Exactly;
// If the size of the owner is defined then try to constrain the absolute // If the size of the owner is defined then try to constrain the absolute
// child to that size as well. This allows text within the absolute child to // child to that size as well. This allows text within the absolute child to
// wrap to the size of its owner. This is the same behavior as many browsers // wrap to the size of its owner. This is the same behavior as many browsers
// implement. // implement.
if (!isMainAxisRow && yoga::isUndefined(childWidth) && if (!isMainAxisRow && yoga::isUndefined(childWidth) &&
widthMode != YGMeasureModeUndefined && !yoga::isUndefined(width) && widthMode != MeasureMode::Undefined && !yoga::isUndefined(width) &&
width > 0) { width > 0) {
childWidth = width; childWidth = width;
childWidthMeasureMode = YGMeasureModeAtMost; childWidthMeasureMode = MeasureMode::AtMost;
} }
calculateLayoutInternal( calculateLayoutInternal(
@@ -442,8 +442,8 @@ static void layoutAbsoluteChild(
childWidth, childWidth,
childHeight, childHeight,
direction, direction,
YGMeasureModeExactly, MeasureMode::Exactly,
YGMeasureModeExactly, MeasureMode::Exactly,
childWidth, childWidth,
childHeight, childHeight,
true, true,
@@ -548,8 +548,8 @@ static void measureNodeWithMeasureFunc(
yoga::Node* const node, yoga::Node* const node,
float availableWidth, float availableWidth,
float availableHeight, float availableHeight,
const YGMeasureMode widthMeasureMode, const MeasureMode widthMeasureMode,
const YGMeasureMode heightMeasureMode, const MeasureMode heightMeasureMode,
const float ownerWidth, const float ownerWidth,
const float ownerHeight, const float ownerHeight,
LayoutData& layoutMarkerData, LayoutData& layoutMarkerData,
@@ -559,10 +559,10 @@ static void measureNodeWithMeasureFunc(
node->hasMeasureFunc(), node->hasMeasureFunc(),
"Expected node to have custom measure function"); "Expected node to have custom measure function");
if (widthMeasureMode == YGMeasureModeUndefined) { if (widthMeasureMode == MeasureMode::Undefined) {
availableWidth = YGUndefined; availableWidth = YGUndefined;
} }
if (heightMeasureMode == YGMeasureModeUndefined) { if (heightMeasureMode == MeasureMode::Undefined) {
availableHeight = YGUndefined; availableHeight = YGUndefined;
} }
@@ -581,8 +581,8 @@ static void measureNodeWithMeasureFunc(
? availableHeight ? availableHeight
: yoga::maxOrDefined(0, availableHeight - paddingAndBorderAxisColumn); : yoga::maxOrDefined(0, availableHeight - paddingAndBorderAxisColumn);
if (widthMeasureMode == YGMeasureModeExactly && if (widthMeasureMode == MeasureMode::Exactly &&
heightMeasureMode == YGMeasureModeExactly) { heightMeasureMode == MeasureMode::Exactly) {
// Don't bother sizing the text if both dimensions are already defined. // Don't bother sizing the text if both dimensions are already defined.
node->setLayoutMeasuredDimension( node->setLayoutMeasuredDimension(
boundAxis( boundAxis(
@@ -610,9 +610,9 @@ static void measureNodeWithMeasureFunc(
Event::publish<Event::MeasureCallbackEnd>( Event::publish<Event::MeasureCallbackEnd>(
node, node,
{innerWidth, {innerWidth,
widthMeasureMode, unscopedEnum(widthMeasureMode),
innerHeight, innerHeight,
heightMeasureMode, unscopedEnum(heightMeasureMode),
measuredSize.width, measuredSize.width,
measuredSize.height, measuredSize.height,
reason}); reason});
@@ -621,8 +621,8 @@ static void measureNodeWithMeasureFunc(
boundAxis( boundAxis(
node, node,
YGFlexDirectionRow, YGFlexDirectionRow,
(widthMeasureMode == YGMeasureModeUndefined || (widthMeasureMode == MeasureMode::Undefined ||
widthMeasureMode == YGMeasureModeAtMost) widthMeasureMode == MeasureMode::AtMost)
? measuredSize.width + paddingAndBorderAxisRow ? measuredSize.width + paddingAndBorderAxisRow
: availableWidth, : availableWidth,
ownerWidth, ownerWidth,
@@ -633,8 +633,8 @@ static void measureNodeWithMeasureFunc(
boundAxis( boundAxis(
node, node,
YGFlexDirectionColumn, YGFlexDirectionColumn,
(heightMeasureMode == YGMeasureModeUndefined || (heightMeasureMode == MeasureMode::Undefined ||
heightMeasureMode == YGMeasureModeAtMost) heightMeasureMode == MeasureMode::AtMost)
? measuredSize.height + paddingAndBorderAxisColumn ? measuredSize.height + paddingAndBorderAxisColumn
: availableHeight, : availableHeight,
ownerHeight, ownerHeight,
@@ -649,16 +649,16 @@ static void measureNodeWithoutChildren(
yoga::Node* const node, yoga::Node* const node,
const float availableWidth, const float availableWidth,
const float availableHeight, const float availableHeight,
const YGMeasureMode widthMeasureMode, const MeasureMode widthMeasureMode,
const YGMeasureMode heightMeasureMode, const MeasureMode heightMeasureMode,
const float ownerWidth, const float ownerWidth,
const float ownerHeight) { const float ownerHeight) {
const auto& padding = node->getLayout().padding; const auto& padding = node->getLayout().padding;
const auto& border = node->getLayout().border; const auto& border = node->getLayout().border;
float width = availableWidth; float width = availableWidth;
if (widthMeasureMode == YGMeasureModeUndefined || if (widthMeasureMode == MeasureMode::Undefined ||
widthMeasureMode == YGMeasureModeAtMost) { widthMeasureMode == MeasureMode::AtMost) {
width = padding[YGEdgeLeft] + padding[YGEdgeRight] + border[YGEdgeLeft] + width = padding[YGEdgeLeft] + padding[YGEdgeRight] + border[YGEdgeLeft] +
border[YGEdgeRight]; border[YGEdgeRight];
} }
@@ -667,8 +667,8 @@ static void measureNodeWithoutChildren(
YGDimensionWidth); YGDimensionWidth);
float height = availableHeight; float height = availableHeight;
if (heightMeasureMode == YGMeasureModeUndefined || if (heightMeasureMode == MeasureMode::Undefined ||
heightMeasureMode == YGMeasureModeAtMost) { heightMeasureMode == MeasureMode::AtMost) {
height = padding[YGEdgeTop] + padding[YGEdgeBottom] + border[YGEdgeTop] + height = padding[YGEdgeTop] + padding[YGEdgeBottom] + border[YGEdgeTop] +
border[YGEdgeBottom]; border[YGEdgeBottom];
} }
@@ -681,22 +681,22 @@ static bool measureNodeWithFixedSize(
yoga::Node* const node, yoga::Node* const node,
const float availableWidth, const float availableWidth,
const float availableHeight, const float availableHeight,
const YGMeasureMode widthMeasureMode, const MeasureMode widthMeasureMode,
const YGMeasureMode heightMeasureMode, const MeasureMode heightMeasureMode,
const float ownerWidth, const float ownerWidth,
const float ownerHeight) { const float ownerHeight) {
if ((!yoga::isUndefined(availableWidth) && if ((!yoga::isUndefined(availableWidth) &&
widthMeasureMode == YGMeasureModeAtMost && availableWidth <= 0.0f) || widthMeasureMode == MeasureMode::AtMost && availableWidth <= 0.0f) ||
(!yoga::isUndefined(availableHeight) && (!yoga::isUndefined(availableHeight) &&
heightMeasureMode == YGMeasureModeAtMost && availableHeight <= 0.0f) || heightMeasureMode == MeasureMode::AtMost && availableHeight <= 0.0f) ||
(widthMeasureMode == YGMeasureModeExactly && (widthMeasureMode == MeasureMode::Exactly &&
heightMeasureMode == YGMeasureModeExactly)) { heightMeasureMode == MeasureMode::Exactly)) {
node->setLayoutMeasuredDimension( node->setLayoutMeasuredDimension(
boundAxis( boundAxis(
node, node,
YGFlexDirectionRow, YGFlexDirectionRow,
yoga::isUndefined(availableWidth) || yoga::isUndefined(availableWidth) ||
(widthMeasureMode == YGMeasureModeAtMost && (widthMeasureMode == MeasureMode::AtMost &&
availableWidth < 0.0f) availableWidth < 0.0f)
? 0.0f ? 0.0f
: availableWidth, : availableWidth,
@@ -709,7 +709,7 @@ static bool measureNodeWithFixedSize(
node, node,
YGFlexDirectionColumn, YGFlexDirectionColumn,
yoga::isUndefined(availableHeight) || yoga::isUndefined(availableHeight) ||
(heightMeasureMode == YGMeasureModeAtMost && (heightMeasureMode == MeasureMode::AtMost &&
availableHeight < 0.0f) availableHeight < 0.0f)
? 0.0f ? 0.0f
: availableHeight, : availableHeight,
@@ -769,8 +769,8 @@ static float computeFlexBasisForChildren(
yoga::Node* const node, yoga::Node* const node,
const float availableInnerWidth, const float availableInnerWidth,
const float availableInnerHeight, const float availableInnerHeight,
YGMeasureMode widthMeasureMode, MeasureMode widthMeasureMode,
YGMeasureMode heightMeasureMode, MeasureMode heightMeasureMode,
YGDirection direction, YGDirection direction,
YGFlexDirection mainAxis, YGFlexDirection mainAxis,
bool performLayout, bool performLayout,
@@ -780,12 +780,12 @@ static float computeFlexBasisForChildren(
float totalOuterFlexBasis = 0.0f; float totalOuterFlexBasis = 0.0f;
YGNodeRef singleFlexChild = nullptr; YGNodeRef singleFlexChild = nullptr;
const auto& children = node->getChildren(); const auto& children = node->getChildren();
YGMeasureMode measureModeMainDim = MeasureMode measureModeMainDim =
isRow(mainAxis) ? widthMeasureMode : heightMeasureMode; isRow(mainAxis) ? widthMeasureMode : heightMeasureMode;
// If there is only one child with flexGrow + flexShrink it means we can set // If there is only one child with flexGrow + flexShrink it means we can set
// the computedFlexBasis to 0 instead of measuring and shrinking / flexing the // the computedFlexBasis to 0 instead of measuring and shrinking / flexing the
// child to exactly match the remaining space // child to exactly match the remaining space
if (measureModeMainDim == YGMeasureModeExactly) { if (measureModeMainDim == MeasureMode::Exactly) {
for (auto child : children) { for (auto child : children) {
if (child->isNodeFlexible()) { if (child->isNodeFlexible()) {
if (singleFlexChild != nullptr || if (singleFlexChild != nullptr ||
@@ -867,7 +867,7 @@ static float distributeFreeSpaceSecondPass(
const float availableInnerWidth, const float availableInnerWidth,
const float availableInnerHeight, const float availableInnerHeight,
const bool mainAxisOverflows, const bool mainAxisOverflows,
const YGMeasureMode measureModeCrossDim, const MeasureMode measureModeCrossDim,
const bool performLayout, const bool performLayout,
LayoutData& layoutMarkerData, LayoutData& layoutMarkerData,
const uint32_t depth, const uint32_t depth,
@@ -942,34 +942,34 @@ static float distributeFreeSpaceSecondPass(
float childCrossSize; float childCrossSize;
float childMainSize = updatedMainSize + marginMain; float childMainSize = updatedMainSize + marginMain;
YGMeasureMode childCrossMeasureMode; MeasureMode childCrossMeasureMode;
YGMeasureMode childMainMeasureMode = YGMeasureModeExactly; MeasureMode childMainMeasureMode = MeasureMode::Exactly;
const auto& childStyle = currentLineChild->getStyle(); const auto& childStyle = currentLineChild->getStyle();
if (!childStyle.aspectRatio().isUndefined()) { if (!childStyle.aspectRatio().isUndefined()) {
childCrossSize = isMainAxisRow childCrossSize = isMainAxisRow
? (childMainSize - marginMain) / childStyle.aspectRatio().unwrap() ? (childMainSize - marginMain) / childStyle.aspectRatio().unwrap()
: (childMainSize - marginMain) * childStyle.aspectRatio().unwrap(); : (childMainSize - marginMain) * childStyle.aspectRatio().unwrap();
childCrossMeasureMode = YGMeasureModeExactly; childCrossMeasureMode = MeasureMode::Exactly;
childCrossSize += marginCross; childCrossSize += marginCross;
} else if ( } else if (
!std::isnan(availableInnerCrossDim) && !std::isnan(availableInnerCrossDim) &&
!styleDefinesDimension( !styleDefinesDimension(
currentLineChild, crossAxis, availableInnerCrossDim) && currentLineChild, crossAxis, availableInnerCrossDim) &&
measureModeCrossDim == YGMeasureModeExactly && measureModeCrossDim == MeasureMode::Exactly &&
!(isNodeFlexWrap && mainAxisOverflows) && !(isNodeFlexWrap && mainAxisOverflows) &&
resolveChildAlignment(node, currentLineChild) == YGAlignStretch && resolveChildAlignment(node, currentLineChild) == YGAlignStretch &&
currentLineChild->marginLeadingValue(crossAxis).unit != YGUnitAuto && currentLineChild->marginLeadingValue(crossAxis).unit != YGUnitAuto &&
currentLineChild->marginTrailingValue(crossAxis).unit != YGUnitAuto) { currentLineChild->marginTrailingValue(crossAxis).unit != YGUnitAuto) {
childCrossSize = availableInnerCrossDim; childCrossSize = availableInnerCrossDim;
childCrossMeasureMode = YGMeasureModeExactly; childCrossMeasureMode = MeasureMode::Exactly;
} else if (!styleDefinesDimension( } else if (!styleDefinesDimension(
currentLineChild, crossAxis, availableInnerCrossDim)) { currentLineChild, crossAxis, availableInnerCrossDim)) {
childCrossSize = availableInnerCrossDim; childCrossSize = availableInnerCrossDim;
childCrossMeasureMode = yoga::isUndefined(childCrossSize) childCrossMeasureMode = yoga::isUndefined(childCrossSize)
? YGMeasureModeUndefined ? MeasureMode::Undefined
: YGMeasureModeAtMost; : MeasureMode::AtMost;
} else { } else {
childCrossSize = childCrossSize =
yoga::resolveValue( yoga::resolveValue(
@@ -980,11 +980,11 @@ static float distributeFreeSpaceSecondPass(
const bool isLoosePercentageMeasurement = const bool isLoosePercentageMeasurement =
currentLineChild->getResolvedDimension(dimension(crossAxis)).unit == currentLineChild->getResolvedDimension(dimension(crossAxis)).unit ==
YGUnitPercent && YGUnitPercent &&
measureModeCrossDim != YGMeasureModeExactly; measureModeCrossDim != MeasureMode::Exactly;
childCrossMeasureMode = childCrossMeasureMode =
yoga::isUndefined(childCrossSize) || isLoosePercentageMeasurement yoga::isUndefined(childCrossSize) || isLoosePercentageMeasurement
? YGMeasureModeUndefined ? MeasureMode::Undefined
: YGMeasureModeExactly; : MeasureMode::Exactly;
} }
constrainMaxSizeForMode( constrainMaxSizeForMode(
@@ -1012,9 +1012,9 @@ static float distributeFreeSpaceSecondPass(
const float childWidth = isMainAxisRow ? childMainSize : childCrossSize; const float childWidth = isMainAxisRow ? childMainSize : childCrossSize;
const float childHeight = !isMainAxisRow ? childMainSize : childCrossSize; const float childHeight = !isMainAxisRow ? childMainSize : childCrossSize;
const YGMeasureMode childWidthMeasureMode = const MeasureMode childWidthMeasureMode =
isMainAxisRow ? childMainMeasureMode : childCrossMeasureMode; isMainAxisRow ? childMainMeasureMode : childCrossMeasureMode;
const YGMeasureMode childHeightMeasureMode = const MeasureMode childHeightMeasureMode =
!isMainAxisRow ? childMainMeasureMode : childCrossMeasureMode; !isMainAxisRow ? childMainMeasureMode : childCrossMeasureMode;
const bool isLayoutPass = performLayout && !requiresStretchLayout; const bool isLayoutPass = performLayout && !requiresStretchLayout;
@@ -1161,7 +1161,7 @@ static void resolveFlexibleLength(
const float availableInnerWidth, const float availableInnerWidth,
const float availableInnerHeight, const float availableInnerHeight,
const bool mainAxisOverflows, const bool mainAxisOverflows,
const YGMeasureMode measureModeCrossDim, const MeasureMode measureModeCrossDim,
const bool performLayout, const bool performLayout,
LayoutData& layoutMarkerData, LayoutData& layoutMarkerData,
const uint32_t depth, const uint32_t depth,
@@ -1202,8 +1202,8 @@ static void YGJustifyMainAxis(
const size_t startOfLineIndex, const size_t startOfLineIndex,
const YGFlexDirection mainAxis, const YGFlexDirection mainAxis,
const YGFlexDirection crossAxis, const YGFlexDirection crossAxis,
const YGMeasureMode measureModeMainDim, const MeasureMode measureModeMainDim,
const YGMeasureMode measureModeCrossDim, const MeasureMode measureModeCrossDim,
const float mainAxisownerSize, const float mainAxisownerSize,
const float ownerWidth, const float ownerWidth,
const float availableInnerMainDim, const float availableInnerMainDim,
@@ -1218,7 +1218,7 @@ static void YGJustifyMainAxis(
const float gap = node->getGapForAxis(mainAxis, ownerWidth).unwrap(); const float gap = node->getGapForAxis(mainAxis, ownerWidth).unwrap();
// If we are using "at most" rules in the main axis, make sure that // If we are using "at most" rules in the main axis, make sure that
// 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 == MeasureMode::AtMost &&
flexLine.layout.remainingFreeSpace > 0) { flexLine.layout.remainingFreeSpace > 0) {
if (!style.minDimensions()[dimension(mainAxis)].isUndefined() && if (!style.minDimensions()[dimension(mainAxis)].isUndefined() &&
!yoga::resolveValue( !yoga::resolveValue(
@@ -1349,7 +1349,7 @@ static void YGJustifyMainAxis(
static_cast<float>(numberOfAutoMarginsOnCurrentLine); static_cast<float>(numberOfAutoMarginsOnCurrentLine);
} }
bool canSkipFlex = bool canSkipFlex =
!performLayout && measureModeCrossDim == YGMeasureModeExactly; !performLayout && measureModeCrossDim == MeasureMode::Exactly;
if (canSkipFlex) { if (canSkipFlex) {
// If we skipped the flex step, then we can't rely on the measuredDims // If we skipped the flex step, then we can't rely on the measuredDims
// because they weren't computed. This means we can't call // because they weren't computed. This means we can't call
@@ -1466,21 +1466,21 @@ static void YGJustifyMainAxis(
// content" because we don't support default minimum main sizes (see above // content" because we don't support default minimum main sizes (see above
// for details). Each of our measure modes maps to a layout mode from the // for details). Each of our measure modes maps to a layout mode from the
// spec (https://www.w3.org/TR/CSS3-sizing/#terms): // spec (https://www.w3.org/TR/CSS3-sizing/#terms):
// - YGMeasureModeUndefined: max content // - MeasureMode::Undefined: max content
// - YGMeasureModeExactly: fill available // - MeasureMode::Exactly: fill available
// - YGMeasureModeAtMost: fit content // - MeasureMode::AtMost: fit content
// //
// When calling calculateLayoutImpl and calculateLayoutInternal, if the // When calling calculateLayoutImpl and calculateLayoutInternal, if the
// caller passes an available size of undefined then it must also pass a // caller passes an available size of undefined then it must also pass a
// measure mode of YGMeasureModeUndefined in that dimension. // measure mode of MeasureMode::Undefined in that dimension.
// //
static void calculateLayoutImpl( static void calculateLayoutImpl(
yoga::Node* const node, yoga::Node* const node,
const float availableWidth, const float availableWidth,
const float availableHeight, const float availableHeight,
const YGDirection ownerDirection, const YGDirection ownerDirection,
const YGMeasureMode widthMeasureMode, const MeasureMode widthMeasureMode,
const YGMeasureMode heightMeasureMode, const MeasureMode heightMeasureMode,
const float ownerWidth, const float ownerWidth,
const float ownerHeight, const float ownerHeight,
const bool performLayout, const bool performLayout,
@@ -1491,17 +1491,17 @@ static void calculateLayoutImpl(
yoga::assertFatalWithNode( yoga::assertFatalWithNode(
node, node,
yoga::isUndefined(availableWidth) yoga::isUndefined(availableWidth)
? widthMeasureMode == YGMeasureModeUndefined ? widthMeasureMode == MeasureMode::Undefined
: true, : true,
"availableWidth is indefinite so widthMeasureMode must be " "availableWidth is indefinite so widthMeasureMode must be "
"YGMeasureModeUndefined"); "MeasureMode::Undefined");
yoga::assertFatalWithNode( yoga::assertFatalWithNode(
node, node,
yoga::isUndefined(availableHeight) yoga::isUndefined(availableHeight)
? heightMeasureMode == YGMeasureModeUndefined ? heightMeasureMode == MeasureMode::Undefined
: true, : true,
"availableHeight is indefinite so heightMeasureMode must be " "availableHeight is indefinite so heightMeasureMode must be "
"YGMeasureModeUndefined"); "MeasureMode::Undefined");
(performLayout ? layoutMarkerData.layouts : layoutMarkerData.measures) += 1; (performLayout ? layoutMarkerData.layouts : layoutMarkerData.measures) += 1;
@@ -1618,9 +1618,9 @@ static void calculateLayoutImpl(
const float paddingAndBorderAxisCross = const float paddingAndBorderAxisCross =
leadingPaddingAndBorderCross + trailingPaddingAndBorderCross; leadingPaddingAndBorderCross + trailingPaddingAndBorderCross;
YGMeasureMode measureModeMainDim = MeasureMode measureModeMainDim =
isMainAxisRow ? widthMeasureMode : heightMeasureMode; isMainAxisRow ? widthMeasureMode : heightMeasureMode;
YGMeasureMode measureModeCrossDim = MeasureMode measureModeCrossDim =
isMainAxisRow ? heightMeasureMode : widthMeasureMode; isMainAxisRow ? heightMeasureMode : widthMeasureMode;
const float paddingAndBorderAxisRow = const float paddingAndBorderAxisRow =
@@ -1672,12 +1672,12 @@ static void calculateLayoutImpl(
} }
const bool mainAxisOverflows = const bool mainAxisOverflows =
(measureModeMainDim != YGMeasureModeUndefined) && (measureModeMainDim != MeasureMode::Undefined) &&
totalMainDim > availableInnerMainDim; totalMainDim > availableInnerMainDim;
if (isNodeFlexWrap && mainAxisOverflows && if (isNodeFlexWrap && mainAxisOverflows &&
measureModeMainDim == YGMeasureModeAtMost) { measureModeMainDim == MeasureMode::AtMost) {
measureModeMainDim = YGMeasureModeExactly; measureModeMainDim = MeasureMode::Exactly;
} }
// STEP 4: COLLECT FLEX ITEMS INTO FLEX LINES // STEP 4: COLLECT FLEX ITEMS INTO FLEX LINES
@@ -1712,7 +1712,7 @@ static void calculateLayoutImpl(
// If we don't need to measure the cross axis, we can skip the entire flex // If we don't need to measure the cross axis, we can skip the entire flex
// step. // step.
const bool canSkipFlex = const bool canSkipFlex =
!performLayout && measureModeCrossDim == YGMeasureModeExactly; !performLayout && measureModeCrossDim == MeasureMode::Exactly;
// STEP 5: RESOLVING FLEXIBLE LENGTHS ON MAIN AXIS // STEP 5: RESOLVING FLEXIBLE LENGTHS ON MAIN AXIS
// Calculate the remaining available space that needs to be allocated. If // Calculate the remaining available space that needs to be allocated. If
@@ -1722,7 +1722,7 @@ static void calculateLayoutImpl(
bool sizeBasedOnContent = false; bool sizeBasedOnContent = false;
// If we don't measure with exact main dimension we want to ensure we don't // If we don't measure with exact main dimension we want to ensure we don't
// violate min and max // violate min and max
if (measureModeMainDim != YGMeasureModeExactly) { if (measureModeMainDim != MeasureMode::Exactly) {
const auto& minDimensions = node->getStyle().minDimensions(); const auto& minDimensions = node->getStyle().minDimensions();
const auto& maxDimensions = node->getStyle().maxDimensions(); const auto& maxDimensions = node->getStyle().maxDimensions();
const float minInnerWidth = const float minInnerWidth =
@@ -1830,8 +1830,8 @@ static void calculateLayoutImpl(
performLayout); performLayout);
float containerCrossAxis = availableInnerCrossDim; float containerCrossAxis = availableInnerCrossDim;
if (measureModeCrossDim == YGMeasureModeUndefined || if (measureModeCrossDim == MeasureMode::Undefined ||
measureModeCrossDim == YGMeasureModeAtMost) { measureModeCrossDim == MeasureMode::AtMost) {
// Compute the cross axis from the max cross dimension of the children. // Compute the cross axis from the max cross dimension of the children.
containerCrossAxis = containerCrossAxis =
boundAxis( boundAxis(
@@ -1844,7 +1844,7 @@ static void calculateLayoutImpl(
} }
// If there's no flex wrap, the cross dimension is defined by the container. // If there's no flex wrap, the cross dimension is defined by the container.
if (!isNodeFlexWrap && measureModeCrossDim == YGMeasureModeExactly) { if (!isNodeFlexWrap && measureModeCrossDim == MeasureMode::Exactly) {
flexLine.layout.crossDim = availableInnerCrossDim; flexLine.layout.crossDim = availableInnerCrossDim;
} }
@@ -1925,8 +1925,8 @@ static void calculateLayoutImpl(
child->getMarginForAxis(mainAxis, availableInnerWidth) child->getMarginForAxis(mainAxis, availableInnerWidth)
.unwrap(); .unwrap();
YGMeasureMode childMainMeasureMode = YGMeasureModeExactly; MeasureMode childMainMeasureMode = MeasureMode::Exactly;
YGMeasureMode childCrossMeasureMode = YGMeasureModeExactly; MeasureMode childCrossMeasureMode = MeasureMode::Exactly;
constrainMaxSizeForMode( constrainMaxSizeForMode(
child, child,
mainAxis, mainAxis,
@@ -1950,16 +1950,16 @@ static void calculateLayoutImpl(
auto alignContent = node->getStyle().alignContent(); auto alignContent = node->getStyle().alignContent();
auto crossAxisDoesNotGrow = auto crossAxisDoesNotGrow =
alignContent != YGAlignStretch && isNodeFlexWrap; alignContent != YGAlignStretch && isNodeFlexWrap;
const YGMeasureMode childWidthMeasureMode = const MeasureMode childWidthMeasureMode =
yoga::isUndefined(childWidth) || yoga::isUndefined(childWidth) ||
(!isMainAxisRow && crossAxisDoesNotGrow) (!isMainAxisRow && crossAxisDoesNotGrow)
? YGMeasureModeUndefined ? MeasureMode::Undefined
: YGMeasureModeExactly; : MeasureMode::Exactly;
const YGMeasureMode childHeightMeasureMode = const MeasureMode childHeightMeasureMode =
yoga::isUndefined(childHeight) || yoga::isUndefined(childHeight) ||
(isMainAxisRow && crossAxisDoesNotGrow) (isMainAxisRow && crossAxisDoesNotGrow)
? YGMeasureModeUndefined ? MeasureMode::Undefined
: YGMeasureModeExactly; : MeasureMode::Exactly;
calculateLayoutInternal( calculateLayoutInternal(
child, child,
@@ -2182,8 +2182,8 @@ static void calculateLayoutImpl(
childWidth, childWidth,
childHeight, childHeight,
direction, direction,
YGMeasureModeExactly, MeasureMode::Exactly,
YGMeasureModeExactly, MeasureMode::Exactly,
availableInnerWidth, availableInnerWidth,
availableInnerHeight, availableInnerHeight,
true, true,
@@ -2241,9 +2241,9 @@ static void calculateLayoutImpl(
// If the user didn't specify a width or height for the node, set the // If the user didn't specify a width or height for the node, set the
// dimensions based on the children. // dimensions based on the children.
if (measureModeMainDim == YGMeasureModeUndefined || if (measureModeMainDim == MeasureMode::Undefined ||
(node->getStyle().overflow() != YGOverflowScroll && (node->getStyle().overflow() != YGOverflowScroll &&
measureModeMainDim == YGMeasureModeAtMost)) { measureModeMainDim == MeasureMode::AtMost)) {
// Clamp the size to the min/max size, if specified, and make sure it // Clamp the size to the min/max size, if specified, and make sure it
// doesn't go below the padding and border amount. // doesn't go below the padding and border amount.
node->setLayoutMeasuredDimension( node->setLayoutMeasuredDimension(
@@ -2252,7 +2252,7 @@ static void calculateLayoutImpl(
dimension(mainAxis)); dimension(mainAxis));
} else if ( } else if (
measureModeMainDim == YGMeasureModeAtMost && measureModeMainDim == MeasureMode::AtMost &&
node->getStyle().overflow() == YGOverflowScroll) { node->getStyle().overflow() == YGOverflowScroll) {
node->setLayoutMeasuredDimension( node->setLayoutMeasuredDimension(
yoga::maxOrDefined( yoga::maxOrDefined(
@@ -2268,9 +2268,9 @@ static void calculateLayoutImpl(
dimension(mainAxis)); dimension(mainAxis));
} }
if (measureModeCrossDim == YGMeasureModeUndefined || if (measureModeCrossDim == MeasureMode::Undefined ||
(node->getStyle().overflow() != YGOverflowScroll && (node->getStyle().overflow() != YGOverflowScroll &&
measureModeCrossDim == YGMeasureModeAtMost)) { measureModeCrossDim == MeasureMode::AtMost)) {
// Clamp the size to the min/max size, if specified, and make sure it // Clamp the size to the min/max size, if specified, and make sure it
// doesn't go below the padding and border amount. // doesn't go below the padding and border amount.
node->setLayoutMeasuredDimension( node->setLayoutMeasuredDimension(
@@ -2283,7 +2283,7 @@ static void calculateLayoutImpl(
dimension(crossAxis)); dimension(crossAxis));
} else if ( } else if (
measureModeCrossDim == YGMeasureModeAtMost && measureModeCrossDim == MeasureMode::AtMost &&
node->getStyle().overflow() == YGOverflowScroll) { node->getStyle().overflow() == YGOverflowScroll) {
node->setLayoutMeasuredDimension( node->setLayoutMeasuredDimension(
yoga::maxOrDefined( yoga::maxOrDefined(
@@ -2383,18 +2383,17 @@ static const char* spacerWithLength(const unsigned long level) {
} }
static const char* measureModeName( static const char* measureModeName(
const YGMeasureMode mode, const MeasureMode mode,
const bool performLayout) { const bool performLayout) {
constexpr auto N = enums::count<YGMeasureMode>(); switch (mode) {
const char* kMeasureModeNames[N] = {"UNDEFINED", "EXACTLY", "AT_MOST"}; case MeasureMode::Undefined:
const char* kLayoutModeNames[N] = { return performLayout ? "LAY_UNDEFINED" : "UNDEFINED";
"LAY_UNDEFINED", "LAY_EXACTLY", "LAY_AT_MOST"}; case MeasureMode::Exactly:
return performLayout ? "LAY_EXACTLY" : "EXACTLY";
if (mode >= N) { case MeasureMode::AtMost:
return ""; return performLayout ? "LAY_AT_MOST" : "AT_MOST";
} }
return "";
return performLayout ? kLayoutModeNames[mode] : kMeasureModeNames[mode];
} }
// //
@@ -2410,8 +2409,8 @@ bool calculateLayoutInternal(
const float availableWidth, const float availableWidth,
const float availableHeight, const float availableHeight,
const YGDirection ownerDirection, const YGDirection ownerDirection,
const YGMeasureMode widthMeasureMode, const MeasureMode widthMeasureMode,
const YGMeasureMode heightMeasureMode, const MeasureMode heightMeasureMode,
const float ownerWidth, const float ownerWidth,
const float ownerHeight, const float ownerHeight,
const bool performLayout, const bool performLayout,
@@ -2432,8 +2431,8 @@ bool calculateLayoutInternal(
layout->nextCachedMeasurementsIndex = 0; layout->nextCachedMeasurementsIndex = 0;
layout->cachedLayout.availableWidth = -1; layout->cachedLayout.availableWidth = -1;
layout->cachedLayout.availableHeight = -1; layout->cachedLayout.availableHeight = -1;
layout->cachedLayout.widthMeasureMode = YGMeasureModeUndefined; layout->cachedLayout.widthMeasureMode = MeasureMode::Undefined;
layout->cachedLayout.heightMeasureMode = YGMeasureModeUndefined; layout->cachedLayout.heightMeasureMode = MeasureMode::Undefined;
layout->cachedLayout.computedWidth = -1; layout->cachedLayout.computedWidth = -1;
layout->cachedLayout.computedHeight = -1; layout->cachedLayout.computedHeight = -1;
} }
@@ -2679,7 +2678,7 @@ void calculateLayout(
gCurrentGenerationCount.fetch_add(1, std::memory_order_relaxed); gCurrentGenerationCount.fetch_add(1, std::memory_order_relaxed);
node->resolveDimension(); node->resolveDimension();
float width = YGUndefined; float width = YGUndefined;
YGMeasureMode widthMeasureMode = YGMeasureModeUndefined; MeasureMode widthMeasureMode = MeasureMode::Undefined;
const auto& maxDimensions = node->getStyle().maxDimensions(); const auto& maxDimensions = node->getStyle().maxDimensions();
if (styleDefinesDimension(node, YGFlexDirectionRow, ownerWidth)) { if (styleDefinesDimension(node, YGFlexDirectionRow, ownerWidth)) {
width = (yoga::resolveValue( width = (yoga::resolveValue(
@@ -2687,36 +2686,36 @@ void calculateLayout(
ownerWidth) + ownerWidth) +
node->getMarginForAxis(YGFlexDirectionRow, ownerWidth)) node->getMarginForAxis(YGFlexDirectionRow, ownerWidth))
.unwrap(); .unwrap();
widthMeasureMode = YGMeasureModeExactly; widthMeasureMode = MeasureMode::Exactly;
} else if (!yoga::resolveValue(maxDimensions[YGDimensionWidth], ownerWidth) } else if (!yoga::resolveValue(maxDimensions[YGDimensionWidth], ownerWidth)
.isUndefined()) { .isUndefined()) {
width = yoga::resolveValue(maxDimensions[YGDimensionWidth], ownerWidth) width = yoga::resolveValue(maxDimensions[YGDimensionWidth], ownerWidth)
.unwrap(); .unwrap();
widthMeasureMode = YGMeasureModeAtMost; widthMeasureMode = MeasureMode::AtMost;
} else { } else {
width = ownerWidth; width = ownerWidth;
widthMeasureMode = yoga::isUndefined(width) ? YGMeasureModeUndefined widthMeasureMode = yoga::isUndefined(width) ? MeasureMode::Undefined
: YGMeasureModeExactly; : MeasureMode::Exactly;
} }
float height = YGUndefined; float height = YGUndefined;
YGMeasureMode heightMeasureMode = YGMeasureModeUndefined; MeasureMode heightMeasureMode = MeasureMode::Undefined;
if (styleDefinesDimension(node, YGFlexDirectionColumn, ownerHeight)) { if (styleDefinesDimension(node, YGFlexDirectionColumn, ownerHeight)) {
height = (yoga::resolveValue( height = (yoga::resolveValue(
node->getResolvedDimension(dimension(YGFlexDirectionColumn)), node->getResolvedDimension(dimension(YGFlexDirectionColumn)),
ownerHeight) + ownerHeight) +
node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth)) node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth))
.unwrap(); .unwrap();
heightMeasureMode = YGMeasureModeExactly; heightMeasureMode = MeasureMode::Exactly;
} else if (!yoga::resolveValue(maxDimensions[YGDimensionHeight], ownerHeight) } else if (!yoga::resolveValue(maxDimensions[YGDimensionHeight], ownerHeight)
.isUndefined()) { .isUndefined()) {
height = yoga::resolveValue(maxDimensions[YGDimensionHeight], ownerHeight) height = yoga::resolveValue(maxDimensions[YGDimensionHeight], ownerHeight)
.unwrap(); .unwrap();
heightMeasureMode = YGMeasureModeAtMost; heightMeasureMode = MeasureMode::AtMost;
} else { } else {
height = ownerHeight; height = ownerHeight;
heightMeasureMode = yoga::isUndefined(height) ? YGMeasureModeUndefined heightMeasureMode = yoga::isUndefined(height) ? MeasureMode::Undefined
: YGMeasureModeExactly; : MeasureMode::Exactly;
} }
if (calculateLayoutInternal( if (calculateLayoutInternal(
node, node,

View File

@@ -10,6 +10,8 @@
#include <cmath> #include <cmath>
#include <yoga/Yoga.h> #include <yoga/Yoga.h>
#include <yoga/enums/MeasureMode.h>
#include <yoga/numeric/Comparison.h> #include <yoga/numeric/Comparison.h>
namespace facebook::yoga { namespace facebook::yoga {
@@ -17,8 +19,8 @@ namespace facebook::yoga {
struct CachedMeasurement { struct CachedMeasurement {
float availableWidth{-1}; float availableWidth{-1};
float availableHeight{-1}; float availableHeight{-1};
YGMeasureMode widthMeasureMode{YGMeasureModeUndefined}; MeasureMode widthMeasureMode{MeasureMode::Undefined};
YGMeasureMode heightMeasureMode{YGMeasureModeUndefined}; MeasureMode heightMeasureMode{MeasureMode::Undefined};
float computedWidth{-1}; float computedWidth{-1};
float computedHeight{-1}; float computedHeight{-1};

View File

@@ -211,10 +211,11 @@ FloatOptional Node::getGapForAxis(
YGSize Node::measure( YGSize Node::measure(
float width, float width,
YGMeasureMode widthMode, MeasureMode widthMode,
float height, float height,
YGMeasureMode heightMode) { MeasureMode heightMode) {
return measureFunc_(this, width, widthMode, height, heightMode); return measureFunc_(
this, width, unscopedEnum(widthMode), height, unscopedEnum(heightMode));
} }
float Node::baseline(float width, float height) const { float Node::baseline(float width, float height) const {

View File

@@ -15,6 +15,7 @@
#include <yoga/config/Config.h> #include <yoga/config/Config.h>
#include <yoga/enums/Errata.h> #include <yoga/enums/Errata.h>
#include <yoga/enums/MeasureMode.h>
#include <yoga/enums/NodeType.h> #include <yoga/enums/NodeType.h>
#include <yoga/node/LayoutResults.h> #include <yoga/node/LayoutResults.h>
#include <yoga/style/CompactValue.h> #include <yoga/style/CompactValue.h>
@@ -102,7 +103,7 @@ class YG_EXPORT Node : public ::YGNode {
return measureFunc_ != nullptr; return measureFunc_ != nullptr;
} }
YGSize measure(float, YGMeasureMode, float, YGMeasureMode); YGSize measure(float, MeasureMode, float, MeasureMode);
bool hasBaselineFunc() const noexcept { bool hasBaselineFunc() const noexcept {
return baselineFunc_ != nullptr; return baselineFunc_ != nullptr;