diff --git a/.eslintrc.js b/.eslintrc.js index a3180f798..59f4d5f7f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -12,7 +12,6 @@ module.exports = { parser: '@typescript-eslint/parser', // Specifies the ESLint parser extends: [ 'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin - 'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier 'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array. ], parserOptions: { diff --git a/src/cpp/include/deps/yoga/BitUtils.h b/src/cpp/include/deps/yoga/BitUtils.h index 1c32e9ecc..8ff415709 100644 --- a/src/cpp/include/deps/yoga/BitUtils.h +++ b/src/cpp/include/deps/yoga/BitUtils.h @@ -7,8 +7,9 @@ #pragma once -#include #include +#include + #include "YGEnums.h" namespace facebook { @@ -27,8 +28,8 @@ constexpr int mask(size_t bitWidth, size_t index) { // The number of bits necessary to represent enums defined with YG_ENUM_SEQ_DECL template constexpr size_t bitWidthFn() { - static_assert( - enums::count() > 0, "Enums must have at least one entries"); + static_assert(enums::count() > 0, + "Enums must have at least one entries"); return log2ceilFn(enums::count() - 1); } @@ -40,13 +41,13 @@ constexpr Enum getEnumData(int flags, size_t index) { template void setEnumData(uint32_t& flags, size_t index, int newValue) { flags = (flags & ~mask(bitWidthFn(), index)) | - ((newValue << index) & (mask(bitWidthFn(), index))); + ((newValue << index) & (mask(bitWidthFn(), index))); } template void setEnumData(uint8_t& flags, size_t index, int newValue) { flags = (flags & ~mask(bitWidthFn(), index)) | - ((newValue << index) & (mask(bitWidthFn(), index))); + ((newValue << index) & (mask(bitWidthFn(), index))); } constexpr bool getBooleanData(int flags, size_t index) { @@ -61,6 +62,6 @@ inline void setBooleanData(uint8_t& flags, size_t index, bool value) { } } -} // namespace detail -} // namespace yoga -} // namespace facebook +} // namespace detail +} // namespace yoga +} // namespace facebook diff --git a/src/cpp/include/deps/yoga/CompactValue.h b/src/cpp/include/deps/yoga/CompactValue.h index f398668e2..e0879398b 100644 --- a/src/cpp/include/deps/yoga/CompactValue.h +++ b/src/cpp/include/deps/yoga/CompactValue.h @@ -7,12 +7,13 @@ #pragma once -#include "YGValue.h" -#include "YGMacros.h" #include #include #include +#include "YGMacros.h" +#include "YGValue.h" + static_assert( std::numeric_limits::is_iec559, "facebook::yoga::detail::CompactValue only works with IEEE754 floats"); @@ -43,7 +44,7 @@ namespace detail { class YOGA_EXPORT CompactValue { friend constexpr bool operator==(CompactValue, CompactValue) noexcept; -public: + public: static constexpr auto LOWER_BOUND = 1.08420217e-19f; static constexpr auto UPPER_BOUND_POINT = 36893485948395847680.0f; static constexpr auto UPPER_BOUND_PERCENT = 18446742974197923840.0f; @@ -125,19 +126,18 @@ public: data.repr &= ~PERCENT_BIT; data.repr += BIAS; - return YGValue{ - data.value, payload_.repr & 0x40000000 ? YGUnitPercent : YGUnitPoint}; + return YGValue{data.value, + payload_.repr & 0x40000000 ? YGUnitPercent : YGUnitPoint}; } bool isUndefined() const noexcept { - return ( - payload_.repr != AUTO_BITS && payload_.repr != ZERO_BITS_POINT && - payload_.repr != ZERO_BITS_PERCENT && std::isnan(payload_.value)); + return (payload_.repr != AUTO_BITS && payload_.repr != ZERO_BITS_POINT && + payload_.repr != ZERO_BITS_PERCENT && std::isnan(payload_.value)); } bool isAuto() const noexcept { return payload_.repr == AUTO_BITS; } -private: + private: union Payload { float value; uint32_t repr; @@ -179,6 +179,6 @@ constexpr bool operator!=(CompactValue a, CompactValue b) noexcept { return !(a == b); } -} // namespace detail -} // namespace yoga -} // namespace facebook +} // namespace detail +} // namespace yoga +} // namespace facebook diff --git a/src/cpp/include/deps/yoga/Utils.cpp b/src/cpp/include/deps/yoga/Utils.cpp index edb198d25..d461276d5 100644 --- a/src/cpp/include/deps/yoga/Utils.cpp +++ b/src/cpp/include/deps/yoga/Utils.cpp @@ -6,16 +6,16 @@ */ #include "Utils.h" + #include using namespace facebook; -YGFlexDirection YGFlexDirectionCross( - const YGFlexDirection flexDirection, - const YGDirection direction) { +YGFlexDirection YGFlexDirectionCross(const YGFlexDirection flexDirection, + const YGDirection direction) { return YGFlexDirectionIsColumn(flexDirection) - ? YGResolveFlexDirection(YGFlexDirectionRow, direction) - : YGFlexDirectionColumn; + ? YGResolveFlexDirection(YGFlexDirectionRow, direction) + : YGFlexDirectionColumn; } float YGFloatMax(const float a, const float b) { diff --git a/src/cpp/include/deps/yoga/Utils.h b/src/cpp/include/deps/yoga/Utils.h index 57e1d45d9..afe9dc29e 100644 --- a/src/cpp/include/deps/yoga/Utils.h +++ b/src/cpp/include/deps/yoga/Utils.h @@ -6,9 +6,9 @@ */ #pragma once +#include "CompactValue.h" #include "YGNode.h" #include "Yoga-internal.h" -#include "CompactValue.h" // This struct is an helper model to hold the data for step 4 of flexbox algo, // which is collecting the flex items in a line. @@ -54,10 +54,9 @@ struct YGCollectFlexItemsRowValues { }; bool YGValueEqual(const YGValue& a, const YGValue& b); -inline bool YGValueEqual( - facebook::yoga::detail::CompactValue a, - facebook::yoga::detail::CompactValue b) { - return YGValueEqual((YGValue) a, (YGValue) b); +inline bool YGValueEqual(facebook::yoga::detail::CompactValue a, + facebook::yoga::detail::CompactValue b) { + return YGValueEqual((YGValue)a, (YGValue)b); } // This custom float equality function returns true if either absolute @@ -68,9 +67,8 @@ bool YGDoubleEqual(const double a, const double b); float YGFloatMax(const float a, const float b); -YGFloatOptional YGFloatOptionalMax( - const YGFloatOptional op1, - const YGFloatOptional op2); +YGFloatOptional YGFloatOptionalMax(const YGFloatOptional op1, + const YGFloatOptional op2); float YGFloatMin(const float a, const float b); @@ -78,9 +76,8 @@ float YGFloatMin(const float a, const float b); // YGFloatsEqual, as the default float comparison operator will not work(Look // at the comments of YGFloatsEqual function). template -bool YGFloatArrayEqual( - const std::array& val1, - const std::array& val2) { +bool YGFloatArrayEqual(const std::array& val1, + const std::array& val2) { bool areEqual = true; for (std::size_t i = 0; i < size && areEqual; ++i) { areEqual = YGFloatsEqual(val1[i], val2[i]); @@ -91,18 +88,16 @@ bool YGFloatArrayEqual( // This function returns 0 if YGFloatIsUndefined(val) is true and val otherwise float YGFloatSanitize(const float val); -YGFlexDirection YGFlexDirectionCross( - const YGFlexDirection flexDirection, - const YGDirection direction); +YGFlexDirection YGFlexDirectionCross(const YGFlexDirection flexDirection, + const YGDirection direction); inline bool YGFlexDirectionIsRow(const YGFlexDirection flexDirection) { return flexDirection == YGFlexDirectionRow || - flexDirection == YGFlexDirectionRowReverse; + flexDirection == YGFlexDirectionRowReverse; } -inline YGFloatOptional YGResolveValue( - const YGValue value, - const float ownerSize) { +inline YGFloatOptional YGResolveValue(const YGValue value, + const float ownerSize) { switch (value.unit) { case YGUnitPoint: return YGFloatOptional{value.value}; @@ -113,20 +108,18 @@ inline YGFloatOptional YGResolveValue( } } -inline YGFloatOptional YGResolveValue( - yoga::detail::CompactValue value, - float ownerSize) { - return YGResolveValue((YGValue) value, ownerSize); +inline YGFloatOptional YGResolveValue(yoga::detail::CompactValue value, + float ownerSize) { + return YGResolveValue((YGValue)value, ownerSize); } inline bool YGFlexDirectionIsColumn(const YGFlexDirection flexDirection) { return flexDirection == YGFlexDirectionColumn || - flexDirection == YGFlexDirectionColumnReverse; + flexDirection == YGFlexDirectionColumnReverse; } inline YGFlexDirection YGResolveFlexDirection( - const YGFlexDirection flexDirection, - const YGDirection direction) { + const YGFlexDirection flexDirection, const YGDirection direction) { if (direction == YGDirectionRTL) { if (flexDirection == YGFlexDirectionRow) { return YGFlexDirectionRowReverse; @@ -138,9 +131,8 @@ inline YGFlexDirection YGResolveFlexDirection( return flexDirection; } -inline YGFloatOptional YGResolveValueMargin( - yoga::detail::CompactValue value, - const float ownerSize) { +inline YGFloatOptional YGResolveValueMargin(yoga::detail::CompactValue value, + const float ownerSize) { return value.isAuto() ? YGFloatOptional{0} : YGResolveValue(value, ownerSize); } diff --git a/src/cpp/include/deps/yoga/YGConfig.cpp b/src/cpp/include/deps/yoga/YGConfig.cpp index fb72e80cf..10345e8d7 100644 --- a/src/cpp/include/deps/yoga/YGConfig.cpp +++ b/src/cpp/include/deps/yoga/YGConfig.cpp @@ -12,13 +12,8 @@ YGConfig::YGConfig(YGLogger logger) : cloneNodeCallback_{nullptr} { loggerUsesContext_ = false; } -void YGConfig::log( - YGConfig* config, - YGNode* node, - YGLogLevel logLevel, - void* logContext, - const char* format, - va_list args) { +void YGConfig::log(YGConfig* config, YGNode* node, YGLogLevel logLevel, + void* logContext, const char* format, va_list args) { if (loggerUsesContext_) { logger_.withContext(config, node, logLevel, logContext, format, args); } else { @@ -26,16 +21,14 @@ void YGConfig::log( } } -YGNodeRef YGConfig::cloneNode( - YGNodeRef node, - YGNodeRef owner, - int childIndex, - void* cloneContext) { +YGNodeRef YGConfig::cloneNode(YGNodeRef node, YGNodeRef owner, int childIndex, + void* cloneContext) { YGNodeRef clone = nullptr; if (cloneNodeCallback_.noContext != nullptr) { clone = cloneNodeUsesContext_ - ? cloneNodeCallback_.withContext(node, owner, childIndex, cloneContext) - : cloneNodeCallback_.noContext(node, owner, childIndex); + ? cloneNodeCallback_.withContext(node, owner, childIndex, + cloneContext) + : cloneNodeCallback_.noContext(node, owner, childIndex); } if (clone == nullptr) { clone = YGNodeClone(node); diff --git a/src/cpp/include/deps/yoga/YGConfig.h b/src/cpp/include/deps/yoga/YGConfig.h index e87d67586..656e87045 100644 --- a/src/cpp/include/deps/yoga/YGConfig.h +++ b/src/cpp/include/deps/yoga/YGConfig.h @@ -10,20 +10,13 @@ #include "Yoga.h" struct YOGA_EXPORT YGConfig { - using LogWithContextFn = int (*)( - YGConfigRef config, - YGNodeRef node, - YGLogLevel level, - void* context, - const char* format, - va_list args); - using CloneWithContextFn = YGNodeRef (*)( - YGNodeRef node, - YGNodeRef owner, - int childIndex, - void* cloneContext); + using LogWithContextFn = int (*)(YGConfigRef config, YGNodeRef node, + YGLogLevel level, void* context, + const char* format, va_list args); + using CloneWithContextFn = YGNodeRef (*)(YGNodeRef node, YGNodeRef owner, + int childIndex, void* cloneContext); -private: + private: union { CloneWithContextFn withContext; YGCloneNodeFunc noContext; @@ -35,7 +28,7 @@ private: bool cloneNodeUsesContext_; bool loggerUsesContext_; -public: + public: bool useWebDefaults = false; bool useLegacyStretchBehaviour = false; bool shouldDiffLayoutWithoutLegacyStretchBehaviour = false; @@ -57,11 +50,8 @@ public: } void setLogger(std::nullptr_t) { setLogger(YGLogger{nullptr}); } - YGNodeRef cloneNode( - YGNodeRef node, - YGNodeRef owner, - int childIndex, - void* cloneContext); + YGNodeRef cloneNode(YGNodeRef node, YGNodeRef owner, int childIndex, + void* cloneContext); void setCloneNodeCallback(YGCloneNodeFunc cloneNode) { cloneNodeCallback_.noContext = cloneNode; cloneNodeUsesContext_ = false; diff --git a/src/cpp/include/deps/yoga/YGEnums.h b/src/cpp/include/deps/yoga/YGEnums.h index 3dc458dcb..f2152f948 100644 --- a/src/cpp/include/deps/yoga/YGEnums.h +++ b/src/cpp/include/deps/yoga/YGEnums.h @@ -15,18 +15,18 @@ namespace yoga { namespace enums { template -constexpr int count(); // can't use `= delete` due to a defect in clang < 3.9 +constexpr int count(); // can't use `= delete` due to a defect in clang < 3.9 namespace detail { template constexpr int n() { return sizeof...(xs); } -} // namespace detail +} // namespace detail -} // namespace enums -} // namespace yoga -} // namespace facebook +} // namespace enums +} // namespace yoga +} // namespace facebook #endif #define YG_ENUM_DECL(NAME, ...) \ @@ -54,98 +54,50 @@ constexpr int n() { YG_EXTERN_C_BEGIN -YG_ENUM_SEQ_DECL( - YGAlign, - YGAlignAuto, - YGAlignFlexStart, - YGAlignCenter, - YGAlignFlexEnd, - YGAlignStretch, - YGAlignBaseline, - YGAlignSpaceBetween, - YGAlignSpaceAround); +YG_ENUM_SEQ_DECL(YGAlign, YGAlignAuto, YGAlignFlexStart, YGAlignCenter, + YGAlignFlexEnd, YGAlignStretch, YGAlignBaseline, + YGAlignSpaceBetween, YGAlignSpaceAround); YG_ENUM_SEQ_DECL(YGDimension, YGDimensionWidth, YGDimensionHeight) -YG_ENUM_SEQ_DECL( - YGDirection, - YGDirectionInherit, - YGDirectionLTR, - YGDirectionRTL) +YG_ENUM_SEQ_DECL(YGDirection, YGDirectionInherit, YGDirectionLTR, + YGDirectionRTL) YG_ENUM_SEQ_DECL(YGDisplay, YGDisplayFlex, YGDisplayNone) -YG_ENUM_SEQ_DECL( - YGEdge, - YGEdgeLeft, - YGEdgeTop, - YGEdgeRight, - YGEdgeBottom, - YGEdgeStart, - YGEdgeEnd, - YGEdgeHorizontal, - YGEdgeVertical, - YGEdgeAll) +YG_ENUM_SEQ_DECL(YGEdge, YGEdgeLeft, YGEdgeTop, YGEdgeRight, YGEdgeBottom, + YGEdgeStart, YGEdgeEnd, YGEdgeHorizontal, YGEdgeVertical, + YGEdgeAll) YG_ENUM_SEQ_DECL(YGExperimentalFeature, YGExperimentalFeatureWebFlexBasis) -YG_ENUM_SEQ_DECL( - YGFlexDirection, - YGFlexDirectionColumn, - YGFlexDirectionColumnReverse, - YGFlexDirectionRow, - YGFlexDirectionRowReverse) +YG_ENUM_SEQ_DECL(YGFlexDirection, YGFlexDirectionColumn, + YGFlexDirectionColumnReverse, YGFlexDirectionRow, + YGFlexDirectionRowReverse) -YG_ENUM_SEQ_DECL( - YGJustify, - YGJustifyFlexStart, - YGJustifyCenter, - YGJustifyFlexEnd, - YGJustifySpaceBetween, - YGJustifySpaceAround, - YGJustifySpaceEvenly) +YG_ENUM_SEQ_DECL(YGJustify, YGJustifyFlexStart, YGJustifyCenter, + YGJustifyFlexEnd, YGJustifySpaceBetween, YGJustifySpaceAround, + YGJustifySpaceEvenly) -YG_ENUM_SEQ_DECL( - YGLogLevel, - YGLogLevelError, - YGLogLevelWarn, - YGLogLevelInfo, - YGLogLevelDebug, - YGLogLevelVerbose, - YGLogLevelFatal) +YG_ENUM_SEQ_DECL(YGLogLevel, YGLogLevelError, YGLogLevelWarn, YGLogLevelInfo, + YGLogLevelDebug, YGLogLevelVerbose, YGLogLevelFatal) -YG_ENUM_SEQ_DECL( - YGMeasureMode, - YGMeasureModeUndefined, - YGMeasureModeExactly, - YGMeasureModeAtMost) +YG_ENUM_SEQ_DECL(YGMeasureMode, YGMeasureModeUndefined, YGMeasureModeExactly, + YGMeasureModeAtMost) YG_ENUM_SEQ_DECL(YGNodeType, YGNodeTypeDefault, YGNodeTypeText) -YG_ENUM_SEQ_DECL( - YGOverflow, - YGOverflowVisible, - YGOverflowHidden, - YGOverflowScroll) +YG_ENUM_SEQ_DECL(YGOverflow, YGOverflowVisible, YGOverflowHidden, + YGOverflowScroll) -YG_ENUM_SEQ_DECL( - YGPositionType, - YGPositionTypeStatic, - YGPositionTypeRelative, - YGPositionTypeAbsolute) +YG_ENUM_SEQ_DECL(YGPositionType, YGPositionTypeStatic, YGPositionTypeRelative, + YGPositionTypeAbsolute) -YG_ENUM_DECL( - YGPrintOptions, - YGPrintOptionsLayout = 1, - YGPrintOptionsStyle = 2, - YGPrintOptionsChildren = 4) +YG_ENUM_DECL(YGPrintOptions, YGPrintOptionsLayout = 1, YGPrintOptionsStyle = 2, + YGPrintOptionsChildren = 4) -YG_ENUM_SEQ_DECL( - YGUnit, - YGUnitUndefined, - YGUnitPoint, - YGUnitPercent, - YGUnitAuto) +YG_ENUM_SEQ_DECL(YGUnit, YGUnitUndefined, YGUnitPoint, YGUnitPercent, + YGUnitAuto) YG_ENUM_SEQ_DECL(YGWrap, YGWrapNoWrap, YGWrapWrap, YGWrapWrapReverse) diff --git a/src/cpp/include/deps/yoga/YGFloatOptional.h b/src/cpp/include/deps/yoga/YGFloatOptional.h index e4cf0284b..1ddf1360a 100644 --- a/src/cpp/include/deps/yoga/YGFloatOptional.h +++ b/src/cpp/include/deps/yoga/YGFloatOptional.h @@ -9,13 +9,14 @@ #include #include + #include "Yoga-internal.h" struct YGFloatOptional { -private: + private: float value_ = std::numeric_limits::quiet_NaN(); -public: + public: explicit constexpr YGFloatOptional(float value) : value_(value) {} constexpr YGFloatOptional() = default; @@ -29,7 +30,7 @@ public: inline bool operator==(YGFloatOptional lhs, YGFloatOptional rhs) { return lhs.unwrap() == rhs.unwrap() || - (lhs.isUndefined() && rhs.isUndefined()); + (lhs.isUndefined() && rhs.isUndefined()); } inline bool operator!=(YGFloatOptional lhs, YGFloatOptional rhs) { return !(lhs == rhs); @@ -38,16 +39,10 @@ inline bool operator!=(YGFloatOptional lhs, YGFloatOptional rhs) { inline bool operator==(YGFloatOptional lhs, float rhs) { return lhs == YGFloatOptional{rhs}; } -inline bool operator!=(YGFloatOptional lhs, float rhs) { - return !(lhs == rhs); -} +inline bool operator!=(YGFloatOptional lhs, float rhs) { return !(lhs == rhs); } -inline bool operator==(float lhs, YGFloatOptional rhs) { - return rhs == lhs; -} -inline bool operator!=(float lhs, YGFloatOptional rhs) { - return !(lhs == rhs); -} +inline bool operator==(float lhs, YGFloatOptional rhs) { return rhs == lhs; } +inline bool operator!=(float lhs, YGFloatOptional rhs) { return !(lhs == rhs); } inline YGFloatOptional operator+(YGFloatOptional lhs, YGFloatOptional rhs) { return YGFloatOptional{lhs.unwrap() + rhs.unwrap()}; diff --git a/src/cpp/include/deps/yoga/YGLayout.cpp b/src/cpp/include/deps/yoga/YGLayout.cpp index e43213cdc..cdce719cb 100644 --- a/src/cpp/include/deps/yoga/YGLayout.cpp +++ b/src/cpp/include/deps/yoga/YGLayout.cpp @@ -6,12 +6,14 @@ */ #include "YGLayout.h" + #include "Utils.h" using namespace facebook; bool YGLayout::operator==(YGLayout layout) const { - bool isEqual = YGFloatArrayEqual(position, layout.position) && + bool isEqual = + YGFloatArrayEqual(position, layout.position) && YGFloatArrayEqual(dimensions, layout.dimensions) && YGFloatArrayEqual(margin, layout.margin) && YGFloatArrayEqual(border, layout.border) && diff --git a/src/cpp/include/deps/yoga/YGLayout.h b/src/cpp/include/deps/yoga/YGLayout.h index b7604d8e2..7004c44a8 100644 --- a/src/cpp/include/deps/yoga/YGLayout.h +++ b/src/cpp/include/deps/yoga/YGLayout.h @@ -19,7 +19,7 @@ struct YGLayout { std::array border = {}; std::array padding = {}; -private: + private: static constexpr size_t directionOffset = 0; static constexpr size_t didUseLegacyFlagOffset = directionOffset + facebook::yoga::detail::bitWidthFn(); @@ -29,7 +29,7 @@ private: doesLegacyStretchFlagAffectsLayoutOffset + 1; uint8_t flags = 0; -public: + public: uint32_t computedFlexBasisGeneration = 0; YGFloatOptional computedFlexBasis = {}; @@ -46,18 +46,18 @@ public: YGCachedMeasurement cachedLayout = YGCachedMeasurement(); YGDirection direction() const { - return facebook::yoga::detail::getEnumData( - flags, directionOffset); + return facebook::yoga::detail::getEnumData(flags, + directionOffset); } void setDirection(YGDirection direction) { - facebook::yoga::detail::setEnumData( - flags, directionOffset, direction); + facebook::yoga::detail::setEnumData(flags, directionOffset, + direction); } bool didUseLegacyFlag() const { - return facebook::yoga::detail::getBooleanData( - flags, didUseLegacyFlagOffset); + return facebook::yoga::detail::getBooleanData(flags, + didUseLegacyFlagOffset); } void setDidUseLegacyFlag(bool val) { @@ -78,8 +78,8 @@ public: return facebook::yoga::detail::getBooleanData(flags, hadOverflowOffset); } void setHadOverflow(bool hadOverflow) { - facebook::yoga::detail::setBooleanData( - flags, hadOverflowOffset, hadOverflow); + facebook::yoga::detail::setBooleanData(flags, hadOverflowOffset, + hadOverflow); } bool operator==(YGLayout layout) const; diff --git a/src/cpp/include/deps/yoga/YGNode.cpp b/src/cpp/include/deps/yoga/YGNode.cpp index 1ee1bde62..34136be92 100644 --- a/src/cpp/include/deps/yoga/YGNode.cpp +++ b/src/cpp/include/deps/yoga/YGNode.cpp @@ -6,8 +6,10 @@ */ #include "YGNode.h" + #include #include + #include "CompactValue.h" #include "Utils.h" @@ -50,114 +52,104 @@ void YGNode::print(void* printContext) { } } -YGFloatOptional YGNode::getLeadingPosition( - const YGFlexDirection axis, - const float axisSize) const { +YGFloatOptional YGNode::getLeadingPosition(const YGFlexDirection axis, + const float axisSize) const { if (YGFlexDirectionIsRow(axis)) { - auto leadingPosition = YGComputedEdgeValue( - style_.position(), YGEdgeStart, CompactValue::ofUndefined()); + auto leadingPosition = YGComputedEdgeValue(style_.position(), YGEdgeStart, + CompactValue::ofUndefined()); if (!leadingPosition.isUndefined()) { return YGResolveValue(leadingPosition, axisSize); } } - auto leadingPosition = YGComputedEdgeValue( - style_.position(), leading[axis], CompactValue::ofUndefined()); + auto leadingPosition = YGComputedEdgeValue(style_.position(), leading[axis], + CompactValue::ofUndefined()); return leadingPosition.isUndefined() - ? YGFloatOptional{0} - : YGResolveValue(leadingPosition, axisSize); + ? YGFloatOptional{0} + : YGResolveValue(leadingPosition, axisSize); } -YGFloatOptional YGNode::getTrailingPosition( - const YGFlexDirection axis, - const float axisSize) const { +YGFloatOptional YGNode::getTrailingPosition(const YGFlexDirection axis, + const float axisSize) const { if (YGFlexDirectionIsRow(axis)) { - auto trailingPosition = YGComputedEdgeValue( - style_.position(), YGEdgeEnd, CompactValue::ofUndefined()); + auto trailingPosition = YGComputedEdgeValue(style_.position(), YGEdgeEnd, + CompactValue::ofUndefined()); if (!trailingPosition.isUndefined()) { return YGResolveValue(trailingPosition, axisSize); } } - auto trailingPosition = YGComputedEdgeValue( - style_.position(), trailing[axis], CompactValue::ofUndefined()); + auto trailingPosition = YGComputedEdgeValue(style_.position(), trailing[axis], + CompactValue::ofUndefined()); return trailingPosition.isUndefined() - ? YGFloatOptional{0} - : YGResolveValue(trailingPosition, axisSize); + ? YGFloatOptional{0} + : YGResolveValue(trailingPosition, axisSize); } bool YGNode::isLeadingPositionDefined(const YGFlexDirection axis) const { return (YGFlexDirectionIsRow(axis) && - !YGComputedEdgeValue( - style_.position(), YGEdgeStart, CompactValue::ofUndefined()) + !YGComputedEdgeValue(style_.position(), YGEdgeStart, + CompactValue::ofUndefined()) .isUndefined()) || - !YGComputedEdgeValue( - style_.position(), leading[axis], CompactValue::ofUndefined()) - .isUndefined(); + !YGComputedEdgeValue(style_.position(), leading[axis], + CompactValue::ofUndefined()) + .isUndefined(); } bool YGNode::isTrailingPosDefined(const YGFlexDirection axis) const { return (YGFlexDirectionIsRow(axis) && - !YGComputedEdgeValue( - style_.position(), YGEdgeEnd, CompactValue::ofUndefined()) + !YGComputedEdgeValue(style_.position(), YGEdgeEnd, + CompactValue::ofUndefined()) .isUndefined()) || - !YGComputedEdgeValue( - style_.position(), trailing[axis], CompactValue::ofUndefined()) - .isUndefined(); + !YGComputedEdgeValue(style_.position(), trailing[axis], + CompactValue::ofUndefined()) + .isUndefined(); } -YGFloatOptional YGNode::getLeadingMargin( - const YGFlexDirection axis, - const float widthSize) const { +YGFloatOptional YGNode::getLeadingMargin(const YGFlexDirection axis, + const float widthSize) const { 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 { +YGFloatOptional YGNode::getTrailingMargin(const YGFlexDirection axis, + const float widthSize) const { if (YGFlexDirectionIsRow(axis) && !style_.margin()[YGEdgeEnd].isUndefined()) { return YGResolveValueMargin(style_.margin()[YGEdgeEnd], widthSize); } return YGResolveValueMargin( - YGComputedEdgeValue( - style_.margin(), trailing[axis], CompactValue::ofZero()), + YGComputedEdgeValue(style_.margin(), trailing[axis], + CompactValue::ofZero()), widthSize); } -YGFloatOptional YGNode::getMarginForAxis( - const YGFlexDirection axis, - const float widthSize) const { +YGFloatOptional YGNode::getMarginForAxis(const YGFlexDirection axis, + const float widthSize) const { return getLeadingMargin(axis, widthSize) + getTrailingMargin(axis, widthSize); } -YGSize YGNode::measure( - float width, - YGMeasureMode widthMode, - float height, - YGMeasureMode heightMode, - void* layoutContext) { - +YGSize YGNode::measure(float width, YGMeasureMode widthMode, float height, + YGMeasureMode heightMode, void* layoutContext) { return facebook::yoga::detail::getBooleanData(flags, measureUsesContext_) - ? measure_.withContext( - this, width, widthMode, height, heightMode, layoutContext) - : measure_.noContext(this, width, widthMode, height, heightMode); + ? measure_.withContext(this, width, widthMode, height, heightMode, + layoutContext) + : measure_.noContext(this, width, widthMode, height, heightMode); } float YGNode::baseline(float width, float height, void* layoutContext) { return facebook::yoga::detail::getBooleanData(flags, baselineUsesContext_) - ? baseline_.withContext(this, width, height, layoutContext) - : baseline_.noContext(this, width, height); + ? baseline_.withContext(this, width, height, layoutContext) + : baseline_.noContext(this, width, height); } // Setters @@ -169,8 +161,7 @@ void YGNode::setMeasureFunc(decltype(YGNode::measure_) measureFunc) { setNodeType(YGNodeTypeDefault); } else { YGAssertWithNode( - this, - children_.size() == 0, + this, children_.size() == 0, "Cannot set measure function: Nodes with measure functions cannot have " "children."); // TODO: t18095186 Move nodeType to opt-in function and mark appropriate @@ -279,9 +270,8 @@ void YGNode::setLayoutDimension(float dimension, int index) { // If both left and right are defined, then use left. Otherwise return +left or // -right depending on which is defined. -YGFloatOptional YGNode::relativePosition( - const YGFlexDirection axis, - const float axisSize) const { +YGFloatOptional YGNode::relativePosition(const YGFlexDirection axis, + const float axisSize) const { if (isLeadingPositionDefined(axis)) { return getLeadingPosition(axis, axisSize); } @@ -293,11 +283,8 @@ YGFloatOptional YGNode::relativePosition( return trailingPosition; } -void YGNode::setPosition( - const YGDirection direction, - const float mainSize, - const float crossSize, - const float ownerWidth) { +void YGNode::setPosition(const YGDirection direction, const float mainSize, + const float crossSize, const float ownerWidth) { /* Root nodes should be always layouted as LTR, so we don't return negative * values. */ const YGDirection directionRespectingRoot = @@ -355,8 +342,8 @@ YGValue YGNode::resolveFlexBasisPtr() const { } if (!style_.flex().isUndefined() && style_.flex().unwrap() > 0.0f) { return facebook::yoga::detail::getBooleanData(flags, useWebDefaults_) - ? YGValueAuto - : YGValueZero; + ? YGValueAuto + : YGValueZero; } return YGValueAuto; } @@ -437,14 +424,13 @@ float YGNode::resolveFlexShrink() const { return -style_.flex().unwrap(); } return facebook::yoga::detail::getBooleanData(flags, useWebDefaults_) - ? kWebDefaultFlexShrink - : kDefaultFlexShrink; + ? kWebDefaultFlexShrink + : kDefaultFlexShrink; } bool YGNode::isNodeFlexible() { - return ( - (style_.positionType() != YGPositionTypeAbsolute) && - (resolveFlexGrow() != 0 || resolveFlexShrink() != 0)); + return ((style_.positionType() != YGPositionTypeAbsolute) && + (resolveFlexGrow() != 0 || resolveFlexShrink() != 0)); } float YGNode::getLeadingBorder(const YGFlexDirection axis) const { @@ -457,8 +443,8 @@ float YGNode::getLeadingBorder(const YGFlexDirection axis) const { } } - leadingBorder = YGComputedEdgeValue( - style_.border(), leading[axis], CompactValue::ofZero()); + leadingBorder = YGComputedEdgeValue(style_.border(), leading[axis], + CompactValue::ofZero()); return YGFloatMax(leadingBorder.value, 0.0f); } @@ -472,14 +458,13 @@ float YGNode::getTrailingBorder(const YGFlexDirection flexDirection) const { } } - trailingBorder = YGComputedEdgeValue( - style_.border(), trailing[flexDirection], CompactValue::ofZero()); + trailingBorder = YGComputedEdgeValue(style_.border(), trailing[flexDirection], + CompactValue::ofZero()); return YGFloatMax(trailingBorder.value, 0.0f); } -YGFloatOptional YGNode::getLeadingPadding( - const YGFlexDirection axis, - const float widthSize) const { +YGFloatOptional YGNode::getLeadingPadding(const YGFlexDirection axis, + const float widthSize) const { const YGFloatOptional paddingEdgeStart = YGResolveValue(style_.padding()[YGEdgeStart], widthSize); if (YGFlexDirectionIsRow(axis) && @@ -488,42 +473,39 @@ YGFloatOptional YGNode::getLeadingPadding( return paddingEdgeStart; } - YGFloatOptional resolvedValue = YGResolveValue( - YGComputedEdgeValue( - style_.padding(), leading[axis], CompactValue::ofZero()), - widthSize); + YGFloatOptional resolvedValue = + YGResolveValue(YGComputedEdgeValue(style_.padding(), leading[axis], + CompactValue::ofZero()), + widthSize); return YGFloatOptionalMax(resolvedValue, YGFloatOptional(0.0f)); } -YGFloatOptional YGNode::getTrailingPadding( - const YGFlexDirection axis, - const float widthSize) const { +YGFloatOptional YGNode::getTrailingPadding(const YGFlexDirection axis, + const float widthSize) const { const YGFloatOptional paddingEdgeEnd = YGResolveValue(style_.padding()[YGEdgeEnd], widthSize); if (YGFlexDirectionIsRow(axis) && paddingEdgeEnd >= YGFloatOptional{0.0f}) { return paddingEdgeEnd; } - YGFloatOptional resolvedValue = YGResolveValue( - YGComputedEdgeValue( - style_.padding(), trailing[axis], CompactValue::ofZero()), - widthSize); + YGFloatOptional resolvedValue = + YGResolveValue(YGComputedEdgeValue(style_.padding(), trailing[axis], + CompactValue::ofZero()), + widthSize); return YGFloatOptionalMax(resolvedValue, YGFloatOptional(0.0f)); } YGFloatOptional YGNode::getLeadingPaddingAndBorder( - const YGFlexDirection axis, - const float widthSize) const { + const YGFlexDirection axis, const float widthSize) const { return getLeadingPadding(axis, widthSize) + - YGFloatOptional(getLeadingBorder(axis)); + YGFloatOptional(getLeadingBorder(axis)); } YGFloatOptional YGNode::getTrailingPaddingAndBorder( - const YGFlexDirection axis, - const float widthSize) const { + const YGFlexDirection axis, const float widthSize) const { return getTrailingPadding(axis, widthSize) + - YGFloatOptional(getTrailingBorder(axis)); + YGFloatOptional(getTrailingBorder(axis)); } bool YGNode::didUseLegacyFlag() { @@ -574,12 +556,10 @@ bool YGNode::isLayoutTreeEqualToNode(const YGNode& node) const { } void YGNode::reset() { - YGAssertWithNode( - this, - children_.size() == 0, - "Cannot reset a node which still has children attached"); - YGAssertWithNode( - this, owner_ == nullptr, "Cannot reset a node still attached to a owner"); + YGAssertWithNode(this, children_.size() == 0, + "Cannot reset a node which still has children attached"); + YGAssertWithNode(this, owner_ == nullptr, + "Cannot reset a node still attached to a owner"); clearChildren(); diff --git a/src/cpp/include/deps/yoga/YGNode.h b/src/cpp/include/deps/yoga/YGNode.h index 63d98fe3a..10cbb17ff 100644 --- a/src/cpp/include/deps/yoga/YGNode.h +++ b/src/cpp/include/deps/yoga/YGNode.h @@ -9,25 +9,27 @@ #ifdef __cplusplus -#include #include + +#include + #include "BitUtils.h" #include "CompactValue.h" #include "YGConfig.h" #include "YGLayout.h" -#include "YGStyle.h" #include "YGMacros.h" +#include "YGStyle.h" #include "Yoga-internal.h" YGConfigRef YGConfigGetDefault(); struct YOGA_EXPORT YGNode { - using MeasureWithContextFn = - YGSize (*)(YGNode*, float, YGMeasureMode, float, YGMeasureMode, void*); + using MeasureWithContextFn = YGSize (*)(YGNode*, float, YGMeasureMode, float, + YGMeasureMode, void*); using BaselineWithContextFn = float (*)(YGNode*, float, float, void*); using PrintWithContextFn = void (*)(YGNode*, void*); -private: + private: static constexpr size_t hasNewLayout_ = 0; static constexpr size_t isReferenceBaseline_ = 1; static constexpr size_t isDirty_ = 2; @@ -62,9 +64,8 @@ private: std::array resolvedDimensions_ = { {YGValueUndefined, YGValueUndefined}}; - YGFloatOptional relativePosition( - const YGFlexDirection axis, - const float axisSize) const; + YGFloatOptional relativePosition(const YGFlexDirection axis, + const float axisSize) const; void setMeasureFunc(decltype(measure_)); void setBaselineFunc(decltype(baseline_)); @@ -84,14 +85,14 @@ private: using CompactValue = facebook::yoga::detail::CompactValue; -public: + public: YGNode() : YGNode{YGConfigGetDefault()} {} explicit YGNode(const YGConfigRef config) : config_{config} { if (config->useWebDefaults) { useWebDefaults(); } }; - ~YGNode() = default; // cleanup of owner/children relationships in YGNodeFree + ~YGNode() = default; // cleanup of owner/children relationships in YGNodeFree YGNode(YGNode&&); @@ -194,37 +195,28 @@ public: } // Methods related to positions, margin, padding and border - YGFloatOptional getLeadingPosition( - const YGFlexDirection axis, - const float axisSize) const; + YGFloatOptional getLeadingPosition(const YGFlexDirection axis, + const float axisSize) const; bool isLeadingPositionDefined(const YGFlexDirection axis) const; bool isTrailingPosDefined(const YGFlexDirection axis) const; - YGFloatOptional getTrailingPosition( - const YGFlexDirection axis, - const float axisSize) const; - YGFloatOptional getLeadingMargin( - const YGFlexDirection axis, - const float widthSize) const; - YGFloatOptional getTrailingMargin( - const YGFlexDirection axis, - const float widthSize) const; + YGFloatOptional getTrailingPosition(const YGFlexDirection axis, + const float axisSize) const; + YGFloatOptional getLeadingMargin(const YGFlexDirection axis, + const float widthSize) const; + YGFloatOptional getTrailingMargin(const YGFlexDirection axis, + const float widthSize) const; float getLeadingBorder(const YGFlexDirection flexDirection) const; float getTrailingBorder(const YGFlexDirection flexDirection) const; - YGFloatOptional getLeadingPadding( - const YGFlexDirection axis, - const float widthSize) const; - YGFloatOptional getTrailingPadding( - const YGFlexDirection axis, - const float widthSize) const; - YGFloatOptional getLeadingPaddingAndBorder( - const YGFlexDirection axis, - const float widthSize) const; - YGFloatOptional getTrailingPaddingAndBorder( - const YGFlexDirection axis, - const float widthSize) const; - YGFloatOptional getMarginForAxis( - const YGFlexDirection axis, - const float widthSize) const; + YGFloatOptional getLeadingPadding(const YGFlexDirection axis, + const float widthSize) const; + YGFloatOptional getTrailingPadding(const YGFlexDirection axis, + const float widthSize) const; + YGFloatOptional getLeadingPaddingAndBorder(const YGFlexDirection axis, + const float widthSize) const; + YGFloatOptional getTrailingPaddingAndBorder(const YGFlexDirection axis, + const float widthSize) const; + YGFloatOptional getMarginForAxis(const YGFlexDirection axis, + const float widthSize) const; // Setters void setContext(void* context) { context_ = context; } @@ -244,8 +236,8 @@ public: } void setNodeType(YGNodeType nodeType) { - return facebook::yoga::detail::setEnumData( - flags, nodeType_, nodeType); + return facebook::yoga::detail::setEnumData(flags, nodeType_, + nodeType); } void setMeasureFunc(YGMeasureFunc measureFunc); @@ -275,8 +267,8 @@ public: void setLineIndex(uint32_t lineIndex) { lineIndex_ = lineIndex; } void setIsReferenceBaseline(bool isReferenceBaseline) { - facebook::yoga::detail::setBooleanData( - flags, isReferenceBaseline_, isReferenceBaseline); + facebook::yoga::detail::setBooleanData(flags, isReferenceBaseline_, + isReferenceBaseline); } void setOwner(YGNodeRef owner) { owner_ = owner; } @@ -300,11 +292,8 @@ public: void setLayoutBorder(float border, int index); void setLayoutPadding(float padding, int index); void setLayoutPosition(float position, int index); - void setPosition( - const YGDirection direction, - const float mainSize, - const float crossSize, - const float ownerWidth); + void setPosition(const YGDirection direction, const float mainSize, + const float crossSize, const float ownerWidth); void setLayoutDoesLegacyFlagAffectsLayout(bool doesLegacyFlagAffectsLayout); void setLayoutDidUseLegacyFlag(bool didUseLegacyFlag); void markDirtyAndPropogateDownwards(); diff --git a/src/cpp/include/deps/yoga/YGNodePrint.cpp b/src/cpp/include/deps/yoga/YGNodePrint.cpp index 26efa4858..a894271be 100644 --- a/src/cpp/include/deps/yoga/YGNodePrint.cpp +++ b/src/cpp/include/deps/yoga/YGNodePrint.cpp @@ -7,11 +7,13 @@ #ifdef DEBUG #include "YGNodePrint.h" + #include + +#include "Utils.h" #include "YGEnums.h" #include "YGNode.h" #include "Yoga-internal.h" -#include "Utils.h" namespace facebook { namespace yoga { @@ -25,7 +27,7 @@ static void indent(string& base, uint32_t level) { static bool areFourValuesEqual(const YGStyle::Edges& four) { return YGValueEqual(four[0], four[1]) && YGValueEqual(four[0], four[2]) && - YGValueEqual(four[0], four[3]); + YGValueEqual(four[0], four[3]); } static void appendFormatedString(string& str, const char* fmt, ...) { @@ -41,43 +43,35 @@ static void appendFormatedString(string& str, const char* fmt, ...) { str.append(result); } -static void appendFloatOptionalIfDefined( - string& base, - const string key, - const YGFloatOptional num) { +static void appendFloatOptionalIfDefined(string& base, const string key, + const YGFloatOptional num) { if (!num.isUndefined()) { appendFormatedString(base, "%s: %g; ", key.c_str(), num.unwrap()); } } -static void appendNumberIfNotUndefined( - string& base, - const string key, - const YGValue number) { +static void appendNumberIfNotUndefined(string& base, const string key, + const YGValue number) { if (number.unit != YGUnitUndefined) { if (number.unit == YGUnitAuto) { base.append(key + ": auto; "); } else { string unit = number.unit == YGUnitPoint ? "px" : "%%"; - appendFormatedString( - base, "%s: %g%s; ", key.c_str(), number.value, unit.c_str()); + appendFormatedString(base, "%s: %g%s; ", key.c_str(), number.value, + unit.c_str()); } } } -static void appendNumberIfNotAuto( - string& base, - const string& key, - const YGValue number) { +static void appendNumberIfNotAuto(string& base, const string& key, + const YGValue number) { if (number.unit != YGUnitAuto) { appendNumberIfNotUndefined(base, key, number); } } -static void appendNumberIfNotZero( - string& base, - const string& str, - const YGValue number) { +static void appendNumberIfNotZero(string& base, const string& str, + const YGValue number) { if (number.unit == YGUnitAuto) { base.append(str + ": auto; "); } else if (!YGFloatsEqual(number.value, 0)) { @@ -85,10 +79,8 @@ static void appendNumberIfNotZero( } } -static void appendEdges( - string& base, - const string& key, - const YGStyle::Edges& edges) { +static void appendEdges(string& base, const string& key, + const YGStyle::Edges& edges) { if (areFourValuesEqual(edges)) { appendNumberIfNotZero(base, key, edges[YGEdgeLeft]); } else { @@ -99,35 +91,29 @@ static void appendEdges( } } -static void appendEdgeIfNotUndefined( - string& base, - const string& str, - const YGStyle::Edges& edges, - const YGEdge edge) { +static void appendEdgeIfNotUndefined(string& base, const string& str, + const YGStyle::Edges& edges, + const YGEdge edge) { appendNumberIfNotUndefined( - base, - str, + base, str, YGComputedEdgeValue(edges, edge, detail::CompactValue::ofUndefined())); } -void YGNodeToString( - std::string& str, - YGNodeRef node, - YGPrintOptions options, - uint32_t level) { +void YGNodeToString(std::string& str, YGNodeRef node, YGPrintOptions options, + uint32_t level) { indent(str, level); appendFormatedString(str, "
getLayout().dimensions[YGDimensionWidth]); - appendFormatedString( - str, "height: %g; ", node->getLayout().dimensions[YGDimensionHeight]); - appendFormatedString( - str, "top: %g; ", node->getLayout().position[YGEdgeTop]); - appendFormatedString( - str, "left: %g;", node->getLayout().position[YGEdgeLeft]); + appendFormatedString(str, "width: %g; ", + node->getLayout().dimensions[YGDimensionWidth]); + appendFormatedString(str, "height: %g; ", + node->getLayout().dimensions[YGDimensionHeight]); + appendFormatedString(str, "top: %g; ", + node->getLayout().position[YGEdgeTop]); + appendFormatedString(str, "left: %g;", + node->getLayout().position[YGEdgeLeft]); appendFormatedString(str, "\" "); } @@ -135,28 +121,24 @@ void YGNodeToString( appendFormatedString(str, "style=\""); const auto& style = node->getStyle(); if (style.flexDirection() != YGNode().getStyle().flexDirection()) { - appendFormatedString( - str, - "flex-direction: %s; ", - YGFlexDirectionToString(style.flexDirection())); + appendFormatedString(str, "flex-direction: %s; ", + YGFlexDirectionToString(style.flexDirection())); } if (style.justifyContent() != YGNode().getStyle().justifyContent()) { - appendFormatedString( - str, - "justify-content: %s; ", - YGJustifyToString(style.justifyContent())); + appendFormatedString(str, "justify-content: %s; ", + YGJustifyToString(style.justifyContent())); } if (style.alignItems() != YGNode().getStyle().alignItems()) { - appendFormatedString( - str, "align-items: %s; ", YGAlignToString(style.alignItems())); + appendFormatedString(str, "align-items: %s; ", + YGAlignToString(style.alignItems())); } if (style.alignContent() != YGNode().getStyle().alignContent()) { - appendFormatedString( - str, "align-content: %s; ", YGAlignToString(style.alignContent())); + appendFormatedString(str, "align-content: %s; ", + YGAlignToString(style.alignContent())); } if (style.alignSelf() != YGNode().getStyle().alignSelf()) { - appendFormatedString( - str, "align-self: %s; ", YGAlignToString(style.alignSelf())); + appendFormatedString(str, "align-self: %s; ", + YGAlignToString(style.alignSelf())); } appendFloatOptionalIfDefined(str, "flex-grow", style.flexGrow()); appendFloatOptionalIfDefined(str, "flex-shrink", style.flexShrink()); @@ -164,18 +146,18 @@ void YGNodeToString( appendFloatOptionalIfDefined(str, "flex", style.flex()); if (style.flexWrap() != YGNode().getStyle().flexWrap()) { - appendFormatedString( - str, "flex-wrap: %s; ", YGWrapToString(style.flexWrap())); + appendFormatedString(str, "flex-wrap: %s; ", + YGWrapToString(style.flexWrap())); } if (style.overflow() != YGNode().getStyle().overflow()) { - appendFormatedString( - str, "overflow: %s; ", YGOverflowToString(style.overflow())); + appendFormatedString(str, "overflow: %s; ", + YGOverflowToString(style.overflow())); } if (style.display() != YGNode().getStyle().display()) { - appendFormatedString( - str, "display: %s; ", YGDisplayToString(style.display())); + appendFormatedString(str, "display: %s; ", + YGDisplayToString(style.display())); } appendEdges(str, "margin", style.margin()); appendEdges(str, "padding", style.padding()); @@ -183,18 +165,18 @@ void YGNodeToString( appendNumberIfNotAuto(str, "width", style.dimensions()[YGDimensionWidth]); appendNumberIfNotAuto(str, "height", style.dimensions()[YGDimensionHeight]); - appendNumberIfNotAuto( - str, "max-width", style.maxDimensions()[YGDimensionWidth]); - appendNumberIfNotAuto( - str, "max-height", style.maxDimensions()[YGDimensionHeight]); - appendNumberIfNotAuto( - str, "min-width", style.minDimensions()[YGDimensionWidth]); - appendNumberIfNotAuto( - str, "min-height", style.minDimensions()[YGDimensionHeight]); + appendNumberIfNotAuto(str, "max-width", + style.maxDimensions()[YGDimensionWidth]); + appendNumberIfNotAuto(str, "max-height", + style.maxDimensions()[YGDimensionHeight]); + appendNumberIfNotAuto(str, "min-width", + style.minDimensions()[YGDimensionWidth]); + appendNumberIfNotAuto(str, "min-height", + style.minDimensions()[YGDimensionHeight]); if (style.positionType() != YGNode().getStyle().positionType()) { - appendFormatedString( - str, "position: %s; ", YGPositionTypeToString(style.positionType())); + appendFormatedString(str, "position: %s; ", + YGPositionTypeToString(style.positionType())); } appendEdgeIfNotUndefined(str, "left", style.position(), YGEdgeLeft); @@ -220,6 +202,6 @@ void YGNodeToString( } appendFormatedString(str, "
"); } -} // namespace yoga -} // namespace facebook +} // namespace yoga +} // namespace facebook #endif diff --git a/src/cpp/include/deps/yoga/YGNodePrint.h b/src/cpp/include/deps/yoga/YGNodePrint.h index 3db504b46..4f1d96351 100644 --- a/src/cpp/include/deps/yoga/YGNodePrint.h +++ b/src/cpp/include/deps/yoga/YGNodePrint.h @@ -14,12 +14,9 @@ namespace facebook { namespace yoga { -void YGNodeToString( - std::string& str, - YGNodeRef node, - YGPrintOptions options, - uint32_t level); +void YGNodeToString(std::string& str, YGNodeRef node, YGPrintOptions options, + uint32_t level); -} // namespace yoga -} // namespace facebook +} // namespace yoga +} // namespace facebook #endif diff --git a/src/cpp/include/deps/yoga/YGStyle.cpp b/src/cpp/include/deps/yoga/YGStyle.cpp index e8033bdf4..b53f7ed82 100644 --- a/src/cpp/include/deps/yoga/YGStyle.cpp +++ b/src/cpp/include/deps/yoga/YGStyle.cpp @@ -6,11 +6,13 @@ */ #include "YGStyle.h" + #include "Utils.h" // Yoga specific properties, not compatible with flexbox specification bool operator==(const YGStyle& lhs, const YGStyle& rhs) { - bool areNonFloatValuesEqual = lhs.direction() == rhs.direction() && + bool areNonFloatValuesEqual = + lhs.direction() == rhs.direction() && lhs.flexDirection() == rhs.flexDirection() && lhs.justifyContent() == rhs.justifyContent() && lhs.alignContent() == rhs.alignContent() && @@ -27,20 +29,22 @@ bool operator==(const YGStyle& lhs, const YGStyle& rhs) { lhs.maxDimensions() == rhs.maxDimensions(); areNonFloatValuesEqual = areNonFloatValuesEqual && - lhs.flex().isUndefined() == rhs.flex().isUndefined(); + lhs.flex().isUndefined() == rhs.flex().isUndefined(); if (areNonFloatValuesEqual && !lhs.flex().isUndefined() && !rhs.flex().isUndefined()) { areNonFloatValuesEqual = areNonFloatValuesEqual && lhs.flex() == rhs.flex(); } - areNonFloatValuesEqual = areNonFloatValuesEqual && + areNonFloatValuesEqual = + areNonFloatValuesEqual && lhs.flexGrow().isUndefined() == rhs.flexGrow().isUndefined(); if (areNonFloatValuesEqual && !lhs.flexGrow().isUndefined()) { areNonFloatValuesEqual = areNonFloatValuesEqual && lhs.flexGrow() == rhs.flexGrow(); } - areNonFloatValuesEqual = areNonFloatValuesEqual && + areNonFloatValuesEqual = + areNonFloatValuesEqual && lhs.flexShrink().isUndefined() == rhs.flexShrink().isUndefined(); if (areNonFloatValuesEqual && !rhs.flexShrink().isUndefined()) { areNonFloatValuesEqual = diff --git a/src/cpp/include/deps/yoga/YGStyle.h b/src/cpp/include/deps/yoga/YGStyle.h index aab7599cc..0c489c517 100644 --- a/src/cpp/include/deps/yoga/YGStyle.h +++ b/src/cpp/include/deps/yoga/YGStyle.h @@ -13,12 +13,13 @@ #include #include #include + +#include "BitUtils.h" #include "CompactValue.h" #include "YGEnums.h" #include "YGFloatOptional.h" #include "Yoga-internal.h" #include "Yoga.h" -#include "BitUtils.h" class YOGA_EXPORT YGStyle { template @@ -26,7 +27,7 @@ class YOGA_EXPORT YGStyle { facebook::yoga::detail::Values()>; using CompactValue = facebook::yoga::detail::CompactValue; -public: + public: using Dimensions = Values; using Edges = Values; @@ -71,7 +72,7 @@ public: style.*Prop = values; return *this; } - operator const Values&() const { return style.*Prop; } + operator const Values &() const { return style.*Prop; } Ref operator[](Idx idx) { return {style, idx}; } CompactValue operator[](Idx idx) const { return (style.*Prop)[idx]; } }; @@ -82,11 +83,12 @@ public: } ~YGStyle() = default; -private: + private: static constexpr size_t directionOffset = 0; static constexpr size_t flexdirectionOffset = directionOffset + facebook::yoga::detail::bitWidthFn(); - static constexpr size_t justifyContentOffset = flexdirectionOffset + + static constexpr size_t justifyContentOffset = + flexdirectionOffset + facebook::yoga::detail::bitWidthFn(); static constexpr size_t alignContentOffset = justifyContentOffset + facebook::yoga::detail::bitWidthFn(); @@ -119,13 +121,13 @@ private: // Yoga specific properties, not compatible with flexbox specification YGFloatOptional aspectRatio_ = {}; -public: + public: // for library users needing a type using ValueRepr = std::remove_reference::type; YGDirection direction() const { - return facebook::yoga::detail::getEnumData( - flags, directionOffset); + return facebook::yoga::detail::getEnumData(flags, + directionOffset); } BitfieldRef direction() { return {*this, directionOffset}; } @@ -138,22 +140,22 @@ public: } YGJustify justifyContent() const { - return facebook::yoga::detail::getEnumData( - flags, justifyContentOffset); + return facebook::yoga::detail::getEnumData(flags, + justifyContentOffset); } BitfieldRef justifyContent() { return {*this, justifyContentOffset}; } YGAlign alignContent() const { - return facebook::yoga::detail::getEnumData( - flags, alignContentOffset); + return facebook::yoga::detail::getEnumData(flags, + alignContentOffset); } BitfieldRef alignContent() { return {*this, alignContentOffset}; } YGAlign alignItems() const { - return facebook::yoga::detail::getEnumData( - flags, alignItemsOffset); + return facebook::yoga::detail::getEnumData(flags, + alignItemsOffset); } BitfieldRef alignItems() { return {*this, alignItemsOffset}; } @@ -176,8 +178,8 @@ public: BitfieldRef flexWrap() { return {*this, flexWrapOffset}; } YGOverflow overflow() const { - return facebook::yoga::detail::getEnumData( - flags, overflowOffset); + return facebook::yoga::detail::getEnumData(flags, + overflowOffset); } BitfieldRef overflow() { return {*this, overflowOffset}; } diff --git a/src/cpp/include/deps/yoga/YGValue.h b/src/cpp/include/deps/yoga/YGValue.h index a20009784..9468c7a4a 100644 --- a/src/cpp/include/deps/yoga/YGValue.h +++ b/src/cpp/include/deps/yoga/YGValue.h @@ -8,6 +8,7 @@ #pragma once #include + #include "YGEnums.h" #include "YGMacros.h" @@ -23,7 +24,7 @@ YG_EXTERN_C_BEGIN // Not defined in MSVC++ #ifndef NAN static const uint32_t __nan = 0x7fc00000; -#define NAN (*(const float*) __nan) +#define NAN (*(const float*)__nan) #endif #define YGUndefined NAN @@ -88,8 +89,8 @@ inline YGValue operator"" _percent(unsigned long long value) { return operator"" _percent(static_cast(value)); } -} // namespace literals -} // namespace yoga -} // namespace facebook +} // namespace literals +} // namespace yoga +} // namespace facebook #endif diff --git a/src/cpp/include/deps/yoga/Yoga-internal.h b/src/cpp/include/deps/yoga/Yoga-internal.h index 1a22f24c9..2560e327e 100644 --- a/src/cpp/include/deps/yoga/Yoga-internal.h +++ b/src/cpp/include/deps/yoga/Yoga-internal.h @@ -10,6 +10,7 @@ #include #include #include + #include "CompactValue.h" #include "Yoga.h" @@ -17,24 +18,20 @@ using YGVector = std::vector; YG_EXTERN_C_BEGIN -void YGNodeCalculateLayoutWithContext( - YGNodeRef node, - float availableWidth, - float availableHeight, - YGDirection ownerDirection, - void* layoutContext); +void YGNodeCalculateLayoutWithContext(YGNodeRef node, float availableWidth, + float availableHeight, + YGDirection ownerDirection, + void* layoutContext); YG_EXTERN_C_END namespace facebook { namespace yoga { -inline bool isUndefined(float value) { - return std::isnan(value); -} +inline bool isUndefined(float value) { return std::isnan(value); } -} // namespace yoga -} // namespace facebook +} // namespace yoga +} // namespace facebook using namespace facebook; @@ -63,7 +60,7 @@ struct YGCachedMeasurement { bool operator==(YGCachedMeasurement measurement) const { bool isEqual = widthMeasureMode == measurement.widthMeasureMode && - heightMeasureMode == measurement.heightMeasureMode; + heightMeasureMode == measurement.heightMeasureMode; if (!yoga::isUndefined(availableWidth) || !yoga::isUndefined(measurement.availableWidth)) { @@ -96,10 +93,10 @@ namespace detail { template class Values { -private: + private: std::array values_; -public: + public: Values() = default; explicit Values(const YGValue& defaultValue) noexcept { values_.fill(defaultValue); @@ -135,9 +132,9 @@ public: Values& operator=(const Values& other) = default; }; -} // namespace detail -} // namespace yoga -} // namespace facebook +} // namespace detail +} // namespace yoga +} // namespace facebook static const float kDefaultFlexGrow = 0.0f; static const float kDefaultFlexShrink = 0.0f; @@ -147,5 +144,4 @@ extern bool YGFloatsEqual(const float a, const float b); extern facebook::yoga::detail::CompactValue YGComputedEdgeValue( const facebook::yoga::detail::Values< facebook::yoga::enums::count()>& edges, - YGEdge edge, - facebook::yoga::detail::CompactValue defaultValue); + YGEdge edge, facebook::yoga::detail::CompactValue defaultValue); diff --git a/src/cpp/include/deps/yoga/Yoga.cpp b/src/cpp/include/deps/yoga/Yoga.cpp index 2db6be21d..968a125e5 100644 --- a/src/cpp/include/deps/yoga/Yoga.cpp +++ b/src/cpp/include/deps/yoga/Yoga.cpp @@ -6,17 +6,20 @@ */ #include "Yoga.h" -#include "log.h" + #include #include + #include #include #include + #include "Utils.h" #include "YGNode.h" #include "YGNodePrint.h" #include "Yoga-internal.h" #include "event/event.h" +#include "log.h" #ifdef _MSC_VER #include @@ -32,29 +35,17 @@ using namespace facebook::yoga; using detail::Log; #ifdef ANDROID -static int YGAndroidLog( - const YGConfigRef config, - const YGNodeRef node, - YGLogLevel level, - const char* format, - va_list args); +static int YGAndroidLog(const YGConfigRef config, const YGNodeRef node, + YGLogLevel level, const char* format, va_list args); #else -static int YGDefaultLog( - const YGConfigRef config, - const YGNodeRef node, - YGLogLevel level, - const char* format, - va_list args); +static int YGDefaultLog(const YGConfigRef config, const YGNodeRef node, + YGLogLevel level, const char* format, va_list args); #endif #ifdef ANDROID #include -static int YGAndroidLog( - const YGConfigRef config, - const YGNodeRef node, - YGLogLevel level, - const char* format, - va_list args) { +static int YGAndroidLog(const YGConfigRef config, const YGNodeRef node, + YGLogLevel level, const char* format, va_list args) { int androidLevel = YGLogLevelDebug; switch (level) { case YGLogLevelFatal: @@ -80,14 +71,10 @@ static int YGAndroidLog( return result; } #else -#define YG_UNUSED(x) (void) (x); +#define YG_UNUSED(x) (void)(x); -static int YGDefaultLog( - const YGConfigRef config, - const YGNodeRef node, - YGLogLevel level, - const char* format, - va_list args) { +static int YGDefaultLog(const YGConfigRef config, const YGNodeRef node, + YGLogLevel level, const char* format, va_list args) { YG_UNUSED(config); YG_UNUSED(node); switch (level) { @@ -110,10 +97,9 @@ YOGA_EXPORT bool YGFloatIsUndefined(const float value) { return facebook::yoga::isUndefined(value); } -detail::CompactValue YGComputedEdgeValue( - const YGStyle::Edges& edges, - YGEdge edge, - detail::CompactValue defaultValue) { +detail::CompactValue YGComputedEdgeValue(const YGStyle::Edges& edges, + YGEdge edge, + detail::CompactValue defaultValue) { if (!edges[edge].isUndefined()) { return edges[edge]; } @@ -152,9 +138,8 @@ YOGA_EXPORT bool YGNodeHasMeasureFunc(YGNodeRef node) { return node->hasMeasureFunc(); } -YOGA_EXPORT void YGNodeSetMeasureFunc( - YGNodeRef node, - YGMeasureFunc measureFunc) { +YOGA_EXPORT void YGNodeSetMeasureFunc(YGNodeRef node, + YGMeasureFunc measureFunc) { node->setMeasureFunc(measureFunc); } @@ -162,9 +147,8 @@ YOGA_EXPORT bool YGNodeHasBaselineFunc(YGNodeRef node) { return node->hasBaselineFunc(); } -YOGA_EXPORT void YGNodeSetBaselineFunc( - YGNodeRef node, - YGBaselineFunc baselineFunc) { +YOGA_EXPORT void YGNodeSetBaselineFunc(YGNodeRef node, + YGBaselineFunc baselineFunc) { node->setBaselineFunc(baselineFunc); } @@ -172,9 +156,8 @@ YOGA_EXPORT YGDirtiedFunc YGNodeGetDirtiedFunc(YGNodeRef node) { return node->getDirtied(); } -YOGA_EXPORT void YGNodeSetDirtiedFunc( - YGNodeRef node, - YGDirtiedFunc dirtiedFunc) { +YOGA_EXPORT void YGNodeSetDirtiedFunc(YGNodeRef node, + YGDirtiedFunc dirtiedFunc) { node->setDirtiedFunc(dirtiedFunc); } @@ -202,9 +185,7 @@ YOGA_EXPORT void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType) { return node->setNodeType(nodeType); } -YOGA_EXPORT bool YGNodeIsDirty(YGNodeRef node) { - return node->isDirty(); -} +YOGA_EXPORT bool YGNodeIsDirty(YGNodeRef node) { return node->isDirty(); } YOGA_EXPORT bool YGNodeLayoutGetDidUseLegacyFlag(const YGNodeRef node) { return node->didUseLegacyFlag(); @@ -219,8 +200,8 @@ int32_t gConfigInstanceCount = 0; YOGA_EXPORT WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config) { const YGNodeRef node = new YGNode{config}; - YGAssertWithConfig( - config, node != nullptr, "Could not allocate memory for node"); + YGAssertWithConfig(config, node != nullptr, + "Could not allocate memory for node"); Event::publish(node, {config}); return node; @@ -237,10 +218,8 @@ YOGA_EXPORT YGNodeRef YGNodeNew(void) { YOGA_EXPORT YGNodeRef YGNodeClone(YGNodeRef oldNode) { YGNodeRef node = new YGNode(*oldNode); - YGAssertWithConfig( - oldNode->getConfig(), - node != nullptr, - "Could not allocate memory for node"); + YGAssertWithConfig(oldNode->getConfig(), node != nullptr, + "Could not allocate memory for node"); Event::publish(node, {node->getConfig()}); node->setOwner(nullptr); return node; @@ -300,9 +279,8 @@ static void YGConfigFreeRecursive(const YGNodeRef root) { } } -YOGA_EXPORT void YGNodeFreeRecursiveWithCleanupFunc( - const YGNodeRef root, - YGNodeCleanupFunc cleanup) { +YOGA_EXPORT void YGNodeFreeRecursiveWithCleanupFunc(const YGNodeRef root, + YGNodeCleanupFunc cleanup) { uint32_t skipped = 0; while (YGNodeGetChildCount(root) > skipped) { const YGNodeRef child = YGNodeGetChild(root, skipped); @@ -324,13 +302,9 @@ YOGA_EXPORT void YGNodeFreeRecursive(const YGNodeRef root) { return YGNodeFreeRecursiveWithCleanupFunc(root, nullptr); } -YOGA_EXPORT void YGNodeReset(YGNodeRef node) { - node->reset(); -} +YOGA_EXPORT void YGNodeReset(YGNodeRef node) { node->reset(); } -int32_t YGConfigGetInstanceCount(void) { - return gConfigInstanceCount; -} +int32_t YGConfigGetInstanceCount(void) { return gConfigInstanceCount; } YOGA_EXPORT YGConfigRef YGConfigNew(void) { #ifdef ANDROID @@ -351,9 +325,8 @@ void YGConfigCopy(const YGConfigRef dest, const YGConfigRef src) { memcpy(dest, src, sizeof(YGConfig)); } -YOGA_EXPORT void YGNodeSetIsReferenceBaseline( - YGNodeRef node, - bool isReferenceBaseline) { +YOGA_EXPORT void YGNodeSetIsReferenceBaseline(YGNodeRef node, + bool isReferenceBaseline) { if (node->isReferenceBaseline() != isReferenceBaseline) { node->setIsReferenceBaseline(isReferenceBaseline); node->markDirtyAndPropogate(); @@ -364,18 +337,13 @@ YOGA_EXPORT bool YGNodeIsReferenceBaseline(YGNodeRef node) { return node->isReferenceBaseline(); } -YOGA_EXPORT void YGNodeInsertChild( - const YGNodeRef owner, - const YGNodeRef child, - const uint32_t index) { - YGAssertWithNode( - owner, - child->getOwner() == nullptr, - "Child already has a owner, it must be removed first."); +YOGA_EXPORT void YGNodeInsertChild(const YGNodeRef owner, const YGNodeRef child, + const uint32_t index) { + YGAssertWithNode(owner, child->getOwner() == nullptr, + "Child already has a owner, it must be removed first."); YGAssertWithNode( - owner, - !owner->hasMeasureFunc(), + owner, !owner->hasMeasureFunc(), "Cannot add child: Nodes with measure functions cannot have children."); owner->insertChild(child, index); @@ -383,17 +351,14 @@ YOGA_EXPORT void YGNodeInsertChild( owner->markDirtyAndPropogate(); } -YOGA_EXPORT void YGNodeSwapChild( - const YGNodeRef owner, - const YGNodeRef child, - const uint32_t index) { +YOGA_EXPORT void YGNodeSwapChild(const YGNodeRef owner, const YGNodeRef child, + const uint32_t index) { owner->replaceChild(child, index); child->setOwner(owner); } -YOGA_EXPORT void YGNodeRemoveChild( - const YGNodeRef owner, - const YGNodeRef excludedChild) { +YOGA_EXPORT void YGNodeRemoveChild(const YGNodeRef owner, + const YGNodeRef excludedChild) { if (YGNodeGetChildCount(owner) == 0) { // This is an empty set. Nothing to remove. return; @@ -405,7 +370,7 @@ YOGA_EXPORT void YGNodeRemoveChild( auto childOwner = excludedChild->getOwner(); if (owner->removeChild(excludedChild)) { if (owner == childOwner) { - excludedChild->setLayout({}); // layout is no longer valid + excludedChild->setLayout({}); // layout is no longer valid excludedChild->setOwner(nullptr); } owner->markDirtyAndPropogate(); @@ -424,7 +389,7 @@ YOGA_EXPORT void YGNodeRemoveAllChildren(const YGNodeRef owner) { // set is unique. for (uint32_t i = 0; i < childCount; i++) { const YGNodeRef oldChild = YGNodeGetChild(owner, i); - oldChild->setLayout(YGNode().getLayout()); // layout is no longer valid + oldChild->setLayout(YGNode().getLayout()); // layout is no longer valid oldChild->setOwner(nullptr); } owner->clearChildren(); @@ -437,9 +402,8 @@ YOGA_EXPORT void YGNodeRemoveAllChildren(const YGNodeRef owner) { owner->markDirtyAndPropogate(); } -static void YGNodeSetChildrenInternal( - YGNodeRef const owner, - const std::vector& children) { +static void YGNodeSetChildrenInternal(YGNodeRef const owner, + const std::vector& children) { if (!owner) { return; } @@ -472,22 +436,19 @@ static void YGNodeSetChildrenInternal( } } -YOGA_EXPORT void YGNodeSetChildren( - const YGNodeRef owner, - const YGNodeRef c[], - const uint32_t count) { +YOGA_EXPORT void YGNodeSetChildren(const YGNodeRef owner, const YGNodeRef c[], + const uint32_t count) { const YGVector children = {c, c + count}; YGNodeSetChildrenInternal(owner, children); } -YOGA_EXPORT void YGNodeSetChildren( - YGNodeRef const owner, - const std::vector& children) { +YOGA_EXPORT void YGNodeSetChildren(YGNodeRef const owner, + const std::vector& children) { YGNodeSetChildrenInternal(owner, children); } -YOGA_EXPORT YGNodeRef -YGNodeGetChild(const YGNodeRef node, const uint32_t index) { +YOGA_EXPORT YGNodeRef YGNodeGetChild(const YGNodeRef node, + const uint32_t index) { if (index < node->getChildren().size()) { return node->getChild(index); } @@ -507,18 +468,15 @@ YOGA_EXPORT YGNodeRef YGNodeGetParent(const YGNodeRef node) { } YOGA_EXPORT void YGNodeMarkDirty(const YGNodeRef node) { - YGAssertWithNode( - node, - node->hasMeasureFunc(), - "Only leaf nodes with custom measure functions" - "should manually mark themselves as dirty"); + YGAssertWithNode(node, node->hasMeasureFunc(), + "Only leaf nodes with custom measure functions" + "should manually mark themselves as dirty"); node->markDirtyAndPropogate(); } -YOGA_EXPORT void YGNodeCopyStyle( - const YGNodeRef dstNode, - const YGNodeRef srcNode) { +YOGA_EXPORT void YGNodeCopyStyle(const YGNodeRef dstNode, + const YGNodeRef srcNode) { if (!(dstNode->getStyle() == srcNode->getStyle())) { dstNode->setStyle(srcNode->getStyle()); dstNode->markDirtyAndPropogate(); @@ -527,25 +485,22 @@ YOGA_EXPORT void YGNodeCopyStyle( YOGA_EXPORT float YGNodeStyleGetFlexGrow(const YGNodeConstRef node) { return node->getStyle().flexGrow().isUndefined() - ? kDefaultFlexGrow - : node->getStyle().flexGrow().unwrap(); + ? kDefaultFlexGrow + : node->getStyle().flexGrow().unwrap(); } YOGA_EXPORT float YGNodeStyleGetFlexShrink(const YGNodeConstRef node) { return node->getStyle().flexShrink().isUndefined() - ? (node->getConfig()->useWebDefaults ? kWebDefaultFlexShrink - : kDefaultFlexShrink) - : node->getStyle().flexShrink().unwrap(); + ? (node->getConfig()->useWebDefaults ? kWebDefaultFlexShrink + : kDefaultFlexShrink) + : node->getStyle().flexShrink().unwrap(); } namespace { template -void updateStyle( - YGNode* node, - T value, - NeedsUpdate&& needsUpdate, - Update&& update) { +void updateStyle(YGNode* node, T value, NeedsUpdate&& needsUpdate, + Update&& update) { if (needsUpdate(node->getStyle(), value)) { update(node->getStyle(), value); node->markDirtyAndPropogate(); @@ -555,27 +510,21 @@ void updateStyle( template void updateStyle(YGNode* node, Ref (YGStyle::*prop)(), T value) { updateStyle( - node, - value, - [prop](YGStyle& s, T x) { return (s.*prop)() != x; }, + node, value, [prop](YGStyle& s, T x) { return (s.*prop)() != x; }, [prop](YGStyle& s, T x) { (s.*prop)() = x; }); } template -void updateIndexedStyleProp( - YGNode* node, - Ref (YGStyle::*prop)(), - Idx idx, - detail::CompactValue value) { +void updateIndexedStyleProp(YGNode* node, Ref (YGStyle::*prop)(), Idx idx, + detail::CompactValue value) { using detail::CompactValue; updateStyle( - node, - value, + node, value, [idx, prop](YGStyle& s, CompactValue x) { return (s.*prop)()[idx] != x; }, [idx, prop](YGStyle& s, CompactValue x) { (s.*prop)()[idx] = x; }); } -} // namespace +} // namespace // MSVC has trouble inferring the return type of pointer to member functions // with const and non-const overloads, instead of preferring the non-const @@ -584,9 +533,8 @@ void updateIndexedStyleProp( // decltype, MSVC will prefer the non-const version. #define MSVC_HINT(PROP) decltype(YGStyle{}.PROP()) -YOGA_EXPORT void YGNodeStyleSetDirection( - const YGNodeRef node, - const YGDirection value) { +YOGA_EXPORT void YGNodeStyleSetDirection(const YGNodeRef node, + const YGDirection value) { updateStyle(node, &YGStyle::direction, value); } YOGA_EXPORT YGDirection YGNodeStyleGetDirection(const YGNodeConstRef node) { @@ -594,86 +542,77 @@ YOGA_EXPORT YGDirection YGNodeStyleGetDirection(const YGNodeConstRef node) { } YOGA_EXPORT void YGNodeStyleSetFlexDirection( - const YGNodeRef node, - const YGFlexDirection flexDirection) { - updateStyle( - node, &YGStyle::flexDirection, flexDirection); + const YGNodeRef node, const YGFlexDirection flexDirection) { + updateStyle(node, &YGStyle::flexDirection, + flexDirection); } YOGA_EXPORT YGFlexDirection YGNodeStyleGetFlexDirection(const YGNodeConstRef node) { return node->getStyle().flexDirection(); } -YOGA_EXPORT void YGNodeStyleSetJustifyContent( - const YGNodeRef node, - const YGJustify justifyContent) { - updateStyle( - node, &YGStyle::justifyContent, justifyContent); +YOGA_EXPORT void YGNodeStyleSetJustifyContent(const YGNodeRef node, + const YGJustify justifyContent) { + updateStyle(node, &YGStyle::justifyContent, + justifyContent); } YOGA_EXPORT YGJustify YGNodeStyleGetJustifyContent(const YGNodeConstRef node) { return node->getStyle().justifyContent(); } -YOGA_EXPORT void YGNodeStyleSetAlignContent( - const YGNodeRef node, - const YGAlign alignContent) { - updateStyle( - node, &YGStyle::alignContent, alignContent); +YOGA_EXPORT void YGNodeStyleSetAlignContent(const YGNodeRef node, + const YGAlign alignContent) { + updateStyle(node, &YGStyle::alignContent, + alignContent); } YOGA_EXPORT YGAlign YGNodeStyleGetAlignContent(const YGNodeConstRef node) { return node->getStyle().alignContent(); } -YOGA_EXPORT void YGNodeStyleSetAlignItems( - const YGNodeRef node, - const YGAlign alignItems) { +YOGA_EXPORT void YGNodeStyleSetAlignItems(const YGNodeRef node, + const YGAlign alignItems) { updateStyle(node, &YGStyle::alignItems, alignItems); } YOGA_EXPORT YGAlign YGNodeStyleGetAlignItems(const YGNodeConstRef node) { return node->getStyle().alignItems(); } -YOGA_EXPORT void YGNodeStyleSetAlignSelf( - const YGNodeRef node, - const YGAlign alignSelf) { +YOGA_EXPORT void YGNodeStyleSetAlignSelf(const YGNodeRef node, + const YGAlign alignSelf) { updateStyle(node, &YGStyle::alignSelf, alignSelf); } YOGA_EXPORT YGAlign YGNodeStyleGetAlignSelf(const YGNodeConstRef node) { return node->getStyle().alignSelf(); } -YOGA_EXPORT void YGNodeStyleSetPositionType( - const YGNodeRef node, - const YGPositionType positionType) { - updateStyle( - node, &YGStyle::positionType, positionType); +YOGA_EXPORT void YGNodeStyleSetPositionType(const YGNodeRef node, + const YGPositionType positionType) { + updateStyle(node, &YGStyle::positionType, + positionType); } YOGA_EXPORT YGPositionType YGNodeStyleGetPositionType(const YGNodeConstRef node) { return node->getStyle().positionType(); } -YOGA_EXPORT void YGNodeStyleSetFlexWrap( - const YGNodeRef node, - const YGWrap flexWrap) { +YOGA_EXPORT void YGNodeStyleSetFlexWrap(const YGNodeRef node, + const YGWrap flexWrap) { updateStyle(node, &YGStyle::flexWrap, flexWrap); } YOGA_EXPORT YGWrap YGNodeStyleGetFlexWrap(const YGNodeConstRef node) { return node->getStyle().flexWrap(); } -YOGA_EXPORT void YGNodeStyleSetOverflow( - const YGNodeRef node, - const YGOverflow overflow) { +YOGA_EXPORT void YGNodeStyleSetOverflow(const YGNodeRef node, + const YGOverflow overflow) { updateStyle(node, &YGStyle::overflow, overflow); } YOGA_EXPORT YGOverflow YGNodeStyleGetOverflow(const YGNodeConstRef node) { return node->getStyle().overflow(); } -YOGA_EXPORT void YGNodeStyleSetDisplay( - const YGNodeRef node, - const YGDisplay display) { +YOGA_EXPORT void YGNodeStyleSetDisplay(const YGNodeRef node, + const YGDisplay display) { updateStyle(node, &YGStyle::display, display); } YOGA_EXPORT YGDisplay YGNodeStyleGetDisplay(const YGNodeConstRef node) { @@ -688,24 +627,22 @@ YOGA_EXPORT void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) { // TODO(T26792433): Change the API to accept YGFloatOptional. YOGA_EXPORT float YGNodeStyleGetFlex(const YGNodeConstRef node) { return node->getStyle().flex().isUndefined() - ? YGUndefined - : node->getStyle().flex().unwrap(); + ? YGUndefined + : node->getStyle().flex().unwrap(); } // TODO(T26792433): Change the API to accept YGFloatOptional. -YOGA_EXPORT void YGNodeStyleSetFlexGrow( - const YGNodeRef node, - const float flexGrow) { - updateStyle( - node, &YGStyle::flexGrow, YGFloatOptional{flexGrow}); +YOGA_EXPORT void YGNodeStyleSetFlexGrow(const YGNodeRef node, + const float flexGrow) { + updateStyle(node, &YGStyle::flexGrow, + YGFloatOptional{flexGrow}); } // TODO(T26792433): Change the API to accept YGFloatOptional. -YOGA_EXPORT void YGNodeStyleSetFlexShrink( - const YGNodeRef node, - const float flexShrink) { - updateStyle( - node, &YGStyle::flexShrink, YGFloatOptional{flexShrink}); +YOGA_EXPORT void YGNodeStyleSetFlexShrink(const YGNodeRef node, + const float flexShrink) { + updateStyle(node, &YGStyle::flexShrink, + YGFloatOptional{flexShrink}); } YOGA_EXPORT YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) { @@ -717,102 +654,85 @@ YOGA_EXPORT YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) { return flexBasis; } -YOGA_EXPORT void YGNodeStyleSetFlexBasis( - const YGNodeRef node, - const float flexBasis) { +YOGA_EXPORT void YGNodeStyleSetFlexBasis(const YGNodeRef node, + const float flexBasis) { auto value = detail::CompactValue::ofMaybe(flexBasis); updateStyle(node, &YGStyle::flexBasis, value); } -YOGA_EXPORT void YGNodeStyleSetFlexBasisPercent( - const YGNodeRef node, - const float flexBasisPercent) { +YOGA_EXPORT void YGNodeStyleSetFlexBasisPercent(const YGNodeRef node, + const float flexBasisPercent) { auto value = detail::CompactValue::ofMaybe(flexBasisPercent); updateStyle(node, &YGStyle::flexBasis, value); } YOGA_EXPORT void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node) { - updateStyle( - node, &YGStyle::flexBasis, detail::CompactValue::ofAuto()); + updateStyle(node, &YGStyle::flexBasis, + detail::CompactValue::ofAuto()); } -YOGA_EXPORT void YGNodeStyleSetPosition( - YGNodeRef node, - YGEdge edge, - float points) { +YOGA_EXPORT void YGNodeStyleSetPosition(YGNodeRef node, YGEdge edge, + float points) { auto value = detail::CompactValue::ofMaybe(points); - updateIndexedStyleProp( - node, &YGStyle::position, edge, value); + updateIndexedStyleProp(node, &YGStyle::position, edge, + value); } -YOGA_EXPORT void YGNodeStyleSetPositionPercent( - YGNodeRef node, - YGEdge edge, - float percent) { +YOGA_EXPORT void YGNodeStyleSetPositionPercent(YGNodeRef node, YGEdge edge, + float percent) { auto value = detail::CompactValue::ofMaybe(percent); - updateIndexedStyleProp( - node, &YGStyle::position, edge, value); + updateIndexedStyleProp(node, &YGStyle::position, edge, + value); } YOGA_EXPORT YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) { return node->getStyle().position()[edge]; } -YOGA_EXPORT void YGNodeStyleSetMargin( - YGNodeRef node, - YGEdge edge, - float points) { +YOGA_EXPORT void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, + float points) { auto value = detail::CompactValue::ofMaybe(points); - updateIndexedStyleProp( - node, &YGStyle::margin, edge, value); + updateIndexedStyleProp(node, &YGStyle::margin, edge, + value); } -YOGA_EXPORT void YGNodeStyleSetMarginPercent( - YGNodeRef node, - YGEdge edge, - float percent) { +YOGA_EXPORT void YGNodeStyleSetMarginPercent(YGNodeRef node, YGEdge edge, + float percent) { auto value = detail::CompactValue::ofMaybe(percent); - updateIndexedStyleProp( - node, &YGStyle::margin, edge, value); + updateIndexedStyleProp(node, &YGStyle::margin, edge, + value); } YOGA_EXPORT void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge) { - updateIndexedStyleProp( - node, &YGStyle::margin, edge, detail::CompactValue::ofAuto()); + updateIndexedStyleProp(node, &YGStyle::margin, edge, + detail::CompactValue::ofAuto()); } YOGA_EXPORT YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) { return node->getStyle().margin()[edge]; } -YOGA_EXPORT void YGNodeStyleSetPadding( - YGNodeRef node, - YGEdge edge, - float points) { +YOGA_EXPORT void YGNodeStyleSetPadding(YGNodeRef node, YGEdge edge, + float points) { auto value = detail::CompactValue::ofMaybe(points); - updateIndexedStyleProp( - node, &YGStyle::padding, edge, value); + updateIndexedStyleProp(node, &YGStyle::padding, edge, + value); } -YOGA_EXPORT void YGNodeStyleSetPaddingPercent( - YGNodeRef node, - YGEdge edge, - float percent) { +YOGA_EXPORT void YGNodeStyleSetPaddingPercent(YGNodeRef node, YGEdge edge, + float percent) { auto value = detail::CompactValue::ofMaybe(percent); - updateIndexedStyleProp( - node, &YGStyle::padding, edge, value); + updateIndexedStyleProp(node, &YGStyle::padding, edge, + value); } YOGA_EXPORT YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge) { return node->getStyle().padding()[edge]; } // TODO(T26792433): Change the API to accept YGFloatOptional. -YOGA_EXPORT void YGNodeStyleSetBorder( - const YGNodeRef node, - const YGEdge edge, - const float border) { +YOGA_EXPORT void YGNodeStyleSetBorder(const YGNodeRef node, const YGEdge edge, + const float border) { auto value = detail::CompactValue::ofMaybe(border); - updateIndexedStyleProp( - node, &YGStyle::border, edge, value); + updateIndexedStyleProp(node, &YGStyle::border, edge, + value); } -YOGA_EXPORT float YGNodeStyleGetBorder( - const YGNodeConstRef node, - const YGEdge edge) { +YOGA_EXPORT float YGNodeStyleGetBorder(const YGNodeConstRef node, + const YGEdge edge) { auto border = node->getStyle().border()[edge]; if (border.isUndefined() || border.isAuto()) { // TODO(T26792433): Rather than returning YGUndefined, change the api to @@ -832,29 +752,26 @@ YOGA_EXPORT float YGNodeStyleGetAspectRatio(const YGNodeConstRef node) { } // TODO(T26792433): Change the API to accept YGFloatOptional. -YOGA_EXPORT void YGNodeStyleSetAspectRatio( - const YGNodeRef node, - const float aspectRatio) { - updateStyle( - node, &YGStyle::aspectRatio, YGFloatOptional{aspectRatio}); +YOGA_EXPORT void YGNodeStyleSetAspectRatio(const YGNodeRef node, + const float aspectRatio) { + updateStyle(node, &YGStyle::aspectRatio, + YGFloatOptional{aspectRatio}); } YOGA_EXPORT void YGNodeStyleSetWidth(YGNodeRef node, float points) { auto value = detail::CompactValue::ofMaybe(points); - updateIndexedStyleProp( - node, &YGStyle::dimensions, YGDimensionWidth, value); + updateIndexedStyleProp(node, &YGStyle::dimensions, + YGDimensionWidth, value); } YOGA_EXPORT void YGNodeStyleSetWidthPercent(YGNodeRef node, float percent) { auto value = detail::CompactValue::ofMaybe(percent); - updateIndexedStyleProp( - node, &YGStyle::dimensions, YGDimensionWidth, value); + updateIndexedStyleProp(node, &YGStyle::dimensions, + YGDimensionWidth, value); } YOGA_EXPORT void YGNodeStyleSetWidthAuto(YGNodeRef node) { - updateIndexedStyleProp( - node, - &YGStyle::dimensions, - YGDimensionWidth, - detail::CompactValue::ofAuto()); + updateIndexedStyleProp(node, &YGStyle::dimensions, + YGDimensionWidth, + detail::CompactValue::ofAuto()); } YOGA_EXPORT YGValue YGNodeStyleGetWidth(YGNodeConstRef node) { return node->getStyle().dimensions()[YGDimensionWidth]; @@ -862,35 +779,31 @@ YOGA_EXPORT YGValue YGNodeStyleGetWidth(YGNodeConstRef node) { YOGA_EXPORT void YGNodeStyleSetHeight(YGNodeRef node, float points) { auto value = detail::CompactValue::ofMaybe(points); - updateIndexedStyleProp( - node, &YGStyle::dimensions, YGDimensionHeight, value); + updateIndexedStyleProp(node, &YGStyle::dimensions, + YGDimensionHeight, value); } YOGA_EXPORT void YGNodeStyleSetHeightPercent(YGNodeRef node, float percent) { auto value = detail::CompactValue::ofMaybe(percent); - updateIndexedStyleProp( - node, &YGStyle::dimensions, YGDimensionHeight, value); + updateIndexedStyleProp(node, &YGStyle::dimensions, + YGDimensionHeight, value); } YOGA_EXPORT void YGNodeStyleSetHeightAuto(YGNodeRef node) { - updateIndexedStyleProp( - node, - &YGStyle::dimensions, - YGDimensionHeight, - detail::CompactValue::ofAuto()); + updateIndexedStyleProp(node, &YGStyle::dimensions, + YGDimensionHeight, + detail::CompactValue::ofAuto()); } YOGA_EXPORT YGValue YGNodeStyleGetHeight(YGNodeConstRef node) { return node->getStyle().dimensions()[YGDimensionHeight]; } -YOGA_EXPORT void YGNodeStyleSetMinWidth( - const YGNodeRef node, - const float minWidth) { +YOGA_EXPORT void YGNodeStyleSetMinWidth(const YGNodeRef node, + const float minWidth) { auto value = detail::CompactValue::ofMaybe(minWidth); updateIndexedStyleProp( node, &YGStyle::minDimensions, YGDimensionWidth, value); } -YOGA_EXPORT void YGNodeStyleSetMinWidthPercent( - const YGNodeRef node, - const float minWidth) { +YOGA_EXPORT void YGNodeStyleSetMinWidthPercent(const YGNodeRef node, + const float minWidth) { auto value = detail::CompactValue::ofMaybe(minWidth); updateIndexedStyleProp( node, &YGStyle::minDimensions, YGDimensionWidth, value); @@ -899,16 +812,14 @@ YOGA_EXPORT YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) { return node->getStyle().minDimensions()[YGDimensionWidth]; }; -YOGA_EXPORT void YGNodeStyleSetMinHeight( - const YGNodeRef node, - const float minHeight) { +YOGA_EXPORT void YGNodeStyleSetMinHeight(const YGNodeRef node, + const float minHeight) { auto value = detail::CompactValue::ofMaybe(minHeight); updateIndexedStyleProp( node, &YGStyle::minDimensions, YGDimensionHeight, value); } -YOGA_EXPORT void YGNodeStyleSetMinHeightPercent( - const YGNodeRef node, - const float minHeight) { +YOGA_EXPORT void YGNodeStyleSetMinHeightPercent(const YGNodeRef node, + const float minHeight) { auto value = detail::CompactValue::ofMaybe(minHeight); updateIndexedStyleProp( node, &YGStyle::minDimensions, YGDimensionHeight, value); @@ -917,16 +828,14 @@ YOGA_EXPORT YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) { return node->getStyle().minDimensions()[YGDimensionHeight]; }; -YOGA_EXPORT void YGNodeStyleSetMaxWidth( - const YGNodeRef node, - const float maxWidth) { +YOGA_EXPORT void YGNodeStyleSetMaxWidth(const YGNodeRef node, + const float maxWidth) { auto value = detail::CompactValue::ofMaybe(maxWidth); updateIndexedStyleProp( node, &YGStyle::maxDimensions, YGDimensionWidth, value); } -YOGA_EXPORT void YGNodeStyleSetMaxWidthPercent( - const YGNodeRef node, - const float maxWidth) { +YOGA_EXPORT void YGNodeStyleSetMaxWidthPercent(const YGNodeRef node, + const float maxWidth) { auto value = detail::CompactValue::ofMaybe(maxWidth); updateIndexedStyleProp( node, &YGStyle::maxDimensions, YGDimensionWidth, value); @@ -935,16 +844,14 @@ YOGA_EXPORT YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) { return node->getStyle().maxDimensions()[YGDimensionWidth]; }; -YOGA_EXPORT void YGNodeStyleSetMaxHeight( - const YGNodeRef node, - const float maxHeight) { +YOGA_EXPORT void YGNodeStyleSetMaxHeight(const YGNodeRef node, + const float maxHeight) { auto value = detail::CompactValue::ofMaybe(maxHeight); updateIndexedStyleProp( node, &YGStyle::maxDimensions, YGDimensionHeight, value); } -YOGA_EXPORT void YGNodeStyleSetMaxHeightPercent( - const YGNodeRef node, - const float maxHeight) { +YOGA_EXPORT void YGNodeStyleSetMaxHeightPercent(const YGNodeRef node, + const float maxHeight) { auto value = detail::CompactValue::ofMaybe(maxHeight); updateIndexedStyleProp( node, &YGStyle::maxDimensions, YGDimensionHeight, value); @@ -958,31 +865,29 @@ YOGA_EXPORT YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) { return node->getLayout().instanceName; \ } -#define YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(type, name, instanceName) \ - YOGA_EXPORT type YGNodeLayoutGet##name( \ - const YGNodeRef node, const YGEdge edge) { \ - YGAssertWithNode( \ - node, \ - edge <= YGEdgeEnd, \ - "Cannot get layout properties of multi-edge shorthands"); \ - \ - if (edge == YGEdgeStart) { \ - if (node->getLayout().direction() == YGDirectionRTL) { \ - return node->getLayout().instanceName[YGEdgeRight]; \ - } else { \ - return node->getLayout().instanceName[YGEdgeLeft]; \ - } \ - } \ - \ - if (edge == YGEdgeEnd) { \ - if (node->getLayout().direction() == YGDirectionRTL) { \ - return node->getLayout().instanceName[YGEdgeLeft]; \ - } else { \ - return node->getLayout().instanceName[YGEdgeRight]; \ - } \ - } \ - \ - return node->getLayout().instanceName[edge]; \ +#define YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(type, name, instanceName) \ + YOGA_EXPORT type YGNodeLayoutGet##name(const YGNodeRef node, \ + const YGEdge edge) { \ + YGAssertWithNode(node, edge <= YGEdgeEnd, \ + "Cannot get layout properties of multi-edge shorthands"); \ + \ + if (edge == YGEdgeStart) { \ + if (node->getLayout().direction() == YGDirectionRTL) { \ + return node->getLayout().instanceName[YGEdgeRight]; \ + } else { \ + return node->getLayout().instanceName[YGEdgeLeft]; \ + } \ + } \ + \ + if (edge == YGEdgeEnd) { \ + if (node->getLayout().direction() == YGDirectionRTL) { \ + return node->getLayout().instanceName[YGEdgeLeft]; \ + } else { \ + return node->getLayout().instanceName[YGEdgeRight]; \ + } \ + } \ + \ + return node->getLayout().instanceName[edge]; \ } YG_NODE_LAYOUT_PROPERTY_IMPL(float, Left, position[YGEdgeLeft]); @@ -1006,34 +911,24 @@ YOGA_EXPORT bool YGNodeLayoutGetDidLegacyStretchFlagAffectLayout( std::atomic gCurrentGenerationCount(0); bool YGLayoutNodeInternal( - const YGNodeRef node, - const float availableWidth, - const float availableHeight, - const YGDirection ownerDirection, - const YGMeasureMode widthMeasureMode, - const YGMeasureMode heightMeasureMode, - const float ownerWidth, - const float ownerHeight, - const bool performLayout, - const LayoutPassReason reason, - const YGConfigRef config, - LayoutData& layoutMarkerData, - void* const layoutContext, - const uint32_t depth, - const uint32_t generationCount); + const YGNodeRef node, const float availableWidth, + const float availableHeight, const YGDirection ownerDirection, + const YGMeasureMode widthMeasureMode, const YGMeasureMode heightMeasureMode, + const float ownerWidth, const float ownerHeight, const bool performLayout, + const LayoutPassReason reason, const YGConfigRef config, + LayoutData& layoutMarkerData, void* const layoutContext, + const uint32_t depth, const uint32_t generationCount); #ifdef DEBUG -static void YGNodePrintInternal( - const YGNodeRef node, - const YGPrintOptions options) { +static void YGNodePrintInternal(const YGNodeRef node, + const YGPrintOptions options) { std::string str; facebook::yoga::YGNodeToString(str, node, options, 0); Log::log(node, YGLogLevelDebug, nullptr, str.c_str()); } -YOGA_EXPORT void YGNodePrint( - const YGNodeRef node, - const YGPrintOptions options) { +YOGA_EXPORT void YGNodePrint(const YGNodeRef node, + const YGPrintOptions options) { YGNodePrintInternal(node, options); } #endif @@ -1053,10 +948,9 @@ static const std::array pos = {{ static const std::array dim = { {YGDimensionHeight, YGDimensionHeight, YGDimensionWidth, YGDimensionWidth}}; -static inline float YGNodePaddingAndBorderForAxis( - const YGNodeConstRef node, - const YGFlexDirection axis, - const float widthSize) { +static inline float YGNodePaddingAndBorderForAxis(const YGNodeConstRef node, + const YGFlexDirection axis, + const float widthSize) { return (node->getLeadingPaddingAndBorder(axis, widthSize) + node->getTrailingPaddingAndBorder(axis, widthSize)) .unwrap(); @@ -1064,8 +958,8 @@ static inline float YGNodePaddingAndBorderForAxis( static inline YGAlign YGNodeAlignItem(const YGNode* node, const YGNode* child) { const YGAlign align = child->getStyle().alignSelf() == YGAlignAuto - ? node->getStyle().alignItems() - : child->getStyle().alignSelf(); + ? node->getStyle().alignItems() + : child->getStyle().alignSelf(); if (align == YGAlignBaseline && YGFlexDirectionIsColumn(node->getStyle().flexDirection())) { return YGAlignFlexStart; @@ -1075,20 +969,16 @@ static inline YGAlign YGNodeAlignItem(const YGNode* node, const YGNode* child) { static float YGBaseline(const YGNodeRef node, void* layoutContext) { if (node->hasBaselineFunc()) { - Event::publish(node); const float baseline = node->baseline( node->getLayout().measuredDimensions[YGDimensionWidth], - node->getLayout().measuredDimensions[YGDimensionHeight], - layoutContext); + node->getLayout().measuredDimensions[YGDimensionHeight], layoutContext); Event::publish(node); - YGAssertWithNode( - node, - !YGFloatIsUndefined(baseline), - "Expect custom baseline function to not return NaN"); + YGAssertWithNode(node, !YGFloatIsUndefined(baseline), + "Expect custom baseline function to not return NaN"); return baseline; } @@ -1140,58 +1030,53 @@ static bool YGIsBaselineLayout(const YGNodeRef node) { return false; } -static inline float YGNodeDimWithMargin( - const YGNodeRef node, - const YGFlexDirection axis, - const float widthSize) { +static inline float YGNodeDimWithMargin(const YGNodeRef node, + const YGFlexDirection axis, + const float widthSize) { return node->getLayout().measuredDimensions[dim[axis]] + - (node->getLeadingMargin(axis, widthSize) + - node->getTrailingMargin(axis, widthSize)) - .unwrap(); + (node->getLeadingMargin(axis, widthSize) + + node->getTrailingMargin(axis, widthSize)) + .unwrap(); } -static inline bool YGNodeIsStyleDimDefined( - const YGNodeRef node, - const YGFlexDirection axis, - const float ownerSize) { +static inline bool YGNodeIsStyleDimDefined(const YGNodeRef node, + const YGFlexDirection axis, + const float ownerSize) { bool isUndefined = YGFloatIsUndefined(node->getResolvedDimension(dim[axis]).value); - return !( - node->getResolvedDimension(dim[axis]).unit == YGUnitAuto || - node->getResolvedDimension(dim[axis]).unit == YGUnitUndefined || - (node->getResolvedDimension(dim[axis]).unit == YGUnitPoint && - !isUndefined && node->getResolvedDimension(dim[axis]).value < 0.0f) || - (node->getResolvedDimension(dim[axis]).unit == YGUnitPercent && - !isUndefined && - (node->getResolvedDimension(dim[axis]).value < 0.0f || - YGFloatIsUndefined(ownerSize)))); + return !(node->getResolvedDimension(dim[axis]).unit == YGUnitAuto || + node->getResolvedDimension(dim[axis]).unit == YGUnitUndefined || + (node->getResolvedDimension(dim[axis]).unit == YGUnitPoint && + !isUndefined && + node->getResolvedDimension(dim[axis]).value < 0.0f) || + (node->getResolvedDimension(dim[axis]).unit == YGUnitPercent && + !isUndefined && + (node->getResolvedDimension(dim[axis]).value < 0.0f || + YGFloatIsUndefined(ownerSize)))); } -static inline bool YGNodeIsLayoutDimDefined( - const YGNodeRef node, - const YGFlexDirection axis) { +static inline bool YGNodeIsLayoutDimDefined(const YGNodeRef node, + const YGFlexDirection axis) { const float value = node->getLayout().measuredDimensions[dim[axis]]; return !YGFloatIsUndefined(value) && value >= 0.0f; } static YGFloatOptional YGNodeBoundAxisWithinMinAndMax( - const YGNodeConstRef node, - const YGFlexDirection axis, - const YGFloatOptional value, - const float axisSize) { + const YGNodeConstRef node, const YGFlexDirection axis, + const YGFloatOptional value, const float axisSize) { YGFloatOptional min; YGFloatOptional max; if (YGFlexDirectionIsColumn(axis)) { - min = YGResolveValue( - node->getStyle().minDimensions()[YGDimensionHeight], axisSize); - max = YGResolveValue( - node->getStyle().maxDimensions()[YGDimensionHeight], axisSize); + min = YGResolveValue(node->getStyle().minDimensions()[YGDimensionHeight], + axisSize); + max = YGResolveValue(node->getStyle().maxDimensions()[YGDimensionHeight], + axisSize); } else if (YGFlexDirectionIsRow(axis)) { - min = YGResolveValue( - node->getStyle().minDimensions()[YGDimensionWidth], axisSize); - max = YGResolveValue( - node->getStyle().maxDimensions()[YGDimensionWidth], axisSize); + min = YGResolveValue(node->getStyle().minDimensions()[YGDimensionWidth], + axisSize); + max = YGResolveValue(node->getStyle().maxDimensions()[YGDimensionWidth], + axisSize); } if (max >= YGFloatOptional{0} && value > max) { @@ -1207,47 +1092,40 @@ static YGFloatOptional YGNodeBoundAxisWithinMinAndMax( // Like YGNodeBoundAxisWithinMinAndMax but also ensures that the value doesn't // go below the padding and border amount. -static inline float YGNodeBoundAxis( - const YGNodeRef node, - const YGFlexDirection axis, - const float value, - const float axisSize, - const float widthSize) { - return YGFloatMax( - YGNodeBoundAxisWithinMinAndMax( - node, axis, YGFloatOptional{value}, axisSize) - .unwrap(), - YGNodePaddingAndBorderForAxis(node, axis, widthSize)); +static inline float YGNodeBoundAxis(const YGNodeRef node, + const YGFlexDirection axis, + const float value, const float axisSize, + const float widthSize) { + return YGFloatMax(YGNodeBoundAxisWithinMinAndMax( + node, axis, YGFloatOptional{value}, axisSize) + .unwrap(), + YGNodePaddingAndBorderForAxis(node, axis, widthSize)); } -static void YGNodeSetChildTrailingPosition( - const YGNodeRef node, - const YGNodeRef child, - const YGFlexDirection axis) { +static void YGNodeSetChildTrailingPosition(const YGNodeRef node, + const YGNodeRef child, + const YGFlexDirection axis) { const float size = child->getLayout().measuredDimensions[dim[axis]]; - child->setLayoutPosition( - node->getLayout().measuredDimensions[dim[axis]] - size - - child->getLayout().position[pos[axis]], - trailing[axis]); + child->setLayoutPosition(node->getLayout().measuredDimensions[dim[axis]] - + size - child->getLayout().position[pos[axis]], + trailing[axis]); } -static void YGConstrainMaxSizeForMode( - const YGNodeConstRef node, - const enum YGFlexDirection axis, - const float ownerAxisSize, - const float ownerWidth, - YGMeasureMode* mode, - float* size) { +static void YGConstrainMaxSizeForMode(const YGNodeConstRef node, + const enum YGFlexDirection axis, + const float ownerAxisSize, + const float ownerWidth, + 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: case YGMeasureModeAtMost: *size = (maxSize.isUndefined() || *size < maxSize.unwrap()) - ? *size - : maxSize.unwrap(); + ? *size + : maxSize.unwrap(); break; case YGMeasureModeUndefined: if (!maxSize.isUndefined()) { @@ -1259,20 +1137,12 @@ static void YGConstrainMaxSizeForMode( } static void YGNodeComputeFlexBasisForChild( - const YGNodeRef node, - const YGNodeRef child, - const float width, - const YGMeasureMode widthMode, - const float height, - const float ownerWidth, - const float ownerHeight, - const YGMeasureMode heightMode, - const YGDirection direction, - const YGConfigRef config, - LayoutData& layoutMarkerData, - void* const layoutContext, - const uint32_t depth, - const uint32_t generationCount) { + const YGNodeRef node, const YGNodeRef child, const float width, + const YGMeasureMode widthMode, const float height, const float ownerWidth, + const float ownerHeight, const YGMeasureMode heightMode, + const YGDirection direction, const YGConfigRef config, + LayoutData& layoutMarkerData, void* const layoutContext, + const uint32_t depth, const uint32_t generationCount) { const YGFlexDirection mainAxis = YGResolveFlexDirection(node->getStyle().flexDirection(), direction); const bool isMainAxisRow = YGFlexDirectionIsRow(mainAxis); @@ -1307,8 +1177,8 @@ static void YGNodeComputeFlexBasisForChild( YGNodePaddingAndBorderForAxis(child, YGFlexDirectionRow, ownerWidth)); child->setLayoutComputedFlexBasis(YGFloatOptionalMax( - YGResolveValue( - child->getResolvedDimensions()[YGDimensionWidth], ownerWidth), + YGResolveValue(child->getResolvedDimensions()[YGDimensionWidth], + ownerWidth), paddingAndBorder)); } else if (!isMainAxisRow && isColumnStyleDimDefined) { // The height is definite, so use that as the flex basis. @@ -1316,8 +1186,8 @@ static void YGNodeComputeFlexBasisForChild( YGFloatOptional(YGNodePaddingAndBorderForAxis( child, YGFlexDirectionColumn, ownerWidth)); child->setLayoutComputedFlexBasis(YGFloatOptionalMax( - YGResolveValue( - child->getResolvedDimensions()[YGDimensionHeight], ownerHeight), + YGResolveValue(child->getResolvedDimensions()[YGDimensionHeight], + ownerHeight), paddingAndBorder)); } else { // Compute the flex basis and hypothetical main size (i.e. the clamped flex @@ -1334,16 +1204,16 @@ static void YGNodeComputeFlexBasisForChild( if (isRowStyleDimDefined) { childWidth = - YGResolveValue( - child->getResolvedDimensions()[YGDimensionWidth], ownerWidth) + YGResolveValue(child->getResolvedDimensions()[YGDimensionWidth], + ownerWidth) .unwrap() + marginRow; childWidthMeasureMode = YGMeasureModeExactly; } if (isColumnStyleDimDefined) { childHeight = - YGResolveValue( - child->getResolvedDimensions()[YGDimensionHeight], ownerHeight) + YGResolveValue(child->getResolvedDimensions()[YGDimensionHeight], + ownerHeight) .unwrap() + marginColumn; childHeightMeasureMode = YGMeasureModeExactly; @@ -1370,13 +1240,13 @@ static void YGNodeComputeFlexBasisForChild( const auto& childStyle = child->getStyle(); if (!childStyle.aspectRatio().isUndefined()) { if (!isMainAxisRow && childWidthMeasureMode == YGMeasureModeExactly) { - childHeight = marginColumn + - (childWidth - marginRow) / childStyle.aspectRatio().unwrap(); + childHeight = marginColumn + (childWidth - marginRow) / + childStyle.aspectRatio().unwrap(); childHeightMeasureMode = YGMeasureModeExactly; - } else if ( - isMainAxisRow && childHeightMeasureMode == YGMeasureModeExactly) { - childWidth = marginRow + - (childHeight - marginColumn) * childStyle.aspectRatio().unwrap(); + } else if (isMainAxisRow && + childHeightMeasureMode == YGMeasureModeExactly) { + childWidth = marginRow + (childHeight - marginColumn) * + childStyle.aspectRatio().unwrap(); childWidthMeasureMode = YGMeasureModeExactly; } } @@ -1417,38 +1287,18 @@ static void YGNodeComputeFlexBasisForChild( } } - YGConstrainMaxSizeForMode( - child, - YGFlexDirectionRow, - ownerWidth, - ownerWidth, - &childWidthMeasureMode, - &childWidth); - YGConstrainMaxSizeForMode( - child, - YGFlexDirectionColumn, - ownerHeight, - ownerWidth, - &childHeightMeasureMode, - &childHeight); + YGConstrainMaxSizeForMode(child, YGFlexDirectionRow, ownerWidth, ownerWidth, + &childWidthMeasureMode, &childWidth); + YGConstrainMaxSizeForMode(child, YGFlexDirectionColumn, ownerHeight, + ownerWidth, &childHeightMeasureMode, + &childHeight); // Measure the child YGLayoutNodeInternal( - child, - childWidth, - childHeight, - direction, - childWidthMeasureMode, - childHeightMeasureMode, - ownerWidth, - ownerHeight, - false, - LayoutPassReason::kMeasureChild, - config, - layoutMarkerData, - layoutContext, - depth, - generationCount); + child, childWidth, childHeight, direction, childWidthMeasureMode, + childHeightMeasureMode, ownerWidth, ownerHeight, false, + LayoutPassReason::kMeasureChild, config, layoutMarkerData, + layoutContext, depth, generationCount); child->setLayoutComputedFlexBasis(YGFloatOptional(YGFloatMax( child->getLayout().measuredDimensions[dim[mainAxis]], @@ -1458,17 +1308,11 @@ static void YGNodeComputeFlexBasisForChild( } static void YGNodeAbsoluteLayoutChild( - const YGNodeRef node, - const YGNodeRef child, - const float width, - const YGMeasureMode widthMode, - const float height, - const YGDirection direction, - const YGConfigRef config, - LayoutData& layoutMarkerData, - void* const layoutContext, - const uint32_t depth, - const uint32_t generationCount) { + const YGNodeRef node, const YGNodeRef child, const float width, + const YGMeasureMode widthMode, const float height, + const YGDirection direction, const YGConfigRef config, + LayoutData& layoutMarkerData, void* const layoutContext, + const uint32_t depth, const uint32_t generationCount) { const YGFlexDirection mainAxis = YGResolveFlexDirection(node->getStyle().flexDirection(), direction); const YGFlexDirection crossAxis = YGFlexDirectionCross(mainAxis, direction); @@ -1494,11 +1338,11 @@ static void YGNodeAbsoluteLayoutChild( if (child->isLeadingPositionDefined(YGFlexDirectionRow) && child->isTrailingPosDefined(YGFlexDirectionRow)) { childWidth = node->getLayout().measuredDimensions[YGDimensionWidth] - - (node->getLeadingBorder(YGFlexDirectionRow) + - node->getTrailingBorder(YGFlexDirectionRow)) - - (child->getLeadingPosition(YGFlexDirectionRow, width) + - child->getTrailingPosition(YGFlexDirectionRow, width)) - .unwrap(); + (node->getLeadingBorder(YGFlexDirectionRow) + + node->getTrailingBorder(YGFlexDirectionRow)) - + (child->getLeadingPosition(YGFlexDirectionRow, width) + + child->getTrailingPosition(YGFlexDirectionRow, width)) + .unwrap(); childWidth = YGNodeBoundAxis(child, YGFlexDirectionRow, childWidth, width, width); } @@ -1508,20 +1352,20 @@ static void YGNodeAbsoluteLayoutChild( childHeight = YGResolveValue( child->getResolvedDimensions()[YGDimensionHeight], height) .unwrap() + - marginColumn; + marginColumn; } else { // If the child doesn't have a specified height, compute the height based on // the top/bottom offsets if they're defined. if (child->isLeadingPositionDefined(YGFlexDirectionColumn) && child->isTrailingPosDefined(YGFlexDirectionColumn)) { childHeight = node->getLayout().measuredDimensions[YGDimensionHeight] - - (node->getLeadingBorder(YGFlexDirectionColumn) + - node->getTrailingBorder(YGFlexDirectionColumn)) - - (child->getLeadingPosition(YGFlexDirectionColumn, height) + - child->getTrailingPosition(YGFlexDirectionColumn, height)) - .unwrap(); - childHeight = YGNodeBoundAxis( - child, YGFlexDirectionColumn, childHeight, height, width); + (node->getLeadingBorder(YGFlexDirectionColumn) + + node->getTrailingBorder(YGFlexDirectionColumn)) - + (child->getLeadingPosition(YGFlexDirectionColumn, height) + + child->getTrailingPosition(YGFlexDirectionColumn, height)) + .unwrap(); + childHeight = YGNodeBoundAxis(child, YGFlexDirectionColumn, childHeight, + height, width); } } @@ -1532,11 +1376,11 @@ static void YGNodeAbsoluteLayoutChild( if (YGFloatIsUndefined(childWidth) ^ YGFloatIsUndefined(childHeight)) { if (!childStyle.aspectRatio().isUndefined()) { if (YGFloatIsUndefined(childWidth)) { - childWidth = marginRow + - (childHeight - marginColumn) * childStyle.aspectRatio().unwrap(); + childWidth = marginRow + (childHeight - marginColumn) * + childStyle.aspectRatio().unwrap(); } else if (YGFloatIsUndefined(childHeight)) { - childHeight = marginColumn + - (childWidth - marginRow) / childStyle.aspectRatio().unwrap(); + childHeight = marginColumn + (childWidth - marginRow) / + childStyle.aspectRatio().unwrap(); } } } @@ -1544,11 +1388,11 @@ static void YGNodeAbsoluteLayoutChild( // If we're still missing one or the other dimension, measure the content. if (YGFloatIsUndefined(childWidth) || YGFloatIsUndefined(childHeight)) { childWidthMeasureMode = YGFloatIsUndefined(childWidth) - ? YGMeasureModeUndefined - : YGMeasureModeExactly; + ? YGMeasureModeUndefined + : YGMeasureModeExactly; childHeightMeasureMode = YGFloatIsUndefined(childHeight) - ? YGMeasureModeUndefined - : YGMeasureModeExactly; + ? YGMeasureModeUndefined + : YGMeasureModeExactly; // 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 @@ -1562,43 +1406,21 @@ static void YGNodeAbsoluteLayoutChild( } YGLayoutNodeInternal( - child, - childWidth, - childHeight, - direction, - childWidthMeasureMode, - childHeightMeasureMode, - childWidth, - childHeight, - false, - LayoutPassReason::kAbsMeasureChild, - config, - layoutMarkerData, - layoutContext, - depth, - generationCount); + child, childWidth, childHeight, direction, childWidthMeasureMode, + childHeightMeasureMode, childWidth, childHeight, false, + LayoutPassReason::kAbsMeasureChild, config, layoutMarkerData, + layoutContext, depth, generationCount); childWidth = child->getLayout().measuredDimensions[YGDimensionWidth] + - child->getMarginForAxis(YGFlexDirectionRow, width).unwrap(); - childHeight = child->getLayout().measuredDimensions[YGDimensionHeight] + + child->getMarginForAxis(YGFlexDirectionRow, width).unwrap(); + childHeight = + child->getLayout().measuredDimensions[YGDimensionHeight] + child->getMarginForAxis(YGFlexDirectionColumn, width).unwrap(); } - YGLayoutNodeInternal( - child, - childWidth, - childHeight, - direction, - YGMeasureModeExactly, - YGMeasureModeExactly, - childWidth, - childHeight, - true, - LayoutPassReason::kAbsLayout, - config, - layoutMarkerData, - layoutContext, - depth, - generationCount); + YGLayoutNodeInternal(child, childWidth, childHeight, direction, + YGMeasureModeExactly, YGMeasureModeExactly, childWidth, + childHeight, true, LayoutPassReason::kAbsLayout, config, + layoutMarkerData, layoutContext, depth, generationCount); if (child->isTrailingPosDefined(mainAxis) && !child->isLeadingPositionDefined(mainAxis)) { @@ -1610,17 +1432,15 @@ static void YGNodeAbsoluteLayoutChild( child->getTrailingPosition(mainAxis, isMainAxisRow ? width : height) .unwrap(), leading[mainAxis]); - } else if ( - !child->isLeadingPositionDefined(mainAxis) && - node->getStyle().justifyContent() == YGJustifyCenter) { + } else if (!child->isLeadingPositionDefined(mainAxis) && + node->getStyle().justifyContent() == YGJustifyCenter) { child->setLayoutPosition( (node->getLayout().measuredDimensions[dim[mainAxis]] - child->getLayout().measuredDimensions[dim[mainAxis]]) / 2.0f, leading[mainAxis]); - } else if ( - !child->isLeadingPositionDefined(mainAxis) && - node->getStyle().justifyContent() == YGJustifyFlexEnd) { + } else if (!child->isLeadingPositionDefined(mainAxis) && + node->getStyle().justifyContent() == YGJustifyFlexEnd) { child->setLayoutPosition( (node->getLayout().measuredDimensions[dim[mainAxis]] - child->getLayout().measuredDimensions[dim[mainAxis]]), @@ -1639,18 +1459,16 @@ static void YGNodeAbsoluteLayoutChild( .unwrap(), leading[crossAxis]); - } else if ( - !child->isLeadingPositionDefined(crossAxis) && - YGNodeAlignItem(node, child) == YGAlignCenter) { + } else if (!child->isLeadingPositionDefined(crossAxis) && + YGNodeAlignItem(node, child) == YGAlignCenter) { child->setLayoutPosition( (node->getLayout().measuredDimensions[dim[crossAxis]] - child->getLayout().measuredDimensions[dim[crossAxis]]) / 2.0f, leading[crossAxis]); - } else if ( - !child->isLeadingPositionDefined(crossAxis) && - ((YGNodeAlignItem(node, child) == YGAlignFlexEnd) ^ - (node->getStyle().flexWrap() == YGWrapWrapReverse))) { + } else if (!child->isLeadingPositionDefined(crossAxis) && + ((YGNodeAlignItem(node, child) == YGAlignFlexEnd) ^ + (node->getStyle().flexWrap() == YGWrapWrapReverse))) { child->setLayoutPosition( (node->getLayout().measuredDimensions[dim[crossAxis]] - child->getLayout().measuredDimensions[dim[crossAxis]]), @@ -1659,20 +1477,13 @@ static void YGNodeAbsoluteLayoutChild( } static void YGNodeWithMeasureFuncSetMeasuredDimensions( - const YGNodeRef node, - float availableWidth, - float availableHeight, - const YGMeasureMode widthMeasureMode, - const YGMeasureMode heightMeasureMode, - const float ownerWidth, - const float ownerHeight, - LayoutData& layoutMarkerData, - void* const layoutContext, + const YGNodeRef node, float availableWidth, float availableHeight, + const YGMeasureMode widthMeasureMode, const YGMeasureMode heightMeasureMode, + const float ownerWidth, const float ownerHeight, + LayoutData& layoutMarkerData, void* const layoutContext, const LayoutPassReason reason) { - YGAssertWithNode( - node, - node->hasMeasureFunc(), - "Expected node to have custom measure function"); + YGAssertWithNode(node, node->hasMeasureFunc(), + "Expected node to have custom measure function"); if (widthMeasureMode == YGMeasureModeUndefined) { availableWidth = YGUndefined; @@ -1692,42 +1503,34 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions( // We want to make sure we don't call measure with negative size const float innerWidth = YGFloatIsUndefined(availableWidth) - ? availableWidth - : YGFloatMax(0, availableWidth - marginAxisRow - paddingAndBorderAxisRow); - const float innerHeight = YGFloatIsUndefined(availableHeight) - ? availableHeight - : YGFloatMax( - 0, availableHeight - marginAxisColumn - paddingAndBorderAxisColumn); + ? availableWidth + : YGFloatMax(0, availableWidth - marginAxisRow - + paddingAndBorderAxisRow); + const float innerHeight = + YGFloatIsUndefined(availableHeight) + ? availableHeight + : YGFloatMax(0, availableHeight - marginAxisColumn - + paddingAndBorderAxisColumn); if (widthMeasureMode == YGMeasureModeExactly && heightMeasureMode == YGMeasureModeExactly) { // Don't bother sizing the text if both dimensions are already defined. node->setLayoutMeasuredDimension( - YGNodeBoundAxis( - node, - YGFlexDirectionRow, - availableWidth - marginAxisRow, - ownerWidth, - ownerWidth), + YGNodeBoundAxis(node, YGFlexDirectionRow, + availableWidth - marginAxisRow, ownerWidth, ownerWidth), YGDimensionWidth); node->setLayoutMeasuredDimension( - YGNodeBoundAxis( - node, - YGFlexDirectionColumn, - availableHeight - marginAxisColumn, - ownerHeight, - ownerWidth), + YGNodeBoundAxis(node, YGFlexDirectionColumn, + availableHeight - marginAxisColumn, ownerHeight, + ownerWidth), YGDimensionHeight); } else { Event::publish(node); // Measure the text under the current constraints. - const YGSize measuredSize = node->measure( - innerWidth, - widthMeasureMode, - innerHeight, - heightMeasureMode, - layoutContext); + const YGSize measuredSize = + node->measure(innerWidth, widthMeasureMode, innerHeight, + heightMeasureMode, layoutContext); layoutMarkerData.measureCallbacks += 1; layoutMarkerData.measureCallbackReasonsCount[static_cast(reason)] += @@ -1735,37 +1538,25 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions( Event::publish( node, - {layoutContext, - innerWidth, - widthMeasureMode, - innerHeight, - heightMeasureMode, - measuredSize.width, - measuredSize.height, - reason}); + {layoutContext, innerWidth, widthMeasureMode, innerHeight, + heightMeasureMode, measuredSize.width, measuredSize.height, reason}); node->setLayoutMeasuredDimension( - YGNodeBoundAxis( - node, - YGFlexDirectionRow, - (widthMeasureMode == YGMeasureModeUndefined || - widthMeasureMode == YGMeasureModeAtMost) - ? measuredSize.width + paddingAndBorderAxisRow - : availableWidth - marginAxisRow, - ownerWidth, - ownerWidth), + YGNodeBoundAxis(node, YGFlexDirectionRow, + (widthMeasureMode == YGMeasureModeUndefined || + widthMeasureMode == YGMeasureModeAtMost) + ? measuredSize.width + paddingAndBorderAxisRow + : availableWidth - marginAxisRow, + ownerWidth, ownerWidth), YGDimensionWidth); node->setLayoutMeasuredDimension( - YGNodeBoundAxis( - node, - YGFlexDirectionColumn, - (heightMeasureMode == YGMeasureModeUndefined || - heightMeasureMode == YGMeasureModeAtMost) - ? measuredSize.height + paddingAndBorderAxisColumn - : availableHeight - marginAxisColumn, - ownerHeight, - ownerWidth), + YGNodeBoundAxis(node, YGFlexDirectionColumn, + (heightMeasureMode == YGMeasureModeUndefined || + heightMeasureMode == YGMeasureModeAtMost) + ? measuredSize.height + paddingAndBorderAxisColumn + : availableHeight - marginAxisColumn, + ownerHeight, ownerWidth), YGDimensionHeight); } } @@ -1773,12 +1564,9 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions( // For nodes with no children, use the available values if they were provided, // or the minimum size as indicated by the padding and border sizes. static void YGNodeEmptyContainerSetMeasuredDimensions( - const YGNodeRef node, - const float availableWidth, - const float availableHeight, - const YGMeasureMode widthMeasureMode, - const YGMeasureMode heightMeasureMode, - const float ownerWidth, + const YGNodeRef node, const float availableWidth, + const float availableHeight, const YGMeasureMode widthMeasureMode, + const YGMeasureMode heightMeasureMode, const float ownerWidth, const float ownerHeight) { const float paddingAndBorderAxisRow = YGNodePaddingAndBorderForAxis(node, YGFlexDirectionRow, ownerWidth); @@ -1790,37 +1578,28 @@ static void YGNodeEmptyContainerSetMeasuredDimensions( node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth).unwrap(); node->setLayoutMeasuredDimension( - YGNodeBoundAxis( - node, - YGFlexDirectionRow, - (widthMeasureMode == YGMeasureModeUndefined || - widthMeasureMode == YGMeasureModeAtMost) - ? paddingAndBorderAxisRow - : availableWidth - marginAxisRow, - ownerWidth, - ownerWidth), + YGNodeBoundAxis(node, YGFlexDirectionRow, + (widthMeasureMode == YGMeasureModeUndefined || + widthMeasureMode == YGMeasureModeAtMost) + ? paddingAndBorderAxisRow + : availableWidth - marginAxisRow, + ownerWidth, ownerWidth), YGDimensionWidth); node->setLayoutMeasuredDimension( - YGNodeBoundAxis( - node, - YGFlexDirectionColumn, - (heightMeasureMode == YGMeasureModeUndefined || - heightMeasureMode == YGMeasureModeAtMost) - ? paddingAndBorderAxisColumn - : availableHeight - marginAxisColumn, - ownerHeight, - ownerWidth), + YGNodeBoundAxis(node, YGFlexDirectionColumn, + (heightMeasureMode == YGMeasureModeUndefined || + heightMeasureMode == YGMeasureModeAtMost) + ? paddingAndBorderAxisColumn + : availableHeight - marginAxisColumn, + ownerHeight, ownerWidth), YGDimensionHeight); } static bool YGNodeFixedSizeSetMeasuredDimensions( - const YGNodeRef node, - const float availableWidth, - const float availableHeight, - const YGMeasureMode widthMeasureMode, - const YGMeasureMode heightMeasureMode, - const float ownerWidth, + const YGNodeRef node, const float availableWidth, + const float availableHeight, const YGMeasureMode widthMeasureMode, + const YGMeasureMode heightMeasureMode, const float ownerWidth, const float ownerHeight) { if ((!YGFloatIsUndefined(availableWidth) && widthMeasureMode == YGMeasureModeAtMost && availableWidth <= 0.0f) || @@ -1834,29 +1613,23 @@ static bool YGNodeFixedSizeSetMeasuredDimensions( node->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap(); node->setLayoutMeasuredDimension( - YGNodeBoundAxis( - node, - YGFlexDirectionRow, - YGFloatIsUndefined(availableWidth) || - (widthMeasureMode == YGMeasureModeAtMost && - availableWidth < 0.0f) - ? 0.0f - : availableWidth - marginAxisRow, - ownerWidth, - ownerWidth), + YGNodeBoundAxis(node, YGFlexDirectionRow, + YGFloatIsUndefined(availableWidth) || + (widthMeasureMode == YGMeasureModeAtMost && + availableWidth < 0.0f) + ? 0.0f + : availableWidth - marginAxisRow, + ownerWidth, ownerWidth), YGDimensionWidth); node->setLayoutMeasuredDimension( - YGNodeBoundAxis( - node, - YGFlexDirectionColumn, - YGFloatIsUndefined(availableHeight) || - (heightMeasureMode == YGMeasureModeAtMost && - availableHeight < 0.0f) - ? 0.0f - : availableHeight - marginAxisColumn, - ownerHeight, - ownerWidth), + YGNodeBoundAxis(node, YGFlexDirectionColumn, + YGFloatIsUndefined(availableHeight) || + (heightMeasureMode == YGMeasureModeAtMost && + availableHeight < 0.0f) + ? 0.0f + : availableHeight - marginAxisColumn, + ownerHeight, ownerWidth), YGDimensionHeight); return true; } @@ -1864,24 +1637,22 @@ static bool YGNodeFixedSizeSetMeasuredDimensions( return false; } -static void YGZeroOutLayoutRecursivly( - const YGNodeRef node, - void* layoutContext) { +static void YGZeroOutLayoutRecursivly(const YGNodeRef node, + void* layoutContext) { node->getLayout() = {}; node->setLayoutDimension(0, 0); node->setLayoutDimension(0, 1); node->setHasNewLayout(true); - node->iterChildrenAfterCloningIfNeeded( - YGZeroOutLayoutRecursivly, layoutContext); + node->iterChildrenAfterCloningIfNeeded(YGZeroOutLayoutRecursivly, + layoutContext); } -static float YGNodeCalculateAvailableInnerDim( - const YGNodeConstRef node, - YGFlexDirection axis, - float availableDim, - float ownerDim, - float ownerDimForMarginPadding) { +static float YGNodeCalculateAvailableInnerDim(const YGNodeConstRef node, + YGFlexDirection axis, + float availableDim, + float ownerDim, + float ownerDimForMarginPadding) { YGFlexDirection direction = YGFlexDirectionIsRow(axis) ? YGFlexDirectionRow : YGFlexDirectionColumn; YGDimension dimension = @@ -1900,16 +1671,18 @@ static float YGNodeCalculateAvailableInnerDim( // constraints const YGFloatOptional minDimensionOptional = YGResolveValue(node->getStyle().minDimensions()[dimension], ownerDim); - const float minInnerDim = minDimensionOptional.isUndefined() - ? 0.0f - : minDimensionOptional.unwrap() - paddingAndBorder; + const float minInnerDim = + minDimensionOptional.isUndefined() + ? 0.0f + : minDimensionOptional.unwrap() - paddingAndBorder; const YGFloatOptional maxDimensionOptional = YGResolveValue(node->getStyle().maxDimensions()[dimension], ownerDim); - const float maxInnerDim = maxDimensionOptional.isUndefined() - ? FLT_MAX - : maxDimensionOptional.unwrap() - paddingAndBorder; + const float maxInnerDim = + maxDimensionOptional.isUndefined() + ? FLT_MAX + : maxDimensionOptional.unwrap() - paddingAndBorder; availableInnerDim = YGFloatMax(YGFloatMin(availableInnerDim, maxInnerDim), minInnerDim); } @@ -1918,19 +1691,12 @@ static float YGNodeCalculateAvailableInnerDim( } static float YGNodeComputeFlexBasisForChildren( - const YGNodeRef node, - const float availableInnerWidth, - const float availableInnerHeight, - YGMeasureMode widthMeasureMode, - YGMeasureMode heightMeasureMode, - YGDirection direction, - YGFlexDirection mainAxis, - const YGConfigRef config, - bool performLayout, - LayoutData& layoutMarkerData, - void* const layoutContext, - const uint32_t depth, - const uint32_t generationCount) { + const YGNodeRef node, const float availableInnerWidth, + const float availableInnerHeight, YGMeasureMode widthMeasureMode, + YGMeasureMode heightMeasureMode, YGDirection direction, + YGFlexDirection mainAxis, const YGConfigRef config, bool performLayout, + LayoutData& layoutMarkerData, void* const layoutContext, + const uint32_t depth, const uint32_t generationCount) { float totalOuterFlexBasis = 0.0f; YGNodeRef singleFlexChild = nullptr; const YGVector& children = node->getChildren(); @@ -1968,13 +1734,13 @@ static float YGNodeComputeFlexBasisForChildren( // Set the initial position (relative to the owner). const YGDirection childDirection = child->resolveDirection(direction); const float mainDim = YGFlexDirectionIsRow(mainAxis) - ? availableInnerWidth - : availableInnerHeight; + ? availableInnerWidth + : availableInnerHeight; const float crossDim = YGFlexDirectionIsRow(mainAxis) - ? availableInnerHeight - : availableInnerWidth; - child->setPosition( - childDirection, mainDim, crossDim, availableInnerWidth); + ? availableInnerHeight + : availableInnerWidth; + child->setPosition(childDirection, mainDim, crossDim, + availableInnerWidth); } if (child->getStyle().positionType() == YGPositionTypeAbsolute) { @@ -1985,20 +1751,10 @@ static float YGNodeComputeFlexBasisForChildren( child->setLayoutComputedFlexBasis(YGFloatOptional(0)); } else { YGNodeComputeFlexBasisForChild( - node, - child, - availableInnerWidth, - widthMeasureMode, - availableInnerHeight, - availableInnerWidth, - availableInnerHeight, - heightMeasureMode, - direction, - config, - layoutMarkerData, - layoutContext, - depth, - generationCount); + node, child, availableInnerWidth, widthMeasureMode, + availableInnerHeight, availableInnerWidth, availableInnerHeight, + heightMeasureMode, direction, config, layoutMarkerData, layoutContext, + depth, generationCount); } totalOuterFlexBasis += @@ -2015,12 +1771,9 @@ static float YGNodeComputeFlexBasisForChildren( // YGNodeComputeFlexBasisForChildren function). This function calculates // YGCollectFlexItemsRowMeasurement static YGCollectFlexItemsRowValues YGCalculateCollectFlexItemsRowValues( - const YGNodeRef& node, - const YGDirection ownerDirection, - const float mainAxisownerSize, - const float availableInnerWidth, - const float availableInnerMainDim, - const uint32_t startOfLineIndex, + const YGNodeRef& node, const YGDirection ownerDirection, + const float mainAxisownerSize, const float availableInnerWidth, + const float availableInnerMainDim, const uint32_t startOfLineIndex, const uint32_t lineCount) { YGCollectFlexItemsRowValues flexAlgoRowMeasurement = {}; flexAlgoRowMeasurement.relativeChildren.reserve(node->getChildren().size()); @@ -2042,11 +1795,9 @@ static YGCollectFlexItemsRowValues YGCalculateCollectFlexItemsRowValues( const float childMarginMainAxis = child->getMarginForAxis(mainAxis, availableInnerWidth).unwrap(); const float flexBasisWithMinAndMaxConstraints = - YGNodeBoundAxisWithinMinAndMax( - child, - mainAxis, - child->getLayout().computedFlexBasis, - mainAxisownerSize) + YGNodeBoundAxisWithinMinAndMax(child, mainAxis, + child->getLayout().computedFlexBasis, + mainAxisownerSize) .unwrap(); // If this is a multi-line flow and this item pushes us over the available @@ -2098,22 +1849,14 @@ static YGCollectFlexItemsRowValues YGCalculateCollectFlexItemsRowValues( // function the child nodes would have proper size. Prior using this function // please ensure that YGDistributeFreeSpaceFirstPass is called. static float YGDistributeFreeSpaceSecondPass( - YGCollectFlexItemsRowValues& collectedFlexItemsValues, - const YGNodeRef node, - const YGFlexDirection mainAxis, - const YGFlexDirection crossAxis, - const float mainAxisownerSize, - const float availableInnerMainDim, - const float availableInnerCrossDim, - const float availableInnerWidth, - const float availableInnerHeight, - const bool flexBasisOverflows, - const YGMeasureMode measureModeCrossDim, - const bool performLayout, - const YGConfigRef config, - LayoutData& layoutMarkerData, - void* const layoutContext, - const uint32_t depth, + YGCollectFlexItemsRowValues& collectedFlexItemsValues, const YGNodeRef node, + const YGFlexDirection mainAxis, const YGFlexDirection crossAxis, + const float mainAxisownerSize, const float availableInnerMainDim, + const float availableInnerCrossDim, const float availableInnerWidth, + const float availableInnerHeight, const bool flexBasisOverflows, + const YGMeasureMode measureModeCrossDim, const bool performLayout, + const YGConfigRef config, LayoutData& layoutMarkerData, + void* const layoutContext, const uint32_t depth, const uint32_t generationCount) { float childFlexBasis = 0; float flexShrinkScaledFactor = 0; @@ -2124,8 +1867,7 @@ static float YGDistributeFreeSpaceSecondPass( for (auto currentRelativeChild : collectedFlexItemsValues.relativeChildren) { childFlexBasis = YGNodeBoundAxisWithinMinAndMax( - currentRelativeChild, - mainAxis, + currentRelativeChild, mainAxis, currentRelativeChild->getLayout().computedFlexBasis, mainAxisownerSize) .unwrap(); @@ -2145,34 +1887,28 @@ static float YGDistributeFreeSpaceSecondPass( childSize = childFlexBasis + flexShrinkScaledFactor; } else { childSize = childFlexBasis + - (collectedFlexItemsValues.remainingFreeSpace / - collectedFlexItemsValues.totalFlexShrinkScaledFactors) * - flexShrinkScaledFactor; + (collectedFlexItemsValues.remainingFreeSpace / + collectedFlexItemsValues.totalFlexShrinkScaledFactors) * + flexShrinkScaledFactor; } - updatedMainSize = YGNodeBoundAxis( - currentRelativeChild, - mainAxis, - childSize, - availableInnerMainDim, - availableInnerWidth); + updatedMainSize = + YGNodeBoundAxis(currentRelativeChild, mainAxis, childSize, + availableInnerMainDim, availableInnerWidth); } - } else if ( - !YGFloatIsUndefined(collectedFlexItemsValues.remainingFreeSpace) && - collectedFlexItemsValues.remainingFreeSpace > 0) { + } else if (!YGFloatIsUndefined( + collectedFlexItemsValues.remainingFreeSpace) && + collectedFlexItemsValues.remainingFreeSpace > 0) { flexGrowFactor = currentRelativeChild->resolveFlexGrow(); // Is this child able to grow? if (!YGFloatIsUndefined(flexGrowFactor) && flexGrowFactor != 0) { updatedMainSize = YGNodeBoundAxis( - currentRelativeChild, - mainAxis, - childFlexBasis + - collectedFlexItemsValues.remainingFreeSpace / - collectedFlexItemsValues.totalFlexGrowFactors * - flexGrowFactor, - availableInnerMainDim, - availableInnerWidth); + currentRelativeChild, mainAxis, + childFlexBasis + collectedFlexItemsValues.remainingFreeSpace / + collectedFlexItemsValues.totalFlexGrowFactors * + flexGrowFactor, + availableInnerMainDim, availableInnerWidth); } } @@ -2192,31 +1928,31 @@ static float YGDistributeFreeSpaceSecondPass( const auto& childStyle = currentRelativeChild->getStyle(); if (!childStyle.aspectRatio().isUndefined()) { - childCrossSize = isMainAxisRow - ? (childMainSize - marginMain) / childStyle.aspectRatio().unwrap() - : (childMainSize - marginMain) * childStyle.aspectRatio().unwrap(); + childCrossSize = isMainAxisRow ? (childMainSize - marginMain) / + childStyle.aspectRatio().unwrap() + : (childMainSize - marginMain) * + childStyle.aspectRatio().unwrap(); childCrossMeasureMode = YGMeasureModeExactly; childCrossSize += marginCross; - } else if ( - !YGFloatIsUndefined(availableInnerCrossDim) && - !YGNodeIsStyleDimDefined( - currentRelativeChild, crossAxis, availableInnerCrossDim) && - measureModeCrossDim == YGMeasureModeExactly && - !(isNodeFlexWrap && flexBasisOverflows) && - YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch && - currentRelativeChild->marginLeadingValue(crossAxis).unit != - YGUnitAuto && - currentRelativeChild->marginTrailingValue(crossAxis).unit != - YGUnitAuto) { + } else if (!YGFloatIsUndefined(availableInnerCrossDim) && + !YGNodeIsStyleDimDefined(currentRelativeChild, crossAxis, + availableInnerCrossDim) && + measureModeCrossDim == YGMeasureModeExactly && + !(isNodeFlexWrap && flexBasisOverflows) && + YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch && + currentRelativeChild->marginLeadingValue(crossAxis).unit != + YGUnitAuto && + currentRelativeChild->marginTrailingValue(crossAxis).unit != + YGUnitAuto) { childCrossSize = availableInnerCrossDim; childCrossMeasureMode = YGMeasureModeExactly; - } else if (!YGNodeIsStyleDimDefined( - currentRelativeChild, crossAxis, availableInnerCrossDim)) { + } else if (!YGNodeIsStyleDimDefined(currentRelativeChild, crossAxis, + availableInnerCrossDim)) { childCrossSize = availableInnerCrossDim; childCrossMeasureMode = YGFloatIsUndefined(childCrossSize) - ? YGMeasureModeUndefined - : YGMeasureModeAtMost; + ? YGMeasureModeUndefined + : YGMeasureModeAtMost; } else { childCrossSize = YGResolveValue( @@ -2230,28 +1966,20 @@ static float YGDistributeFreeSpaceSecondPass( measureModeCrossDim != YGMeasureModeExactly; childCrossMeasureMode = YGFloatIsUndefined(childCrossSize) || isLoosePercentageMeasurement - ? YGMeasureModeUndefined - : YGMeasureModeExactly; + ? YGMeasureModeUndefined + : YGMeasureModeExactly; } - YGConstrainMaxSizeForMode( - currentRelativeChild, - mainAxis, - availableInnerMainDim, - availableInnerWidth, - &childMainMeasureMode, - &childMainSize); - YGConstrainMaxSizeForMode( - currentRelativeChild, - crossAxis, - availableInnerCrossDim, - availableInnerWidth, - &childCrossMeasureMode, - &childCrossSize); + YGConstrainMaxSizeForMode(currentRelativeChild, mainAxis, + availableInnerMainDim, availableInnerWidth, + &childMainMeasureMode, &childMainSize); + YGConstrainMaxSizeForMode(currentRelativeChild, crossAxis, + availableInnerCrossDim, availableInnerWidth, + &childCrossMeasureMode, &childCrossSize); const bool requiresStretchLayout = - !YGNodeIsStyleDimDefined( - currentRelativeChild, crossAxis, availableInnerCrossDim) && + !YGNodeIsStyleDimDefined(currentRelativeChild, crossAxis, + availableInnerCrossDim) && YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch && currentRelativeChild->marginLeadingValue(crossAxis).unit != YGUnitAuto && @@ -2268,26 +1996,16 @@ static float YGDistributeFreeSpaceSecondPass( const bool isLayoutPass = performLayout && !requiresStretchLayout; // Recursively call the layout algorithm for this child with the updated // main size. - YGLayoutNodeInternal( - currentRelativeChild, - childWidth, - childHeight, - node->getLayout().direction(), - childWidthMeasureMode, - childHeightMeasureMode, - availableInnerWidth, - availableInnerHeight, - isLayoutPass, - isLayoutPass ? LayoutPassReason::kFlexLayout - : LayoutPassReason::kFlexMeasure, - config, - layoutMarkerData, - layoutContext, - depth, - generationCount); - node->setLayoutHadOverflow( - node->getLayout().hadOverflow() | - currentRelativeChild->getLayout().hadOverflow()); + YGLayoutNodeInternal(currentRelativeChild, childWidth, childHeight, + node->getLayout().direction(), childWidthMeasureMode, + childHeightMeasureMode, availableInnerWidth, + availableInnerHeight, isLayoutPass, + isLayoutPass ? LayoutPassReason::kFlexLayout + : LayoutPassReason::kFlexMeasure, + config, layoutMarkerData, layoutContext, depth, + generationCount); + node->setLayoutHadOverflow(node->getLayout().hadOverflow() | + currentRelativeChild->getLayout().hadOverflow()); } return deltaFreeSpace; } @@ -2297,10 +2015,8 @@ static float YGDistributeFreeSpaceSecondPass( // is removed from the remaingfreespace. static void YGDistributeFreeSpaceFirstPass( YGCollectFlexItemsRowValues& collectedFlexItemsValues, - const YGFlexDirection mainAxis, - const float mainAxisownerSize, - const float availableInnerMainDim, - const float availableInnerWidth) { + const YGFlexDirection mainAxis, const float mainAxisownerSize, + const float availableInnerMainDim, const float availableInnerWidth) { float flexShrinkScaledFactor = 0; float flexGrowFactor = 0; float baseMainSize = 0; @@ -2310,8 +2026,7 @@ static void YGDistributeFreeSpaceFirstPass( for (auto currentRelativeChild : collectedFlexItemsValues.relativeChildren) { float childFlexBasis = YGNodeBoundAxisWithinMinAndMax( - currentRelativeChild, - mainAxis, + currentRelativeChild, mainAxis, currentRelativeChild->getLayout().computedFlexBasis, mainAxisownerSize) .unwrap(); @@ -2323,16 +2038,14 @@ static void YGDistributeFreeSpaceFirstPass( // Is this child able to shrink? if (!YGFloatIsUndefined(flexShrinkScaledFactor) && flexShrinkScaledFactor != 0) { - baseMainSize = childFlexBasis + + baseMainSize = + childFlexBasis + collectedFlexItemsValues.remainingFreeSpace / collectedFlexItemsValues.totalFlexShrinkScaledFactors * flexShrinkScaledFactor; - boundMainSize = YGNodeBoundAxis( - currentRelativeChild, - mainAxis, - baseMainSize, - availableInnerMainDim, - availableInnerWidth); + boundMainSize = + YGNodeBoundAxis(currentRelativeChild, mainAxis, baseMainSize, + availableInnerMainDim, availableInnerWidth); if (!YGFloatIsUndefined(baseMainSize) && !YGFloatIsUndefined(boundMainSize) && baseMainSize != boundMainSize) { @@ -2346,22 +2059,20 @@ static void YGDistributeFreeSpaceFirstPass( currentRelativeChild->getLayout().computedFlexBasis.unwrap()); } } - } else if ( - !YGFloatIsUndefined(collectedFlexItemsValues.remainingFreeSpace) && - collectedFlexItemsValues.remainingFreeSpace > 0) { + } else if (!YGFloatIsUndefined( + collectedFlexItemsValues.remainingFreeSpace) && + collectedFlexItemsValues.remainingFreeSpace > 0) { flexGrowFactor = currentRelativeChild->resolveFlexGrow(); // Is this child able to grow? if (!YGFloatIsUndefined(flexGrowFactor) && flexGrowFactor != 0) { - baseMainSize = childFlexBasis + - collectedFlexItemsValues.remainingFreeSpace / - collectedFlexItemsValues.totalFlexGrowFactors * flexGrowFactor; - boundMainSize = YGNodeBoundAxis( - currentRelativeChild, - mainAxis, - baseMainSize, - availableInnerMainDim, - availableInnerWidth); + baseMainSize = + childFlexBasis + collectedFlexItemsValues.remainingFreeSpace / + collectedFlexItemsValues.totalFlexGrowFactors * + flexGrowFactor; + boundMainSize = + YGNodeBoundAxis(currentRelativeChild, mainAxis, baseMainSize, + availableInnerMainDim, availableInnerWidth); if (!YGFloatIsUndefined(baseMainSize) && !YGFloatIsUndefined(boundMainSize) && @@ -2402,50 +2113,27 @@ static void YGDistributeFreeSpaceFirstPass( // assigned to them. // static void YGResolveFlexibleLength( - const YGNodeRef node, - YGCollectFlexItemsRowValues& collectedFlexItemsValues, - const YGFlexDirection mainAxis, - const YGFlexDirection crossAxis, - const float mainAxisownerSize, - const float availableInnerMainDim, - const float availableInnerCrossDim, - const float availableInnerWidth, - const float availableInnerHeight, - const bool flexBasisOverflows, - const YGMeasureMode measureModeCrossDim, - const bool performLayout, - const YGConfigRef config, - LayoutData& layoutMarkerData, - void* const layoutContext, - const uint32_t depth, + const YGNodeRef node, YGCollectFlexItemsRowValues& collectedFlexItemsValues, + const YGFlexDirection mainAxis, const YGFlexDirection crossAxis, + const float mainAxisownerSize, const float availableInnerMainDim, + const float availableInnerCrossDim, const float availableInnerWidth, + const float availableInnerHeight, const bool flexBasisOverflows, + const YGMeasureMode measureModeCrossDim, const bool performLayout, + const YGConfigRef config, LayoutData& layoutMarkerData, + void* const layoutContext, const uint32_t depth, const uint32_t generationCount) { const float originalFreeSpace = collectedFlexItemsValues.remainingFreeSpace; // First pass: detect the flex items whose min/max constraints trigger - YGDistributeFreeSpaceFirstPass( - collectedFlexItemsValues, - mainAxis, - mainAxisownerSize, - availableInnerMainDim, - availableInnerWidth); + YGDistributeFreeSpaceFirstPass(collectedFlexItemsValues, mainAxis, + mainAxisownerSize, availableInnerMainDim, + availableInnerWidth); // Second pass: resolve the sizes of the flexible items const float distributedFreeSpace = YGDistributeFreeSpaceSecondPass( - collectedFlexItemsValues, - node, - mainAxis, - crossAxis, - mainAxisownerSize, - availableInnerMainDim, - availableInnerCrossDim, - availableInnerWidth, - availableInnerHeight, - flexBasisOverflows, - measureModeCrossDim, - performLayout, - config, - layoutMarkerData, - layoutContext, - depth, + collectedFlexItemsValues, node, mainAxis, crossAxis, mainAxisownerSize, + availableInnerMainDim, availableInnerCrossDim, availableInnerWidth, + availableInnerHeight, flexBasisOverflows, measureModeCrossDim, + performLayout, config, layoutMarkerData, layoutContext, depth, generationCount); collectedFlexItemsValues.remainingFreeSpace = @@ -2453,20 +2141,13 @@ static void YGResolveFlexibleLength( } static void YGJustifyMainAxis( - const YGNodeRef node, - YGCollectFlexItemsRowValues& collectedFlexItemsValues, - const uint32_t startOfLineIndex, - const YGFlexDirection mainAxis, - const YGFlexDirection crossAxis, - const YGMeasureMode measureModeMainDim, - const YGMeasureMode measureModeCrossDim, - const float mainAxisownerSize, - const float ownerWidth, - const float availableInnerMainDim, - const float availableInnerCrossDim, - const float availableInnerWidth, - const bool performLayout, - void* const layoutContext) { + const YGNodeRef node, YGCollectFlexItemsRowValues& collectedFlexItemsValues, + const uint32_t startOfLineIndex, const YGFlexDirection mainAxis, + const YGFlexDirection crossAxis, const YGMeasureMode measureModeMainDim, + const YGMeasureMode measureModeCrossDim, const float mainAxisownerSize, + const float ownerWidth, const float availableInnerMainDim, + const float availableInnerCrossDim, const float availableInnerWidth, + const bool performLayout, void* const layoutContext) { const auto& style = node->getStyle(); const float leadingPaddingAndBorderMain = node->getLeadingPaddingAndBorder(mainAxis, ownerWidth).unwrap(); @@ -2487,8 +2168,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 = @@ -2502,8 +2183,7 @@ static void YGJustifyMainAxis( int numberOfAutoMarginsOnCurrentLine = 0; for (uint32_t i = startOfLineIndex; - i < collectedFlexItemsValues.endOfLineIndex; - i++) { + i < collectedFlexItemsValues.endOfLineIndex; i++) { const YGNodeRef child = node->getChild(i); if (child->getStyle().positionType() != YGPositionTypeAbsolute) { if (child->marginLeadingValue(mainAxis).unit == YGUnitAuto) { @@ -2542,13 +2222,13 @@ static void YGJustifyMainAxis( case YGJustifySpaceEvenly: // Space is distributed evenly across all elements betweenMainDim = collectedFlexItemsValues.remainingFreeSpace / - (collectedFlexItemsValues.itemsOnLine + 1); + (collectedFlexItemsValues.itemsOnLine + 1); leadingMainDim = betweenMainDim; break; case YGJustifySpaceAround: // Space on the edges is half of the space between elements betweenMainDim = collectedFlexItemsValues.remainingFreeSpace / - collectedFlexItemsValues.itemsOnLine; + collectedFlexItemsValues.itemsOnLine; leadingMainDim = betweenMainDim / 2; break; case YGJustifyFlexStart: @@ -2564,8 +2244,7 @@ static void YGJustifyMainAxis( float maxDescentForCurrentLine = 0; bool isNodeBaselineLayout = YGIsBaselineLayout(node); for (uint32_t i = startOfLineIndex; - i < collectedFlexItemsValues.endOfLineIndex; - i++) { + i < collectedFlexItemsValues.endOfLineIndex; i++) { const YGNodeRef child = node->getChild(i); const YGStyle& childStyle = child->getStyle(); const YGLayout childLayout = child->getLayout(); @@ -2597,10 +2276,9 @@ static void YGJustifyMainAxis( } if (performLayout) { - child->setLayoutPosition( - childLayout.position[pos[mainAxis]] + - collectedFlexItemsValues.mainDim, - pos[mainAxis]); + child->setLayoutPosition(childLayout.position[pos[mainAxis]] + + collectedFlexItemsValues.mainDim, + pos[mainAxis]); } if (child->marginTrailingValue(mainAxis).unit == YGUnitAuto) { @@ -2614,29 +2292,31 @@ static void YGJustifyMainAxis( // 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 // YGNodeDimWithMargin. - collectedFlexItemsValues.mainDim += betweenMainDim + + collectedFlexItemsValues.mainDim += + betweenMainDim + child->getMarginForAxis(mainAxis, availableInnerWidth).unwrap() + childLayout.computedFlexBasis.unwrap(); collectedFlexItemsValues.crossDim = availableInnerCrossDim; } else { // The main dimension is the sum of all the elements dimension plus // the spacing. - collectedFlexItemsValues.mainDim += betweenMainDim + + collectedFlexItemsValues.mainDim += + betweenMainDim + YGNodeDimWithMargin(child, mainAxis, availableInnerWidth); if (isNodeBaselineLayout) { // If the child is baseline aligned then the cross dimension is // calculated by adding maxAscent and maxDescent from the baseline. const float ascent = YGBaseline(child, layoutContext) + - child - ->getLeadingMargin( - YGFlexDirectionColumn, availableInnerWidth) - .unwrap(); + child + ->getLeadingMargin(YGFlexDirectionColumn, + availableInnerWidth) + .unwrap(); const float descent = child->getLayout().measuredDimensions[YGDimensionHeight] + child - ->getMarginForAxis( - YGFlexDirectionColumn, availableInnerWidth) + ->getMarginForAxis(YGFlexDirectionColumn, + availableInnerWidth) .unwrap() - ascent; @@ -2654,10 +2334,10 @@ static void YGJustifyMainAxis( } } } else if (performLayout) { - child->setLayoutPosition( - childLayout.position[pos[mainAxis]] + - node->getLeadingBorder(mainAxis) + leadingMainDim, - pos[mainAxis]); + child->setLayoutPosition(childLayout.position[pos[mainAxis]] + + node->getLeadingBorder(mainAxis) + + leadingMainDim, + pos[mainAxis]); } } } @@ -2735,35 +2415,25 @@ static void YGJustifyMainAxis( // mode of YGMeasureModeUndefined in that dimension. // static void YGNodelayoutImpl( - const YGNodeRef node, - const float availableWidth, - const float availableHeight, - const YGDirection ownerDirection, - const YGMeasureMode widthMeasureMode, - const YGMeasureMode heightMeasureMode, - const float ownerWidth, - const float ownerHeight, - const bool performLayout, - const YGConfigRef config, - LayoutData& layoutMarkerData, - void* const layoutContext, - const uint32_t depth, - const uint32_t generationCount, - const LayoutPassReason reason) { - YGAssertWithNode( - node, - YGFloatIsUndefined(availableWidth) - ? widthMeasureMode == YGMeasureModeUndefined - : true, - "availableWidth is indefinite so widthMeasureMode must be " - "YGMeasureModeUndefined"); - YGAssertWithNode( - node, - YGFloatIsUndefined(availableHeight) - ? heightMeasureMode == YGMeasureModeUndefined - : true, - "availableHeight is indefinite so heightMeasureMode must be " - "YGMeasureModeUndefined"); + const YGNodeRef node, const float availableWidth, + const float availableHeight, const YGDirection ownerDirection, + const YGMeasureMode widthMeasureMode, const YGMeasureMode heightMeasureMode, + const float ownerWidth, const float ownerHeight, const bool performLayout, + const YGConfigRef config, LayoutData& layoutMarkerData, + void* const layoutContext, const uint32_t depth, + const uint32_t generationCount, const LayoutPassReason reason) { + YGAssertWithNode(node, + YGFloatIsUndefined(availableWidth) + ? widthMeasureMode == YGMeasureModeUndefined + : true, + "availableWidth is indefinite so widthMeasureMode must be " + "YGMeasureModeUndefined"); + YGAssertWithNode(node, + YGFloatIsUndefined(availableHeight) + ? heightMeasureMode == YGMeasureModeUndefined + : true, + "availableHeight is indefinite so heightMeasureMode must be " + "YGMeasureModeUndefined"); (performLayout ? layoutMarkerData.layouts : layoutMarkerData.measures) += 1; @@ -2793,8 +2463,8 @@ static void YGNodelayoutImpl( node->setLayoutBorder(node->getLeadingBorder(flexRowDirection), startEdge); node->setLayoutBorder(node->getTrailingBorder(flexRowDirection), endEdge); node->setLayoutBorder(node->getLeadingBorder(flexColumnDirection), YGEdgeTop); - node->setLayoutBorder( - node->getTrailingBorder(flexColumnDirection), YGEdgeBottom); + node->setLayoutBorder(node->getTrailingBorder(flexColumnDirection), + YGEdgeBottom); node->setLayoutPadding( node->getLeadingPadding(flexRowDirection, ownerWidth).unwrap(), @@ -2810,29 +2480,17 @@ static void YGNodelayoutImpl( if (node->hasMeasureFunc()) { YGNodeWithMeasureFuncSetMeasuredDimensions( - node, - availableWidth, - availableHeight, - widthMeasureMode, - heightMeasureMode, - ownerWidth, - ownerHeight, - layoutMarkerData, - layoutContext, - reason); + node, availableWidth, availableHeight, widthMeasureMode, + heightMeasureMode, ownerWidth, ownerHeight, layoutMarkerData, + layoutContext, reason); return; } const uint32_t childCount = YGNodeGetChildCount(node); if (childCount == 0) { YGNodeEmptyContainerSetMeasuredDimensions( - node, - availableWidth, - availableHeight, - widthMeasureMode, - heightMeasureMode, - ownerWidth, - ownerHeight); + node, availableWidth, availableHeight, widthMeasureMode, + heightMeasureMode, ownerWidth, ownerHeight); return; } @@ -2840,13 +2498,8 @@ static void YGNodelayoutImpl( // if we already know the size if (!performLayout && YGNodeFixedSizeSetMeasuredDimensions( - node, - availableWidth, - availableHeight, - widthMeasureMode, - heightMeasureMode, - ownerWidth, - ownerHeight)) { + node, availableWidth, availableHeight, widthMeasureMode, + heightMeasureMode, ownerWidth, ownerHeight)) { return; } @@ -2921,23 +2574,14 @@ static void YGNodelayoutImpl( // STEP 3: DETERMINE FLEX BASIS FOR EACH ITEM float totalOuterFlexBasis = YGNodeComputeFlexBasisForChildren( - node, - availableInnerWidth, - availableInnerHeight, - widthMeasureMode, - heightMeasureMode, - direction, - mainAxis, - config, - performLayout, - layoutMarkerData, - layoutContext, - depth, - generationCount); + node, availableInnerWidth, availableInnerHeight, widthMeasureMode, + heightMeasureMode, direction, mainAxis, config, performLayout, + layoutMarkerData, layoutContext, depth, generationCount); - const bool flexBasisOverflows = measureModeMainDim == YGMeasureModeUndefined - ? false - : totalOuterFlexBasis > availableInnerMainDim; + const bool flexBasisOverflows = + measureModeMainDim == YGMeasureModeUndefined + ? false + : totalOuterFlexBasis > availableInnerMainDim; if (isNodeFlexWrap && flexBasisOverflows && measureModeMainDim == YGMeasureModeAtMost) { measureModeMainDim = YGMeasureModeExactly; @@ -2960,13 +2604,8 @@ static void YGNodelayoutImpl( for (; endOfLineIndex < childCount; lineCount++, startOfLineIndex = endOfLineIndex) { collectedFlexItemsValues = YGCalculateCollectFlexItemsRowValues( - node, - ownerDirection, - mainAxisownerSize, - availableInnerWidth, - availableInnerMainDim, - startOfLineIndex, - lineCount); + node, ownerDirection, mainAxisownerSize, availableInnerWidth, + availableInnerMainDim, startOfLineIndex, lineCount); endOfLineIndex = collectedFlexItemsValues.endOfLineIndex; // If we don't need to measure the cross axis, we can skip the entire flex @@ -2987,10 +2626,9 @@ static void YGNodelayoutImpl( collectedFlexItemsValues.sizeConsumedOnCurrentLine < minInnerMainDim) { availableInnerMainDim = minInnerMainDim; - } else if ( - !YGFloatIsUndefined(maxInnerMainDim) && - collectedFlexItemsValues.sizeConsumedOnCurrentLine > - maxInnerMainDim) { + } else if (!YGFloatIsUndefined(maxInnerMainDim) && + collectedFlexItemsValues.sizeConsumedOnCurrentLine > + maxInnerMainDim) { availableInnerMainDim = maxInnerMainDim; } else { if (!node->getConfig()->useLegacyStretchBehaviour && @@ -3014,7 +2652,8 @@ static void YGNodelayoutImpl( } if (!sizeBasedOnContent && !YGFloatIsUndefined(availableInnerMainDim)) { - collectedFlexItemsValues.remainingFreeSpace = availableInnerMainDim - + collectedFlexItemsValues.remainingFreeSpace = + availableInnerMainDim - collectedFlexItemsValues.sizeConsumedOnCurrentLine; } else if (collectedFlexItemsValues.sizeConsumedOnCurrentLine < 0) { // availableInnerMainDim is indefinite which means the node is being sized @@ -3027,23 +2666,11 @@ static void YGNodelayoutImpl( if (!canSkipFlex) { YGResolveFlexibleLength( - node, - collectedFlexItemsValues, - mainAxis, - crossAxis, - mainAxisownerSize, - availableInnerMainDim, - availableInnerCrossDim, - availableInnerWidth, - availableInnerHeight, - flexBasisOverflows, - measureModeCrossDim, - performLayout, - config, - layoutMarkerData, - layoutContext, - depth, - generationCount); + node, collectedFlexItemsValues, mainAxis, crossAxis, + mainAxisownerSize, availableInnerMainDim, availableInnerCrossDim, + availableInnerWidth, availableInnerHeight, flexBasisOverflows, + measureModeCrossDim, performLayout, config, layoutMarkerData, + layoutContext, depth, generationCount); } node->setLayoutHadOverflow( @@ -3057,34 +2684,21 @@ static void YGNodelayoutImpl( // of items that are aligned "stretch". We need to compute these stretch // values and set the final positions. - YGJustifyMainAxis( - node, - collectedFlexItemsValues, - startOfLineIndex, - mainAxis, - crossAxis, - measureModeMainDim, - measureModeCrossDim, - mainAxisownerSize, - ownerWidth, - availableInnerMainDim, - availableInnerCrossDim, - availableInnerWidth, - performLayout, - layoutContext); + YGJustifyMainAxis(node, collectedFlexItemsValues, startOfLineIndex, + mainAxis, crossAxis, measureModeMainDim, + measureModeCrossDim, mainAxisownerSize, ownerWidth, + availableInnerMainDim, availableInnerCrossDim, + availableInnerWidth, performLayout, layoutContext); float containerCrossAxis = availableInnerCrossDim; if (measureModeCrossDim == YGMeasureModeUndefined || measureModeCrossDim == YGMeasureModeAtMost) { // Compute the cross axis from the max cross dimension of the children. - containerCrossAxis = - YGNodeBoundAxis( - node, - crossAxis, - collectedFlexItemsValues.crossDim + paddingAndBorderAxisCross, - crossAxisownerSize, - ownerWidth) - - paddingAndBorderAxisCross; + containerCrossAxis = YGNodeBoundAxis(node, crossAxis, + collectedFlexItemsValues.crossDim + + paddingAndBorderAxisCross, + crossAxisownerSize, ownerWidth) - + paddingAndBorderAxisCross; } // If there's no flex wrap, the cross dimension is defined by the container. @@ -3095,11 +2709,9 @@ static void YGNodelayoutImpl( // Clamp to the min/max size specified on the container. collectedFlexItemsValues.crossDim = YGNodeBoundAxis( - node, - crossAxis, + node, crossAxis, collectedFlexItemsValues.crossDim + paddingAndBorderAxisCross, - crossAxisownerSize, - ownerWidth) - + crossAxisownerSize, ownerWidth) - paddingAndBorderAxisCross; // STEP 7: CROSS-AXIS ALIGNMENT @@ -3151,18 +2763,21 @@ static void YGNodelayoutImpl( child->marginTrailingValue(crossAxis).unit != YGUnitAuto) { // If the child defines a definite size for its cross axis, there's // no need to stretch. - if (!YGNodeIsStyleDimDefined( - child, crossAxis, availableInnerCrossDim)) { + if (!YGNodeIsStyleDimDefined(child, crossAxis, + availableInnerCrossDim)) { float childMainSize = child->getLayout().measuredDimensions[dim[mainAxis]]; const auto& childStyle = child->getStyle(); - float childCrossSize = !childStyle.aspectRatio().isUndefined() - ? child->getMarginForAxis(crossAxis, availableInnerWidth) - .unwrap() + - (isMainAxisRow - ? childMainSize / childStyle.aspectRatio().unwrap() - : childMainSize * childStyle.aspectRatio().unwrap()) - : collectedFlexItemsValues.crossDim; + float childCrossSize = + !childStyle.aspectRatio().isUndefined() + ? child->getMarginForAxis(crossAxis, availableInnerWidth) + .unwrap() + + (isMainAxisRow + ? childMainSize / + childStyle.aspectRatio().unwrap() + : childMainSize * + childStyle.aspectRatio().unwrap()) + : collectedFlexItemsValues.crossDim; childMainSize += child->getMarginForAxis(mainAxis, availableInnerWidth) @@ -3170,20 +2785,12 @@ static void YGNodelayoutImpl( YGMeasureMode childMainMeasureMode = YGMeasureModeExactly; YGMeasureMode childCrossMeasureMode = YGMeasureModeExactly; + YGConstrainMaxSizeForMode(child, mainAxis, availableInnerMainDim, + availableInnerWidth, + &childMainMeasureMode, &childMainSize); YGConstrainMaxSizeForMode( - child, - mainAxis, - availableInnerMainDim, - availableInnerWidth, - &childMainMeasureMode, - &childMainSize); - YGConstrainMaxSizeForMode( - child, - crossAxis, - availableInnerCrossDim, - availableInnerWidth, - &childCrossMeasureMode, - &childCrossSize); + child, crossAxis, availableInnerCrossDim, availableInnerWidth, + &childCrossMeasureMode, &childCrossSize); const float childWidth = isMainAxisRow ? childMainSize : childCrossSize; @@ -3195,44 +2802,35 @@ static void YGNodelayoutImpl( alignContent != YGAlignStretch && isNodeFlexWrap; const YGMeasureMode childWidthMeasureMode = YGFloatIsUndefined(childWidth) || - (!isMainAxisRow && crossAxisDoesNotGrow) - ? YGMeasureModeUndefined - : YGMeasureModeExactly; + (!isMainAxisRow && crossAxisDoesNotGrow) + ? YGMeasureModeUndefined + : YGMeasureModeExactly; const YGMeasureMode childHeightMeasureMode = YGFloatIsUndefined(childHeight) || - (isMainAxisRow && crossAxisDoesNotGrow) - ? YGMeasureModeUndefined - : YGMeasureModeExactly; + (isMainAxisRow && crossAxisDoesNotGrow) + ? YGMeasureModeUndefined + : YGMeasureModeExactly; YGLayoutNodeInternal( - child, - childWidth, - childHeight, - direction, - childWidthMeasureMode, - childHeightMeasureMode, - availableInnerWidth, - availableInnerHeight, - true, - LayoutPassReason::kStretch, - config, - layoutMarkerData, - layoutContext, - depth, - generationCount); + child, childWidth, childHeight, direction, + childWidthMeasureMode, childHeightMeasureMode, + availableInnerWidth, availableInnerHeight, true, + LayoutPassReason::kStretch, config, layoutMarkerData, + layoutContext, depth, generationCount); } } else { - const float remainingCrossDim = containerCrossAxis - + const float remainingCrossDim = + containerCrossAxis - YGNodeDimWithMargin(child, crossAxis, availableInnerWidth); if (child->marginLeadingValue(crossAxis).unit == YGUnitAuto && child->marginTrailingValue(crossAxis).unit == YGUnitAuto) { leadingCrossDim += YGFloatMax(0.0f, remainingCrossDim / 2); - } else if ( - child->marginTrailingValue(crossAxis).unit == YGUnitAuto) { + } else if (child->marginTrailingValue(crossAxis).unit == + YGUnitAuto) { // No-Op - } else if ( - child->marginLeadingValue(crossAxis).unit == YGUnitAuto) { + } else if (child->marginLeadingValue(crossAxis).unit == + YGUnitAuto) { leadingCrossDim += YGFloatMax(0.0f, remainingCrossDim); } else if (alignItem == YGAlignFlexStart) { // No-Op @@ -3243,10 +2841,9 @@ static void YGNodelayoutImpl( } } // And we apply the position - child->setLayoutPosition( - child->getLayout().position[pos[crossAxis]] + totalLineCrossDim + - leadingCrossDim, - pos[crossAxis]); + child->setLayoutPosition(child->getLayout().position[pos[crossAxis]] + + totalLineCrossDim + leadingCrossDim, + pos[crossAxis]); } } } @@ -3324,15 +2921,15 @@ static void YGNodelayoutImpl( } if (YGNodeAlignItem(node, child) == YGAlignBaseline) { const float ascent = YGBaseline(child, layoutContext) + - child - ->getLeadingMargin( - YGFlexDirectionColumn, availableInnerWidth) - .unwrap(); + child + ->getLeadingMargin(YGFlexDirectionColumn, + availableInnerWidth) + .unwrap(); const float descent = child->getLayout().measuredDimensions[YGDimensionHeight] + child - ->getMarginForAxis( - YGFlexDirectionColumn, availableInnerWidth) + ->getMarginForAxis(YGFlexDirectionColumn, + availableInnerWidth) .unwrap() - ascent; maxAscentForCurrentLine = @@ -3390,21 +2987,27 @@ static void YGNodelayoutImpl( // Remeasure child with the line height as it as been only // measured with the owners height yet. - if (!YGNodeIsStyleDimDefined( - child, crossAxis, availableInnerCrossDim)) { - const float childWidth = isMainAxisRow - ? (child->getLayout() - .measuredDimensions[YGDimensionWidth] + - child->getMarginForAxis(mainAxis, availableInnerWidth) - .unwrap()) - : lineHeight; + if (!YGNodeIsStyleDimDefined(child, crossAxis, + availableInnerCrossDim)) { + const float childWidth = + isMainAxisRow + ? (child->getLayout() + .measuredDimensions[YGDimensionWidth] + + child + ->getMarginForAxis(mainAxis, + availableInnerWidth) + .unwrap()) + : lineHeight; - const float childHeight = !isMainAxisRow - ? (child->getLayout() - .measuredDimensions[YGDimensionHeight] + - child->getMarginForAxis(crossAxis, availableInnerWidth) - .unwrap()) - : lineHeight; + const float childHeight = + !isMainAxisRow + ? (child->getLayout() + .measuredDimensions[YGDimensionHeight] + + child + ->getMarginForAxis(crossAxis, + availableInnerWidth) + .unwrap()) + : lineHeight; if (!(YGFloatsEqual( childWidth, @@ -3415,20 +3018,11 @@ static void YGNodelayoutImpl( child->getLayout() .measuredDimensions[YGDimensionHeight]))) { YGLayoutNodeInternal( - child, - childWidth, - childHeight, - direction, - YGMeasureModeExactly, - YGMeasureModeExactly, - availableInnerWidth, - availableInnerHeight, - true, - LayoutPassReason::kMultilineStretch, - config, - layoutMarkerData, - layoutContext, - depth, + child, childWidth, childHeight, direction, + YGMeasureModeExactly, YGMeasureModeExactly, + availableInnerWidth, availableInnerHeight, true, + LayoutPassReason::kMultilineStretch, config, + layoutMarkerData, layoutContext, depth, generationCount); } } @@ -3439,8 +3033,8 @@ static void YGNodelayoutImpl( currentLead + maxAscentForCurrentLine - YGBaseline(child, layoutContext) + child - ->getLeadingPosition( - YGFlexDirectionColumn, availableInnerCrossDim) + ->getLeadingPosition(YGFlexDirectionColumn, + availableInnerCrossDim) .unwrap(), YGEdgeTop); @@ -3461,21 +3055,14 @@ static void YGNodelayoutImpl( // STEP 9: COMPUTING FINAL DIMENSIONS node->setLayoutMeasuredDimension( - YGNodeBoundAxis( - node, - YGFlexDirectionRow, - availableWidth - marginAxisRow, - ownerWidth, - ownerWidth), + YGNodeBoundAxis(node, YGFlexDirectionRow, availableWidth - marginAxisRow, + ownerWidth, ownerWidth), YGDimensionWidth); node->setLayoutMeasuredDimension( - YGNodeBoundAxis( - node, - YGFlexDirectionColumn, - availableHeight - marginAxisColumn, - ownerHeight, - ownerWidth), + YGNodeBoundAxis(node, YGFlexDirectionColumn, + availableHeight - marginAxisColumn, ownerHeight, + ownerWidth), YGDimensionHeight); // If the user didn't specify a width or height for the node, set the @@ -3486,23 +3073,19 @@ static void YGNodelayoutImpl( // 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( - YGNodeBoundAxis( - node, mainAxis, maxLineMainDim, mainAxisownerSize, ownerWidth), + YGNodeBoundAxis(node, mainAxis, maxLineMainDim, mainAxisownerSize, + ownerWidth), dim[mainAxis]); - } else if ( - measureModeMainDim == YGMeasureModeAtMost && - node->getStyle().overflow() == YGOverflowScroll) { + } else if (measureModeMainDim == YGMeasureModeAtMost && + node->getStyle().overflow() == YGOverflowScroll) { node->setLayoutMeasuredDimension( YGFloatMax( - YGFloatMin( - availableInnerMainDim + paddingAndBorderAxisMain, - YGNodeBoundAxisWithinMinAndMax( - node, - mainAxis, - YGFloatOptional{maxLineMainDim}, - mainAxisownerSize) - .unwrap()), + YGFloatMin(availableInnerMainDim + paddingAndBorderAxisMain, + YGNodeBoundAxisWithinMinAndMax( + node, mainAxis, YGFloatOptional{maxLineMainDim}, + mainAxisownerSize) + .unwrap()), paddingAndBorderAxisMain), dim[mainAxis]); } @@ -3513,28 +3096,22 @@ static void YGNodelayoutImpl( // 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( - YGNodeBoundAxis( - node, - crossAxis, - totalLineCrossDim + paddingAndBorderAxisCross, - crossAxisownerSize, - ownerWidth), + YGNodeBoundAxis(node, crossAxis, + totalLineCrossDim + paddingAndBorderAxisCross, + crossAxisownerSize, ownerWidth), dim[crossAxis]); - } else if ( - measureModeCrossDim == YGMeasureModeAtMost && - node->getStyle().overflow() == YGOverflowScroll) { + } else if (measureModeCrossDim == YGMeasureModeAtMost && + node->getStyle().overflow() == YGOverflowScroll) { node->setLayoutMeasuredDimension( YGFloatMax( - YGFloatMin( - availableInnerCrossDim + paddingAndBorderAxisCross, - YGNodeBoundAxisWithinMinAndMax( - node, - crossAxis, - YGFloatOptional{ - totalLineCrossDim + paddingAndBorderAxisCross}, - crossAxisownerSize) - .unwrap()), + YGFloatMin(availableInnerCrossDim + paddingAndBorderAxisCross, + YGNodeBoundAxisWithinMinAndMax( + node, crossAxis, + YGFloatOptional{totalLineCrossDim + + paddingAndBorderAxisCross}, + crossAxisownerSize) + .unwrap()), paddingAndBorderAxisCross), dim[crossAxis]); } @@ -3561,23 +3138,17 @@ static void YGNodelayoutImpl( continue; } YGNodeAbsoluteLayoutChild( - node, - child, - availableInnerWidth, + node, child, availableInnerWidth, isMainAxisRow ? measureModeMainDim : measureModeCrossDim, - availableInnerHeight, - direction, - config, - layoutMarkerData, - layoutContext, - depth, - generationCount); + availableInnerHeight, direction, config, layoutMarkerData, + layoutContext, depth, generationCount); } // STEP 11: SETTING TRAILING POSITIONS FOR CHILDREN const bool needsMainTrailingPos = mainAxis == YGFlexDirectionRowReverse || - mainAxis == YGFlexDirectionColumnReverse; - const bool needsCrossTrailingPos = crossAxis == YGFlexDirectionRowReverse || + mainAxis == YGFlexDirectionColumnReverse; + const bool needsCrossTrailingPos = + crossAxis == YGFlexDirectionRowReverse || crossAxis == YGFlexDirectionColumnReverse; // Set trailing position if necessary. @@ -3614,13 +3185,12 @@ static const char* YGSpacer(const unsigned long level) { } } -static const char* YGMeasureModeName( - const YGMeasureMode mode, - const bool performLayout) { +static const char* YGMeasureModeName(const YGMeasureMode mode, + const bool performLayout) { constexpr auto N = enums::count(); const char* kMeasureModeNames[N] = {"UNDEFINED", "EXACTLY", "AT_MOST"}; - const char* kLayoutModeNames[N] = { - "LAY_UNDEFINED", "LAY_EXACTLY", "LAY_AT_MOST"}; + const char* kLayoutModeNames[N] = {"LAY_UNDEFINED", "LAY_EXACTLY", + "LAY_AT_MOST"}; if (mode >= N) { return ""; @@ -3630,42 +3200,34 @@ static const char* YGMeasureModeName( } static inline bool YGMeasureModeSizeIsExactAndMatchesOldMeasuredSize( - YGMeasureMode sizeMode, - float size, - float lastComputedSize) { + YGMeasureMode sizeMode, float size, float lastComputedSize) { return sizeMode == YGMeasureModeExactly && - YGFloatsEqual(size, lastComputedSize); + YGFloatsEqual(size, lastComputedSize); } static inline bool YGMeasureModeOldSizeIsUnspecifiedAndStillFits( - YGMeasureMode sizeMode, - float size, - YGMeasureMode lastSizeMode, + YGMeasureMode sizeMode, float size, YGMeasureMode lastSizeMode, float lastComputedSize) { return sizeMode == YGMeasureModeAtMost && - lastSizeMode == YGMeasureModeUndefined && - (size >= lastComputedSize || YGFloatsEqual(size, lastComputedSize)); + lastSizeMode == YGMeasureModeUndefined && + (size >= lastComputedSize || YGFloatsEqual(size, lastComputedSize)); } static inline bool YGMeasureModeNewMeasureSizeIsStricterAndStillValid( - YGMeasureMode sizeMode, - float size, - YGMeasureMode lastSizeMode, - float lastSize, - float lastComputedSize) { + YGMeasureMode sizeMode, float size, YGMeasureMode lastSizeMode, + float lastSize, float lastComputedSize) { return lastSizeMode == YGMeasureModeAtMost && - sizeMode == YGMeasureModeAtMost && !YGFloatIsUndefined(lastSize) && - !YGFloatIsUndefined(size) && !YGFloatIsUndefined(lastComputedSize) && - lastSize > size && - (lastComputedSize <= size || YGFloatsEqual(size, lastComputedSize)); + sizeMode == YGMeasureModeAtMost && !YGFloatIsUndefined(lastSize) && + !YGFloatIsUndefined(size) && !YGFloatIsUndefined(lastComputedSize) && + lastSize > size && + (lastComputedSize <= size || YGFloatsEqual(size, lastComputedSize)); } -YOGA_EXPORT float YGRoundValueToPixelGrid( - const double value, - const double pointScaleFactor, - const bool forceCeil, - const bool forceFloor) { - double scaledValue = ((double) value) * pointScaleFactor; +YOGA_EXPORT float YGRoundValueToPixelGrid(const double value, + const double pointScaleFactor, + const bool forceCeil, + const bool forceFloor) { + double scaledValue = ((double)value) * pointScaleFactor; // We want to calculate `fractial` such that `floor(scaledValue) = scaledValue // - fractial`. double fractial = fmod(scaledValue, 1.0f); @@ -3700,55 +3262,54 @@ YOGA_EXPORT float YGRoundValueToPixelGrid( } else { // Finally we just round the value scaledValue = scaledValue - fractial + - (!YGFloatIsUndefined(fractial) && - (fractial > 0.5f || YGDoubleEqual(fractial, 0.5f)) - ? 1.0f - : 0.0f); + (!YGFloatIsUndefined(fractial) && + (fractial > 0.5f || YGDoubleEqual(fractial, 0.5f)) + ? 1.0f + : 0.0f); } return (YGFloatIsUndefined(scaledValue) || YGFloatIsUndefined(pointScaleFactor)) - ? YGUndefined - : scaledValue / pointScaleFactor; + ? YGUndefined + : scaledValue / pointScaleFactor; } YOGA_EXPORT bool YGNodeCanUseCachedMeasurement( - const YGMeasureMode widthMode, - const float width, - const YGMeasureMode heightMode, - const float height, - const YGMeasureMode lastWidthMode, - const float lastWidth, - const YGMeasureMode lastHeightMode, - const float lastHeight, - const float lastComputedWidth, - const float lastComputedHeight, - const float marginRow, - const float marginColumn, - const YGConfigRef config) { + const YGMeasureMode widthMode, const float width, + const YGMeasureMode heightMode, const float height, + const YGMeasureMode lastWidthMode, const float lastWidth, + const YGMeasureMode lastHeightMode, const float lastHeight, + const float lastComputedWidth, const float lastComputedHeight, + const float marginRow, const float marginColumn, const YGConfigRef config) { if ((!YGFloatIsUndefined(lastComputedHeight) && lastComputedHeight < 0) || (!YGFloatIsUndefined(lastComputedWidth) && lastComputedWidth < 0)) { return false; } bool useRoundedComparison = config != nullptr && config->pointScaleFactor != 0; - const float effectiveWidth = useRoundedComparison - ? YGRoundValueToPixelGrid(width, config->pointScaleFactor, false, false) - : width; - const float effectiveHeight = useRoundedComparison - ? YGRoundValueToPixelGrid(height, config->pointScaleFactor, false, false) - : height; - const float effectiveLastWidth = useRoundedComparison - ? YGRoundValueToPixelGrid( - lastWidth, config->pointScaleFactor, false, false) - : lastWidth; - const float effectiveLastHeight = useRoundedComparison - ? YGRoundValueToPixelGrid( - lastHeight, config->pointScaleFactor, false, false) - : lastHeight; + const float effectiveWidth = + useRoundedComparison ? YGRoundValueToPixelGrid( + width, config->pointScaleFactor, false, false) + : width; + const float effectiveHeight = + useRoundedComparison ? YGRoundValueToPixelGrid( + height, config->pointScaleFactor, false, false) + : height; + const float effectiveLastWidth = + useRoundedComparison + ? YGRoundValueToPixelGrid(lastWidth, config->pointScaleFactor, false, + false) + : lastWidth; + const float effectiveLastHeight = + useRoundedComparison + ? YGRoundValueToPixelGrid(lastHeight, config->pointScaleFactor, false, + false) + : lastHeight; - const bool hasSameWidthSpec = lastWidthMode == widthMode && + const bool hasSameWidthSpec = + lastWidthMode == widthMode && YGFloatsEqual(effectiveLastWidth, effectiveWidth); - const bool hasSameHeightSpec = lastHeightMode == heightMode && + const bool hasSameHeightSpec = + lastHeightMode == heightMode && YGFloatsEqual(effectiveLastHeight, effectiveHeight); const bool widthIsCompatible = @@ -3758,10 +3319,7 @@ YOGA_EXPORT bool YGNodeCanUseCachedMeasurement( YGMeasureModeOldSizeIsUnspecifiedAndStillFits( widthMode, width - marginRow, lastWidthMode, lastComputedWidth) || YGMeasureModeNewMeasureSizeIsStricterAndStillValid( - widthMode, - width - marginRow, - lastWidthMode, - lastWidth, + widthMode, width - marginRow, lastWidthMode, lastWidth, lastComputedWidth); const bool heightIsCompatible = @@ -3769,15 +3327,10 @@ YOGA_EXPORT bool YGNodeCanUseCachedMeasurement( YGMeasureModeSizeIsExactAndMatchesOldMeasuredSize( heightMode, height - marginColumn, lastComputedHeight) || YGMeasureModeOldSizeIsUnspecifiedAndStillFits( - heightMode, - height - marginColumn, - lastHeightMode, + heightMode, height - marginColumn, lastHeightMode, lastComputedHeight) || YGMeasureModeNewMeasureSizeIsStricterAndStillValid( - heightMode, - height - marginColumn, - lastHeightMode, - lastHeight, + heightMode, height - marginColumn, lastHeightMode, lastHeight, lastComputedHeight); return widthIsCompatible && heightIsCompatible; @@ -3792,20 +3345,12 @@ YOGA_EXPORT bool YGNodeCanUseCachedMeasurement( // Return parameter is true if layout was performed, false if skipped // bool YGLayoutNodeInternal( - const YGNodeRef node, - const float availableWidth, - const float availableHeight, - const YGDirection ownerDirection, - const YGMeasureMode widthMeasureMode, - const YGMeasureMode heightMeasureMode, - const float ownerWidth, - const float ownerHeight, - const bool performLayout, - const LayoutPassReason reason, - const YGConfigRef config, - LayoutData& layoutMarkerData, - void* const layoutContext, - uint32_t depth, + const YGNodeRef node, const float availableWidth, + const float availableHeight, const YGDirection ownerDirection, + const YGMeasureMode widthMeasureMode, const YGMeasureMode heightMeasureMode, + const float ownerWidth, const float ownerHeight, const bool performLayout, + const LayoutPassReason reason, const YGConfigRef config, + LayoutData& layoutMarkerData, void* const layoutContext, uint32_t depth, const uint32_t generationCount) { YGLayout* layout = &node->getLayout(); @@ -3844,37 +3389,27 @@ bool YGLayoutNodeInternal( // First, try to use the layout cache. if (YGNodeCanUseCachedMeasurement( - widthMeasureMode, - availableWidth, - heightMeasureMode, - availableHeight, - layout->cachedLayout.widthMeasureMode, + widthMeasureMode, availableWidth, heightMeasureMode, + availableHeight, layout->cachedLayout.widthMeasureMode, layout->cachedLayout.availableWidth, layout->cachedLayout.heightMeasureMode, layout->cachedLayout.availableHeight, layout->cachedLayout.computedWidth, - layout->cachedLayout.computedHeight, - marginAxisRow, - marginAxisColumn, - config)) { + layout->cachedLayout.computedHeight, marginAxisRow, + marginAxisColumn, config)) { cachedResults = &layout->cachedLayout; } else { // Try to use the measurement cache. for (uint32_t i = 0; i < layout->nextCachedMeasurementsIndex; i++) { if (YGNodeCanUseCachedMeasurement( - widthMeasureMode, - availableWidth, - heightMeasureMode, - availableHeight, - layout->cachedMeasurements[i].widthMeasureMode, + widthMeasureMode, availableWidth, heightMeasureMode, + availableHeight, layout->cachedMeasurements[i].widthMeasureMode, layout->cachedMeasurements[i].availableWidth, layout->cachedMeasurements[i].heightMeasureMode, layout->cachedMeasurements[i].availableHeight, layout->cachedMeasurements[i].computedWidth, - layout->cachedMeasurements[i].computedHeight, - marginAxisRow, - marginAxisColumn, - config)) { + layout->cachedMeasurements[i].computedHeight, marginAxisRow, + marginAxisColumn, config)) { cachedResults = &layout->cachedMeasurements[i]; break; } @@ -3889,10 +3424,10 @@ bool YGLayoutNodeInternal( } } else { for (uint32_t i = 0; i < layout->nextCachedMeasurementsIndex; i++) { - if (YGFloatsEqual( - layout->cachedMeasurements[i].availableWidth, availableWidth) && - YGFloatsEqual( - layout->cachedMeasurements[i].availableHeight, availableHeight) && + if (YGFloatsEqual(layout->cachedMeasurements[i].availableWidth, + availableWidth) && + YGFloatsEqual(layout->cachedMeasurements[i].availableHeight, + availableHeight) && layout->cachedMeasurements[i].widthMeasureMode == widthMeasureMode && layout->cachedMeasurements[i].heightMeasureMode == heightMeasureMode) { @@ -3911,94 +3446,52 @@ bool YGLayoutNodeInternal( : layoutMarkerData.cachedMeasures) += 1; if (gPrintChanges && gPrintSkips) { - Log::log( - node, - YGLogLevelVerbose, - nullptr, - "%s%d.{[skipped] ", - YGSpacer(depth), - depth); + Log::log(node, YGLogLevelVerbose, nullptr, "%s%d.{[skipped] ", + YGSpacer(depth), depth); node->print(layoutContext); - Log::log( - node, - YGLogLevelVerbose, - nullptr, - "wm: %s, hm: %s, aw: %f ah: %f => d: (%f, %f) %s\n", - YGMeasureModeName(widthMeasureMode, performLayout), - YGMeasureModeName(heightMeasureMode, performLayout), - availableWidth, - availableHeight, - cachedResults->computedWidth, - cachedResults->computedHeight, - LayoutPassReasonToString(reason)); + Log::log(node, YGLogLevelVerbose, nullptr, + "wm: %s, hm: %s, aw: %f ah: %f => d: (%f, %f) %s\n", + YGMeasureModeName(widthMeasureMode, performLayout), + YGMeasureModeName(heightMeasureMode, performLayout), + availableWidth, availableHeight, cachedResults->computedWidth, + cachedResults->computedHeight, LayoutPassReasonToString(reason)); } } else { if (gPrintChanges) { - Log::log( - node, - YGLogLevelVerbose, - nullptr, - "%s%d.{%s", - YGSpacer(depth), - depth, - needToVisitNode ? "*" : ""); + Log::log(node, YGLogLevelVerbose, nullptr, "%s%d.{%s", YGSpacer(depth), + depth, needToVisitNode ? "*" : ""); node->print(layoutContext); - Log::log( - node, - YGLogLevelVerbose, - nullptr, - "wm: %s, hm: %s, aw: %f ah: %f %s\n", - YGMeasureModeName(widthMeasureMode, performLayout), - YGMeasureModeName(heightMeasureMode, performLayout), - availableWidth, - availableHeight, - LayoutPassReasonToString(reason)); + Log::log(node, YGLogLevelVerbose, nullptr, + "wm: %s, hm: %s, aw: %f ah: %f %s\n", + YGMeasureModeName(widthMeasureMode, performLayout), + YGMeasureModeName(heightMeasureMode, performLayout), + availableWidth, availableHeight, + LayoutPassReasonToString(reason)); } - YGNodelayoutImpl( - node, - availableWidth, - availableHeight, - ownerDirection, - widthMeasureMode, - heightMeasureMode, - ownerWidth, - ownerHeight, - performLayout, - config, - layoutMarkerData, - layoutContext, - depth, - generationCount, - reason); + YGNodelayoutImpl(node, availableWidth, availableHeight, ownerDirection, + widthMeasureMode, heightMeasureMode, ownerWidth, + ownerHeight, performLayout, config, layoutMarkerData, + layoutContext, depth, generationCount, reason); if (gPrintChanges) { - Log::log( - node, - YGLogLevelVerbose, - nullptr, - "%s%d.}%s", - YGSpacer(depth), - depth, - needToVisitNode ? "*" : ""); + Log::log(node, YGLogLevelVerbose, nullptr, "%s%d.}%s", YGSpacer(depth), + depth, needToVisitNode ? "*" : ""); node->print(layoutContext); - Log::log( - node, - YGLogLevelVerbose, - nullptr, - "wm: %s, hm: %s, d: (%f, %f) %s\n", - YGMeasureModeName(widthMeasureMode, performLayout), - YGMeasureModeName(heightMeasureMode, performLayout), - layout->measuredDimensions[YGDimensionWidth], - layout->measuredDimensions[YGDimensionHeight], - LayoutPassReasonToString(reason)); + Log::log(node, YGLogLevelVerbose, nullptr, + "wm: %s, hm: %s, d: (%f, %f) %s\n", + YGMeasureModeName(widthMeasureMode, performLayout), + YGMeasureModeName(heightMeasureMode, performLayout), + layout->measuredDimensions[YGDimensionWidth], + layout->measuredDimensions[YGDimensionHeight], + LayoutPassReasonToString(reason)); } layout->lastOwnerDirection = ownerDirection; if (cachedResults == nullptr) { if (layout->nextCachedMeasurementsIndex + 1 > - (uint32_t) layoutMarkerData.maxMeasureCache) { + (uint32_t)layoutMarkerData.maxMeasureCache) { layoutMarkerData.maxMeasureCache = layout->nextCachedMeasurementsIndex + 1; } @@ -4048,8 +3541,8 @@ bool YGLayoutNodeInternal( LayoutType layoutType; if (performLayout) { layoutType = !needToVisitNode && cachedResults == &layout->cachedLayout - ? LayoutType::kCachedLayout - : LayoutType::kLayout; + ? LayoutType::kCachedLayout + : LayoutType::kLayout; } else { layoutType = cachedResults != nullptr ? LayoutType::kCachedMeasure : LayoutType::kMeasure; @@ -4059,13 +3552,10 @@ bool YGLayoutNodeInternal( return (needToVisitNode || cachedResults == nullptr); } -YOGA_EXPORT void YGConfigSetPointScaleFactor( - const YGConfigRef config, - const float pixelsInPoint) { - YGAssertWithConfig( - config, - pixelsInPoint >= 0.0f, - "Scale factor should not be less than zero"); +YOGA_EXPORT void YGConfigSetPointScaleFactor(const YGConfigRef config, + const float pixelsInPoint) { + YGAssertWithConfig(config, pixelsInPoint >= 0.0f, + "Scale factor should not be less than zero"); // We store points for Pixel as we will use it for rounding if (pixelsInPoint == 0.0f) { @@ -4076,11 +3566,10 @@ YOGA_EXPORT void YGConfigSetPointScaleFactor( } } -static void YGRoundToPixelGrid( - const YGNodeRef node, - const double pointScaleFactor, - const double absoluteLeft, - const double absoluteTop) { +static void YGRoundToPixelGrid(const YGNodeRef node, + const double pointScaleFactor, + const double absoluteLeft, + const double absoluteTop) { if (pointScaleFactor == 0.0f) { return; } @@ -4120,32 +3609,25 @@ static void YGRoundToPixelGrid( !YGDoubleEqual(fmod(nodeHeight * pointScaleFactor, 1.0), 1.0); node->setLayoutDimension( - YGRoundValueToPixelGrid( - absoluteNodeRight, - pointScaleFactor, - (textRounding && hasFractionalWidth), - (textRounding && !hasFractionalWidth)) - - YGRoundValueToPixelGrid( - absoluteNodeLeft, pointScaleFactor, false, textRounding), + YGRoundValueToPixelGrid(absoluteNodeRight, pointScaleFactor, + (textRounding && hasFractionalWidth), + (textRounding && !hasFractionalWidth)) - + YGRoundValueToPixelGrid(absoluteNodeLeft, pointScaleFactor, false, + textRounding), YGDimensionWidth); node->setLayoutDimension( - YGRoundValueToPixelGrid( - absoluteNodeBottom, - pointScaleFactor, - (textRounding && hasFractionalHeight), - (textRounding && !hasFractionalHeight)) - - YGRoundValueToPixelGrid( - absoluteNodeTop, pointScaleFactor, false, textRounding), + YGRoundValueToPixelGrid(absoluteNodeBottom, pointScaleFactor, + (textRounding && hasFractionalHeight), + (textRounding && !hasFractionalHeight)) - + YGRoundValueToPixelGrid(absoluteNodeTop, pointScaleFactor, false, + textRounding), YGDimensionHeight); const uint32_t childCount = YGNodeGetChildCount(node); for (uint32_t i = 0; i < childCount; i++) { - YGRoundToPixelGrid( - YGNodeGetChild(node, i), - pointScaleFactor, - absoluteNodeLeft, - absoluteNodeTop); + YGRoundToPixelGrid(YGNodeGetChild(node, i), pointScaleFactor, + absoluteNodeLeft, absoluteNodeTop); } } @@ -4157,12 +3639,8 @@ static void unsetUseLegacyFlagRecursively(YGNodeRef node) { } YOGA_EXPORT void YGNodeCalculateLayoutWithContext( - const YGNodeRef node, - const float ownerWidth, - const float ownerHeight, - const YGDirection ownerDirection, - void* layoutContext) { - + const YGNodeRef node, const float ownerWidth, const float ownerHeight, + const YGDirection ownerDirection, void* layoutContext) { Event::publish(node, {layoutContext}); LayoutData markerData = {}; @@ -4175,11 +3653,10 @@ YOGA_EXPORT void YGNodeCalculateLayoutWithContext( YGMeasureMode widthMeasureMode = YGMeasureModeUndefined; const auto& maxDimensions = node->getStyle().maxDimensions(); if (YGNodeIsStyleDimDefined(node, YGFlexDirectionRow, ownerWidth)) { - width = - (YGResolveValue( - node->getResolvedDimension(dim[YGFlexDirectionRow]), ownerWidth) + - node->getMarginForAxis(YGFlexDirectionRow, ownerWidth)) - .unwrap(); + width = (YGResolveValue(node->getResolvedDimension(dim[YGFlexDirectionRow]), + ownerWidth) + + node->getMarginForAxis(YGFlexDirectionRow, ownerWidth)) + .unwrap(); widthMeasureMode = YGMeasureModeExactly; } else if (!YGResolveValue(maxDimensions[YGDimensionWidth], ownerWidth) .isUndefined()) { @@ -4195,11 +3672,11 @@ YOGA_EXPORT void YGNodeCalculateLayoutWithContext( float height = YGUndefined; YGMeasureMode heightMeasureMode = YGMeasureModeUndefined; if (YGNodeIsStyleDimDefined(node, YGFlexDirectionColumn, ownerHeight)) { - height = (YGResolveValue( - node->getResolvedDimension(dim[YGFlexDirectionColumn]), - ownerHeight) + - node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth)) - .unwrap(); + height = + (YGResolveValue(node->getResolvedDimension(dim[YGFlexDirectionColumn]), + ownerHeight) + + node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth)) + .unwrap(); heightMeasureMode = YGMeasureModeExactly; } else if (!YGResolveValue(maxDimensions[YGDimensionHeight], ownerHeight) .isUndefined()) { @@ -4212,32 +3689,21 @@ YOGA_EXPORT void YGNodeCalculateLayoutWithContext( : YGMeasureModeExactly; } if (YGLayoutNodeInternal( - node, - width, - height, - ownerDirection, - widthMeasureMode, - heightMeasureMode, - ownerWidth, - ownerHeight, - true, - LayoutPassReason::kInitial, - node->getConfig(), - markerData, + node, width, height, ownerDirection, widthMeasureMode, + heightMeasureMode, ownerWidth, ownerHeight, true, + LayoutPassReason::kInitial, node->getConfig(), markerData, layoutContext, - 0, // tree root + 0, // tree root gCurrentGenerationCount.load(std::memory_order_relaxed))) { - node->setPosition( - node->getLayout().direction(), ownerWidth, ownerHeight, ownerWidth); + node->setPosition(node->getLayout().direction(), ownerWidth, ownerHeight, + ownerWidth); YGRoundToPixelGrid(node, node->getConfig()->pointScaleFactor, 0.0f, 0.0f); #ifdef DEBUG if (node->getConfig()->printTree) { YGNodePrint( - node, - (YGPrintOptions)( - YGPrintOptionsLayout | YGPrintOptionsChildren | - YGPrintOptionsStyle)); + node, (YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsChildren | + YGPrintOptionsStyle)); } #endif } @@ -4262,31 +3728,18 @@ YOGA_EXPORT void YGNodeCalculateLayoutWithContext( unsetUseLegacyFlagRecursively(nodeWithoutLegacyFlag); LayoutData layoutMarkerData = {}; if (YGLayoutNodeInternal( - nodeWithoutLegacyFlag, - width, - height, - ownerDirection, - widthMeasureMode, - heightMeasureMode, - ownerWidth, - ownerHeight, - true, - LayoutPassReason::kInitial, - nodeWithoutLegacyFlag->getConfig(), - layoutMarkerData, - layoutContext, - 0, // tree root + nodeWithoutLegacyFlag, width, height, ownerDirection, + widthMeasureMode, heightMeasureMode, ownerWidth, ownerHeight, true, + LayoutPassReason::kInitial, nodeWithoutLegacyFlag->getConfig(), + layoutMarkerData, layoutContext, + 0, // tree root gCurrentGenerationCount.load(std::memory_order_relaxed))) { nodeWithoutLegacyFlag->setPosition( - nodeWithoutLegacyFlag->getLayout().direction(), - ownerWidth, - ownerHeight, - ownerWidth); - YGRoundToPixelGrid( - nodeWithoutLegacyFlag, - nodeWithoutLegacyFlag->getConfig()->pointScaleFactor, - 0.0f, - 0.0f); + nodeWithoutLegacyFlag->getLayout().direction(), ownerWidth, + ownerHeight, ownerWidth); + YGRoundToPixelGrid(nodeWithoutLegacyFlag, + nodeWithoutLegacyFlag->getConfig()->pointScaleFactor, + 0.0f, 0.0f); // Set whether the two layouts are different or not. auto neededLegacyStretchBehaviour = @@ -4297,9 +3750,8 @@ YOGA_EXPORT void YGNodeCalculateLayoutWithContext( if (nodeWithoutLegacyFlag->getConfig()->printTree) { YGNodePrint( nodeWithoutLegacyFlag, - (YGPrintOptions)( - YGPrintOptionsLayout | YGPrintOptionsChildren | - YGPrintOptionsStyle)); + (YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsChildren | + YGPrintOptionsStyle)); } #endif } @@ -4308,13 +3760,12 @@ YOGA_EXPORT void YGNodeCalculateLayoutWithContext( } } -YOGA_EXPORT void YGNodeCalculateLayout( - const YGNodeRef node, - const float ownerWidth, - const float ownerHeight, - const YGDirection ownerDirection) { - YGNodeCalculateLayoutWithContext( - node, ownerWidth, ownerHeight, ownerDirection, nullptr); +YOGA_EXPORT void YGNodeCalculateLayout(const YGNodeRef node, + const float ownerWidth, + const float ownerHeight, + const YGDirection ownerDirection) { + YGNodeCalculateLayoutWithContext(node, ownerWidth, ownerHeight, + ownerDirection, nullptr); } YOGA_EXPORT void YGConfigSetLogger(const YGConfigRef config, YGLogger logger) { @@ -4330,8 +3781,7 @@ YOGA_EXPORT void YGConfigSetLogger(const YGConfigRef config, YGLogger logger) { } YOGA_EXPORT void YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour( - const YGConfigRef config, - const bool shouldDiffLayout) { + const YGConfigRef config, const bool shouldDiffLayout) { config->shouldDiffLayoutWithoutLegacyStretchBehaviour = shouldDiffLayout; } @@ -4342,20 +3792,16 @@ void YGAssert(const bool condition, const char* message) { } } -void YGAssertWithNode( - const YGNodeRef node, - const bool condition, - const char* message) { +void YGAssertWithNode(const YGNodeRef node, const bool condition, + const char* message) { if (!condition) { Log::log(node, YGLogLevelFatal, nullptr, "%s\n", message); throwLogicalErrorWithMessage(message); } } -void YGAssertWithConfig( - const YGConfigRef config, - const bool condition, - const char* message) { +void YGAssertWithConfig(const YGConfigRef config, const bool condition, + const char* message) { if (!condition) { Log::log(config, YGLogLevelFatal, nullptr, "%s\n", message); throwLogicalErrorWithMessage(message); @@ -4363,27 +3809,23 @@ void YGAssertWithConfig( } YOGA_EXPORT void YGConfigSetExperimentalFeatureEnabled( - const YGConfigRef config, - const YGExperimentalFeature feature, + const YGConfigRef config, const YGExperimentalFeature feature, const bool enabled) { config->experimentalFeatures[feature] = enabled; } inline bool YGConfigIsExperimentalFeatureEnabled( - const YGConfigRef config, - const YGExperimentalFeature feature) { + const YGConfigRef config, const YGExperimentalFeature feature) { return config->experimentalFeatures[feature]; } -YOGA_EXPORT void YGConfigSetUseWebDefaults( - const YGConfigRef config, - const bool enabled) { +YOGA_EXPORT void YGConfigSetUseWebDefaults(const YGConfigRef config, + const bool enabled) { config->useWebDefaults = enabled; } YOGA_EXPORT void YGConfigSetUseLegacyStretchBehaviour( - const YGConfigRef config, - const bool useLegacyStretchBehaviour) { + const YGConfigRef config, const bool useLegacyStretchBehaviour) { config->useLegacyStretchBehaviour = useLegacyStretchBehaviour; } @@ -4399,24 +3841,21 @@ YOGA_EXPORT void* YGConfigGetContext(const YGConfigRef config) { return config->context; } -YOGA_EXPORT void YGConfigSetCloneNodeFunc( - const YGConfigRef config, - const YGCloneNodeFunc callback) { +YOGA_EXPORT void YGConfigSetCloneNodeFunc(const YGConfigRef config, + const YGCloneNodeFunc callback) { config->setCloneNodeCallback(callback); } static void YGTraverseChildrenPreOrder( - const YGVector& children, - const std::function& f) { + const YGVector& children, const std::function& f) { for (YGNodeRef node : children) { f(node); YGTraverseChildrenPreOrder(node->getChildren(), f); } } -void YGTraversePreOrder( - YGNodeRef const node, - std::function&& f) { +void YGTraversePreOrder(YGNodeRef const node, + std::function&& f) { if (!node) { return; } diff --git a/src/cpp/include/deps/yoga/Yoga.h b/src/cpp/include/deps/yoga/Yoga.h index 87901a280..ab3ec9cec 100644 --- a/src/cpp/include/deps/yoga/Yoga.h +++ b/src/cpp/include/deps/yoga/Yoga.h @@ -34,45 +34,33 @@ typedef struct YGConfig* YGConfigRef; typedef struct YGNode* YGNodeRef; typedef const struct YGNode* YGNodeConstRef; -typedef YGSize (*YGMeasureFunc)( - YGNodeRef node, - float width, - YGMeasureMode widthMode, - float height, - YGMeasureMode heightMode); +typedef YGSize (*YGMeasureFunc)(YGNodeRef node, float width, + YGMeasureMode widthMode, float height, + YGMeasureMode heightMode); typedef float (*YGBaselineFunc)(YGNodeRef node, float width, float height); typedef void (*YGDirtiedFunc)(YGNodeRef node); typedef void (*YGPrintFunc)(YGNodeRef node); typedef void (*YGNodeCleanupFunc)(YGNodeRef node); -typedef int (*YGLogger)( - YGConfigRef config, - YGNodeRef node, - YGLogLevel level, - const char* format, - va_list args); -typedef YGNodeRef ( - *YGCloneNodeFunc)(YGNodeRef oldNode, YGNodeRef owner, int childIndex); +typedef int (*YGLogger)(YGConfigRef config, YGNodeRef node, YGLogLevel level, + const char* format, va_list args); +typedef YGNodeRef (*YGCloneNodeFunc)(YGNodeRef oldNode, YGNodeRef owner, + int childIndex); // YGNode WIN_EXPORT YGNodeRef YGNodeNew(void); WIN_EXPORT YGNodeRef YGNodeNewWithConfig(YGConfigRef config); WIN_EXPORT YGNodeRef YGNodeClone(YGNodeRef node); WIN_EXPORT void YGNodeFree(YGNodeRef node); -WIN_EXPORT void YGNodeFreeRecursiveWithCleanupFunc( - YGNodeRef node, - YGNodeCleanupFunc cleanup); +WIN_EXPORT void YGNodeFreeRecursiveWithCleanupFunc(YGNodeRef node, + YGNodeCleanupFunc cleanup); WIN_EXPORT void YGNodeFreeRecursive(YGNodeRef node); WIN_EXPORT void YGNodeReset(YGNodeRef node); -WIN_EXPORT void YGNodeInsertChild( - YGNodeRef node, - YGNodeRef child, - uint32_t index); +WIN_EXPORT void YGNodeInsertChild(YGNodeRef node, YGNodeRef child, + uint32_t index); -WIN_EXPORT void YGNodeSwapChild( - YGNodeRef node, - YGNodeRef child, - uint32_t index); +WIN_EXPORT void YGNodeSwapChild(YGNodeRef node, YGNodeRef child, + uint32_t index); WIN_EXPORT void YGNodeRemoveChild(YGNodeRef node, YGNodeRef child); WIN_EXPORT void YGNodeRemoveAllChildren(YGNodeRef node); @@ -80,22 +68,17 @@ WIN_EXPORT YGNodeRef YGNodeGetChild(YGNodeRef node, uint32_t index); WIN_EXPORT YGNodeRef YGNodeGetOwner(YGNodeRef node); WIN_EXPORT YGNodeRef YGNodeGetParent(YGNodeRef node); WIN_EXPORT uint32_t YGNodeGetChildCount(YGNodeRef node); -WIN_EXPORT void YGNodeSetChildren( - YGNodeRef owner, - const YGNodeRef children[], - uint32_t count); +WIN_EXPORT void YGNodeSetChildren(YGNodeRef owner, const YGNodeRef children[], + uint32_t count); -WIN_EXPORT void YGNodeSetIsReferenceBaseline( - YGNodeRef node, - bool isReferenceBaseline); +WIN_EXPORT void YGNodeSetIsReferenceBaseline(YGNodeRef node, + bool isReferenceBaseline); WIN_EXPORT bool YGNodeIsReferenceBaseline(YGNodeRef node); -WIN_EXPORT void YGNodeCalculateLayout( - YGNodeRef node, - float availableWidth, - float availableHeight, - YGDirection ownerDirection); +WIN_EXPORT void YGNodeCalculateLayout(YGNodeRef node, float availableWidth, + float availableHeight, + YGDirection ownerDirection); // Mark a node as dirty. Only valid for nodes with a custom measure function // set. @@ -116,18 +99,10 @@ WIN_EXPORT void YGNodePrint(YGNodeRef node, YGPrintOptions options); WIN_EXPORT bool YGFloatIsUndefined(float value); WIN_EXPORT bool YGNodeCanUseCachedMeasurement( - YGMeasureMode widthMode, - float width, - YGMeasureMode heightMode, - float height, - YGMeasureMode lastWidthMode, - float lastWidth, - YGMeasureMode lastHeightMode, - float lastHeight, - float lastComputedWidth, - float lastComputedHeight, - float marginRow, - float marginColumn, + YGMeasureMode widthMode, float width, YGMeasureMode heightMode, + float height, YGMeasureMode lastWidthMode, float lastWidth, + YGMeasureMode lastHeightMode, float lastHeight, float lastComputedWidth, + float lastComputedHeight, float marginRow, float marginColumn, YGConfigRef config); WIN_EXPORT void YGNodeCopyStyle(YGNodeRef dstNode, YGNodeRef srcNode); @@ -152,19 +127,16 @@ bool YGNodeLayoutGetDidUseLegacyFlag(YGNodeRef node); WIN_EXPORT void YGNodeStyleSetDirection(YGNodeRef node, YGDirection direction); WIN_EXPORT YGDirection YGNodeStyleGetDirection(YGNodeConstRef node); -WIN_EXPORT void YGNodeStyleSetFlexDirection( - YGNodeRef node, - YGFlexDirection flexDirection); +WIN_EXPORT void YGNodeStyleSetFlexDirection(YGNodeRef node, + YGFlexDirection flexDirection); WIN_EXPORT YGFlexDirection YGNodeStyleGetFlexDirection(YGNodeConstRef node); -WIN_EXPORT void YGNodeStyleSetJustifyContent( - YGNodeRef node, - YGJustify justifyContent); +WIN_EXPORT void YGNodeStyleSetJustifyContent(YGNodeRef node, + YGJustify justifyContent); WIN_EXPORT YGJustify YGNodeStyleGetJustifyContent(YGNodeConstRef node); -WIN_EXPORT void YGNodeStyleSetAlignContent( - YGNodeRef node, - YGAlign alignContent); +WIN_EXPORT void YGNodeStyleSetAlignContent(YGNodeRef node, + YGAlign alignContent); WIN_EXPORT YGAlign YGNodeStyleGetAlignContent(YGNodeConstRef node); WIN_EXPORT void YGNodeStyleSetAlignItems(YGNodeRef node, YGAlign alignItems); @@ -173,9 +145,8 @@ WIN_EXPORT YGAlign YGNodeStyleGetAlignItems(YGNodeConstRef node); WIN_EXPORT void YGNodeStyleSetAlignSelf(YGNodeRef node, YGAlign alignSelf); WIN_EXPORT YGAlign YGNodeStyleGetAlignSelf(YGNodeConstRef node); -WIN_EXPORT void YGNodeStyleSetPositionType( - YGNodeRef node, - YGPositionType positionType); +WIN_EXPORT void YGNodeStyleSetPositionType(YGNodeRef node, + YGPositionType positionType); WIN_EXPORT YGPositionType YGNodeStyleGetPositionType(YGNodeConstRef node); WIN_EXPORT void YGNodeStyleSetFlexWrap(YGNodeRef node, YGWrap flexWrap); @@ -201,32 +172,22 @@ WIN_EXPORT void YGNodeStyleSetFlexBasisPercent(YGNodeRef node, float flexBasis); WIN_EXPORT void YGNodeStyleSetFlexBasisAuto(YGNodeRef node); WIN_EXPORT YGValue YGNodeStyleGetFlexBasis(YGNodeConstRef node); -WIN_EXPORT void YGNodeStyleSetPosition( - YGNodeRef node, - YGEdge edge, - float position); -WIN_EXPORT void YGNodeStyleSetPositionPercent( - YGNodeRef node, - YGEdge edge, - float position); +WIN_EXPORT void YGNodeStyleSetPosition(YGNodeRef node, YGEdge edge, + float position); +WIN_EXPORT void YGNodeStyleSetPositionPercent(YGNodeRef node, YGEdge edge, + float position); WIN_EXPORT YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge); WIN_EXPORT void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, float margin); -WIN_EXPORT void YGNodeStyleSetMarginPercent( - YGNodeRef node, - YGEdge edge, - float margin); +WIN_EXPORT void YGNodeStyleSetMarginPercent(YGNodeRef node, YGEdge edge, + float margin); WIN_EXPORT void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge); WIN_EXPORT YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge); -WIN_EXPORT void YGNodeStyleSetPadding( - YGNodeRef node, - YGEdge edge, - float padding); -WIN_EXPORT void YGNodeStyleSetPaddingPercent( - YGNodeRef node, - YGEdge edge, - float padding); +WIN_EXPORT void YGNodeStyleSetPadding(YGNodeRef node, YGEdge edge, + float padding); +WIN_EXPORT void YGNodeStyleSetPaddingPercent(YGNodeRef node, YGEdge edge, + float padding); WIN_EXPORT YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge); WIN_EXPORT void YGNodeStyleSetBorder(YGNodeRef node, YGEdge edge, float border); @@ -296,22 +257,16 @@ WIN_EXPORT float YGNodeLayoutGetPadding(YGNodeRef node, YGEdge edge); WIN_EXPORT void YGConfigSetLogger(YGConfigRef config, YGLogger logger); WIN_EXPORT void YGAssert(bool condition, const char* message); -WIN_EXPORT void YGAssertWithNode( - YGNodeRef node, - bool condition, - const char* message); -WIN_EXPORT void YGAssertWithConfig( - YGConfigRef config, - bool condition, - const char* message); +WIN_EXPORT void YGAssertWithNode(YGNodeRef node, bool condition, + const char* message); +WIN_EXPORT void YGAssertWithConfig(YGConfigRef config, bool condition, + const char* message); // Set this to number of pixels in 1 point to round calculation results If you // want to avoid rounding - set PointScaleFactor to 0 -WIN_EXPORT void YGConfigSetPointScaleFactor( - YGConfigRef config, - float pixelsInPoint); +WIN_EXPORT void YGConfigSetPointScaleFactor(YGConfigRef config, + float pixelsInPoint); void YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour( - YGConfigRef config, - bool shouldDiffLayout); + YGConfigRef config, bool shouldDiffLayout); // Yoga previously had an error where containers would take the maximum space // possible instead of the minimum like they are supposed to. In practice this @@ -319,8 +274,7 @@ void YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour( // was such a long-standing bug we must allow legacy users to switch back to // this behaviour. WIN_EXPORT void YGConfigSetUseLegacyStretchBehaviour( - YGConfigRef config, - bool useLegacyStretchBehaviour); + YGConfigRef config, bool useLegacyStretchBehaviour); // YGConfig WIN_EXPORT YGConfigRef YGConfigNew(void); @@ -329,21 +283,17 @@ WIN_EXPORT void YGConfigCopy(YGConfigRef dest, YGConfigRef src); WIN_EXPORT int32_t YGConfigGetInstanceCount(void); WIN_EXPORT void YGConfigSetExperimentalFeatureEnabled( - YGConfigRef config, - YGExperimentalFeature feature, - bool enabled); + YGConfigRef config, YGExperimentalFeature feature, bool enabled); WIN_EXPORT bool YGConfigIsExperimentalFeatureEnabled( - YGConfigRef config, - YGExperimentalFeature feature); + YGConfigRef config, YGExperimentalFeature feature); // Using the web defaults is the preferred configuration for new projects. Usage // of non web defaults should be considered as legacy. WIN_EXPORT void YGConfigSetUseWebDefaults(YGConfigRef config, bool enabled); WIN_EXPORT bool YGConfigGetUseWebDefaults(YGConfigRef config); -WIN_EXPORT void YGConfigSetCloneNodeFunc( - YGConfigRef config, - YGCloneNodeFunc callback); +WIN_EXPORT void YGConfigSetCloneNodeFunc(YGConfigRef config, + YGCloneNodeFunc callback); // Export only for C# WIN_EXPORT YGConfigRef YGConfigGetDefault(void); @@ -351,11 +301,8 @@ WIN_EXPORT YGConfigRef YGConfigGetDefault(void); WIN_EXPORT void YGConfigSetContext(YGConfigRef config, void* context); WIN_EXPORT void* YGConfigGetContext(YGConfigRef config); -WIN_EXPORT float YGRoundValueToPixelGrid( - double value, - double pointScaleFactor, - bool forceCeil, - bool forceFloor); +WIN_EXPORT float YGRoundValueToPixelGrid(double value, double pointScaleFactor, + bool forceCeil, bool forceFloor); YG_EXTERN_C_END @@ -365,9 +312,8 @@ YG_EXTERN_C_END #include // Calls f on each node in the tree including the given node argument. -void YGTraversePreOrder( - YGNodeRef node, - std::function&& f); +void YGTraversePreOrder(YGNodeRef node, + std::function&& f); void YGNodeSetChildren(YGNodeRef owner, const std::vector& children); diff --git a/src/cpp/include/deps/yoga/event/event.cpp b/src/cpp/include/deps/yoga/event/event.cpp index 3af3e83a0..99e4c4496 100644 --- a/src/cpp/include/deps/yoga/event/event.cpp +++ b/src/cpp/include/deps/yoga/event/event.cpp @@ -6,6 +6,7 @@ */ #include "event.h" + #include #include @@ -59,7 +60,7 @@ Node* push(Node* newHead) { return oldHead; } -} // namespace +} // namespace void Event::reset() { auto head = push(nullptr); @@ -76,11 +77,10 @@ void Event::subscribe(std::function&& subscriber) { void Event::publish(const YGNode& node, Type eventType, const Data& eventData) { for (auto subscriber = subscribers.load(std::memory_order_relaxed); - subscriber != nullptr; - subscriber = subscriber->next) { + subscriber != nullptr; subscriber = subscriber->next) { subscriber->subscriber(node, eventType, eventData); } } -} // namespace yoga -} // namespace facebook +} // namespace yoga +} // namespace facebook diff --git a/src/cpp/include/deps/yoga/event/event.h b/src/cpp/include/deps/yoga/event/event.h index 404ec3766..f2b3203e9 100644 --- a/src/cpp/include/deps/yoga/event/event.h +++ b/src/cpp/include/deps/yoga/event/event.h @@ -7,11 +7,12 @@ #pragma once +#include +#include + +#include #include #include -#include -#include -#include struct YGConfig; struct YGNode; @@ -73,7 +74,7 @@ struct YOGA_EXPORT Event { class Data { const void* data_; - public: + public: template Data(const TypedData& data) : data_{&data} {} @@ -99,7 +100,7 @@ struct YOGA_EXPORT Event { publish(*node, eventData); } -private: + private: static void publish(const YGNode&, Type, const Data&); }; @@ -142,5 +143,5 @@ struct Event::TypedData { void* layoutContext; }; -} // namespace yoga -} // namespace facebook +} // namespace yoga +} // namespace facebook diff --git a/src/cpp/include/deps/yoga/internal/experiments-inl.h b/src/cpp/include/deps/yoga/internal/experiments-inl.h index 959d9c332..4aa038532 100644 --- a/src/cpp/include/deps/yoga/internal/experiments-inl.h +++ b/src/cpp/include/deps/yoga/internal/experiments-inl.h @@ -7,26 +7,24 @@ #pragma once -#include "experiments.h" - #include +#include "experiments.h" + namespace facebook { namespace yoga { namespace internal { namespace detail { extern std::bitset enabledExperiments; -} // namespace detail +} // namespace detail inline bool isEnabled(Experiment experiment) { return detail::enabledExperiments.test(static_cast(experiment)); } -inline void disableAllExperiments() { - detail::enabledExperiments = 0; -} +inline void disableAllExperiments() { detail::enabledExperiments = 0; } -} // namespace internal -} // namespace yoga -} // namespace facebook +} // namespace internal +} // namespace yoga +} // namespace facebook diff --git a/src/cpp/include/deps/yoga/internal/experiments.cpp b/src/cpp/include/deps/yoga/internal/experiments.cpp index 16f196d5e..7412a47c0 100644 --- a/src/cpp/include/deps/yoga/internal/experiments.cpp +++ b/src/cpp/include/deps/yoga/internal/experiments.cpp @@ -6,6 +6,7 @@ */ #include "experiments.h" + #include "experiments-inl.h" namespace facebook { @@ -16,7 +17,7 @@ namespace detail { std::bitset enabledExperiments = 0; -} // namespace detail +} // namespace detail void enable(Experiment experiment) { detail::enabledExperiments.set(static_cast(experiment)); @@ -33,6 +34,6 @@ bool toggle(Experiment experiment) { return previousState; } -} // namespace internal -} // namespace yoga -} // namespace facebook +} // namespace internal +} // namespace yoga +} // namespace facebook diff --git a/src/cpp/include/deps/yoga/internal/experiments.h b/src/cpp/include/deps/yoga/internal/experiments.h index 1bdb7014b..13b4e4017 100644 --- a/src/cpp/include/deps/yoga/internal/experiments.h +++ b/src/cpp/include/deps/yoga/internal/experiments.h @@ -21,6 +21,6 @@ void enable(Experiment); void disable(Experiment); bool toggle(Experiment); -} // namespace internal -} // namespace yoga -} // namespace facebook +} // namespace internal +} // namespace yoga +} // namespace facebook diff --git a/src/cpp/include/deps/yoga/log.cpp b/src/cpp/include/deps/yoga/log.cpp index eb3da039c..3c7eec67a 100644 --- a/src/cpp/include/deps/yoga/log.cpp +++ b/src/cpp/include/deps/yoga/log.cpp @@ -7,9 +7,9 @@ #include "log.h" -#include "Yoga.h" #include "YGConfig.h" #include "YGNode.h" +#include "Yoga.h" namespace facebook { namespace yoga { @@ -17,48 +17,30 @@ namespace detail { namespace { -void vlog( - YGConfig* config, - YGNode* node, - YGLogLevel level, - void* context, - const char* format, - va_list args) { +void vlog(YGConfig* config, YGNode* node, YGLogLevel level, void* context, + const char* format, va_list args) { YGConfig* logConfig = config != nullptr ? config : YGConfigGetDefault(); logConfig->log(logConfig, node, level, context, format, args); } -} // namespace +} // namespace -YOGA_EXPORT void Log::log( - YGNode* node, - YGLogLevel level, - void* context, - const char* format, - ...) noexcept { +YOGA_EXPORT void Log::log(YGNode* node, YGLogLevel level, void* context, + const char* format, ...) noexcept { va_list args; va_start(args, format); - vlog( - node == nullptr ? nullptr : node->getConfig(), - node, - level, - context, - format, - args); + vlog(node == nullptr ? nullptr : node->getConfig(), node, level, context, + format, args); va_end(args); } -void Log::log( - YGConfig* config, - YGLogLevel level, - void* context, - const char* format, - ...) noexcept { +void Log::log(YGConfig* config, YGLogLevel level, void* context, + const char* format, ...) noexcept { va_list args; va_start(args, format); vlog(config, nullptr, level, context, format, args); va_end(args); } -} // namespace detail -} // namespace yoga -} // namespace facebook +} // namespace detail +} // namespace yoga +} // namespace facebook diff --git a/src/cpp/include/deps/yoga/log.h b/src/cpp/include/deps/yoga/log.h index ae33744c5..ab608f19a 100644 --- a/src/cpp/include/deps/yoga/log.h +++ b/src/cpp/include/deps/yoga/log.h @@ -18,21 +18,13 @@ namespace yoga { namespace detail { struct Log { - static void log( - YGNode* node, - YGLogLevel level, - void*, - const char* message, - ...) noexcept; + static void log(YGNode* node, YGLogLevel level, void*, const char* message, + ...) noexcept; - static void log( - YGConfig* config, - YGLogLevel level, - void*, - const char* format, - ...) noexcept; + static void log(YGConfig* config, YGLogLevel level, void*, const char* format, + ...) noexcept; }; -} // namespace detail -} // namespace yoga -} // namespace facebook +} // namespace detail +} // namespace yoga +} // namespace facebook diff --git a/src/demo.ts b/src/demo.ts index fcb97f8b6..46e1725fd 100644 --- a/src/demo.ts +++ b/src/demo.ts @@ -3,7 +3,6 @@ import { QLabel } from './lib/QtWidgets/QLabel'; import { QScrollArea } from './lib/QtWidgets/QScrollArea'; import { FlexLayout } from './lib/core/FlexLayout'; import { WidgetEventTypes } from './lib/core/EventWidget'; -import { SizeConstraint } from './lib/QtWidgets/QLayout'; const win = new QMainWindow(); win.resize(500, 500);