diff --git a/tests/YGStyleAccessorsTest.cpp b/tests/YGStyleAccessorsTest.cpp new file mode 100644 index 00000000..9e65ad55 --- /dev/null +++ b/tests/YGStyleAccessorsTest.cpp @@ -0,0 +1,246 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the LICENSE + * file in the root directory of this source tree. + */ +#include +#include +#include + +#include + +#define ACCESSOR_TESTS_1(NAME, X) \ + style.NAME() = X; \ + ASSERT_EQ(style.NAME(), X); +#define ACCESSOR_TESTS_2(NAME, X, ...) \ + ACCESSOR_TESTS_1(NAME, X); \ + ACCESSOR_TESTS_1(NAME, __VA_ARGS__); +#define ACCESSOR_TESTS_3(NAME, X, ...) \ + ACCESSOR_TESTS_1(NAME, X); \ + ACCESSOR_TESTS_2(NAME, __VA_ARGS__); +#define ACCESSOR_TESTS_4(NAME, X, ...) \ + ACCESSOR_TESTS_1(NAME, X); \ + ACCESSOR_TESTS_3(NAME, __VA_ARGS__); +#define ACCESSOR_TESTS_5(NAME, X, ...) \ + ACCESSOR_TESTS_1(NAME, X); \ + ACCESSOR_TESTS_4(NAME, __VA_ARGS__) + +#define ACCESSOR_TESTS_N(a, b, c, d, e, COUNT, ...) ACCESSOR_TESTS_##COUNT +#define ACCESSOR_TESTS(...) ACCESSOR_TESTS_N(__VA_ARGS__, 5, 4, 3, 2, 1) + +#define INDEX_ACCESSOR_TESTS_1(NAME, IDX, X) \ + style.NAME()[IDX] = X; \ + ASSERT_EQ(style.NAME()[IDX], X); + +#define INDEX_ACCESSOR_TESTS_2(NAME, IDX, X, Y) \ + INDEX_ACCESSOR_TESTS_1(NAME, IDX, X) \ + INDEX_ACCESSOR_TESTS_1(NAME, IDX, Y) + +#define INDEX_ACCESSOR_TESTS_3(NAME, IDX, X, ...) \ + INDEX_ACCESSOR_TESTS_1(NAME, IDX, X) \ + INDEX_ACCESSOR_TESTS_2(NAME, IDX, __VA_ARGS__) + +#define INDEX_ACCESSOR_TESTS_4(NAME, IDX, X, ...) \ + INDEX_ACCESSOR_TESTS_1(NAME, IDX, X) \ + INDEX_ACCESSOR_TESTS_3(NAME, IDX, __VA_ARGS__) + +#define INDEX_ACCESSOR_TESTS_5(NAME, IDX, X, ...) \ + INDEX_ACCESSOR_TESTS_1(NAME, IDX, X) \ + INDEX_ACCESSOR_TESTS_4(NAME, IDX, __VA_ARGS__) + +#define INDEX_ACCESSOR_TESTS_N(a, b, c, d, e, COUNT, ...) \ + INDEX_ACCESSOR_TESTS_##COUNT +#define INDEX_ACCESSOR_TESTS(...) \ + INDEX_ACCESSOR_TESTS_N(__VA_ARGS__, 5, 4, 3, 2, 1) + +// test macro for up to 5 values. If more are needed, extend the macros above. +#define ACCESSOR_TEST(NAME, DEFAULT_VAL, ...) \ + TEST(YGStyle, style_##NAME##_access) { \ + auto style = YGStyle{}; \ + ASSERT_EQ(style.NAME(), DEFAULT_VAL); \ + ACCESSOR_TESTS(__VA_ARGS__)(NAME, __VA_ARGS__) \ + } + +#define INDEX_ACCESSOR_TEST(NAME, DEFAULT_VAL, IDX, ...) \ + TEST(YGStyle, style_##NAME##_access) { \ + auto style = YGStyle{}; \ + ASSERT_EQ(style.NAME()[IDX], DEFAULT_VAL); \ + INDEX_ACCESSOR_TESTS(__VA_ARGS__)(NAME, IDX, __VA_ARGS__) \ + } + +namespace facebook { +namespace yoga { + +using CompactValue = detail::CompactValue; + +ACCESSOR_TEST( + direction, + YGDirectionInherit, + YGDirectionLTR, + YGDirectionRTL, + YGDirectionInherit); + +ACCESSOR_TEST( + flexDirection, + YGFlexDirectionColumn, + YGFlexDirectionColumnReverse, + YGFlexDirectionRowReverse, + YGFlexDirectionRow) + +ACCESSOR_TEST( + justifyContent, + YGJustifyFlexStart, + YGJustifyFlexEnd, + YGJustifySpaceAround, + YGJustifyFlexStart, + YGJustifySpaceEvenly) + +ACCESSOR_TEST( + alignContent, + YGAlignFlexStart, + YGAlignAuto, + YGAlignFlexStart, + YGAlignCenter, + YGAlignFlexEnd, + YGAlignStretch) + +ACCESSOR_TEST( + alignItems, + YGAlignStretch, + YGAlignFlexStart, + YGAlignFlexEnd, + YGAlignBaseline, + YGAlignSpaceBetween, + YGAlignSpaceAround) + +ACCESSOR_TEST( + alignSelf, + YGAlignAuto, + YGAlignFlexStart, + YGAlignCenter, + YGAlignAuto, + YGAlignFlexEnd, + YGAlignStretch) + +ACCESSOR_TEST( + positionType, + YGPositionTypeRelative, + YGPositionTypeAbsolute, + YGPositionTypeRelative) + +ACCESSOR_TEST( + flexWrap, + YGWrapNoWrap, + YGWrapWrap, + YGWrapWrapReverse, + YGWrapNoWrap) + +ACCESSOR_TEST( + overflow, + YGOverflowVisible, + YGOverflowHidden, + YGOverflowScroll, + YGOverflowVisible) + +ACCESSOR_TEST(display, YGDisplayFlex, YGDisplayNone, YGDisplayFlex) + +ACCESSOR_TEST( + flex, + YGFloatOptional{}, + YGFloatOptional{123.45f}, + YGFloatOptional{-9.87f}, + YGFloatOptional{}) + +ACCESSOR_TEST( + flexGrow, + YGFloatOptional{}, + YGFloatOptional{123.45f}, + YGFloatOptional{-9.87f}, + YGFloatOptional{}) + +ACCESSOR_TEST( + flexShrink, + YGFloatOptional{}, + YGFloatOptional{123.45f}, + YGFloatOptional{-9.87f}, + YGFloatOptional{}) + +ACCESSOR_TEST( + flexBasis, + CompactValue::ofAuto(), + CompactValue::ofUndefined(), + CompactValue::ofAuto(), + CompactValue::of(7777.77f), + CompactValue::of(-100.0f)) + +INDEX_ACCESSOR_TEST( + position, + CompactValue::ofUndefined(), + YGEdgeBottom, + CompactValue::ofAuto(), + CompactValue::ofUndefined(), + CompactValue::of(7777.77f), + CompactValue::of(-100.0f)) + +INDEX_ACCESSOR_TEST( + margin, + CompactValue::ofUndefined(), + YGEdgeTop, + CompactValue::ofAuto(), + CompactValue::ofUndefined(), + CompactValue::of(7777.77f), + CompactValue::of(-100.0f)) + +INDEX_ACCESSOR_TEST( + padding, + CompactValue::ofUndefined(), + YGEdgeAll, + CompactValue::of(7777.77f), + CompactValue::ofUndefined(), + CompactValue::of(-100.0f)) + +INDEX_ACCESSOR_TEST( + border, + CompactValue::ofUndefined(), + YGEdgeHorizontal, + CompactValue::of(-7777.77f), + CompactValue::ofUndefined()) + +INDEX_ACCESSOR_TEST( + dimensions, + CompactValue::ofAuto(), + YGDimensionWidth, + CompactValue::ofUndefined(), + CompactValue::ofAuto(), + CompactValue::of(7777.77f), + CompactValue::of(-100.0f)) + +INDEX_ACCESSOR_TEST( + minDimensions, + CompactValue::ofUndefined(), + YGDimensionHeight, + CompactValue::ofAuto(), + CompactValue::ofUndefined(), + CompactValue::of(7777.77f), + CompactValue::of(-100.0f)) + +INDEX_ACCESSOR_TEST( + maxDimensions, + CompactValue::ofUndefined(), + YGDimensionHeight, + CompactValue::ofAuto(), + CompactValue::ofUndefined(), + CompactValue::of(7777.77f), + CompactValue::of(-100.0f)) + +ACCESSOR_TEST( + aspectRatio, + YGFloatOptional{}, + YGFloatOptional{-123.45f}, + YGFloatOptional{9876.5f}, + YGFloatOptional{0.0f}, + YGFloatOptional{}); + +} // namespace yoga +} // namespace facebook diff --git a/yoga/YGNode.cpp b/yoga/YGNode.cpp index 2fb4510c..2c68d607 100644 --- a/yoga/YGNode.cpp +++ b/yoga/YGNode.cpp @@ -53,14 +53,14 @@ YGFloatOptional YGNode::getLeadingPosition( const float axisSize) const { if (YGFlexDirectionIsRow(axis)) { auto leadingPosition = YGComputedEdgeValue( - style_.position, YGEdgeStart, CompactValue::ofUndefined()); + style_.position(), YGEdgeStart, CompactValue::ofUndefined()); if (!leadingPosition.isUndefined()) { return YGResolveValue(leadingPosition, axisSize); } } auto leadingPosition = YGComputedEdgeValue( - style_.position, leading[axis], CompactValue::ofUndefined()); + style_.position(), leading[axis], CompactValue::ofUndefined()); return leadingPosition.isUndefined() ? YGFloatOptional{0} @@ -72,14 +72,14 @@ YGFloatOptional YGNode::getTrailingPosition( const float axisSize) const { if (YGFlexDirectionIsRow(axis)) { auto trailingPosition = YGComputedEdgeValue( - style_.position, YGEdgeEnd, CompactValue::ofUndefined()); + style_.position(), YGEdgeEnd, CompactValue::ofUndefined()); if (!trailingPosition.isUndefined()) { return YGResolveValue(trailingPosition, axisSize); } } auto trailingPosition = YGComputedEdgeValue( - style_.position, trailing[axis], CompactValue::ofUndefined()); + style_.position(), trailing[axis], CompactValue::ofUndefined()); return trailingPosition.isUndefined() ? YGFloatOptional{0} @@ -89,45 +89,47 @@ YGFloatOptional YGNode::getTrailingPosition( bool YGNode::isLeadingPositionDefined(const YGFlexDirection axis) const { return (YGFlexDirectionIsRow(axis) && !YGComputedEdgeValue( - style_.position, YGEdgeStart, CompactValue::ofUndefined()) + style_.position(), YGEdgeStart, CompactValue::ofUndefined()) .isUndefined()) || !YGComputedEdgeValue( - style_.position, leading[axis], CompactValue::ofUndefined()) + style_.position(), leading[axis], CompactValue::ofUndefined()) .isUndefined(); } bool YGNode::isTrailingPosDefined(const YGFlexDirection axis) const { return (YGFlexDirectionIsRow(axis) && !YGComputedEdgeValue( - style_.position, YGEdgeEnd, CompactValue::ofUndefined()) + style_.position(), YGEdgeEnd, CompactValue::ofUndefined()) .isUndefined()) || !YGComputedEdgeValue( - style_.position, trailing[axis], CompactValue::ofUndefined()) + style_.position(), trailing[axis], CompactValue::ofUndefined()) .isUndefined(); } YGFloatOptional YGNode::getLeadingMargin( const YGFlexDirection axis, const float widthSize) const { - if (YGFlexDirectionIsRow(axis) && !style_.margin[YGEdgeStart].isUndefined()) { - return YGResolveValueMargin(style_.margin[YGEdgeStart], widthSize); + if (YGFlexDirectionIsRow(axis) && + !style_.margin()[YGEdgeStart].isUndefined()) { + return YGResolveValueMargin(style_.margin()[YGEdgeStart], widthSize); } return YGResolveValueMargin( - YGComputedEdgeValue(style_.margin, leading[axis], CompactValue::ofZero()), + YGComputedEdgeValue( + style_.margin(), leading[axis], CompactValue::ofZero()), widthSize); } YGFloatOptional YGNode::getTrailingMargin( const YGFlexDirection axis, const float widthSize) const { - if (YGFlexDirectionIsRow(axis) && !style_.margin[YGEdgeEnd].isUndefined()) { - return YGResolveValueMargin(style_.margin[YGEdgeEnd], widthSize); + if (YGFlexDirectionIsRow(axis) && !style_.margin()[YGEdgeEnd].isUndefined()) { + return YGResolveValueMargin(style_.margin()[YGEdgeEnd], widthSize); } return YGResolveValueMargin( YGComputedEdgeValue( - style_.margin, trailing[axis], CompactValue::ofZero()), + style_.margin(), trailing[axis], CompactValue::ofZero()), widthSize); } @@ -299,7 +301,7 @@ void YGNode::setPosition( const YGDirection directionRespectingRoot = owner_ != nullptr ? direction : YGDirectionLTR; const YGFlexDirection mainAxis = - YGResolveFlexDirection(style_.flexDirection, directionRespectingRoot); + YGResolveFlexDirection(style_.flexDirection(), directionRespectingRoot); const YGFlexDirection crossAxis = YGFlexDirectionCross(mainAxis, directionRespectingRoot); @@ -325,27 +327,28 @@ void YGNode::setPosition( } YGValue YGNode::marginLeadingValue(const YGFlexDirection axis) const { - if (YGFlexDirectionIsRow(axis) && !style_.margin[YGEdgeStart].isUndefined()) { - return style_.margin[YGEdgeStart]; + if (YGFlexDirectionIsRow(axis) && + !style_.margin()[YGEdgeStart].isUndefined()) { + return style_.margin()[YGEdgeStart]; } else { - return style_.margin[leading[axis]]; + return style_.margin()[leading[axis]]; } } YGValue YGNode::marginTrailingValue(const YGFlexDirection axis) const { - if (YGFlexDirectionIsRow(axis) && !style_.margin[YGEdgeEnd].isUndefined()) { - return style_.margin[YGEdgeEnd]; + if (YGFlexDirectionIsRow(axis) && !style_.margin()[YGEdgeEnd].isUndefined()) { + return style_.margin()[YGEdgeEnd]; } else { - return style_.margin[trailing[axis]]; + return style_.margin()[trailing[axis]]; } } YGValue YGNode::resolveFlexBasisPtr() const { - YGValue flexBasis = style_.flexBasis; + YGValue flexBasis = style_.flexBasis(); if (flexBasis.unit != YGUnitAuto && flexBasis.unit != YGUnitUndefined) { return flexBasis; } - if (!style_.flex.isUndefined() && style_.flex.unwrap() > 0.0f) { + if (!style_.flex().isUndefined() && style_.flex().unwrap() > 0.0f) { return config_->useWebDefaults ? YGValueAuto : YGValueZero; } return YGValueAuto; @@ -353,23 +356,23 @@ YGValue YGNode::resolveFlexBasisPtr() const { void YGNode::resolveDimension() { using namespace yoga; - for (int dim = YGDimensionWidth; dim < enums::count(); dim++) { - if (!getStyle().maxDimensions[dim].isUndefined() && - YGValueEqual( - getStyle().maxDimensions[dim], style_.minDimensions[dim])) { - resolvedDimensions_[dim] = style_.maxDimensions[dim]; + const YGStyle& style = getStyle(); + for (auto dim : {YGDimensionWidth, YGDimensionHeight}) { + if (!style.maxDimensions()[dim].isUndefined() && + YGValueEqual(style.maxDimensions()[dim], style.minDimensions()[dim])) { + resolvedDimensions_[dim] = style.maxDimensions()[dim]; } else { - resolvedDimensions_[dim] = style_.dimensions[dim]; + resolvedDimensions_[dim] = style.dimensions()[dim]; } } } YGDirection YGNode::resolveDirection(const YGDirection ownerDirection) { - if (style_.direction == YGDirectionInherit) { + if (style_.direction() == YGDirectionInherit) { return ownerDirection > YGDirectionInherit ? ownerDirection : YGDirectionLTR; } else { - return style_.direction; + return style_.direction(); } } @@ -401,66 +404,67 @@ void YGNode::markDirtyAndPropogateDownwards() { }); } -float YGNode::resolveFlexGrow() { +float YGNode::resolveFlexGrow() const { // Root nodes flexGrow should always be 0 if (owner_ == nullptr) { return 0.0; } - if (!style_.flexGrow.isUndefined()) { - return style_.flexGrow.unwrap(); + if (!style_.flexGrow().isUndefined()) { + return style_.flexGrow().unwrap(); } - if (!style_.flex.isUndefined() && style_.flex.unwrap() > 0.0f) { - return style_.flex.unwrap(); + if (!style_.flex().isUndefined() && style_.flex().unwrap() > 0.0f) { + return style_.flex().unwrap(); } return kDefaultFlexGrow; } -float YGNode::resolveFlexShrink() { +float YGNode::resolveFlexShrink() const { if (owner_ == nullptr) { return 0.0; } - if (!style_.flexShrink.isUndefined()) { - return style_.flexShrink.unwrap(); + if (!style_.flexShrink().isUndefined()) { + return style_.flexShrink().unwrap(); } - if (!config_->useWebDefaults && !style_.flex.isUndefined() && - style_.flex.unwrap() < 0.0f) { - return -style_.flex.unwrap(); + if (!config_->useWebDefaults && !style_.flex().isUndefined() && + style_.flex().unwrap() < 0.0f) { + return -style_.flex().unwrap(); } return config_->useWebDefaults ? kWebDefaultFlexShrink : kDefaultFlexShrink; } bool YGNode::isNodeFlexible() { return ( - (style_.positionType == YGPositionTypeRelative) && + (style_.positionType() == YGPositionTypeRelative) && (resolveFlexGrow() != 0 || resolveFlexShrink() != 0)); } float YGNode::getLeadingBorder(const YGFlexDirection axis) const { YGValue leadingBorder; - if (YGFlexDirectionIsRow(axis) && !style_.border[YGEdgeStart].isUndefined()) { - leadingBorder = style_.border[YGEdgeStart]; + if (YGFlexDirectionIsRow(axis) && + !style_.border()[YGEdgeStart].isUndefined()) { + leadingBorder = style_.border()[YGEdgeStart]; if (leadingBorder.value >= 0) { return leadingBorder.value; } } - leadingBorder = - YGComputedEdgeValue(style_.border, leading[axis], CompactValue::ofZero()); + leadingBorder = YGComputedEdgeValue( + style_.border(), leading[axis], CompactValue::ofZero()); return YGFloatMax(leadingBorder.value, 0.0f); } float YGNode::getTrailingBorder(const YGFlexDirection flexDirection) const { YGValue trailingBorder; if (YGFlexDirectionIsRow(flexDirection) && - !style_.border[YGEdgeEnd].isUndefined()) { - trailingBorder = style_.border[YGEdgeEnd]; + !style_.border()[YGEdgeEnd].isUndefined()) { + trailingBorder = style_.border()[YGEdgeEnd]; if (trailingBorder.value >= 0.0f) { return trailingBorder.value; } } trailingBorder = YGComputedEdgeValue( - style_.border, trailing[flexDirection], CompactValue::ofZero()); + style_.border(), trailing[flexDirection], CompactValue::ofZero()); return YGFloatMax(trailingBorder.value, 0.0f); } @@ -468,16 +472,16 @@ YGFloatOptional YGNode::getLeadingPadding( const YGFlexDirection axis, const float widthSize) const { const YGFloatOptional paddingEdgeStart = - YGResolveValue(style_.padding[YGEdgeStart], widthSize); + YGResolveValue(style_.padding()[YGEdgeStart], widthSize); if (YGFlexDirectionIsRow(axis) && - !style_.padding[YGEdgeStart].isUndefined() && + !style_.padding()[YGEdgeStart].isUndefined() && !paddingEdgeStart.isUndefined() && paddingEdgeStart.unwrap() >= 0.0f) { return paddingEdgeStart; } YGFloatOptional resolvedValue = YGResolveValue( YGComputedEdgeValue( - style_.padding, leading[axis], CompactValue::ofZero()), + style_.padding(), leading[axis], CompactValue::ofZero()), widthSize); return YGFloatOptionalMax(resolvedValue, YGFloatOptional(0.0f)); } @@ -486,14 +490,14 @@ YGFloatOptional YGNode::getTrailingPadding( const YGFlexDirection axis, const float widthSize) const { const YGFloatOptional paddingEdgeEnd = - YGResolveValue(style_.padding[YGEdgeEnd], widthSize); + YGResolveValue(style_.padding()[YGEdgeEnd], widthSize); if (YGFlexDirectionIsRow(axis) && paddingEdgeEnd >= YGFloatOptional{0.0f}) { return paddingEdgeEnd; } YGFloatOptional resolvedValue = YGResolveValue( YGComputedEdgeValue( - style_.padding, trailing[axis], CompactValue::ofZero()), + style_.padding(), trailing[axis], CompactValue::ofZero()), widthSize); return YGFloatOptionalMax(resolvedValue, YGFloatOptional(0.0f)); @@ -580,8 +584,8 @@ void YGNode::reset() { auto config = getConfig(); *this = YGNode{}; if (config->useWebDefaults) { - setStyleFlexDirection(YGFlexDirectionRow); - setStyleAlignContent(YGAlignStretch); + style_.flexDirection() = YGFlexDirectionRow; + style_.alignContent() = YGAlignStretch; } setConfig(config); } diff --git a/yoga/YGNode.h b/yoga/YGNode.h index 086e3ca0..021c3372 100644 --- a/yoga/YGNode.h +++ b/yoga/YGNode.h @@ -6,6 +6,7 @@ */ #pragma once #include +#include "CompactValue.h" #include "YGConfig.h" #include "YGLayout.h" #include "YGStyle.h" @@ -62,6 +63,8 @@ private: // DO NOT CHANGE THE VISIBILITY OF THIS METHOD! YGNode& operator=(YGNode&&) = default; + using CompactValue = facebook::yoga::detail::CompactValue; + public: YGNode() : hasNewLayout_{true}, @@ -210,14 +213,6 @@ public: void setNodeType(YGNodeType nodeType) { nodeType_ = nodeType; } - void setStyleFlexDirection(YGFlexDirection direction) { - style_.flexDirection = direction; - } - - void setStyleAlignContent(YGAlign alignContent) { - style_.alignContent = alignContent; - } - void setMeasureFunc(YGMeasureFunc measureFunc); void setMeasureFunc(MeasureWithContextFn); void setMeasureFunc(std::nullptr_t) { @@ -296,8 +291,8 @@ public: void cloneChildrenIfNeeded(void*); void markDirtyAndPropogate(); - float resolveFlexGrow(); - float resolveFlexShrink(); + float resolveFlexGrow() const; + float resolveFlexShrink() const; bool isNodeFlexible(); bool didUseLegacyFlag(); bool isLayoutTreeEqualToNode(const YGNode& node) const; diff --git a/yoga/YGNodePrint.cpp b/yoga/YGNodePrint.cpp index cc3ead74..ae730f68 100644 --- a/yoga/YGNodePrint.cpp +++ b/yoga/YGNodePrint.cpp @@ -132,85 +132,92 @@ void YGNodeToString( if (options & YGPrintOptionsStyle) { appendFormatedString(str, "style=\""); - if (node->getStyle().flexDirection != YGNode().getStyle().flexDirection) { + if (node->getStyle().flexDirection() != + YGNode().getStyle().flexDirection()) { appendFormatedString( str, "flex-direction: %s; ", - YGFlexDirectionToString(node->getStyle().flexDirection)); + YGFlexDirectionToString(node->getStyle().flexDirection())); } - if (node->getStyle().justifyContent != YGNode().getStyle().justifyContent) { + if (node->getStyle().justifyContent() != + YGNode().getStyle().justifyContent()) { appendFormatedString( str, "justify-content: %s; ", - YGJustifyToString(node->getStyle().justifyContent)); + YGJustifyToString(node->getStyle().justifyContent())); } - if (node->getStyle().alignItems != YGNode().getStyle().alignItems) { + if (node->getStyle().alignItems() != YGNode().getStyle().alignItems()) { appendFormatedString( str, "align-items: %s; ", - YGAlignToString(node->getStyle().alignItems)); + YGAlignToString(node->getStyle().alignItems())); } - if (node->getStyle().alignContent != YGNode().getStyle().alignContent) { + if (node->getStyle().alignContent() != YGNode().getStyle().alignContent()) { appendFormatedString( str, "align-content: %s; ", - YGAlignToString(node->getStyle().alignContent)); + YGAlignToString(node->getStyle().alignContent())); } - if (node->getStyle().alignSelf != YGNode().getStyle().alignSelf) { + if (node->getStyle().alignSelf() != YGNode().getStyle().alignSelf()) { appendFormatedString( - str, "align-self: %s; ", YGAlignToString(node->getStyle().alignSelf)); + str, + "align-self: %s; ", + YGAlignToString(node->getStyle().alignSelf())); } - appendFloatOptionalIfDefined(str, "flex-grow", node->getStyle().flexGrow); + appendFloatOptionalIfDefined(str, "flex-grow", node->getStyle().flexGrow()); appendFloatOptionalIfDefined( - str, "flex-shrink", node->getStyle().flexShrink); - appendNumberIfNotAuto(str, "flex-basis", node->getStyle().flexBasis); - appendFloatOptionalIfDefined(str, "flex", node->getStyle().flex); + str, "flex-shrink", node->getStyle().flexShrink()); + appendNumberIfNotAuto(str, "flex-basis", node->getStyle().flexBasis()); + appendFloatOptionalIfDefined(str, "flex", node->getStyle().flex()); - if (node->getStyle().flexWrap != YGNode().getStyle().flexWrap) { + if (node->getStyle().flexWrap() != YGNode().getStyle().flexWrap()) { appendFormatedString( - str, "flex-wrap: %s; ", YGWrapToString(node->getStyle().flexWrap)); + str, "flex-wrap: %s; ", YGWrapToString(node->getStyle().flexWrap())); } - if (node->getStyle().overflow != YGNode().getStyle().overflow) { + if (node->getStyle().overflow() != YGNode().getStyle().overflow()) { appendFormatedString( - str, "overflow: %s; ", YGOverflowToString(node->getStyle().overflow)); + str, + "overflow: %s; ", + YGOverflowToString(node->getStyle().overflow())); } - if (node->getStyle().display != YGNode().getStyle().display) { + if (node->getStyle().display() != YGNode().getStyle().display()) { appendFormatedString( - str, "display: %s; ", YGDisplayToString(node->getStyle().display)); + str, "display: %s; ", YGDisplayToString(node->getStyle().display())); } - appendEdges(str, "margin", node->getStyle().margin); - appendEdges(str, "padding", node->getStyle().padding); - appendEdges(str, "border", node->getStyle().border); + appendEdges(str, "margin", node->getStyle().margin()); + appendEdges(str, "padding", node->getStyle().padding()); + appendEdges(str, "border", node->getStyle().border()); appendNumberIfNotAuto( - str, "width", node->getStyle().dimensions[YGDimensionWidth]); + str, "width", node->getStyle().dimensions()[YGDimensionWidth]); appendNumberIfNotAuto( - str, "height", node->getStyle().dimensions[YGDimensionHeight]); + str, "height", node->getStyle().dimensions()[YGDimensionHeight]); appendNumberIfNotAuto( - str, "max-width", node->getStyle().maxDimensions[YGDimensionWidth]); + str, "max-width", node->getStyle().maxDimensions()[YGDimensionWidth]); appendNumberIfNotAuto( - str, "max-height", node->getStyle().maxDimensions[YGDimensionHeight]); + str, "max-height", node->getStyle().maxDimensions()[YGDimensionHeight]); appendNumberIfNotAuto( - str, "min-width", node->getStyle().minDimensions[YGDimensionWidth]); + str, "min-width", node->getStyle().minDimensions()[YGDimensionWidth]); appendNumberIfNotAuto( - str, "min-height", node->getStyle().minDimensions[YGDimensionHeight]); + str, "min-height", node->getStyle().minDimensions()[YGDimensionHeight]); - if (node->getStyle().positionType != YGNode().getStyle().positionType) { + if (node->getStyle().positionType() != YGNode().getStyle().positionType()) { appendFormatedString( str, "position: %s; ", - YGPositionTypeToString(node->getStyle().positionType)); + YGPositionTypeToString(node->getStyle().positionType())); } appendEdgeIfNotUndefined( - str, "left", node->getStyle().position, YGEdgeLeft); + str, "left", node->getStyle().position(), YGEdgeLeft); appendEdgeIfNotUndefined( - str, "right", node->getStyle().position, YGEdgeRight); - appendEdgeIfNotUndefined(str, "top", node->getStyle().position, YGEdgeTop); + str, "right", node->getStyle().position(), YGEdgeRight); appendEdgeIfNotUndefined( - str, "bottom", node->getStyle().position, YGEdgeBottom); + str, "top", node->getStyle().position(), YGEdgeTop); + appendEdgeIfNotUndefined( + str, "bottom", node->getStyle().position(), YGEdgeBottom); appendFormatedString(str, "\" "); if (node->hasMeasureFunc()) { diff --git a/yoga/YGStyle.cpp b/yoga/YGStyle.cpp index 26b0f269..6672c81f 100644 --- a/yoga/YGStyle.cpp +++ b/yoga/YGStyle.cpp @@ -9,43 +9,46 @@ // Yoga specific properties, not compatible with flexbox specification bool operator==(const YGStyle& lhs, const YGStyle& rhs) { - bool areNonFloatValuesEqual = lhs.direction == rhs.direction && - lhs.flexDirection == rhs.flexDirection && - lhs.justifyContent == rhs.justifyContent && - lhs.alignContent == rhs.alignContent && - lhs.alignItems == rhs.alignItems && lhs.alignSelf == rhs.alignSelf && - lhs.positionType == rhs.positionType && lhs.flexWrap == rhs.flexWrap && - lhs.overflow == rhs.overflow && lhs.display == rhs.display && - YGValueEqual(lhs.flexBasis, rhs.flexBasis) && lhs.margin == rhs.margin && - lhs.position == rhs.position && lhs.padding == rhs.padding && - lhs.border == rhs.border && lhs.dimensions == rhs.dimensions && - lhs.minDimensions == rhs.minDimensions && - lhs.maxDimensions == rhs.maxDimensions; + bool areNonFloatValuesEqual = lhs.direction() == rhs.direction() && + lhs.flexDirection() == rhs.flexDirection() && + lhs.justifyContent() == rhs.justifyContent() && + lhs.alignContent() == rhs.alignContent() && + lhs.alignItems() == rhs.alignItems() && + lhs.alignSelf() == rhs.alignSelf() && + lhs.positionType() == rhs.positionType() && + lhs.flexWrap() == rhs.flexWrap() && lhs.overflow() == rhs.overflow() && + lhs.display() == rhs.display() && + YGValueEqual(lhs.flexBasis(), rhs.flexBasis()) && + lhs.margin() == rhs.margin() && lhs.position() == rhs.position() && + lhs.padding() == rhs.padding() && lhs.border() == rhs.border() && + lhs.dimensions() == rhs.dimensions() && + lhs.minDimensions() == rhs.minDimensions() && + lhs.maxDimensions() == rhs.maxDimensions(); areNonFloatValuesEqual = areNonFloatValuesEqual && - lhs.flex.isUndefined() == rhs.flex.isUndefined(); - if (areNonFloatValuesEqual && !lhs.flex.isUndefined() && - !rhs.flex.isUndefined()) { - areNonFloatValuesEqual = areNonFloatValuesEqual && lhs.flex == rhs.flex; + lhs.flex().isUndefined() == rhs.flex().isUndefined(); + if (areNonFloatValuesEqual && !lhs.flex().isUndefined() && + !rhs.flex().isUndefined()) { + areNonFloatValuesEqual = areNonFloatValuesEqual && lhs.flex() == rhs.flex(); } areNonFloatValuesEqual = areNonFloatValuesEqual && - lhs.flexGrow.isUndefined() == rhs.flexGrow.isUndefined(); - if (areNonFloatValuesEqual && !lhs.flexGrow.isUndefined()) { + lhs.flexGrow().isUndefined() == rhs.flexGrow().isUndefined(); + if (areNonFloatValuesEqual && !lhs.flexGrow().isUndefined()) { areNonFloatValuesEqual = - areNonFloatValuesEqual && lhs.flexGrow == rhs.flexGrow; + areNonFloatValuesEqual && lhs.flexGrow() == rhs.flexGrow(); } areNonFloatValuesEqual = areNonFloatValuesEqual && - lhs.flexShrink.isUndefined() == rhs.flexShrink.isUndefined(); - if (areNonFloatValuesEqual && !rhs.flexShrink.isUndefined()) { + lhs.flexShrink().isUndefined() == rhs.flexShrink().isUndefined(); + if (areNonFloatValuesEqual && !rhs.flexShrink().isUndefined()) { areNonFloatValuesEqual = - areNonFloatValuesEqual && lhs.flexShrink == rhs.flexShrink; + areNonFloatValuesEqual && lhs.flexShrink() == rhs.flexShrink(); } - if (!(lhs.aspectRatio.isUndefined() && rhs.aspectRatio.isUndefined())) { + if (!(lhs.aspectRatio().isUndefined() && rhs.aspectRatio().isUndefined())) { areNonFloatValuesEqual = - areNonFloatValuesEqual && lhs.aspectRatio == rhs.aspectRatio; + areNonFloatValuesEqual && lhs.aspectRatio() == rhs.aspectRatio(); } return areNonFloatValuesEqual; diff --git a/yoga/YGStyle.h b/yoga/YGStyle.h index 7e93502a..dd946832 100644 --- a/yoga/YGStyle.h +++ b/yoga/YGStyle.h @@ -20,8 +20,14 @@ #define BITFIELD_ENUM_SIZED(num) #endif -struct YGStyle { -private: +#define BITFIELD_ACCESSORS(FIELD) \ + decltype(FIELD##_) get_##FIELD() const { return FIELD##_; } \ + void set_##FIELD(decltype(FIELD##_) x) { FIELD##_ = x; } + +#define BITFIELD_REF(FIELD) \ + { *this, &YGStyle::get_##FIELD, &YGStyle::set_##FIELD } + +class YGStyle { using CompactValue = facebook::yoga::detail::CompactValue; public: @@ -29,47 +35,149 @@ public: using Edges = facebook::yoga::detail::Values()>; - /* Some platforms don't support enum bitfields, - so please use BITFIELD_ENUM_SIZED(BITS_COUNT) */ - YGDirection direction BITFIELD_ENUM_SIZED(2); - YGFlexDirection flexDirection BITFIELD_ENUM_SIZED(2); - YGJustify justifyContent BITFIELD_ENUM_SIZED(3); - YGAlign alignContent BITFIELD_ENUM_SIZED(3); - YGAlign alignItems BITFIELD_ENUM_SIZED(3); - YGAlign alignSelf BITFIELD_ENUM_SIZED(3); - YGPositionType positionType BITFIELD_ENUM_SIZED(1); - YGWrap flexWrap BITFIELD_ENUM_SIZED(2); - YGOverflow overflow BITFIELD_ENUM_SIZED(2); - YGDisplay display BITFIELD_ENUM_SIZED(1); - YGFloatOptional flex = {}; - YGFloatOptional flexGrow = {}; - YGFloatOptional flexShrink = {}; - CompactValue flexBasis = CompactValue::ofAuto(); - Edges margin = {}; - Edges position = {}; - Edges padding = {}; - Edges border = {}; - Dimensions dimensions{CompactValue::ofAuto()}; - Dimensions minDimensions = {}; - Dimensions maxDimensions = {}; - // Yoga specific properties, not compatible with flexbox specification - YGFloatOptional aspectRatio = {}; + template + struct BitfieldRef { + YGStyle& style; + T (YGStyle::*get)() const; + void (YGStyle::*set)(T); + + operator T() const { return (style.*get)(); } + BitfieldRef& operator=(T x) { + (style.*set)(x); + return *this; + } + }; YGStyle() - : direction(YGDirectionInherit), - flexDirection(YGFlexDirectionColumn), - justifyContent(YGJustifyFlexStart), - alignContent(YGAlignFlexStart), - alignItems(YGAlignStretch), - alignSelf(YGAlignAuto), - positionType(YGPositionTypeRelative), - flexWrap(YGWrapNoWrap), - overflow(YGOverflowVisible), - display(YGDisplayFlex) {} + : direction_(YGDirectionInherit), + flexDirection_(YGFlexDirectionColumn), + justifyContent_(YGJustifyFlexStart), + alignContent_(YGAlignFlexStart), + alignItems_(YGAlignStretch), + alignSelf_(YGAlignAuto), + positionType_(YGPositionTypeRelative), + flexWrap_(YGWrapNoWrap), + overflow_(YGOverflowVisible), + display_(YGDisplayFlex) {} ~YGStyle() = default; + + YGDirection direction() const { return direction_; } + BitfieldRef direction() { return BITFIELD_REF(direction); } + + YGFlexDirection flexDirection() const { return flexDirection_; } + BitfieldRef flexDirection() { + return BITFIELD_REF(flexDirection); + } + + YGJustify justifyContent() const { return justifyContent_; } + BitfieldRef justifyContent() { + return BITFIELD_REF(justifyContent); + } + + YGAlign alignContent() const { return alignContent_; } + BitfieldRef alignContent() { return BITFIELD_REF(alignContent); } + + YGAlign alignItems() const { return alignItems_; } + BitfieldRef alignItems() { return BITFIELD_REF(alignItems); } + + YGAlign alignSelf() const { return alignSelf_; } + BitfieldRef alignSelf() { return BITFIELD_REF(alignSelf); } + + YGPositionType positionType() const { return positionType_; } + BitfieldRef positionType() { + return BITFIELD_REF(positionType); + } + + YGWrap flexWrap() const { return flexWrap_; } + BitfieldRef flexWrap() { return BITFIELD_REF(flexWrap); } + + YGOverflow overflow() const { return overflow_; } + BitfieldRef overflow() { return BITFIELD_REF(overflow); } + + YGDisplay display() const { return display_; } + BitfieldRef display() { return BITFIELD_REF(display); } + + YGFloatOptional flex() const { return flex_; } + YGFloatOptional& flex() { return flex_; } + + YGFloatOptional flexGrow() const { return flexGrow_; } + YGFloatOptional& flexGrow() { return flexGrow_; } + + YGFloatOptional flexShrink() const { return flexShrink_; } + YGFloatOptional& flexShrink() { return flexShrink_; } + + CompactValue flexBasis() const { return flexBasis_; } + CompactValue& flexBasis() { return flexBasis_; } + + const Edges& margin() const { return margin_; } + Edges& margin() { return margin_; } + + const Edges& position() const { return position_; } + Edges& position() { return position_; } + + const Edges& padding() const { return padding_; } + Edges& padding() { return padding_; } + + const Edges& border() const { return border_; } + Edges& border() { return border_; } + + const Dimensions& dimensions() const { return dimensions_; } + Dimensions& dimensions() { return dimensions_; } + + const Dimensions& minDimensions() const { return minDimensions_; } + Dimensions& minDimensions() { return minDimensions_; } + + const Dimensions& maxDimensions() const { return maxDimensions_; } + Dimensions& maxDimensions() { return maxDimensions_; } + + // Yoga specific properties, not compatible with flexbox specification + YGFloatOptional aspectRatio() const { return aspectRatio_; } + YGFloatOptional& aspectRatio() { return aspectRatio_; } + +private: + /* Some platforms don't support enum bitfields, + so please use BITFIELD_ENUM_SIZED(BITS_COUNT) */ + YGDirection direction_ BITFIELD_ENUM_SIZED(2); + YGFlexDirection flexDirection_ BITFIELD_ENUM_SIZED(2); + YGJustify justifyContent_ BITFIELD_ENUM_SIZED(3); + YGAlign alignContent_ BITFIELD_ENUM_SIZED(3); + YGAlign alignItems_ BITFIELD_ENUM_SIZED(3); + YGAlign alignSelf_ BITFIELD_ENUM_SIZED(3); + YGPositionType positionType_ BITFIELD_ENUM_SIZED(1); + YGWrap flexWrap_ BITFIELD_ENUM_SIZED(2); + YGOverflow overflow_ BITFIELD_ENUM_SIZED(2); + YGDisplay display_ BITFIELD_ENUM_SIZED(1); + YGFloatOptional flex_ = {}; + YGFloatOptional flexGrow_ = {}; + YGFloatOptional flexShrink_ = {}; + CompactValue flexBasis_ = CompactValue::ofAuto(); + Edges margin_ = {}; + Edges position_ = {}; + Edges padding_ = {}; + Edges border_ = {}; + Dimensions dimensions_{CompactValue::ofAuto()}; + Dimensions minDimensions_ = {}; + Dimensions maxDimensions_ = {}; + // Yoga specific properties, not compatible with flexbox specification + YGFloatOptional aspectRatio_ = {}; + + BITFIELD_ACCESSORS(direction) + BITFIELD_ACCESSORS(flexDirection) + BITFIELD_ACCESSORS(justifyContent) + BITFIELD_ACCESSORS(alignContent); + BITFIELD_ACCESSORS(alignItems); + BITFIELD_ACCESSORS(alignSelf); + BITFIELD_ACCESSORS(positionType); + BITFIELD_ACCESSORS(flexWrap); + BITFIELD_ACCESSORS(overflow); + BITFIELD_ACCESSORS(display); }; bool operator==(const YGStyle& lhs, const YGStyle& rhs); inline bool operator!=(const YGStyle& lhs, const YGStyle& rhs) { return !(lhs == rhs); } + +#undef BITFIELD_ENUM_SIZED +#undef BITFIELD_ACCESSORS +#undef BITFIELD_REF diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index f041a6d3..bb9c6aea 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -224,8 +224,8 @@ WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config) { gNodeInstanceCount++; if (config->useWebDefaults) { - node->setStyleFlexDirection(YGFlexDirectionRow); - node->setStyleAlignContent(YGAlignStretch); + node->getStyle().flexDirection() = YGFlexDirectionRow; + node->getStyle().alignContent() = YGAlignStretch; } node->setConfig(config); return node; @@ -522,61 +522,69 @@ void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode) { } } -float YGNodeStyleGetFlexGrow(const YGNodeRef node) { - return node->getStyle().flexGrow.isUndefined() +float YGNodeStyleGetFlexGrow(const YGNodeRef n) { + const YGNode* node = n; + return node->getStyle().flexGrow().isUndefined() ? kDefaultFlexGrow - : node->getStyle().flexGrow.unwrap(); + : node->getStyle().flexGrow().unwrap(); } -float YGNodeStyleGetFlexShrink(const YGNodeRef node) { - return node->getStyle().flexShrink.isUndefined() +float YGNodeStyleGetFlexShrink(const YGNodeRef n) { + const YGNode* node = n; + return node->getStyle().flexShrink().isUndefined() ? (node->getConfig()->useWebDefaults ? kWebDefaultFlexShrink : kDefaultFlexShrink) - : node->getStyle().flexShrink.unwrap(); + : node->getStyle().flexShrink().unwrap(); } namespace { template -void updateNodeProp( +void updateStyle( YGNode* node, T value, NeedsUpdate&& needsUpdate, Update&& update) { - if (needsUpdate(node, value)) { - update(node, value); + if (needsUpdate(node->getStyle(), value)) { + update(node->getStyle(), value); node->markDirtyAndPropogate(); } } -template -void updateStyleProp(YGNode* node, T value) { - updateNodeProp( +template (YGStyle::*Prop)()> +void updateStyle(YGNode* node, T value) { + updateStyle( node, value, - [](YGNode* n, T x) { return (n->getStyle().*Prop) != x; }, - [](YGNode* n, T x) { (n->getStyle().*Prop) = x; }); + [](YGStyle& s, T x) { return (s.*Prop)() != x; }, + [](YGStyle& s, T x) { (s.*Prop)() = x; }); } -template ()> YGStyle::*Prop> +template +void updateStyle(YGNode* node, T value) { + updateStyle( + node, + value, + [](YGStyle& s, T x) { return (s.*Prop)() != x; }, + [](YGStyle& s, T x) { (s.*Prop)() = x; }); +} + +template ()>& (YGStyle::*Prop)()> void updateIndexedStyleProp(YGNode* node, Idx idx, detail::CompactValue value) { - updateNodeProp( + using detail::CompactValue; + updateStyle( node, value, - [idx](YGNode* n, detail::CompactValue x) { - return (n->getStyle().*Prop)[idx] != x; - }, - [idx](YGNode* n, detail::CompactValue x) { - (n->getStyle().*Prop)[idx] = x; - }); + [idx](YGStyle& s, CompactValue x) { return (s.*Prop)()[idx] != x; }, + [idx](YGStyle& s, CompactValue x) { (s.*Prop)()[idx] = x; }); } -template ()> YGStyle::*Prop> +template void updateEdgeProp(YGNode* node, YGEdge edge, detail::CompactValue value) { updateIndexedStyleProp(node, edge, value); } -template ()> YGStyle::*Prop> +template void updateDimensionProp( YGNode* node, YGDimension dimension, @@ -584,141 +592,127 @@ void updateDimensionProp( updateIndexedStyleProp(node, dimension, value); } -#define YG_UPDATE_STYLE_PROP_BITFIELD(PROP_NAME, node, value) \ - updateNodeProp( \ - node, \ - value, \ - [](YGNode* n, decltype(value) x) { \ - return n->getStyle().PROP_NAME != x; \ - }, \ - [](YGNode* n, decltype(value) x) { n->getStyle().PROP_NAME = x; }) - } // namespace void YGNodeStyleSetDirection(const YGNodeRef node, const YGDirection value) { - YG_UPDATE_STYLE_PROP_BITFIELD(direction, node, value); + updateStyle(node, value); } YGDirection YGNodeStyleGetDirection(const YGNodeRef node) { - return node->getStyle().direction; + return node->getStyle().direction(); } void YGNodeStyleSetFlexDirection( const YGNodeRef node, const YGFlexDirection flexDirection) { - YG_UPDATE_STYLE_PROP_BITFIELD(flexDirection, node, flexDirection); + updateStyle(node, flexDirection); } YGFlexDirection YGNodeStyleGetFlexDirection(const YGNodeRef node) { - return node->getStyle().flexDirection; + return node->getStyle().flexDirection(); } void YGNodeStyleSetJustifyContent( const YGNodeRef node, const YGJustify justifyContent) { - YG_UPDATE_STYLE_PROP_BITFIELD(justifyContent, node, justifyContent); + updateStyle(node, justifyContent); } YGJustify YGNodeStyleGetJustifyContent(const YGNodeRef node) { - return node->getStyle().justifyContent; + return node->getStyle().justifyContent(); } void YGNodeStyleSetAlignContent( const YGNodeRef node, const YGAlign alignContent) { - YG_UPDATE_STYLE_PROP_BITFIELD(alignContent, node, alignContent); + updateStyle(node, alignContent); } YGAlign YGNodeStyleGetAlignContent(const YGNodeRef node) { - return node->getStyle().alignContent; + return node->getStyle().alignContent(); } void YGNodeStyleSetAlignItems(const YGNodeRef node, const YGAlign alignItems) { - YG_UPDATE_STYLE_PROP_BITFIELD(alignItems, node, alignItems); + updateStyle(node, alignItems); } YGAlign YGNodeStyleGetAlignItems(const YGNodeRef node) { - return node->getStyle().alignItems; + return node->getStyle().alignItems(); } void YGNodeStyleSetAlignSelf(const YGNodeRef node, const YGAlign alignSelf) { - YG_UPDATE_STYLE_PROP_BITFIELD(alignSelf, node, alignSelf); + updateStyle(node, alignSelf); } YGAlign YGNodeStyleGetAlignSelf(const YGNodeRef node) { - return node->getStyle().alignSelf; + return node->getStyle().alignSelf(); } void YGNodeStyleSetPositionType( const YGNodeRef node, const YGPositionType positionType) { - YG_UPDATE_STYLE_PROP_BITFIELD(positionType, node, positionType); + updateStyle(node, positionType); } YGPositionType YGNodeStyleGetPositionType(const YGNodeRef node) { - return node->getStyle().positionType; + return node->getStyle().positionType(); } void YGNodeStyleSetFlexWrap(const YGNodeRef node, const YGWrap flexWrap) { - YG_UPDATE_STYLE_PROP_BITFIELD(flexWrap, node, flexWrap); + updateStyle(node, flexWrap); } YGWrap YGNodeStyleGetFlexWrap(const YGNodeRef node) { - return node->getStyle().flexWrap; + return node->getStyle().flexWrap(); } void YGNodeStyleSetOverflow(const YGNodeRef node, const YGOverflow overflow) { - YG_UPDATE_STYLE_PROP_BITFIELD(overflow, node, overflow); + updateStyle(node, overflow); } YGOverflow YGNodeStyleGetOverflow(const YGNodeRef node) { - return node->getStyle().overflow; + return node->getStyle().overflow(); } void YGNodeStyleSetDisplay(const YGNodeRef node, const YGDisplay display) { - YG_UPDATE_STYLE_PROP_BITFIELD(display, node, display); + updateStyle(node, display); } YGDisplay YGNodeStyleGetDisplay(const YGNodeRef node) { - return node->getStyle().display; + return node->getStyle().display(); } // TODO(T26792433): Change the API to accept YGFloatOptional. void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) { - updateStyleProp(node, YGFloatOptional{flex}); + updateStyle(node, YGFloatOptional{flex}); } // TODO(T26792433): Change the API to accept YGFloatOptional. float YGNodeStyleGetFlex(const YGNodeRef node) { - return node->getStyle().flex.isUndefined() ? YGUndefined - : node->getStyle().flex.unwrap(); + const auto& style = node->getStyle(); + return style.flex().isUndefined() ? YGUndefined : style.flex().unwrap(); } // TODO(T26792433): Change the API to accept YGFloatOptional. void YGNodeStyleSetFlexGrow(const YGNodeRef node, const float flexGrow) { - updateStyleProp( + updateStyle( node, YGFloatOptional{flexGrow}); } // TODO(T26792433): Change the API to accept YGFloatOptional. void YGNodeStyleSetFlexShrink(const YGNodeRef node, const float flexShrink) { - updateStyleProp( + updateStyle( node, YGFloatOptional{flexShrink}); } YGValue YGNodeStyleGetFlexBasis(const YGNodeRef node) { - YGValue flexBasis = node->getStyle().flexBasis; - if (flexBasis.unit == YGUnitUndefined || flexBasis.unit == YGUnitAuto) { - // TODO(T26792433): Get rid off the use of YGUndefined at client side - flexBasis.value = YGUndefined; - } - return flexBasis; + return static_cast(node)->getStyle().flexBasis(); } void YGNodeStyleSetFlexBasis(const YGNodeRef node, const float flexBasis) { auto value = detail::CompactValue::ofMaybe(flexBasis); - updateStyleProp(node, value); + updateStyle(node, value); } void YGNodeStyleSetFlexBasisPercent( const YGNodeRef node, const float flexBasisPercent) { auto value = detail::CompactValue::ofMaybe(flexBasisPercent); - updateStyleProp(node, value); + updateStyle(node, value); } void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node) { - updateStyleProp( + updateStyle( node, detail::CompactValue::ofAuto()); } @@ -731,7 +725,7 @@ void YGNodeStyleSetPositionPercent(YGNodeRef node, YGEdge edge, float percent) { updateEdgeProp<&YGStyle::position>(node, edge, value); } YGValue YGNodeStyleGetPosition(YGNodeRef node, YGEdge edge) { - return node->getStyle().position[edge]; + return static_cast(node)->getStyle().position()[edge]; } void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, float points) { @@ -746,7 +740,7 @@ void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge) { updateEdgeProp<&YGStyle::margin>(node, edge, detail::CompactValue::ofAuto()); } YGValue YGNodeStyleGetMargin(YGNodeRef node, YGEdge edge) { - return node->getStyle().margin[edge]; + return static_cast(node)->getStyle().margin()[edge]; } void YGNodeStyleSetPadding(YGNodeRef node, YGEdge edge, float points) { @@ -758,7 +752,7 @@ void YGNodeStyleSetPaddingPercent(YGNodeRef node, YGEdge edge, float percent) { updateEdgeProp<&YGStyle::padding>(node, edge, value); } YGValue YGNodeStyleGetPadding(YGNodeRef node, YGEdge edge) { - return node->getStyle().padding[edge]; + return static_cast(node)->getStyle().padding()[edge]; } // TODO(T26792433): Change the API to accept YGFloatOptional. @@ -771,14 +765,14 @@ void YGNodeStyleSetBorder( } float YGNodeStyleGetBorder(const YGNodeRef node, const YGEdge edge) { - if (node->getStyle().border[edge].isUndefined() || - node->getStyle().border[edge].isAuto()) { + const auto& style = node->getStyle(); + if (style.border()[edge].isUndefined() || style.border()[edge].isAuto()) { // TODO(T26792433): Rather than returning YGUndefined, change the api to // return YGFloatOptional. return YGUndefined; } - auto border = (YGValue) node->getStyle().border[edge]; + auto border = (YGValue) style.border()[edge]; return border.value; } @@ -786,13 +780,13 @@ float YGNodeStyleGetBorder(const YGNodeRef node, const YGEdge edge) { // TODO(T26792433): Change the API to accept YGFloatOptional. float YGNodeStyleGetAspectRatio(const YGNodeRef node) { - const YGFloatOptional op = node->getStyle().aspectRatio; + const YGFloatOptional op = node->getStyle().aspectRatio(); return op.isUndefined() ? YGUndefined : op.unwrap(); } // TODO(T26792433): Change the API to accept YGFloatOptional. void YGNodeStyleSetAspectRatio(const YGNodeRef node, const float aspectRatio) { - updateStyleProp( + updateStyle( node, YGFloatOptional{aspectRatio}); } @@ -809,7 +803,9 @@ void YGNodeStyleSetWidthAuto(YGNodeRef node) { node, YGDimensionWidth, detail::CompactValue::ofAuto()); } YGValue YGNodeStyleGetWidth(YGNodeRef node) { - return node->getStyle().dimensions[YGDimensionWidth]; + return static_cast(node) + ->getStyle() + .dimensions()[YGDimensionWidth]; } void YGNodeStyleSetHeight(YGNodeRef node, float points) { @@ -825,7 +821,9 @@ void YGNodeStyleSetHeightAuto(YGNodeRef node) { node, YGDimensionHeight, detail::CompactValue::ofAuto()); } YGValue YGNodeStyleGetHeight(YGNodeRef node) { - return node->getStyle().dimensions[YGDimensionHeight]; + return static_cast(node) + ->getStyle() + .dimensions()[YGDimensionHeight]; } void YGNodeStyleSetMinWidth(const YGNodeRef node, const float minWidth) { @@ -837,7 +835,9 @@ void YGNodeStyleSetMinWidthPercent(const YGNodeRef node, const float minWidth) { updateDimensionProp<&YGStyle::minDimensions>(node, YGDimensionWidth, value); } YGValue YGNodeStyleGetMinWidth(const YGNodeRef node) { - return node->getStyle().minDimensions[YGDimensionWidth]; + return static_cast(node) + ->getStyle() + .minDimensions()[YGDimensionWidth]; }; void YGNodeStyleSetMinHeight(const YGNodeRef node, const float minHeight) { @@ -851,7 +851,9 @@ void YGNodeStyleSetMinHeightPercent( updateDimensionProp<&YGStyle::minDimensions>(node, YGDimensionHeight, value); } YGValue YGNodeStyleGetMinHeight(const YGNodeRef node) { - return node->getStyle().minDimensions[YGDimensionHeight]; + return static_cast(node) + ->getStyle() + .minDimensions()[YGDimensionHeight]; }; void YGNodeStyleSetMaxWidth(const YGNodeRef node, const float maxWidth) { @@ -863,7 +865,9 @@ void YGNodeStyleSetMaxWidthPercent(const YGNodeRef node, const float maxWidth) { updateDimensionProp<&YGStyle::maxDimensions>(node, YGDimensionWidth, value); } YGValue YGNodeStyleGetMaxWidth(const YGNodeRef node) { - return node->getStyle().maxDimensions[YGDimensionWidth]; + return static_cast(node) + ->getStyle() + .maxDimensions()[YGDimensionWidth]; }; void YGNodeStyleSetMaxHeight(const YGNodeRef node, const float maxHeight) { @@ -877,7 +881,9 @@ void YGNodeStyleSetMaxHeightPercent( updateDimensionProp<&YGStyle::maxDimensions>(node, YGDimensionHeight, value); } YGValue YGNodeStyleGetMaxHeight(const YGNodeRef node) { - return node->getStyle().maxDimensions[YGDimensionHeight]; + return static_cast(node) + ->getStyle() + .maxDimensions()[YGDimensionHeight]; }; #define YG_NODE_LAYOUT_PROPERTY_IMPL(type, name, instanceName) \ @@ -983,14 +989,12 @@ static inline float YGNodePaddingAndBorderForAxis( .unwrap(); } -static inline YGAlign YGNodeAlignItem( - const YGNodeRef node, - const YGNodeRef child) { - const YGAlign align = child->getStyle().alignSelf == YGAlignAuto - ? node->getStyle().alignItems - : child->getStyle().alignSelf; +static inline YGAlign YGNodeAlignItem(const YGNode* node, const YGNode* child) { + const YGAlign align = child->getStyle().alignSelf() == YGAlignAuto + ? node->getStyle().alignItems() + : child->getStyle().alignSelf(); if (align == YGAlignBaseline && - YGFlexDirectionIsColumn(node->getStyle().flexDirection)) { + YGFlexDirectionIsColumn(node->getStyle().flexDirection())) { return YGAlignFlexStart; } return align; @@ -1018,7 +1022,7 @@ static float YGBaseline(const YGNodeRef node, void* layoutContext) { if (child->getLineIndex() > 0) { break; } - if (child->getStyle().positionType == YGPositionTypeAbsolute) { + if (child->getStyle().positionType() == YGPositionTypeAbsolute) { continue; } if (YGNodeAlignItem(node, child) == YGAlignBaseline || @@ -1041,17 +1045,17 @@ static float YGBaseline(const YGNodeRef node, void* layoutContext) { } static bool YGIsBaselineLayout(const YGNodeRef node) { - if (YGFlexDirectionIsColumn(node->getStyle().flexDirection)) { + if (YGFlexDirectionIsColumn(node->getStyle().flexDirection())) { return false; } - if (node->getStyle().alignItems == YGAlignBaseline) { + if (node->getStyle().alignItems() == YGAlignBaseline) { return true; } const uint32_t childCount = YGNodeGetChildCount(node); for (uint32_t i = 0; i < childCount; i++) { const YGNodeRef child = YGNodeGetChild(node, i); - if (child->getStyle().positionType == YGPositionTypeRelative && - child->getStyle().alignSelf == YGAlignBaseline) { + if (child->getStyle().positionType() == YGPositionTypeRelative && + child->getStyle().alignSelf() == YGAlignBaseline) { return true; } } @@ -1103,14 +1107,14 @@ static YGFloatOptional YGNodeBoundAxisWithinMinAndMax( if (YGFlexDirectionIsColumn(axis)) { min = YGResolveValue( - node->getStyle().minDimensions[YGDimensionHeight], axisSize); + node->getStyle().minDimensions()[YGDimensionHeight], axisSize); max = YGResolveValue( - node->getStyle().maxDimensions[YGDimensionHeight], axisSize); + node->getStyle().maxDimensions()[YGDimensionHeight], axisSize); } else if (YGFlexDirectionIsRow(axis)) { min = YGResolveValue( - node->getStyle().minDimensions[YGDimensionWidth], axisSize); + node->getStyle().minDimensions()[YGDimensionWidth], axisSize); max = YGResolveValue( - node->getStyle().maxDimensions[YGDimensionWidth], axisSize); + node->getStyle().maxDimensions()[YGDimensionWidth], axisSize); } if (max >= YGFloatOptional{0} && value > max) { @@ -1158,7 +1162,8 @@ static void YGConstrainMaxSizeForMode( YGMeasureMode* mode, float* size) { const YGFloatOptional maxSize = - YGResolveValue(node->getStyle().maxDimensions[dim[axis]], ownerAxisSize) + + YGResolveValue( + node->getStyle().maxDimensions()[dim[axis]], ownerAxisSize) + YGFloatOptional(node->getMarginForAxis(axis, ownerWidth)); switch (*mode) { case YGMeasureModeExactly: @@ -1190,7 +1195,7 @@ static void YGNodeComputeFlexBasisForChild( YGMarkerLayoutData& layoutMarkerData, void* const layoutContext) { const YGFlexDirection mainAxis = - YGResolveFlexDirection(node->getStyle().flexDirection, direction); + YGResolveFlexDirection(node->getStyle().flexDirection(), direction); const bool isMainAxisRow = YGFlexDirectionIsRow(mainAxis); const float mainAxisSize = isMainAxisRow ? width : height; const float mainAxisownerSize = isMainAxisRow ? ownerWidth : ownerHeight; @@ -1225,7 +1230,7 @@ static void YGNodeComputeFlexBasisForChild( child->setLayoutComputedFlexBasis(YGFloatOptionalMax( YGResolveValue( - child->getResolvedDimension(YGDimensionWidth), ownerWidth), + child->getResolvedDimensions()[YGDimensionWidth], ownerWidth), paddingAndBorder)); } else if (!isMainAxisRow && isColumnStyleDimDefined) { // The height is definite, so use that as the flex basis. @@ -1234,7 +1239,7 @@ static void YGNodeComputeFlexBasisForChild( child, YGFlexDirectionColumn, ownerWidth)); child->setLayoutComputedFlexBasis(YGFloatOptionalMax( YGResolveValue( - child->getResolvedDimension(YGDimensionHeight), ownerHeight), + child->getResolvedDimensions()[YGDimensionHeight], ownerHeight), paddingAndBorder)); } else { // Compute the flex basis and hypothetical main size (i.e. the clamped flex @@ -1252,7 +1257,7 @@ static void YGNodeComputeFlexBasisForChild( if (isRowStyleDimDefined) { childWidth = YGResolveValue( - child->getResolvedDimension(YGDimensionWidth), ownerWidth) + child->getResolvedDimensions()[YGDimensionWidth], ownerWidth) .unwrap() + marginRow; childWidthMeasureMode = YGMeasureModeExactly; @@ -1260,7 +1265,7 @@ static void YGNodeComputeFlexBasisForChild( if (isColumnStyleDimDefined) { childHeight = YGResolveValue( - child->getResolvedDimension(YGDimensionHeight), ownerHeight) + child->getResolvedDimensions()[YGDimensionHeight], ownerHeight) .unwrap() + marginColumn; childHeightMeasureMode = YGMeasureModeExactly; @@ -1268,32 +1273,32 @@ static void YGNodeComputeFlexBasisForChild( // The W3C spec doesn't say anything about the 'overflow' property, but all // major browsers appear to implement the following logic. - if ((!isMainAxisRow && node->getStyle().overflow == YGOverflowScroll) || - node->getStyle().overflow != YGOverflowScroll) { + if ((!isMainAxisRow && node->getStyle().overflow() == YGOverflowScroll) || + node->getStyle().overflow() != YGOverflowScroll) { if (YGFloatIsUndefined(childWidth) && !YGFloatIsUndefined(width)) { childWidth = width; childWidthMeasureMode = YGMeasureModeAtMost; } } - if ((isMainAxisRow && node->getStyle().overflow == YGOverflowScroll) || - node->getStyle().overflow != YGOverflowScroll) { + if ((isMainAxisRow && node->getStyle().overflow() == YGOverflowScroll) || + node->getStyle().overflow() != YGOverflowScroll) { if (YGFloatIsUndefined(childHeight) && !YGFloatIsUndefined(height)) { childHeight = height; childHeightMeasureMode = YGMeasureModeAtMost; } } - if (!child->getStyle().aspectRatio.isUndefined()) { + const auto& childStyle = child->getStyle(); + if (!childStyle.aspectRatio().isUndefined()) { if (!isMainAxisRow && childWidthMeasureMode == YGMeasureModeExactly) { childHeight = marginColumn + - (childWidth - marginRow) / child->getStyle().aspectRatio.unwrap(); + (childWidth - marginRow) / childStyle.aspectRatio().unwrap(); childHeightMeasureMode = YGMeasureModeExactly; } else if ( isMainAxisRow && childHeightMeasureMode == YGMeasureModeExactly) { childWidth = marginRow + - (childHeight - marginColumn) * - child->getStyle().aspectRatio.unwrap(); + (childHeight - marginColumn) * childStyle.aspectRatio().unwrap(); childWidthMeasureMode = YGMeasureModeExactly; } } @@ -1310,9 +1315,9 @@ static void YGNodeComputeFlexBasisForChild( childWidthStretch) { childWidth = width; childWidthMeasureMode = YGMeasureModeExactly; - if (!child->getStyle().aspectRatio.isUndefined()) { + if (!childStyle.aspectRatio().isUndefined()) { childHeight = - (childWidth - marginRow) / child->getStyle().aspectRatio.unwrap(); + (childWidth - marginRow) / childStyle.aspectRatio().unwrap(); childHeightMeasureMode = YGMeasureModeExactly; } } @@ -1327,9 +1332,9 @@ static void YGNodeComputeFlexBasisForChild( childHeight = height; childHeightMeasureMode = YGMeasureModeExactly; - if (!child->getStyle().aspectRatio.isUndefined()) { - childWidth = (childHeight - marginColumn) * - child->getStyle().aspectRatio.unwrap(); + if (!childStyle.aspectRatio().isUndefined()) { + childWidth = + (childHeight - marginColumn) * childStyle.aspectRatio().unwrap(); childWidthMeasureMode = YGMeasureModeExactly; } } @@ -1383,7 +1388,7 @@ static void YGNodeAbsoluteLayoutChild( YGMarkerLayoutData& layoutMarkerData, void* const layoutContext) { const YGFlexDirection mainAxis = - YGResolveFlexDirection(node->getStyle().flexDirection, direction); + YGResolveFlexDirection(node->getStyle().flexDirection(), direction); const YGFlexDirection crossAxis = YGFlexDirectionCross(mainAxis, direction); const bool isMainAxisRow = YGFlexDirectionIsRow(mainAxis); @@ -1398,7 +1403,7 @@ static void YGNodeAbsoluteLayoutChild( if (YGNodeIsStyleDimDefined(child, YGFlexDirectionRow, width)) { childWidth = - YGResolveValue(child->getResolvedDimension(YGDimensionWidth), width) + YGResolveValue(child->getResolvedDimensions()[YGDimensionWidth], width) .unwrap() + marginRow; } else { @@ -1418,9 +1423,9 @@ static void YGNodeAbsoluteLayoutChild( } if (YGNodeIsStyleDimDefined(child, YGFlexDirectionColumn, height)) { - childHeight = - YGResolveValue(child->getResolvedDimension(YGDimensionHeight), height) - .unwrap() + + childHeight = YGResolveValue( + child->getResolvedDimensions()[YGDimensionHeight], height) + .unwrap() + marginColumn; } else { // If the child doesn't have a specified height, compute the height based on @@ -1441,15 +1446,15 @@ static void YGNodeAbsoluteLayoutChild( // Exactly one dimension needs to be defined for us to be able to do aspect // ratio calculation. One dimension being the anchor and the other being // flexible. + const auto& childStyle = child->getStyle(); if (YGFloatIsUndefined(childWidth) ^ YGFloatIsUndefined(childHeight)) { - if (!child->getStyle().aspectRatio.isUndefined()) { + if (!childStyle.aspectRatio().isUndefined()) { if (YGFloatIsUndefined(childWidth)) { childWidth = marginRow + - (childHeight - marginColumn) * - child->getStyle().aspectRatio.unwrap(); + (childHeight - marginColumn) * childStyle.aspectRatio().unwrap(); } else if (YGFloatIsUndefined(childHeight)) { childHeight = marginColumn + - (childWidth - marginRow) / child->getStyle().aspectRatio.unwrap(); + (childWidth - marginRow) / childStyle.aspectRatio().unwrap(); } } } @@ -1521,7 +1526,7 @@ static void YGNodeAbsoluteLayoutChild( leading[mainAxis]); } else if ( !child->isLeadingPositionDefined(mainAxis) && - node->getStyle().justifyContent == YGJustifyCenter) { + node->getStyle().justifyContent() == YGJustifyCenter) { child->setLayoutPosition( (node->getLayout().measuredDimensions[dim[mainAxis]] - child->getLayout().measuredDimensions[dim[mainAxis]]) / @@ -1529,7 +1534,7 @@ static void YGNodeAbsoluteLayoutChild( leading[mainAxis]); } else if ( !child->isLeadingPositionDefined(mainAxis) && - node->getStyle().justifyContent == YGJustifyFlexEnd) { + node->getStyle().justifyContent() == YGJustifyFlexEnd) { child->setLayoutPosition( (node->getLayout().measuredDimensions[dim[mainAxis]] - child->getLayout().measuredDimensions[dim[mainAxis]]), @@ -1559,7 +1564,7 @@ static void YGNodeAbsoluteLayoutChild( } else if ( !child->isLeadingPositionDefined(crossAxis) && ((YGNodeAlignItem(node, child) == YGAlignFlexEnd) ^ - (node->getStyle().flexWrap == YGWrapWrapReverse))) { + (node->getStyle().flexWrap() == YGWrapWrapReverse))) { child->setLayoutPosition( (node->getLayout().measuredDimensions[dim[crossAxis]] - child->getLayout().measuredDimensions[dim[crossAxis]]), @@ -1782,13 +1787,13 @@ static float YGNodeCalculateAvailableInnerDim( // We want to make sure our available height does not violate min and max // constraints const YGFloatOptional minDimensionOptional = - YGResolveValue(node->getStyle().minDimensions[dimension], ownerDim); + YGResolveValue(node->getStyle().minDimensions()[dimension], ownerDim); const float minInnerDim = minDimensionOptional.isUndefined() ? 0.0f : minDimensionOptional.unwrap() - paddingAndBorder; const YGFloatOptional maxDimensionOptional = - YGResolveValue(node->getStyle().maxDimensions[dimension], ownerDim); + YGResolveValue(node->getStyle().maxDimensions()[dimension], ownerDim); const float maxInnerDim = maxDimensionOptional.isUndefined() ? FLT_MAX @@ -1839,7 +1844,7 @@ static float YGNodeComputeFlexBasisForChildren( for (auto child : children) { child->resolveDimension(); - if (child->getStyle().display == YGDisplayNone) { + if (child->getStyle().display() == YGDisplayNone) { YGZeroOutLayoutRecursivly(child, layoutContext); child->setHasNewLayout(true); child->setDirty(false); @@ -1858,7 +1863,7 @@ static float YGNodeComputeFlexBasisForChildren( childDirection, mainDim, crossDim, availableInnerWidth); } - if (child->getStyle().positionType == YGPositionTypeAbsolute) { + if (child->getStyle().positionType() == YGPositionTypeAbsolute) { continue; } if (child == singleFlexChild) { @@ -1906,15 +1911,15 @@ static YGCollectFlexItemsRowValues YGCalculateCollectFlexItemsRowValues( float sizeConsumedOnCurrentLineIncludingMinConstraint = 0; const YGFlexDirection mainAxis = YGResolveFlexDirection( - node->getStyle().flexDirection, node->resolveDirection(ownerDirection)); - const bool isNodeFlexWrap = node->getStyle().flexWrap != YGWrapNoWrap; + node->getStyle().flexDirection(), node->resolveDirection(ownerDirection)); + const bool isNodeFlexWrap = node->getStyle().flexWrap() != YGWrapNoWrap; // Add items to the current line until it's full or we run out of items. uint32_t endOfLineIndex = startOfLineIndex; for (; endOfLineIndex < node->getChildren().size(); endOfLineIndex++) { const YGNodeRef child = node->getChild(endOfLineIndex); - if (child->getStyle().display == YGDisplayNone || - child->getStyle().positionType == YGPositionTypeAbsolute) { + if (child->getStyle().display() == YGDisplayNone || + child->getStyle().positionType() == YGPositionTypeAbsolute) { continue; } child->setLineIndex(lineCount); @@ -1997,7 +2002,7 @@ static float YGDistributeFreeSpaceSecondPass( float flexGrowFactor = 0; float deltaFreeSpace = 0; const bool isMainAxisRow = YGFlexDirectionIsRow(mainAxis); - const bool isNodeFlexWrap = node->getStyle().flexWrap != YGWrapNoWrap; + const bool isNodeFlexWrap = node->getStyle().flexWrap() != YGWrapNoWrap; for (auto currentRelativeChild : collectedFlexItemsValues.relativeChildren) { childFlexBasis = YGNodeBoundAxisWithinMinAndMax( @@ -2067,11 +2072,11 @@ static float YGDistributeFreeSpaceSecondPass( YGMeasureMode childCrossMeasureMode; YGMeasureMode childMainMeasureMode = YGMeasureModeExactly; - if (!currentRelativeChild->getStyle().aspectRatio.isUndefined()) { - childCrossSize = isMainAxisRow ? (childMainSize - marginMain) / - currentRelativeChild->getStyle().aspectRatio.unwrap() - : (childMainSize - marginMain) * - currentRelativeChild->getStyle().aspectRatio.unwrap(); + const auto& childStyle = currentRelativeChild->getStyle(); + if (!childStyle.aspectRatio().isUndefined()) { + childCrossSize = isMainAxisRow + ? (childMainSize - marginMain) / childStyle.aspectRatio().unwrap() + : (childMainSize - marginMain) * childStyle.aspectRatio().unwrap(); childCrossMeasureMode = YGMeasureModeExactly; childCrossSize += marginCross; @@ -2335,7 +2340,7 @@ static void YGJustifyMainAxis( const float availableInnerWidth, const bool performLayout, void* const layoutContext) { - const YGStyle& style = node->getStyle(); + const auto& style = node->getStyle(); const float leadingPaddingAndBorderMain = node->getLeadingPaddingAndBorder(mainAxis, ownerWidth).unwrap(); const float trailingPaddingAndBorderMain = @@ -2344,8 +2349,8 @@ static void YGJustifyMainAxis( // remainingFreeSpace is 0 when min main dimension is not given if (measureModeMainDim == YGMeasureModeAtMost && collectedFlexItemsValues.remainingFreeSpace > 0) { - if (!style.minDimensions[dim[mainAxis]].isUndefined() && - !YGResolveValue(style.minDimensions[dim[mainAxis]], mainAxisownerSize) + if (!style.minDimensions()[dim[mainAxis]].isUndefined() && + !YGResolveValue(style.minDimensions()[dim[mainAxis]], mainAxisownerSize) .isUndefined()) { // This condition makes sure that if the size of main dimension(after // considering child nodes main dim, leading and trailing padding etc) @@ -2355,7 +2360,8 @@ static void YGJustifyMainAxis( // `minAvailableMainDim` denotes minimum available space in which child // can be laid out, it will exclude space consumed by padding and border. const float minAvailableMainDim = - YGResolveValue(style.minDimensions[dim[mainAxis]], mainAxisownerSize) + YGResolveValue( + style.minDimensions()[dim[mainAxis]], mainAxisownerSize) .unwrap() - leadingPaddingAndBorderMain - trailingPaddingAndBorderMain; const float occupiedSpaceByChildNodes = @@ -2372,7 +2378,7 @@ static void YGJustifyMainAxis( i < collectedFlexItemsValues.endOfLineIndex; i++) { const YGNodeRef child = node->getChild(i); - if (child->getStyle().positionType == YGPositionTypeRelative) { + if (child->getStyle().positionType() == YGPositionTypeRelative) { if (child->marginLeadingValue(mainAxis).unit == YGUnitAuto) { numberOfAutoMarginsOnCurrentLine++; } @@ -2387,7 +2393,7 @@ static void YGJustifyMainAxis( // each two elements. float leadingMainDim = 0; float betweenMainDim = 0; - const YGJustify justifyContent = node->getStyle().justifyContent; + const YGJustify justifyContent = node->getStyle().justifyContent(); if (numberOfAutoMarginsOnCurrentLine == 0) { switch (justifyContent) { @@ -2436,10 +2442,10 @@ static void YGJustifyMainAxis( const YGNodeRef child = node->getChild(i); const YGStyle& childStyle = child->getStyle(); const YGLayout childLayout = child->getLayout(); - if (childStyle.display == YGDisplayNone) { + if (childStyle.display() == YGDisplayNone) { continue; } - if (childStyle.positionType == YGPositionTypeAbsolute && + if (childStyle.positionType() == YGPositionTypeAbsolute && child->isLeadingPositionDefined(mainAxis)) { if (performLayout) { // In case the child is position absolute and has left/top being @@ -2456,7 +2462,7 @@ static void YGJustifyMainAxis( // Now that we placed the element, we need to update the variables. // We need to do that only for relative elements. Absolute elements do not // take part in that phase. - if (childStyle.positionType == YGPositionTypeRelative) { + if (childStyle.positionType() == YGPositionTypeRelative) { if (child->marginLeadingValue(mainAxis).unit == YGUnitAuto) { collectedFlexItemsValues.mainDim += collectedFlexItemsValues.remainingFreeSpace / @@ -2720,10 +2726,10 @@ static void YGNodelayoutImpl( // STEP 1: CALCULATE VALUES FOR REMAINDER OF ALGORITHM const YGFlexDirection mainAxis = - YGResolveFlexDirection(node->getStyle().flexDirection, direction); + YGResolveFlexDirection(node->getStyle().flexDirection(), direction); const YGFlexDirection crossAxis = YGFlexDirectionCross(mainAxis, direction); const bool isMainAxisRow = YGFlexDirectionIsRow(mainAxis); - const bool isNodeFlexWrap = node->getStyle().flexWrap != YGWrapNoWrap; + const bool isNodeFlexWrap = node->getStyle().flexWrap() != YGWrapNoWrap; const float mainAxisownerSize = isMainAxisRow ? ownerWidth : ownerHeight; const float crossAxisownerSize = isMainAxisRow ? ownerHeight : ownerWidth; @@ -2752,22 +2758,22 @@ static void YGNodelayoutImpl( const float minInnerWidth = YGResolveValue( - node->getStyle().minDimensions[YGDimensionWidth], ownerWidth) + node->getStyle().minDimensions()[YGDimensionWidth], ownerWidth) .unwrap() - paddingAndBorderAxisRow; const float maxInnerWidth = YGResolveValue( - node->getStyle().maxDimensions[YGDimensionWidth], ownerWidth) + node->getStyle().maxDimensions()[YGDimensionWidth], ownerWidth) .unwrap() - paddingAndBorderAxisRow; const float minInnerHeight = YGResolveValue( - node->getStyle().minDimensions[YGDimensionHeight], ownerHeight) + node->getStyle().minDimensions()[YGDimensionHeight], ownerHeight) .unwrap() - paddingAndBorderAxisColumn; const float maxInnerHeight = YGResolveValue( - node->getStyle().maxDimensions[YGDimensionHeight], ownerHeight) + node->getStyle().maxDimensions()[YGDimensionHeight], ownerHeight) .unwrap() - paddingAndBorderAxisColumn; @@ -2971,10 +2977,10 @@ static void YGNodelayoutImpl( if (performLayout) { for (uint32_t i = startOfLineIndex; i < endOfLineIndex; i++) { const YGNodeRef child = node->getChild(i); - if (child->getStyle().display == YGDisplayNone) { + if (child->getStyle().display() == YGDisplayNone) { continue; } - if (child->getStyle().positionType == YGPositionTypeAbsolute) { + if (child->getStyle().positionType() == YGPositionTypeAbsolute) { // If the child is absolutely positioned and has a // top/left/bottom/right set, override all the previously computed // positions to set it correctly. @@ -3019,14 +3025,13 @@ static void YGNodelayoutImpl( child, crossAxis, availableInnerCrossDim)) { float childMainSize = child->getLayout().measuredDimensions[dim[mainAxis]]; - float childCrossSize = - !child->getStyle().aspectRatio.isUndefined() + const auto& childStyle = child->getStyle(); + float childCrossSize = !childStyle.aspectRatio().isUndefined() ? child->getMarginForAxis(crossAxis, availableInnerWidth) .unwrap() + - (isMainAxisRow ? childMainSize / - child->getStyle().aspectRatio.unwrap() - : childMainSize * - child->getStyle().aspectRatio.unwrap()) + (isMainAxisRow + ? childMainSize / childStyle.aspectRatio().unwrap() + : childMainSize * childStyle.aspectRatio().unwrap()) : collectedFlexItemsValues.crossDim; childMainSize += @@ -3055,7 +3060,7 @@ static void YGNodelayoutImpl( const float childHeight = !isMainAxisRow ? childMainSize : childCrossSize; - auto alignContent = node->getStyle().alignContent; + auto alignContent = node->getStyle().alignContent(); auto crossAxisDoesNotGrow = alignContent != YGAlignStretch && isNodeFlexWrap; const YGMeasureMode childWidthMeasureMode = @@ -3127,7 +3132,7 @@ static void YGNodelayoutImpl( if (!YGFloatIsUndefined(availableInnerCrossDim)) { const float remainingAlignContentDim = availableInnerCrossDim - totalLineCrossDim; - switch (node->getStyle().alignContent) { + switch (node->getStyle().alignContent()) { case YGAlignFlexEnd: currentLead += remainingAlignContentDim; break; @@ -3171,10 +3176,10 @@ static void YGNodelayoutImpl( float maxDescentForCurrentLine = 0; for (ii = startIndex; ii < childCount; ii++) { const YGNodeRef child = node->getChild(ii); - if (child->getStyle().display == YGDisplayNone) { + if (child->getStyle().display() == YGDisplayNone) { continue; } - if (child->getStyle().positionType == YGPositionTypeRelative) { + if (child->getStyle().positionType() == YGPositionTypeRelative) { if (child->getLineIndex() != i) { break; } @@ -3213,10 +3218,10 @@ static void YGNodelayoutImpl( if (performLayout) { for (ii = startIndex; ii < endIndex; ii++) { const YGNodeRef child = node->getChild(ii); - if (child->getStyle().display == YGDisplayNone) { + if (child->getStyle().display() == YGDisplayNone) { continue; } - if (child->getStyle().positionType == YGPositionTypeRelative) { + if (child->getStyle().positionType() == YGPositionTypeRelative) { switch (YGNodeAlignItem(node, child)) { case YGAlignFlexStart: { child->setLayoutPosition( @@ -3342,7 +3347,7 @@ static void YGNodelayoutImpl( // If the user didn't specify a width or height for the node, set the // dimensions based on the children. if (measureModeMainDim == YGMeasureModeUndefined || - (node->getStyle().overflow != YGOverflowScroll && + (node->getStyle().overflow() != YGOverflowScroll && measureModeMainDim == YGMeasureModeAtMost)) { // Clamp the size to the min/max size, if specified, and make sure it // doesn't go below the padding and border amount. @@ -3353,7 +3358,7 @@ static void YGNodelayoutImpl( } else if ( measureModeMainDim == YGMeasureModeAtMost && - node->getStyle().overflow == YGOverflowScroll) { + node->getStyle().overflow() == YGOverflowScroll) { node->setLayoutMeasuredDimension( YGFloatMax( YGFloatMin( @@ -3369,7 +3374,7 @@ static void YGNodelayoutImpl( } if (measureModeCrossDim == YGMeasureModeUndefined || - (node->getStyle().overflow != YGOverflowScroll && + (node->getStyle().overflow() != YGOverflowScroll && measureModeCrossDim == YGMeasureModeAtMost)) { // Clamp the size to the min/max size, if specified, and make sure it // doesn't go below the padding and border amount. @@ -3384,7 +3389,7 @@ static void YGNodelayoutImpl( } else if ( measureModeCrossDim == YGMeasureModeAtMost && - node->getStyle().overflow == YGOverflowScroll) { + node->getStyle().overflow() == YGOverflowScroll) { node->setLayoutMeasuredDimension( YGFloatMax( YGFloatMin( @@ -3402,10 +3407,10 @@ static void YGNodelayoutImpl( // As we only wrapped in normal direction yet, we need to reverse the // positions on wrap-reverse. - if (performLayout && node->getStyle().flexWrap == YGWrapWrapReverse) { + if (performLayout && node->getStyle().flexWrap() == YGWrapWrapReverse) { for (uint32_t i = 0; i < childCount; i++) { const YGNodeRef child = YGNodeGetChild(node, i); - if (child->getStyle().positionType == YGPositionTypeRelative) { + if (child->getStyle().positionType() == YGPositionTypeRelative) { child->setLayoutPosition( node->getLayout().measuredDimensions[dim[crossAxis]] - child->getLayout().position[pos[crossAxis]] - @@ -3418,7 +3423,7 @@ static void YGNodelayoutImpl( if (performLayout) { // STEP 10: SIZING AND POSITIONING ABSOLUTE CHILDREN for (auto child : node->getChildren()) { - if (child->getStyle().positionType != YGPositionTypeAbsolute) { + if (child->getStyle().positionType() != YGPositionTypeAbsolute) { continue; } YGNodeAbsoluteLayoutChild( @@ -3443,7 +3448,7 @@ static void YGNodelayoutImpl( if (needsMainTrailingPos || needsCrossTrailingPos) { for (uint32_t i = 0; i < childCount; i++) { const YGNodeRef child = node->getChild(i); - if (child->getStyle().display == YGDisplayNone) { + if (child->getStyle().display() == YGDisplayNone) { continue; } if (needsMainTrailingPos) { @@ -4014,10 +4019,11 @@ void YGNodeCalculateLayoutWithContext( .unwrap(); widthMeasureMode = YGMeasureModeExactly; } else if (!YGResolveValue( - node->getStyle().maxDimensions[YGDimensionWidth], ownerWidth) + node->getStyle().maxDimensions()[YGDimensionWidth], + ownerWidth) .isUndefined()) { width = YGResolveValue( - node->getStyle().maxDimensions[YGDimensionWidth], ownerWidth) + node->getStyle().maxDimensions()[YGDimensionWidth], ownerWidth) .unwrap(); widthMeasureMode = YGMeasureModeAtMost; } else { @@ -4036,12 +4042,13 @@ void YGNodeCalculateLayoutWithContext( .unwrap(); heightMeasureMode = YGMeasureModeExactly; } else if (!YGResolveValue( - node->getStyle().maxDimensions[YGDimensionHeight], + node->getStyle().maxDimensions()[YGDimensionHeight], ownerHeight) .isUndefined()) { - height = YGResolveValue( - node->getStyle().maxDimensions[YGDimensionHeight], ownerHeight) - .unwrap(); + height = + YGResolveValue( + node->getStyle().maxDimensions()[YGDimensionHeight], ownerHeight) + .unwrap(); heightMeasureMode = YGMeasureModeAtMost; } else { height = ownerHeight;