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

Closed
NickGerleman wants to merge 7 commits from export-D49271165 into main
39 changed files with 1178 additions and 273 deletions

View File

@@ -1 +0,0 @@
^lib/.*

View File

@@ -4,6 +4,7 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import math
import os
ENUMS = {
@@ -88,7 +89,7 @@ def get_license(ext):
*/
// @{"generated"} by enums.py
{"// clang-format off" if ext == "cpp" else ""}
"""
@@ -121,7 +122,6 @@ with open(root + "/yoga/YGEnums.h", "w") as f:
f.write(get_license("cpp"))
f.write("#pragma once\n")
f.write("#include <yoga/YGMacros.h>\n\n")
f.write("// clang-format off\n\n\n")
f.write("YG_EXTERN_C_BEGIN\n\n")
items = sorted(ENUMS.items())
@@ -146,6 +146,52 @@ with open(root + "/yoga/YGEnums.h", "w") as f:
f.write("\n")
f.write("YG_EXTERN_C_END\n")
# Write out C++ scoped enums
for name, values in sorted(ENUMS.items()):
with open(f"{root}/yoga/enums/{name}.h", "w") as f:
f.write(get_license("cpp"))
f.write("#pragma once\n\n")
f.write("#include <cstdint>\n")
f.write("#include <yoga/YGEnums.h>\n")
f.write("#include <yoga/enums/YogaEnums.h>\n\n")
f.write("namespace facebook::yoga {\n\n")
width = "uint32_t" if name in BITSET_ENUMS else "uint8_t"
f.write(f"enum class {name} : {width} {{\n")
for value in values:
ordinal = value[0] if isinstance(value, tuple) else value
f.write(f" {ordinal} = YG{name}{ordinal},\n")
f.write("};\n\n")
f.write(
f"YG_DEFINE_ENUM_FLAG_OPERATORS({name})\n\n" if name in BITSET_ENUMS else ""
)
f.write("template <>\n")
f.write(f"constexpr inline int32_t ordinalCount<{name}>() {{\n")
f.write(f" return {len(values)};\n")
f.write("} \n\n")
f.write("template <>\n")
f.write(f"constexpr inline int32_t bitCount<{name}>() {{\n")
f.write(f" return {math.ceil(math.log(len(values), 2))};\n")
f.write("} \n\n")
f.write(f"constexpr inline {name} scopedEnum(YG{name} unscoped) {{\n")
f.write(f" return static_cast<{name}>(unscoped);\n")
f.write("}\n\n")
f.write(f"constexpr inline YG{name} unscopedEnum({name} scoped) {{\n")
f.write(f" return static_cast<YG{name}>(scoped);\n")
f.write("}\n\n")
f.write(f"inline const char* toString({name} e) {{\n")
f.write(f" return YG{name}ToString(unscopedEnum(e));\n")
f.write("}\n\n")
f.write("} // namespace facebook::yoga\n")
# write out C body for printing
with open(root + "/yoga/YGEnums.cpp", "w") as f:
f.write(get_license("cpp"))

View File

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

View File

@@ -6,7 +6,7 @@
*/
// @generated by enums.py
// clang-format off
#include <yoga/YGEnums.h>
const char* YGAlignToString(const YGAlign value) {

View File

@@ -6,13 +6,10 @@
*/
// @generated by enums.py
// clang-format off
#pragma once
#include <yoga/YGMacros.h>
// clang-format off
YG_EXTERN_C_BEGIN
YG_ENUM_SEQ_DECL(

View File

@@ -81,11 +81,11 @@ void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout) {
}
YGNodeType YGNodeGetNodeType(YGNodeConstRef node) {
return resolveRef(node)->getNodeType();
return unscopedEnum(resolveRef(node)->getNodeType());
}
void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType) {
return resolveRef(node)->setNodeType(nodeType);
return resolveRef(node)->setNodeType(scopedEnum(nodeType));
}
bool YGNodeIsDirty(YGNodeConstRef node) {
@@ -801,11 +801,8 @@ YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Border, border)
YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Padding, padding)
#ifdef DEBUG
void YGNodePrint(const YGNodeConstRef nodeRef, const YGPrintOptions options) {
const auto node = resolveRef(nodeRef);
std::string str;
yoga::nodeToString(str, node, options, 0);
yoga::log(node, YGLogLevelDebug, str.c_str());
void YGNodePrint(const YGNodeConstRef node, const YGPrintOptions options) {
yoga::print(resolveRef(node), scopedEnum(options));
}
#endif
@@ -851,13 +848,14 @@ void YGConfigSetExperimentalFeatureEnabled(
const YGConfigRef config,
const YGExperimentalFeature feature,
const bool enabled) {
resolveRef(config)->setExperimentalFeatureEnabled(feature, enabled);
resolveRef(config)->setExperimentalFeatureEnabled(
scopedEnum(feature), enabled);
}
bool YGConfigIsExperimentalFeatureEnabled(
const YGConfigConstRef config,
const YGExperimentalFeature feature) {
return resolveRef(config)->isExperimentalFeatureEnabled(feature);
return resolveRef(config)->isExperimentalFeatureEnabled(scopedEnum(feature));
}
void YGConfigSetUseWebDefaults(const YGConfigRef config, const bool enabled) {
@@ -877,11 +875,11 @@ void* YGConfigGetContext(const YGConfigConstRef config) {
}
void YGConfigSetErrata(YGConfigRef config, YGErrata errata) {
resolveRef(config)->setErrata(errata);
resolveRef(config)->setErrata(scopedEnum(errata));
}
YGErrata YGConfigGetErrata(YGConfigConstRef config) {
return resolveRef(config)->getErrata();
return unscopedEnum(resolveRef(config)->getErrata());
}
void YGConfigSetCloneNodeFunc(
@@ -907,13 +905,13 @@ bool YGNodeCanUseCachedMeasurement(
float marginColumn,
YGConfigRef config) {
return yoga::canUseCachedMeasurement(
widthMode,
scopedEnum(widthMode),
availableWidth,
heightMode,
scopedEnum(heightMode),
availableHeight,
lastWidthMode,
scopedEnum(lastWidthMode),
lastAvailableWidth,
lastHeightMode,
scopedEnum(lastHeightMode),
lastAvailableHeight,
lastComputedWidth,
lastComputedHeight,

View File

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

View File

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

View File

@@ -24,6 +24,7 @@
#include <yoga/algorithm/ResolveValue.h>
#include <yoga/debug/AssertFatal.h>
#include <yoga/debug/Log.h>
#include <yoga/debug/NodeToString.h>
#include <yoga/event/event.h>
#include <yoga/node/Node.h>
#include <yoga/numeric/Comparison.h>
@@ -38,8 +39,8 @@ bool calculateLayoutInternal(
const float availableWidth,
const float availableHeight,
const YGDirection ownerDirection,
const YGMeasureMode widthMeasureMode,
const YGMeasureMode heightMeasureMode,
const MeasureMode widthMeasureMode,
const MeasureMode heightMeasureMode,
const float ownerWidth,
const float ownerHeight,
const bool performLayout,
@@ -98,22 +99,22 @@ static void constrainMaxSizeForMode(
const enum YGFlexDirection axis,
const float ownerAxisSize,
const float ownerWidth,
YGMeasureMode* mode,
MeasureMode* mode,
float* size) {
const FloatOptional maxSize =
yoga::resolveValue(
node->getStyle().maxDimensions()[dimension(axis)], ownerAxisSize) +
FloatOptional(node->getMarginForAxis(axis, ownerWidth));
switch (*mode) {
case YGMeasureModeExactly:
case YGMeasureModeAtMost:
case MeasureMode::Exactly:
case MeasureMode::AtMost:
*size = (maxSize.isUndefined() || *size < maxSize.unwrap())
? *size
: maxSize.unwrap();
break;
case YGMeasureModeUndefined:
case MeasureMode::Undefined:
if (!maxSize.isUndefined()) {
*mode = YGMeasureModeAtMost;
*mode = MeasureMode::AtMost;
*size = maxSize.unwrap();
}
break;
@@ -124,11 +125,11 @@ static void computeFlexBasisForChild(
const yoga::Node* const node,
yoga::Node* const child,
const float width,
const YGMeasureMode widthMode,
const MeasureMode widthMode,
const float height,
const float ownerWidth,
const float ownerHeight,
const YGMeasureMode heightMode,
const MeasureMode heightMode,
const YGDirection direction,
LayoutData& layoutMarkerData,
const uint32_t depth,
@@ -141,8 +142,8 @@ static void computeFlexBasisForChild(
float childWidth;
float childHeight;
YGMeasureMode childWidthMeasureMode;
YGMeasureMode childHeightMeasureMode;
MeasureMode childWidthMeasureMode;
MeasureMode childHeightMeasureMode;
const FloatOptional resolvedFlexBasis =
yoga::resolveValue(child->resolveFlexBasisPtr(), mainAxisownerSize);
@@ -154,7 +155,7 @@ static void computeFlexBasisForChild(
if (!resolvedFlexBasis.isUndefined() && !yoga::isUndefined(mainAxisSize)) {
if (child->getLayout().computedFlexBasis.isUndefined() ||
(child->getConfig()->isExperimentalFeatureEnabled(
YGExperimentalFeatureWebFlexBasis) &&
ExperimentalFeature::WebFlexBasis) &&
child->getLayout().computedFlexBasisGeneration != generationCount)) {
const FloatOptional paddingAndBorder =
FloatOptional(paddingAndBorderForAxis(child, mainAxis, ownerWidth));
@@ -183,8 +184,8 @@ static void computeFlexBasisForChild(
// basis).
childWidth = YGUndefined;
childHeight = YGUndefined;
childWidthMeasureMode = YGMeasureModeUndefined;
childHeightMeasureMode = YGMeasureModeUndefined;
childWidthMeasureMode = MeasureMode::Undefined;
childHeightMeasureMode = MeasureMode::Undefined;
auto marginRow =
child->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap();
@@ -197,7 +198,7 @@ static void computeFlexBasisForChild(
child->getResolvedDimensions()[YGDimensionWidth], ownerWidth)
.unwrap() +
marginRow;
childWidthMeasureMode = YGMeasureModeExactly;
childWidthMeasureMode = MeasureMode::Exactly;
}
if (isColumnStyleDimDefined) {
childHeight =
@@ -205,7 +206,7 @@ static void computeFlexBasisForChild(
child->getResolvedDimensions()[YGDimensionHeight], ownerHeight)
.unwrap() +
marginColumn;
childHeightMeasureMode = YGMeasureModeExactly;
childHeightMeasureMode = MeasureMode::Exactly;
}
// The W3C spec doesn't say anything about the 'overflow' property, but all
@@ -214,7 +215,7 @@ static void computeFlexBasisForChild(
node->getStyle().overflow() != YGOverflowScroll) {
if (yoga::isUndefined(childWidth) && !yoga::isUndefined(width)) {
childWidth = width;
childWidthMeasureMode = YGMeasureModeAtMost;
childWidthMeasureMode = MeasureMode::AtMost;
}
}
@@ -222,21 +223,21 @@ static void computeFlexBasisForChild(
node->getStyle().overflow() != YGOverflowScroll) {
if (yoga::isUndefined(childHeight) && !yoga::isUndefined(height)) {
childHeight = height;
childHeightMeasureMode = YGMeasureModeAtMost;
childHeightMeasureMode = MeasureMode::AtMost;
}
}
const auto& childStyle = child->getStyle();
if (!childStyle.aspectRatio().isUndefined()) {
if (!isMainAxisRow && childWidthMeasureMode == YGMeasureModeExactly) {
if (!isMainAxisRow && childWidthMeasureMode == MeasureMode::Exactly) {
childHeight = marginColumn +
(childWidth - marginRow) / childStyle.aspectRatio().unwrap();
childHeightMeasureMode = YGMeasureModeExactly;
childHeightMeasureMode = MeasureMode::Exactly;
} else if (
isMainAxisRow && childHeightMeasureMode == YGMeasureModeExactly) {
isMainAxisRow && childHeightMeasureMode == MeasureMode::Exactly) {
childWidth = marginRow +
(childHeight - marginColumn) * childStyle.aspectRatio().unwrap();
childWidthMeasureMode = YGMeasureModeExactly;
childWidthMeasureMode = MeasureMode::Exactly;
}
}
@@ -244,35 +245,35 @@ static void computeFlexBasisForChild(
// the cross axis to be measured exactly with the available inner width
const bool hasExactWidth =
!yoga::isUndefined(width) && widthMode == YGMeasureModeExactly;
!yoga::isUndefined(width) && widthMode == MeasureMode::Exactly;
const bool childWidthStretch =
resolveChildAlignment(node, child) == YGAlignStretch &&
childWidthMeasureMode != YGMeasureModeExactly;
childWidthMeasureMode != MeasureMode::Exactly;
if (!isMainAxisRow && !isRowStyleDimDefined && hasExactWidth &&
childWidthStretch) {
childWidth = width;
childWidthMeasureMode = YGMeasureModeExactly;
childWidthMeasureMode = MeasureMode::Exactly;
if (!childStyle.aspectRatio().isUndefined()) {
childHeight =
(childWidth - marginRow) / childStyle.aspectRatio().unwrap();
childHeightMeasureMode = YGMeasureModeExactly;
childHeightMeasureMode = MeasureMode::Exactly;
}
}
const bool hasExactHeight =
!yoga::isUndefined(height) && heightMode == YGMeasureModeExactly;
!yoga::isUndefined(height) && heightMode == MeasureMode::Exactly;
const bool childHeightStretch =
resolveChildAlignment(node, child) == YGAlignStretch &&
childHeightMeasureMode != YGMeasureModeExactly;
childHeightMeasureMode != MeasureMode::Exactly;
if (isMainAxisRow && !isColumnStyleDimDefined && hasExactHeight &&
childHeightStretch) {
childHeight = height;
childHeightMeasureMode = YGMeasureModeExactly;
childHeightMeasureMode = MeasureMode::Exactly;
if (!childStyle.aspectRatio().isUndefined()) {
childWidth =
(childHeight - marginColumn) * childStyle.aspectRatio().unwrap();
childWidthMeasureMode = YGMeasureModeExactly;
childWidthMeasureMode = MeasureMode::Exactly;
}
}
@@ -318,7 +319,7 @@ static void layoutAbsoluteChild(
const yoga::Node* const node,
yoga::Node* const child,
const float width,
const YGMeasureMode widthMode,
const MeasureMode widthMode,
const float height,
const YGDirection direction,
LayoutData& layoutMarkerData,
@@ -331,8 +332,8 @@ static void layoutAbsoluteChild(
float childWidth = YGUndefined;
float childHeight = YGUndefined;
YGMeasureMode childWidthMeasureMode = YGMeasureModeUndefined;
YGMeasureMode childHeightMeasureMode = YGMeasureModeUndefined;
MeasureMode childWidthMeasureMode = MeasureMode::Undefined;
MeasureMode childHeightMeasureMode = MeasureMode::Undefined;
auto marginRow = child->getMarginForAxis(YGFlexDirectionRow, width).unwrap();
auto marginColumn =
@@ -399,21 +400,21 @@ static void layoutAbsoluteChild(
// If we're still missing one or the other dimension, measure the content.
if (yoga::isUndefined(childWidth) || yoga::isUndefined(childHeight)) {
childWidthMeasureMode = yoga::isUndefined(childWidth)
? YGMeasureModeUndefined
: YGMeasureModeExactly;
? MeasureMode::Undefined
: MeasureMode::Exactly;
childHeightMeasureMode = yoga::isUndefined(childHeight)
? YGMeasureModeUndefined
: YGMeasureModeExactly;
? MeasureMode::Undefined
: MeasureMode::Exactly;
// 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
// wrap to the size of its owner. This is the same behavior as many browsers
// implement.
if (!isMainAxisRow && yoga::isUndefined(childWidth) &&
widthMode != YGMeasureModeUndefined && !yoga::isUndefined(width) &&
widthMode != MeasureMode::Undefined && !yoga::isUndefined(width) &&
width > 0) {
childWidth = width;
childWidthMeasureMode = YGMeasureModeAtMost;
childWidthMeasureMode = MeasureMode::AtMost;
}
calculateLayoutInternal(
@@ -441,8 +442,8 @@ static void layoutAbsoluteChild(
childWidth,
childHeight,
direction,
YGMeasureModeExactly,
YGMeasureModeExactly,
MeasureMode::Exactly,
MeasureMode::Exactly,
childWidth,
childHeight,
true,
@@ -479,7 +480,7 @@ static void layoutAbsoluteChild(
leadingEdge(mainAxis));
} else if (
node->getConfig()->isExperimentalFeatureEnabled(
YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge) &&
ExperimentalFeature::AbsolutePercentageAgainstPaddingEdge) &&
child->isLeadingPositionDefined(mainAxis)) {
child->setLayoutPosition(
child->getLeadingPosition(
@@ -526,7 +527,7 @@ static void layoutAbsoluteChild(
leadingEdge(crossAxis));
} else if (
node->getConfig()->isExperimentalFeatureEnabled(
YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge) &&
ExperimentalFeature::AbsolutePercentageAgainstPaddingEdge) &&
child->isLeadingPositionDefined(crossAxis)) {
child->setLayoutPosition(
child->getLeadingPosition(
@@ -547,8 +548,8 @@ static void measureNodeWithMeasureFunc(
yoga::Node* const node,
float availableWidth,
float availableHeight,
const YGMeasureMode widthMeasureMode,
const YGMeasureMode heightMeasureMode,
const MeasureMode widthMeasureMode,
const MeasureMode heightMeasureMode,
const float ownerWidth,
const float ownerHeight,
LayoutData& layoutMarkerData,
@@ -558,10 +559,10 @@ static void measureNodeWithMeasureFunc(
node->hasMeasureFunc(),
"Expected node to have custom measure function");
if (widthMeasureMode == YGMeasureModeUndefined) {
if (widthMeasureMode == MeasureMode::Undefined) {
availableWidth = YGUndefined;
}
if (heightMeasureMode == YGMeasureModeUndefined) {
if (heightMeasureMode == MeasureMode::Undefined) {
availableHeight = YGUndefined;
}
@@ -580,8 +581,8 @@ static void measureNodeWithMeasureFunc(
? availableHeight
: yoga::maxOrDefined(0, availableHeight - paddingAndBorderAxisColumn);
if (widthMeasureMode == YGMeasureModeExactly &&
heightMeasureMode == YGMeasureModeExactly) {
if (widthMeasureMode == MeasureMode::Exactly &&
heightMeasureMode == MeasureMode::Exactly) {
// Don't bother sizing the text if both dimensions are already defined.
node->setLayoutMeasuredDimension(
boundAxis(
@@ -609,9 +610,9 @@ static void measureNodeWithMeasureFunc(
Event::publish<Event::MeasureCallbackEnd>(
node,
{innerWidth,
widthMeasureMode,
unscopedEnum(widthMeasureMode),
innerHeight,
heightMeasureMode,
unscopedEnum(heightMeasureMode),
measuredSize.width,
measuredSize.height,
reason});
@@ -620,8 +621,8 @@ static void measureNodeWithMeasureFunc(
boundAxis(
node,
YGFlexDirectionRow,
(widthMeasureMode == YGMeasureModeUndefined ||
widthMeasureMode == YGMeasureModeAtMost)
(widthMeasureMode == MeasureMode::Undefined ||
widthMeasureMode == MeasureMode::AtMost)
? measuredSize.width + paddingAndBorderAxisRow
: availableWidth,
ownerWidth,
@@ -632,8 +633,8 @@ static void measureNodeWithMeasureFunc(
boundAxis(
node,
YGFlexDirectionColumn,
(heightMeasureMode == YGMeasureModeUndefined ||
heightMeasureMode == YGMeasureModeAtMost)
(heightMeasureMode == MeasureMode::Undefined ||
heightMeasureMode == MeasureMode::AtMost)
? measuredSize.height + paddingAndBorderAxisColumn
: availableHeight,
ownerHeight,
@@ -648,16 +649,16 @@ static void measureNodeWithoutChildren(
yoga::Node* const node,
const float availableWidth,
const float availableHeight,
const YGMeasureMode widthMeasureMode,
const YGMeasureMode heightMeasureMode,
const MeasureMode widthMeasureMode,
const MeasureMode heightMeasureMode,
const float ownerWidth,
const float ownerHeight) {
const auto& padding = node->getLayout().padding;
const auto& border = node->getLayout().border;
float width = availableWidth;
if (widthMeasureMode == YGMeasureModeUndefined ||
widthMeasureMode == YGMeasureModeAtMost) {
if (widthMeasureMode == MeasureMode::Undefined ||
widthMeasureMode == MeasureMode::AtMost) {
width = padding[YGEdgeLeft] + padding[YGEdgeRight] + border[YGEdgeLeft] +
border[YGEdgeRight];
}
@@ -666,8 +667,8 @@ static void measureNodeWithoutChildren(
YGDimensionWidth);
float height = availableHeight;
if (heightMeasureMode == YGMeasureModeUndefined ||
heightMeasureMode == YGMeasureModeAtMost) {
if (heightMeasureMode == MeasureMode::Undefined ||
heightMeasureMode == MeasureMode::AtMost) {
height = padding[YGEdgeTop] + padding[YGEdgeBottom] + border[YGEdgeTop] +
border[YGEdgeBottom];
}
@@ -680,22 +681,22 @@ static bool measureNodeWithFixedSize(
yoga::Node* const node,
const float availableWidth,
const float availableHeight,
const YGMeasureMode widthMeasureMode,
const YGMeasureMode heightMeasureMode,
const MeasureMode widthMeasureMode,
const MeasureMode heightMeasureMode,
const float ownerWidth,
const float ownerHeight) {
if ((!yoga::isUndefined(availableWidth) &&
widthMeasureMode == YGMeasureModeAtMost && availableWidth <= 0.0f) ||
widthMeasureMode == MeasureMode::AtMost && availableWidth <= 0.0f) ||
(!yoga::isUndefined(availableHeight) &&
heightMeasureMode == YGMeasureModeAtMost && availableHeight <= 0.0f) ||
(widthMeasureMode == YGMeasureModeExactly &&
heightMeasureMode == YGMeasureModeExactly)) {
heightMeasureMode == MeasureMode::AtMost && availableHeight <= 0.0f) ||
(widthMeasureMode == MeasureMode::Exactly &&
heightMeasureMode == MeasureMode::Exactly)) {
node->setLayoutMeasuredDimension(
boundAxis(
node,
YGFlexDirectionRow,
yoga::isUndefined(availableWidth) ||
(widthMeasureMode == YGMeasureModeAtMost &&
(widthMeasureMode == MeasureMode::AtMost &&
availableWidth < 0.0f)
? 0.0f
: availableWidth,
@@ -708,7 +709,7 @@ static bool measureNodeWithFixedSize(
node,
YGFlexDirectionColumn,
yoga::isUndefined(availableHeight) ||
(heightMeasureMode == YGMeasureModeAtMost &&
(heightMeasureMode == MeasureMode::AtMost &&
availableHeight < 0.0f)
? 0.0f
: availableHeight,
@@ -768,8 +769,8 @@ static float computeFlexBasisForChildren(
yoga::Node* const node,
const float availableInnerWidth,
const float availableInnerHeight,
YGMeasureMode widthMeasureMode,
YGMeasureMode heightMeasureMode,
MeasureMode widthMeasureMode,
MeasureMode heightMeasureMode,
YGDirection direction,
YGFlexDirection mainAxis,
bool performLayout,
@@ -779,12 +780,12 @@ static float computeFlexBasisForChildren(
float totalOuterFlexBasis = 0.0f;
YGNodeRef singleFlexChild = nullptr;
const auto& children = node->getChildren();
YGMeasureMode measureModeMainDim =
MeasureMode measureModeMainDim =
isRow(mainAxis) ? widthMeasureMode : heightMeasureMode;
// 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
// child to exactly match the remaining space
if (measureModeMainDim == YGMeasureModeExactly) {
if (measureModeMainDim == MeasureMode::Exactly) {
for (auto child : children) {
if (child->isNodeFlexible()) {
if (singleFlexChild != nullptr ||
@@ -866,7 +867,7 @@ static float distributeFreeSpaceSecondPass(
const float availableInnerWidth,
const float availableInnerHeight,
const bool mainAxisOverflows,
const YGMeasureMode measureModeCrossDim,
const MeasureMode measureModeCrossDim,
const bool performLayout,
LayoutData& layoutMarkerData,
const uint32_t depth,
@@ -941,34 +942,34 @@ static float distributeFreeSpaceSecondPass(
float childCrossSize;
float childMainSize = updatedMainSize + marginMain;
YGMeasureMode childCrossMeasureMode;
YGMeasureMode childMainMeasureMode = YGMeasureModeExactly;
MeasureMode childCrossMeasureMode;
MeasureMode childMainMeasureMode = MeasureMode::Exactly;
const auto& childStyle = currentLineChild->getStyle();
if (!childStyle.aspectRatio().isUndefined()) {
childCrossSize = isMainAxisRow
? (childMainSize - marginMain) / childStyle.aspectRatio().unwrap()
: (childMainSize - marginMain) * childStyle.aspectRatio().unwrap();
childCrossMeasureMode = YGMeasureModeExactly;
childCrossMeasureMode = MeasureMode::Exactly;
childCrossSize += marginCross;
} else if (
!std::isnan(availableInnerCrossDim) &&
!styleDefinesDimension(
currentLineChild, crossAxis, availableInnerCrossDim) &&
measureModeCrossDim == YGMeasureModeExactly &&
measureModeCrossDim == MeasureMode::Exactly &&
!(isNodeFlexWrap && mainAxisOverflows) &&
resolveChildAlignment(node, currentLineChild) == YGAlignStretch &&
currentLineChild->marginLeadingValue(crossAxis).unit != YGUnitAuto &&
currentLineChild->marginTrailingValue(crossAxis).unit != YGUnitAuto) {
childCrossSize = availableInnerCrossDim;
childCrossMeasureMode = YGMeasureModeExactly;
childCrossMeasureMode = MeasureMode::Exactly;
} else if (!styleDefinesDimension(
currentLineChild, crossAxis, availableInnerCrossDim)) {
childCrossSize = availableInnerCrossDim;
childCrossMeasureMode = yoga::isUndefined(childCrossSize)
? YGMeasureModeUndefined
: YGMeasureModeAtMost;
? MeasureMode::Undefined
: MeasureMode::AtMost;
} else {
childCrossSize =
yoga::resolveValue(
@@ -979,11 +980,11 @@ static float distributeFreeSpaceSecondPass(
const bool isLoosePercentageMeasurement =
currentLineChild->getResolvedDimension(dimension(crossAxis)).unit ==
YGUnitPercent &&
measureModeCrossDim != YGMeasureModeExactly;
measureModeCrossDim != MeasureMode::Exactly;
childCrossMeasureMode =
yoga::isUndefined(childCrossSize) || isLoosePercentageMeasurement
? YGMeasureModeUndefined
: YGMeasureModeExactly;
? MeasureMode::Undefined
: MeasureMode::Exactly;
}
constrainMaxSizeForMode(
@@ -1011,9 +1012,9 @@ static float distributeFreeSpaceSecondPass(
const float childWidth = isMainAxisRow ? childMainSize : childCrossSize;
const float childHeight = !isMainAxisRow ? childMainSize : childCrossSize;
const YGMeasureMode childWidthMeasureMode =
const MeasureMode childWidthMeasureMode =
isMainAxisRow ? childMainMeasureMode : childCrossMeasureMode;
const YGMeasureMode childHeightMeasureMode =
const MeasureMode childHeightMeasureMode =
!isMainAxisRow ? childMainMeasureMode : childCrossMeasureMode;
const bool isLayoutPass = performLayout && !requiresStretchLayout;
@@ -1160,7 +1161,7 @@ static void resolveFlexibleLength(
const float availableInnerWidth,
const float availableInnerHeight,
const bool mainAxisOverflows,
const YGMeasureMode measureModeCrossDim,
const MeasureMode measureModeCrossDim,
const bool performLayout,
LayoutData& layoutMarkerData,
const uint32_t depth,
@@ -1201,8 +1202,8 @@ static void YGJustifyMainAxis(
const size_t startOfLineIndex,
const YGFlexDirection mainAxis,
const YGFlexDirection crossAxis,
const YGMeasureMode measureModeMainDim,
const YGMeasureMode measureModeCrossDim,
const MeasureMode measureModeMainDim,
const MeasureMode measureModeCrossDim,
const float mainAxisownerSize,
const float ownerWidth,
const float availableInnerMainDim,
@@ -1217,7 +1218,7 @@ static void YGJustifyMainAxis(
const float gap = node->getGapForAxis(mainAxis, ownerWidth).unwrap();
// If we are using "at most" rules in the main axis, make sure that
// remainingFreeSpace is 0 when min main dimension is not given
if (measureModeMainDim == YGMeasureModeAtMost &&
if (measureModeMainDim == MeasureMode::AtMost &&
flexLine.layout.remainingFreeSpace > 0) {
if (!style.minDimensions()[dimension(mainAxis)].isUndefined() &&
!yoga::resolveValue(
@@ -1348,7 +1349,7 @@ static void YGJustifyMainAxis(
static_cast<float>(numberOfAutoMarginsOnCurrentLine);
}
bool canSkipFlex =
!performLayout && measureModeCrossDim == YGMeasureModeExactly;
!performLayout && measureModeCrossDim == MeasureMode::Exactly;
if (canSkipFlex) {
// 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
@@ -1465,21 +1466,21 @@ static void YGJustifyMainAxis(
// 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
// spec (https://www.w3.org/TR/CSS3-sizing/#terms):
// - YGMeasureModeUndefined: max content
// - YGMeasureModeExactly: fill available
// - YGMeasureModeAtMost: fit content
// - MeasureMode::Undefined: max content
// - MeasureMode::Exactly: fill available
// - MeasureMode::AtMost: fit content
//
// When calling calculateLayoutImpl and calculateLayoutInternal, if the
// 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(
yoga::Node* const node,
const float availableWidth,
const float availableHeight,
const YGDirection ownerDirection,
const YGMeasureMode widthMeasureMode,
const YGMeasureMode heightMeasureMode,
const MeasureMode widthMeasureMode,
const MeasureMode heightMeasureMode,
const float ownerWidth,
const float ownerHeight,
const bool performLayout,
@@ -1490,17 +1491,17 @@ static void calculateLayoutImpl(
yoga::assertFatalWithNode(
node,
yoga::isUndefined(availableWidth)
? widthMeasureMode == YGMeasureModeUndefined
? widthMeasureMode == MeasureMode::Undefined
: true,
"availableWidth is indefinite so widthMeasureMode must be "
"YGMeasureModeUndefined");
"MeasureMode::Undefined");
yoga::assertFatalWithNode(
node,
yoga::isUndefined(availableHeight)
? heightMeasureMode == YGMeasureModeUndefined
? heightMeasureMode == MeasureMode::Undefined
: true,
"availableHeight is indefinite so heightMeasureMode must be "
"YGMeasureModeUndefined");
"MeasureMode::Undefined");
(performLayout ? layoutMarkerData.layouts : layoutMarkerData.measures) += 1;
@@ -1617,9 +1618,9 @@ static void calculateLayoutImpl(
const float paddingAndBorderAxisCross =
leadingPaddingAndBorderCross + trailingPaddingAndBorderCross;
YGMeasureMode measureModeMainDim =
MeasureMode measureModeMainDim =
isMainAxisRow ? widthMeasureMode : heightMeasureMode;
YGMeasureMode measureModeCrossDim =
MeasureMode measureModeCrossDim =
isMainAxisRow ? heightMeasureMode : widthMeasureMode;
const float paddingAndBorderAxisRow =
@@ -1671,12 +1672,12 @@ static void calculateLayoutImpl(
}
const bool mainAxisOverflows =
(measureModeMainDim != YGMeasureModeUndefined) &&
(measureModeMainDim != MeasureMode::Undefined) &&
totalMainDim > availableInnerMainDim;
if (isNodeFlexWrap && mainAxisOverflows &&
measureModeMainDim == YGMeasureModeAtMost) {
measureModeMainDim = YGMeasureModeExactly;
measureModeMainDim == MeasureMode::AtMost) {
measureModeMainDim = MeasureMode::Exactly;
}
// STEP 4: COLLECT FLEX ITEMS INTO FLEX LINES
@@ -1711,7 +1712,7 @@ static void calculateLayoutImpl(
// If we don't need to measure the cross axis, we can skip the entire flex
// step.
const bool canSkipFlex =
!performLayout && measureModeCrossDim == YGMeasureModeExactly;
!performLayout && measureModeCrossDim == MeasureMode::Exactly;
// STEP 5: RESOLVING FLEXIBLE LENGTHS ON MAIN AXIS
// Calculate the remaining available space that needs to be allocated. If
@@ -1721,7 +1722,7 @@ static void calculateLayoutImpl(
bool sizeBasedOnContent = false;
// If we don't measure with exact main dimension we want to ensure we don't
// violate min and max
if (measureModeMainDim != YGMeasureModeExactly) {
if (measureModeMainDim != MeasureMode::Exactly) {
const auto& minDimensions = node->getStyle().minDimensions();
const auto& maxDimensions = node->getStyle().maxDimensions();
const float minInnerWidth =
@@ -1755,7 +1756,7 @@ static void calculateLayoutImpl(
availableInnerMainDim = maxInnerMainDim;
} else {
bool useLegacyStretchBehaviour =
node->hasErrata(YGErrataStretchFlexBasis);
node->hasErrata(Errata::StretchFlexBasis);
if (!useLegacyStretchBehaviour &&
((!yoga::isUndefined(flexLine.layout.totalFlexGrowFactors) &&
@@ -1829,8 +1830,8 @@ static void calculateLayoutImpl(
performLayout);
float containerCrossAxis = availableInnerCrossDim;
if (measureModeCrossDim == YGMeasureModeUndefined ||
measureModeCrossDim == YGMeasureModeAtMost) {
if (measureModeCrossDim == MeasureMode::Undefined ||
measureModeCrossDim == MeasureMode::AtMost) {
// Compute the cross axis from the max cross dimension of the children.
containerCrossAxis =
boundAxis(
@@ -1843,7 +1844,7 @@ static void calculateLayoutImpl(
}
// 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;
}
@@ -1924,8 +1925,8 @@ static void calculateLayoutImpl(
child->getMarginForAxis(mainAxis, availableInnerWidth)
.unwrap();
YGMeasureMode childMainMeasureMode = YGMeasureModeExactly;
YGMeasureMode childCrossMeasureMode = YGMeasureModeExactly;
MeasureMode childMainMeasureMode = MeasureMode::Exactly;
MeasureMode childCrossMeasureMode = MeasureMode::Exactly;
constrainMaxSizeForMode(
child,
mainAxis,
@@ -1949,16 +1950,16 @@ static void calculateLayoutImpl(
auto alignContent = node->getStyle().alignContent();
auto crossAxisDoesNotGrow =
alignContent != YGAlignStretch && isNodeFlexWrap;
const YGMeasureMode childWidthMeasureMode =
const MeasureMode childWidthMeasureMode =
yoga::isUndefined(childWidth) ||
(!isMainAxisRow && crossAxisDoesNotGrow)
? YGMeasureModeUndefined
: YGMeasureModeExactly;
const YGMeasureMode childHeightMeasureMode =
? MeasureMode::Undefined
: MeasureMode::Exactly;
const MeasureMode childHeightMeasureMode =
yoga::isUndefined(childHeight) ||
(isMainAxisRow && crossAxisDoesNotGrow)
? YGMeasureModeUndefined
: YGMeasureModeExactly;
? MeasureMode::Undefined
: MeasureMode::Exactly;
calculateLayoutInternal(
child,
@@ -2181,8 +2182,8 @@ static void calculateLayoutImpl(
childWidth,
childHeight,
direction,
YGMeasureModeExactly,
YGMeasureModeExactly,
MeasureMode::Exactly,
MeasureMode::Exactly,
availableInnerWidth,
availableInnerHeight,
true,
@@ -2240,9 +2241,9 @@ static void calculateLayoutImpl(
// If the user didn't specify a width or height for the node, set the
// dimensions based on the children.
if (measureModeMainDim == YGMeasureModeUndefined ||
if (measureModeMainDim == MeasureMode::Undefined ||
(node->getStyle().overflow() != YGOverflowScroll &&
measureModeMainDim == YGMeasureModeAtMost)) {
measureModeMainDim == MeasureMode::AtMost)) {
// Clamp the size to the min/max size, if specified, and make sure it
// doesn't go below the padding and border amount.
node->setLayoutMeasuredDimension(
@@ -2251,7 +2252,7 @@ static void calculateLayoutImpl(
dimension(mainAxis));
} else if (
measureModeMainDim == YGMeasureModeAtMost &&
measureModeMainDim == MeasureMode::AtMost &&
node->getStyle().overflow() == YGOverflowScroll) {
node->setLayoutMeasuredDimension(
yoga::maxOrDefined(
@@ -2267,9 +2268,9 @@ static void calculateLayoutImpl(
dimension(mainAxis));
}
if (measureModeCrossDim == YGMeasureModeUndefined ||
if (measureModeCrossDim == MeasureMode::Undefined ||
(node->getStyle().overflow() != YGOverflowScroll &&
measureModeCrossDim == YGMeasureModeAtMost)) {
measureModeCrossDim == MeasureMode::AtMost)) {
// Clamp the size to the min/max size, if specified, and make sure it
// doesn't go below the padding and border amount.
node->setLayoutMeasuredDimension(
@@ -2282,7 +2283,7 @@ static void calculateLayoutImpl(
dimension(crossAxis));
} else if (
measureModeCrossDim == YGMeasureModeAtMost &&
measureModeCrossDim == MeasureMode::AtMost &&
node->getStyle().overflow() == YGOverflowScroll) {
node->setLayoutMeasuredDimension(
yoga::maxOrDefined(
@@ -2323,7 +2324,7 @@ static void calculateLayoutImpl(
}
const bool absolutePercentageAgainstPaddingEdge =
node->getConfig()->isExperimentalFeatureEnabled(
YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge);
ExperimentalFeature::AbsolutePercentageAgainstPaddingEdge);
layoutAbsoluteChild(
node,
@@ -2382,18 +2383,17 @@ static const char* spacerWithLength(const unsigned long level) {
}
static const char* measureModeName(
const YGMeasureMode mode,
const MeasureMode mode,
const bool performLayout) {
constexpr auto N = enums::count<YGMeasureMode>();
const char* kMeasureModeNames[N] = {"UNDEFINED", "EXACTLY", "AT_MOST"};
const char* kLayoutModeNames[N] = {
"LAY_UNDEFINED", "LAY_EXACTLY", "LAY_AT_MOST"};
if (mode >= N) {
return "";
switch (mode) {
case MeasureMode::Undefined:
return performLayout ? "LAY_UNDEFINED" : "UNDEFINED";
case MeasureMode::Exactly:
return performLayout ? "LAY_EXACTLY" : "EXACTLY";
case MeasureMode::AtMost:
return performLayout ? "LAY_AT_MOST" : "AT_MOST";
}
return performLayout ? kLayoutModeNames[mode] : kMeasureModeNames[mode];
return "";
}
//
@@ -2409,8 +2409,8 @@ bool calculateLayoutInternal(
const float availableWidth,
const float availableHeight,
const YGDirection ownerDirection,
const YGMeasureMode widthMeasureMode,
const YGMeasureMode heightMeasureMode,
const MeasureMode widthMeasureMode,
const MeasureMode heightMeasureMode,
const float ownerWidth,
const float ownerHeight,
const bool performLayout,
@@ -2431,8 +2431,8 @@ bool calculateLayoutInternal(
layout->nextCachedMeasurementsIndex = 0;
layout->cachedLayout.availableWidth = -1;
layout->cachedLayout.availableHeight = -1;
layout->cachedLayout.widthMeasureMode = YGMeasureModeUndefined;
layout->cachedLayout.heightMeasureMode = YGMeasureModeUndefined;
layout->cachedLayout.widthMeasureMode = MeasureMode::Undefined;
layout->cachedLayout.heightMeasureMode = MeasureMode::Undefined;
layout->cachedLayout.computedWidth = -1;
layout->cachedLayout.computedHeight = -1;
}
@@ -2526,14 +2526,14 @@ bool calculateLayoutInternal(
if (gPrintChanges && gPrintSkips) {
yoga::log(
node,
YGLogLevelVerbose,
LogLevel::Verbose,
"%s%d.{[skipped] ",
spacerWithLength(depth),
depth);
node->print();
yoga::log(
node,
YGLogLevelVerbose,
LogLevel::Verbose,
"wm: %s, hm: %s, aw: %f ah: %f => d: (%f, %f) %s\n",
measureModeName(widthMeasureMode, performLayout),
measureModeName(heightMeasureMode, performLayout),
@@ -2547,7 +2547,7 @@ bool calculateLayoutInternal(
if (gPrintChanges) {
yoga::log(
node,
YGLogLevelVerbose,
LogLevel::Verbose,
"%s%d.{%s",
spacerWithLength(depth),
depth,
@@ -2555,7 +2555,7 @@ bool calculateLayoutInternal(
node->print();
yoga::log(
node,
YGLogLevelVerbose,
LogLevel::Verbose,
"wm: %s, hm: %s, aw: %f ah: %f %s\n",
measureModeName(widthMeasureMode, performLayout),
measureModeName(heightMeasureMode, performLayout),
@@ -2582,7 +2582,7 @@ bool calculateLayoutInternal(
if (gPrintChanges) {
yoga::log(
node,
YGLogLevelVerbose,
LogLevel::Verbose,
"%s%d.}%s",
spacerWithLength(depth),
depth,
@@ -2590,7 +2590,7 @@ bool calculateLayoutInternal(
node->print();
yoga::log(
node,
YGLogLevelVerbose,
LogLevel::Verbose,
"wm: %s, hm: %s, d: (%f, %f) %s\n",
measureModeName(widthMeasureMode, performLayout),
measureModeName(heightMeasureMode, performLayout),
@@ -2609,7 +2609,7 @@ bool calculateLayoutInternal(
if (layout->nextCachedMeasurementsIndex ==
LayoutResults::MaxCachedMeasurements) {
if (gPrintChanges) {
yoga::log(node, YGLogLevelVerbose, "Out of cache entries!\n");
yoga::log(node, LogLevel::Verbose, "Out of cache entries!\n");
}
layout->nextCachedMeasurementsIndex = 0;
}
@@ -2678,7 +2678,7 @@ void calculateLayout(
gCurrentGenerationCount.fetch_add(1, std::memory_order_relaxed);
node->resolveDimension();
float width = YGUndefined;
YGMeasureMode widthMeasureMode = YGMeasureModeUndefined;
MeasureMode widthMeasureMode = MeasureMode::Undefined;
const auto& maxDimensions = node->getStyle().maxDimensions();
if (styleDefinesDimension(node, YGFlexDirectionRow, ownerWidth)) {
width = (yoga::resolveValue(
@@ -2686,36 +2686,36 @@ void calculateLayout(
ownerWidth) +
node->getMarginForAxis(YGFlexDirectionRow, ownerWidth))
.unwrap();
widthMeasureMode = YGMeasureModeExactly;
widthMeasureMode = MeasureMode::Exactly;
} else if (!yoga::resolveValue(maxDimensions[YGDimensionWidth], ownerWidth)
.isUndefined()) {
width = yoga::resolveValue(maxDimensions[YGDimensionWidth], ownerWidth)
.unwrap();
widthMeasureMode = YGMeasureModeAtMost;
widthMeasureMode = MeasureMode::AtMost;
} else {
width = ownerWidth;
widthMeasureMode = yoga::isUndefined(width) ? YGMeasureModeUndefined
: YGMeasureModeExactly;
widthMeasureMode = yoga::isUndefined(width) ? MeasureMode::Undefined
: MeasureMode::Exactly;
}
float height = YGUndefined;
YGMeasureMode heightMeasureMode = YGMeasureModeUndefined;
MeasureMode heightMeasureMode = MeasureMode::Undefined;
if (styleDefinesDimension(node, YGFlexDirectionColumn, ownerHeight)) {
height = (yoga::resolveValue(
node->getResolvedDimension(dimension(YGFlexDirectionColumn)),
ownerHeight) +
node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth))
.unwrap();
heightMeasureMode = YGMeasureModeExactly;
heightMeasureMode = MeasureMode::Exactly;
} else if (!yoga::resolveValue(maxDimensions[YGDimensionHeight], ownerHeight)
.isUndefined()) {
height = yoga::resolveValue(maxDimensions[YGDimensionHeight], ownerHeight)
.unwrap();
heightMeasureMode = YGMeasureModeAtMost;
heightMeasureMode = MeasureMode::AtMost;
} else {
height = ownerHeight;
heightMeasureMode = yoga::isUndefined(height) ? YGMeasureModeUndefined
: YGMeasureModeExactly;
heightMeasureMode = yoga::isUndefined(height) ? MeasureMode::Undefined
: MeasureMode::Exactly;
}
if (calculateLayoutInternal(
node,
@@ -2737,9 +2737,9 @@ void calculateLayout(
#ifdef DEBUG
if (node->getConfig()->shouldPrintTree()) {
YGNodePrint(
yoga::print(
node,
(YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsChildren | YGPrintOptionsStyle));
PrintOptions::Layout | PrintOptions::Children | PrintOptions::Style);
}
#endif
}

View File

@@ -83,7 +83,7 @@ void roundLayoutResultsToPixelGrid(
if (pointScaleFactor != 0.0f) {
// If a node has a custom measure function we never want to round down its
// size as this could lead to unwanted text truncation.
const bool textRounding = node->getNodeType() == YGNodeTypeText;
const bool textRounding = node->getNodeType() == NodeType::Text;
node->setLayoutPosition(
roundValueToPixelGrid(nodeLeft, pointScaleFactor, false, textRounding),

View File

@@ -41,37 +41,37 @@ bool Config::shouldPrintTree() const {
}
void Config::setExperimentalFeatureEnabled(
YGExperimentalFeature feature,
ExperimentalFeature feature,
bool enabled) {
experimentalFeatures_.set(feature, enabled);
experimentalFeatures_.set(static_cast<size_t>(feature), enabled);
}
bool Config::isExperimentalFeatureEnabled(YGExperimentalFeature feature) const {
return experimentalFeatures_.test(feature);
bool Config::isExperimentalFeatureEnabled(ExperimentalFeature feature) const {
return experimentalFeatures_.test(static_cast<size_t>(feature));
}
EnumBitset<YGExperimentalFeature> Config::getEnabledExperiments() const {
ExperimentalFeatureSet Config::getEnabledExperiments() const {
return experimentalFeatures_;
}
void Config::setErrata(YGErrata errata) {
void Config::setErrata(Errata errata) {
errata_ = errata;
}
void Config::addErrata(YGErrata errata) {
void Config::addErrata(Errata errata) {
errata_ |= errata;
}
void Config::removeErrata(YGErrata errata) {
void Config::removeErrata(Errata errata) {
errata_ &= (~errata);
}
YGErrata Config::getErrata() const {
Errata Config::getErrata() const {
return errata_;
}
bool Config::hasErrata(YGErrata errata) const {
return (errata_ & errata) != YGErrataNone;
bool Config::hasErrata(Errata errata) const {
return (errata_ & errata) != Errata::None;
}
void Config::setPointScaleFactor(float pointScaleFactor) {
@@ -96,10 +96,10 @@ void Config::setLogger(YGLogger logger) {
void Config::log(
const yoga::Node* node,
YGLogLevel logLevel,
LogLevel logLevel,
const char* format,
va_list args) const {
logger_(this, node, logLevel, format, args);
logger_(this, node, unscopedEnum(logLevel), format, args);
}
void Config::setCloneNodeCallback(YGCloneNodeFunc cloneNode) {

View File

@@ -7,8 +7,12 @@
#pragma once
#include <bitset>
#include <yoga/Yoga.h>
#include <yoga/bits/EnumBitset.h>
#include <yoga/enums/Errata.h>
#include <yoga/enums/ExperimentalFeature.h>
#include <yoga/enums/LogLevel.h>
// Tag struct used to form the opaque YGConfigRef for the public C API
struct YGConfig {};
@@ -18,6 +22,8 @@ namespace facebook::yoga {
class Config;
class Node;
using ExperimentalFeatureSet = std::bitset<ordinalCount<ExperimentalFeature>()>;
// Whether moving a node from an old to new config should dirty previously
// calculated layout results.
bool configUpdateInvalidatesLayout(
@@ -43,17 +49,15 @@ class YG_EXPORT Config : public ::YGConfig {
void setShouldPrintTree(bool printTree);
bool shouldPrintTree() const;
void setExperimentalFeatureEnabled(
YGExperimentalFeature feature,
bool enabled);
bool isExperimentalFeatureEnabled(YGExperimentalFeature feature) const;
EnumBitset<YGExperimentalFeature> getEnabledExperiments() const;
void setExperimentalFeatureEnabled(ExperimentalFeature feature, bool enabled);
bool isExperimentalFeatureEnabled(ExperimentalFeature feature) const;
ExperimentalFeatureSet getEnabledExperiments() const;
void setErrata(YGErrata errata);
void addErrata(YGErrata errata);
void removeErrata(YGErrata errata);
YGErrata getErrata() const;
bool hasErrata(YGErrata errata) const;
void setErrata(Errata errata);
void addErrata(Errata errata);
void removeErrata(Errata errata);
Errata getErrata() const;
bool hasErrata(Errata errata) const;
void setPointScaleFactor(float pointScaleFactor);
float getPointScaleFactor() const;
@@ -64,7 +68,7 @@ class YG_EXPORT Config : public ::YGConfig {
void setLogger(YGLogger logger);
void log(
const yoga::Node* node,
YGLogLevel logLevel,
LogLevel logLevel,
const char* format,
va_list args) const;
@@ -79,8 +83,8 @@ class YG_EXPORT Config : public ::YGConfig {
YGLogger logger_;
ConfigFlags flags_{};
EnumBitset<YGExperimentalFeature> experimentalFeatures_{};
YGErrata errata_ = YGErrataNone;
ExperimentalFeatureSet experimentalFeatures_{};
Errata errata_ = Errata::None;
float pointScaleFactor_ = 1.0f;
void* context_ = nullptr;
};

View File

@@ -22,7 +22,7 @@ namespace facebook::yoga {
void assertFatal(const bool condition, const char* message) {
if (!condition) {
yoga::log(YGLogLevelFatal, "%s\n", message);
yoga::log(LogLevel::Fatal, "%s\n", message);
fatalWithMessage(message);
}
}
@@ -32,7 +32,7 @@ void assertFatalWithNode(
const bool condition,
const char* message) {
if (!condition) {
yoga::log(node, YGLogLevelFatal, "%s\n", message);
yoga::log(node, LogLevel::Fatal, "%s\n", message);
fatalWithMessage(message);
}
}
@@ -42,7 +42,7 @@ void assertFatalWithConfig(
const bool condition,
const char* message) {
if (!condition) {
yoga::log(config, YGLogLevelFatal, "%s\n", message);
yoga::log(config, LogLevel::Fatal, "%s\n", message);
fatalWithMessage(message);
}
}

View File

@@ -18,18 +18,18 @@ namespace {
void vlog(
const yoga::Config* config,
const yoga::Node* node,
YGLogLevel level,
LogLevel level,
const char* format,
va_list args) {
if (config == nullptr) {
getDefaultLogger()(nullptr, node, level, format, args);
getDefaultLogger()(nullptr, node, unscopedEnum(level), format, args);
} else {
config->log(node, level, format, args);
}
}
} // namespace
void log(YGLogLevel level, const char* format, ...) noexcept {
void log(LogLevel level, const char* format, ...) noexcept {
va_list args;
va_start(args, format);
vlog(nullptr, nullptr, level, format, args);
@@ -38,7 +38,7 @@ void log(YGLogLevel level, const char* format, ...) noexcept {
void log(
const yoga::Node* node,
YGLogLevel level,
LogLevel level,
const char* format,
...) noexcept {
va_list args;
@@ -50,7 +50,7 @@ void log(
void log(
const yoga::Config* config,
YGLogLevel level,
LogLevel level,
const char* format,
...) noexcept {
va_list args;

View File

@@ -9,23 +9,23 @@
#include <yoga/Yoga.h>
#include <yoga/YGEnums.h>
#include <yoga/config/Config.h>
#include <yoga/enums/LogLevel.h>
#include <yoga/node/Node.h>
namespace facebook::yoga {
void log(YGLogLevel level, const char* format, ...) noexcept;
void log(LogLevel level, const char* format, ...) noexcept;
void log(
const yoga::Node* node,
YGLogLevel level,
LogLevel level,
const char* message,
...) noexcept;
void log(
const yoga::Config* config,
YGLogLevel level,
LogLevel level,
const char* format,
...) noexcept;

View File

@@ -11,6 +11,7 @@
#include <yoga/YGEnums.h>
#include <yoga/debug/Log.h>
#include <yoga/debug/NodeToString.h>
#include <yoga/numeric/Comparison.h>
@@ -118,12 +119,12 @@ static void appendEdgeIfNotUndefined(
void nodeToString(
std::string& str,
const yoga::Node* node,
YGPrintOptions options,
PrintOptions options,
uint32_t level) {
indent(str, level);
appendFormattedString(str, "<div ");
if (options & YGPrintOptionsLayout) {
if ((options & PrintOptions::Layout) == PrintOptions::Layout) {
appendFormattedString(str, "layout=\"");
appendFormattedString(
str, "width: %g; ", node->getLayout().dimensions[YGDimensionWidth]);
@@ -136,7 +137,7 @@ void nodeToString(
appendFormattedString(str, "\" ");
}
if (options & YGPrintOptionsStyle) {
if ((options & PrintOptions::Style) == PrintOptions::Style) {
appendFormattedString(str, "style=\"");
const auto& style = node->getStyle();
if (style.flexDirection() != yoga::Node{}.getStyle().flexDirection()) {
@@ -228,7 +229,8 @@ void nodeToString(
appendFormattedString(str, ">");
const size_t childCount = node->getChildCount();
if (options & YGPrintOptionsChildren && childCount > 0) {
if ((options & PrintOptions::Children) == PrintOptions::Children &&
childCount > 0) {
for (size_t i = 0; i < childCount; i++) {
appendFormattedString(str, "\n");
nodeToString(str, node->getChild(i), options, level + 1);
@@ -239,5 +241,11 @@ void nodeToString(
appendFormattedString(str, "</div>");
}
void print(const yoga::Node* node, PrintOptions options) {
std::string str;
yoga::nodeToString(str, node, options, 0);
yoga::log(node, LogLevel::Debug, str.c_str());
}
} // namespace facebook::yoga
#endif

View File

@@ -11,7 +11,7 @@
#include <string>
#include <yoga/Yoga.h>
#include <yoga/enums/PrintOptions.h>
#include <yoga/node/Node.h>
namespace facebook::yoga {
@@ -19,9 +19,11 @@ namespace facebook::yoga {
void nodeToString(
std::string& str,
const yoga::Node* node,
YGPrintOptions options,
PrintOptions options,
uint32_t level);
void print(const yoga::Node* node, PrintOptions options);
} // namespace facebook::yoga
#endif

51
yoga/enums/Align.h Normal file
View File

@@ -0,0 +1,51 @@
/*
* 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.
*/
// @generated by enums.py
// clang-format off
#pragma once
#include <cstdint>
#include <yoga/YGEnums.h>
#include <yoga/enums/YogaEnums.h>
namespace facebook::yoga {
enum class Align : uint8_t {
Auto = YGAlignAuto,
FlexStart = YGAlignFlexStart,
Center = YGAlignCenter,
FlexEnd = YGAlignFlexEnd,
Stretch = YGAlignStretch,
Baseline = YGAlignBaseline,
SpaceBetween = YGAlignSpaceBetween,
SpaceAround = YGAlignSpaceAround,
};
template <>
constexpr inline int32_t ordinalCount<Align>() {
return 8;
}
template <>
constexpr inline int32_t bitCount<Align>() {
return 3;
}
constexpr inline Align scopedEnum(YGAlign unscoped) {
return static_cast<Align>(unscoped);
}
constexpr inline YGAlign unscopedEnum(Align scoped) {
return static_cast<YGAlign>(scoped);
}
inline const char* toString(Align e) {
return YGAlignToString(unscopedEnum(e));
}
} // namespace facebook::yoga

45
yoga/enums/Dimension.h Normal file
View File

@@ -0,0 +1,45 @@
/*
* 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.
*/
// @generated by enums.py
// clang-format off
#pragma once
#include <cstdint>
#include <yoga/YGEnums.h>
#include <yoga/enums/YogaEnums.h>
namespace facebook::yoga {
enum class Dimension : uint8_t {
Width = YGDimensionWidth,
Height = YGDimensionHeight,
};
template <>
constexpr inline int32_t ordinalCount<Dimension>() {
return 2;
}
template <>
constexpr inline int32_t bitCount<Dimension>() {
return 1;
}
constexpr inline Dimension scopedEnum(YGDimension unscoped) {
return static_cast<Dimension>(unscoped);
}
constexpr inline YGDimension unscopedEnum(Dimension scoped) {
return static_cast<YGDimension>(scoped);
}
inline const char* toString(Dimension e) {
return YGDimensionToString(unscopedEnum(e));
}
} // namespace facebook::yoga

46
yoga/enums/Direction.h Normal file
View File

@@ -0,0 +1,46 @@
/*
* 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.
*/
// @generated by enums.py
// clang-format off
#pragma once
#include <cstdint>
#include <yoga/YGEnums.h>
#include <yoga/enums/YogaEnums.h>
namespace facebook::yoga {
enum class Direction : uint8_t {
Inherit = YGDirectionInherit,
LTR = YGDirectionLTR,
RTL = YGDirectionRTL,
};
template <>
constexpr inline int32_t ordinalCount<Direction>() {
return 3;
}
template <>
constexpr inline int32_t bitCount<Direction>() {
return 2;
}
constexpr inline Direction scopedEnum(YGDirection unscoped) {
return static_cast<Direction>(unscoped);
}
constexpr inline YGDirection unscopedEnum(Direction scoped) {
return static_cast<YGDirection>(scoped);
}
inline const char* toString(Direction e) {
return YGDirectionToString(unscopedEnum(e));
}
} // namespace facebook::yoga

45
yoga/enums/Display.h Normal file
View File

@@ -0,0 +1,45 @@
/*
* 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.
*/
// @generated by enums.py
// clang-format off
#pragma once
#include <cstdint>
#include <yoga/YGEnums.h>
#include <yoga/enums/YogaEnums.h>
namespace facebook::yoga {
enum class Display : uint8_t {
Flex = YGDisplayFlex,
None = YGDisplayNone,
};
template <>
constexpr inline int32_t ordinalCount<Display>() {
return 2;
}
template <>
constexpr inline int32_t bitCount<Display>() {
return 1;
}
constexpr inline Display scopedEnum(YGDisplay unscoped) {
return static_cast<Display>(unscoped);
}
constexpr inline YGDisplay unscopedEnum(Display scoped) {
return static_cast<YGDisplay>(scoped);
}
inline const char* toString(Display e) {
return YGDisplayToString(unscopedEnum(e));
}
} // namespace facebook::yoga

52
yoga/enums/Edge.h Normal file
View File

@@ -0,0 +1,52 @@
/*
* 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.
*/
// @generated by enums.py
// clang-format off
#pragma once
#include <cstdint>
#include <yoga/YGEnums.h>
#include <yoga/enums/YogaEnums.h>
namespace facebook::yoga {
enum class Edge : uint8_t {
Left = YGEdgeLeft,
Top = YGEdgeTop,
Right = YGEdgeRight,
Bottom = YGEdgeBottom,
Start = YGEdgeStart,
End = YGEdgeEnd,
Horizontal = YGEdgeHorizontal,
Vertical = YGEdgeVertical,
All = YGEdgeAll,
};
template <>
constexpr inline int32_t ordinalCount<Edge>() {
return 9;
}
template <>
constexpr inline int32_t bitCount<Edge>() {
return 4;
}
constexpr inline Edge scopedEnum(YGEdge unscoped) {
return static_cast<Edge>(unscoped);
}
constexpr inline YGEdge unscopedEnum(Edge scoped) {
return static_cast<YGEdge>(scoped);
}
inline const char* toString(Edge e) {
return YGEdgeToString(unscopedEnum(e));
}
} // namespace facebook::yoga

49
yoga/enums/Errata.h Normal file
View File

@@ -0,0 +1,49 @@
/*
* 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.
*/
// @generated by enums.py
// clang-format off
#pragma once
#include <cstdint>
#include <yoga/YGEnums.h>
#include <yoga/enums/YogaEnums.h>
namespace facebook::yoga {
enum class Errata : uint32_t {
None = YGErrataNone,
StretchFlexBasis = YGErrataStretchFlexBasis,
All = YGErrataAll,
Classic = YGErrataClassic,
};
YG_DEFINE_ENUM_FLAG_OPERATORS(Errata)
template <>
constexpr inline int32_t ordinalCount<Errata>() {
return 4;
}
template <>
constexpr inline int32_t bitCount<Errata>() {
return 2;
}
constexpr inline Errata scopedEnum(YGErrata unscoped) {
return static_cast<Errata>(unscoped);
}
constexpr inline YGErrata unscopedEnum(Errata scoped) {
return static_cast<YGErrata>(scoped);
}
inline const char* toString(Errata e) {
return YGErrataToString(unscopedEnum(e));
}
} // namespace facebook::yoga

View File

@@ -0,0 +1,45 @@
/*
* 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.
*/
// @generated by enums.py
// clang-format off
#pragma once
#include <cstdint>
#include <yoga/YGEnums.h>
#include <yoga/enums/YogaEnums.h>
namespace facebook::yoga {
enum class ExperimentalFeature : uint8_t {
WebFlexBasis = YGExperimentalFeatureWebFlexBasis,
AbsolutePercentageAgainstPaddingEdge = YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge,
};
template <>
constexpr inline int32_t ordinalCount<ExperimentalFeature>() {
return 2;
}
template <>
constexpr inline int32_t bitCount<ExperimentalFeature>() {
return 1;
}
constexpr inline ExperimentalFeature scopedEnum(YGExperimentalFeature unscoped) {
return static_cast<ExperimentalFeature>(unscoped);
}
constexpr inline YGExperimentalFeature unscopedEnum(ExperimentalFeature scoped) {
return static_cast<YGExperimentalFeature>(scoped);
}
inline const char* toString(ExperimentalFeature e) {
return YGExperimentalFeatureToString(unscopedEnum(e));
}
} // namespace facebook::yoga

View File

@@ -0,0 +1,47 @@
/*
* 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.
*/
// @generated by enums.py
// clang-format off
#pragma once
#include <cstdint>
#include <yoga/YGEnums.h>
#include <yoga/enums/YogaEnums.h>
namespace facebook::yoga {
enum class FlexDirection : uint8_t {
Column = YGFlexDirectionColumn,
ColumnReverse = YGFlexDirectionColumnReverse,
Row = YGFlexDirectionRow,
RowReverse = YGFlexDirectionRowReverse,
};
template <>
constexpr inline int32_t ordinalCount<FlexDirection>() {
return 4;
}
template <>
constexpr inline int32_t bitCount<FlexDirection>() {
return 2;
}
constexpr inline FlexDirection scopedEnum(YGFlexDirection unscoped) {
return static_cast<FlexDirection>(unscoped);
}
constexpr inline YGFlexDirection unscopedEnum(FlexDirection scoped) {
return static_cast<YGFlexDirection>(scoped);
}
inline const char* toString(FlexDirection e) {
return YGFlexDirectionToString(unscopedEnum(e));
}
} // namespace facebook::yoga

46
yoga/enums/Gutter.h Normal file
View File

@@ -0,0 +1,46 @@
/*
* 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.
*/
// @generated by enums.py
// clang-format off
#pragma once
#include <cstdint>
#include <yoga/YGEnums.h>
#include <yoga/enums/YogaEnums.h>
namespace facebook::yoga {
enum class Gutter : uint8_t {
Column = YGGutterColumn,
Row = YGGutterRow,
All = YGGutterAll,
};
template <>
constexpr inline int32_t ordinalCount<Gutter>() {
return 3;
}
template <>
constexpr inline int32_t bitCount<Gutter>() {
return 2;
}
constexpr inline Gutter scopedEnum(YGGutter unscoped) {
return static_cast<Gutter>(unscoped);
}
constexpr inline YGGutter unscopedEnum(Gutter scoped) {
return static_cast<YGGutter>(scoped);
}
inline const char* toString(Gutter e) {
return YGGutterToString(unscopedEnum(e));
}
} // namespace facebook::yoga

49
yoga/enums/Justify.h Normal file
View File

@@ -0,0 +1,49 @@
/*
* 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.
*/
// @generated by enums.py
// clang-format off
#pragma once
#include <cstdint>
#include <yoga/YGEnums.h>
#include <yoga/enums/YogaEnums.h>
namespace facebook::yoga {
enum class Justify : uint8_t {
FlexStart = YGJustifyFlexStart,
Center = YGJustifyCenter,
FlexEnd = YGJustifyFlexEnd,
SpaceBetween = YGJustifySpaceBetween,
SpaceAround = YGJustifySpaceAround,
SpaceEvenly = YGJustifySpaceEvenly,
};
template <>
constexpr inline int32_t ordinalCount<Justify>() {
return 6;
}
template <>
constexpr inline int32_t bitCount<Justify>() {
return 3;
}
constexpr inline Justify scopedEnum(YGJustify unscoped) {
return static_cast<Justify>(unscoped);
}
constexpr inline YGJustify unscopedEnum(Justify scoped) {
return static_cast<YGJustify>(scoped);
}
inline const char* toString(Justify e) {
return YGJustifyToString(unscopedEnum(e));
}
} // namespace facebook::yoga

49
yoga/enums/LogLevel.h Normal file
View File

@@ -0,0 +1,49 @@
/*
* 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.
*/
// @generated by enums.py
// clang-format off
#pragma once
#include <cstdint>
#include <yoga/YGEnums.h>
#include <yoga/enums/YogaEnums.h>
namespace facebook::yoga {
enum class LogLevel : uint8_t {
Error = YGLogLevelError,
Warn = YGLogLevelWarn,
Info = YGLogLevelInfo,
Debug = YGLogLevelDebug,
Verbose = YGLogLevelVerbose,
Fatal = YGLogLevelFatal,
};
template <>
constexpr inline int32_t ordinalCount<LogLevel>() {
return 6;
}
template <>
constexpr inline int32_t bitCount<LogLevel>() {
return 3;
}
constexpr inline LogLevel scopedEnum(YGLogLevel unscoped) {
return static_cast<LogLevel>(unscoped);
}
constexpr inline YGLogLevel unscopedEnum(LogLevel scoped) {
return static_cast<YGLogLevel>(scoped);
}
inline const char* toString(LogLevel e) {
return YGLogLevelToString(unscopedEnum(e));
}
} // namespace facebook::yoga

46
yoga/enums/MeasureMode.h Normal file
View File

@@ -0,0 +1,46 @@
/*
* 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.
*/
// @generated by enums.py
// clang-format off
#pragma once
#include <cstdint>
#include <yoga/YGEnums.h>
#include <yoga/enums/YogaEnums.h>
namespace facebook::yoga {
enum class MeasureMode : uint8_t {
Undefined = YGMeasureModeUndefined,
Exactly = YGMeasureModeExactly,
AtMost = YGMeasureModeAtMost,
};
template <>
constexpr inline int32_t ordinalCount<MeasureMode>() {
return 3;
}
template <>
constexpr inline int32_t bitCount<MeasureMode>() {
return 2;
}
constexpr inline MeasureMode scopedEnum(YGMeasureMode unscoped) {
return static_cast<MeasureMode>(unscoped);
}
constexpr inline YGMeasureMode unscopedEnum(MeasureMode scoped) {
return static_cast<YGMeasureMode>(scoped);
}
inline const char* toString(MeasureMode e) {
return YGMeasureModeToString(unscopedEnum(e));
}
} // namespace facebook::yoga

45
yoga/enums/NodeType.h Normal file
View File

@@ -0,0 +1,45 @@
/*
* 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.
*/
// @generated by enums.py
// clang-format off
#pragma once
#include <cstdint>
#include <yoga/YGEnums.h>
#include <yoga/enums/YogaEnums.h>
namespace facebook::yoga {
enum class NodeType : uint8_t {
Default = YGNodeTypeDefault,
Text = YGNodeTypeText,
};
template <>
constexpr inline int32_t ordinalCount<NodeType>() {
return 2;
}
template <>
constexpr inline int32_t bitCount<NodeType>() {
return 1;
}
constexpr inline NodeType scopedEnum(YGNodeType unscoped) {
return static_cast<NodeType>(unscoped);
}
constexpr inline YGNodeType unscopedEnum(NodeType scoped) {
return static_cast<YGNodeType>(scoped);
}
inline const char* toString(NodeType e) {
return YGNodeTypeToString(unscopedEnum(e));
}
} // namespace facebook::yoga

46
yoga/enums/Overflow.h Normal file
View File

@@ -0,0 +1,46 @@
/*
* 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.
*/
// @generated by enums.py
// clang-format off
#pragma once
#include <cstdint>
#include <yoga/YGEnums.h>
#include <yoga/enums/YogaEnums.h>
namespace facebook::yoga {
enum class Overflow : uint8_t {
Visible = YGOverflowVisible,
Hidden = YGOverflowHidden,
Scroll = YGOverflowScroll,
};
template <>
constexpr inline int32_t ordinalCount<Overflow>() {
return 3;
}
template <>
constexpr inline int32_t bitCount<Overflow>() {
return 2;
}
constexpr inline Overflow scopedEnum(YGOverflow unscoped) {
return static_cast<Overflow>(unscoped);
}
constexpr inline YGOverflow unscopedEnum(Overflow scoped) {
return static_cast<YGOverflow>(scoped);
}
inline const char* toString(Overflow e) {
return YGOverflowToString(unscopedEnum(e));
}
} // namespace facebook::yoga

46
yoga/enums/PositionType.h Normal file
View File

@@ -0,0 +1,46 @@
/*
* 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.
*/
// @generated by enums.py
// clang-format off
#pragma once
#include <cstdint>
#include <yoga/YGEnums.h>
#include <yoga/enums/YogaEnums.h>
namespace facebook::yoga {
enum class PositionType : uint8_t {
Static = YGPositionTypeStatic,
Relative = YGPositionTypeRelative,
Absolute = YGPositionTypeAbsolute,
};
template <>
constexpr inline int32_t ordinalCount<PositionType>() {
return 3;
}
template <>
constexpr inline int32_t bitCount<PositionType>() {
return 2;
}
constexpr inline PositionType scopedEnum(YGPositionType unscoped) {
return static_cast<PositionType>(unscoped);
}
constexpr inline YGPositionType unscopedEnum(PositionType scoped) {
return static_cast<YGPositionType>(scoped);
}
inline const char* toString(PositionType e) {
return YGPositionTypeToString(unscopedEnum(e));
}
} // namespace facebook::yoga

48
yoga/enums/PrintOptions.h Normal file
View File

@@ -0,0 +1,48 @@
/*
* 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.
*/
// @generated by enums.py
// clang-format off
#pragma once
#include <cstdint>
#include <yoga/YGEnums.h>
#include <yoga/enums/YogaEnums.h>
namespace facebook::yoga {
enum class PrintOptions : uint32_t {
Layout = YGPrintOptionsLayout,
Style = YGPrintOptionsStyle,
Children = YGPrintOptionsChildren,
};
YG_DEFINE_ENUM_FLAG_OPERATORS(PrintOptions)
template <>
constexpr inline int32_t ordinalCount<PrintOptions>() {
return 3;
}
template <>
constexpr inline int32_t bitCount<PrintOptions>() {
return 2;
}
constexpr inline PrintOptions scopedEnum(YGPrintOptions unscoped) {
return static_cast<PrintOptions>(unscoped);
}
constexpr inline YGPrintOptions unscopedEnum(PrintOptions scoped) {
return static_cast<YGPrintOptions>(scoped);
}
inline const char* toString(PrintOptions e) {
return YGPrintOptionsToString(unscopedEnum(e));
}
} // namespace facebook::yoga

47
yoga/enums/Unit.h Normal file
View File

@@ -0,0 +1,47 @@
/*
* 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.
*/
// @generated by enums.py
// clang-format off
#pragma once
#include <cstdint>
#include <yoga/YGEnums.h>
#include <yoga/enums/YogaEnums.h>
namespace facebook::yoga {
enum class Unit : uint8_t {
Undefined = YGUnitUndefined,
Point = YGUnitPoint,
Percent = YGUnitPercent,
Auto = YGUnitAuto,
};
template <>
constexpr inline int32_t ordinalCount<Unit>() {
return 4;
}
template <>
constexpr inline int32_t bitCount<Unit>() {
return 2;
}
constexpr inline Unit scopedEnum(YGUnit unscoped) {
return static_cast<Unit>(unscoped);
}
constexpr inline YGUnit unscopedEnum(Unit scoped) {
return static_cast<YGUnit>(scoped);
}
inline const char* toString(Unit e) {
return YGUnitToString(unscopedEnum(e));
}
} // namespace facebook::yoga

46
yoga/enums/Wrap.h Normal file
View File

@@ -0,0 +1,46 @@
/*
* 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.
*/
// @generated by enums.py
// clang-format off
#pragma once
#include <cstdint>
#include <yoga/YGEnums.h>
#include <yoga/enums/YogaEnums.h>
namespace facebook::yoga {
enum class Wrap : uint8_t {
NoWrap = YGWrapNoWrap,
Wrap = YGWrapWrap,
WrapReverse = YGWrapWrapReverse,
};
template <>
constexpr inline int32_t ordinalCount<Wrap>() {
return 3;
}
template <>
constexpr inline int32_t bitCount<Wrap>() {
return 2;
}
constexpr inline Wrap scopedEnum(YGWrap unscoped) {
return static_cast<Wrap>(unscoped);
}
constexpr inline YGWrap unscopedEnum(Wrap scoped) {
return static_cast<YGWrap>(scoped);
}
inline const char* toString(Wrap e) {
return YGWrapToString(unscopedEnum(e));
}
} // namespace facebook::yoga

View File

@@ -7,13 +7,12 @@
#pragma once
#include <yoga/YGEnums.h>
#include <bitset>
namespace facebook::yoga {
// std::bitset with one bit for each option defined in YG_ENUM_SEQ_DECL
template <typename Enum>
using EnumBitset = std::bitset<enums::count<Enum>()>;
template <typename EnumT>
constexpr inline int32_t ordinalCount();
template <typename EnumT>
constexpr inline int32_t bitCount();
} // namespace facebook::yoga

View File

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

View File

@@ -211,10 +211,11 @@ FloatOptional Node::getGapForAxis(
YGSize Node::measure(
float width,
YGMeasureMode widthMode,
MeasureMode widthMode,
float height,
YGMeasureMode heightMode) {
return measureFunc_(this, width, widthMode, height, heightMode);
MeasureMode heightMode) {
return measureFunc_(
this, width, unscopedEnum(widthMode), height, unscopedEnum(heightMode));
}
float Node::baseline(float width, float height) const {
@@ -227,7 +228,7 @@ void Node::setMeasureFunc(YGMeasureFunc measureFunc) {
if (measureFunc == nullptr) {
// TODO: t18095186 Move nodeType to opt-in function and mark appropriate
// places in Litho
setNodeType(YGNodeTypeDefault);
setNodeType(NodeType::Default);
} else {
yoga::assertFatalWithNode(
this,
@@ -236,7 +237,7 @@ void Node::setMeasureFunc(YGMeasureFunc measureFunc) {
"children.");
// TODO: t18095186 Move nodeType to opt-in function and mark appropriate
// places in Litho
setNodeType(YGNodeTypeText);
setNodeType(NodeType::Text);
}
measureFunc_ = measureFunc;

View File

@@ -14,6 +14,9 @@
#include <yoga/Yoga.h>
#include <yoga/config/Config.h>
#include <yoga/enums/Errata.h>
#include <yoga/enums/MeasureMode.h>
#include <yoga/enums/NodeType.h>
#include <yoga/node/LayoutResults.h>
#include <yoga/style/CompactValue.h>
#include <yoga/style/Style.h>
@@ -29,7 +32,7 @@ struct NodeFlags {
bool hasNewLayout : 1;
bool isReferenceBaseline : 1;
bool isDirty : 1;
uint32_t nodeType : 1;
NodeType nodeType : bitCount<NodeType>();
};
#pragma pack(pop)
@@ -92,15 +95,15 @@ class YG_EXPORT Node : public ::YGNode {
return flags_.hasNewLayout;
}
YGNodeType getNodeType() const {
return static_cast<YGNodeType>(flags_.nodeType);
NodeType getNodeType() const {
return flags_.nodeType;
}
bool hasMeasureFunc() const noexcept {
return measureFunc_ != nullptr;
}
YGSize measure(float, YGMeasureMode, float, YGMeasureMode);
YGSize measure(float, MeasureMode, float, MeasureMode);
bool hasBaselineFunc() const noexcept {
return baselineFunc_ != nullptr;
@@ -108,7 +111,7 @@ class YG_EXPORT Node : public ::YGNode {
float baseline(float width, float height) const;
bool hasErrata(YGErrata errata) const {
bool hasErrata(Errata errata) const {
return config_->hasErrata(errata);
}
@@ -250,8 +253,8 @@ class YG_EXPORT Node : public ::YGNode {
flags_.hasNewLayout = hasNewLayout;
}
void setNodeType(YGNodeType nodeType) {
flags_.nodeType = static_cast<uint32_t>(nodeType) & 0x01;
void setNodeType(NodeType nodeType) {
flags_.nodeType = nodeType;
}
void setMeasureFunc(YGMeasureFunc measureFunc);