From 8d04d41b19030bae08018ad09a2d6e59708b6ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Tue, 20 Apr 2021 10:18:06 +0800 Subject: [PATCH] update yoga to cbf6495d66a7a8066d1354daa14d3bb1af19f6ef --- doric-Qt/doric/doric.pro | 2 +- doric-Qt/doric/yoga/BitUtils.h | 67 ++++++ doric-Qt/doric/yoga/Bitfield.h | 145 ------------ doric-Qt/doric/yoga/CompactValue.h | 4 +- doric-Qt/doric/yoga/Utils.cpp | 12 + doric-Qt/doric/yoga/Utils.h | 4 + doric-Qt/doric/yoga/YGEnums.cpp | 2 + doric-Qt/doric/yoga/YGEnums.h | 6 +- doric-Qt/doric/yoga/YGLayout.h | 62 +++-- doric-Qt/doric/yoga/YGNode.cpp | 274 +++++++++++----------- doric-Qt/doric/yoga/YGNode.h | 61 +++-- doric-Qt/doric/yoga/YGNodePrint.cpp | 11 +- doric-Qt/doric/yoga/YGStyle.h | 155 ++++++++----- doric-Qt/doric/yoga/YGValue.h | 11 + doric-Qt/doric/yoga/Yoga-internal.h | 17 +- doric-Qt/doric/yoga/Yoga.cpp | 347 +++++++++++++--------------- doric-Qt/doric/yoga/Yoga.h | 11 +- doric-Qt/doric/yoga/event/event.cpp | 1 - doric-Qt/doric/yoga/event/event.h | 1 + doric-Qt/doric/yoga/log.cpp | 4 - 20 files changed, 609 insertions(+), 588 deletions(-) create mode 100644 doric-Qt/doric/yoga/BitUtils.h delete mode 100644 doric-Qt/doric/yoga/Bitfield.h diff --git a/doric-Qt/doric/doric.pro b/doric-Qt/doric/doric.pro index 55150222..344dc06c 100644 --- a/doric-Qt/doric/doric.pro +++ b/doric-Qt/doric/doric.pro @@ -123,7 +123,7 @@ HEADERS += \ widget/flex/FlexLayout.h \ widget/flex/FlexLayoutConfig.h \ widget/flex/FlexLayoutService.h \ - yoga/Bitfield.h \ + yoga/BitUtils.h \ yoga/CompactValue.h \ yoga/Utils.h \ yoga/YGConfig.h \ diff --git a/doric-Qt/doric/yoga/BitUtils.h b/doric-Qt/doric/yoga/BitUtils.h new file mode 100644 index 00000000..2161effc --- /dev/null +++ b/doric-Qt/doric/yoga/BitUtils.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include +#include +#include "YGEnums.h" + +namespace facebook { +namespace yoga { + +namespace detail { + +constexpr size_t log2ceilFn(size_t n) { + return n < 1 ? 0 : (1 + log2ceilFn(n / 2)); +} + +constexpr int mask(size_t bitWidth, size_t index) { + return ((1 << bitWidth) - 1) << 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"); + return log2ceilFn(enums::count() - 1); +} + +template +constexpr Enum getEnumData(int flags, size_t index) { + return static_cast((flags & mask(bitWidthFn(), index)) >> index); +} + +template +void setEnumData(uint32_t& flags, size_t index, int newValue) { + flags = (flags & ~mask(bitWidthFn(), index)) | + ((newValue << index) & (mask(bitWidthFn(), index))); +} + +template +void setEnumData(uint8_t& flags, size_t index, int newValue) { + flags = (flags & ~static_cast(mask(bitWidthFn(), index))) | + ((newValue << index) & + (static_cast(mask(bitWidthFn(), index)))); +} + +constexpr bool getBooleanData(int flags, size_t index) { + return (flags >> index) & 1; +} + +inline void setBooleanData(uint8_t& flags, size_t index, bool value) { + if (value) { + flags |= 1 << index; + } else { + flags &= ~(1 << index); + } +} + +} // namespace detail +} // namespace yoga +} // namespace facebook diff --git a/doric-Qt/doric/yoga/Bitfield.h b/doric-Qt/doric/yoga/Bitfield.h deleted file mode 100644 index 02645961..00000000 --- a/doric-Qt/doric/yoga/Bitfield.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include -#include -#include - -namespace facebook { -namespace yoga { - -namespace detail { - -constexpr size_t log2ceil(size_t n) { - return n < 1 ? 0 : (1 + log2ceil(n / 2)); -} - -// The number of bits necessary to represent enums defined with YG_ENUM_SEQ_DECL -template -constexpr size_t bitWidth() { - static_assert( - enums::count() > 0, "Enums must have at least one entries"); - return log2ceil(enums::count() - 1); -} - -// Number of bits needed for a boolean -template <> -constexpr size_t bitWidth() { - return 1; -} - -template -struct BitTraits {}; - -template -struct BitTraits { - // Base cases - static constexpr size_t width(size_t) { return 0; } - static constexpr size_t shift(size_t) { return 0; } -}; - -template -struct BitTraits { - using Rest = BitTraits; - - static constexpr size_t width(size_t idx) { - return idx == 0 ? bitWidth() : Rest::width(idx - 1); - } - - static constexpr size_t shift(size_t idx) { - return idx == 0 ? Rest::width(0) + Rest::shift(0) : Rest::shift(idx - 1); - } - - static constexpr U mask(size_t idx) { - return ((U{1} << width(idx)) - 1) << shift(idx); - } -}; - -template -struct IndexedType { - using Type = typename IndexedType::Type; -}; - -template -struct IndexedType<0, T, Ts...> { - using Type = T; -}; - -} // namespace detail - -template -class Bitfield { - static_assert( - std::is_integral::value, - "Bitfield needs an integral storage type"); - static_assert( - std::is_unsigned::value, - "Bitfield needs an unsigned storage type"); - static_assert(sizeof...(Fields) > 0, "Bitfield needs at least one member"); - - using BitTraits = detail::BitTraits; - -#if !defined(_MSC_VER) || _MSC_VER > 1914 - static_assert( - BitTraits::shift(0) + BitTraits::width(0) <= - std::numeric_limits::digits, - "Specified storage type is too narrow to hold all types"); -#endif - - template - using TypeAt = typename detail::IndexedType::Type; - - template - static constexpr Storage initStorage(Value value, Values... values) { - return ((value << BitTraits::shift(Idx)) & BitTraits::mask(Idx)) | - initStorage(values...); - } - - template - static constexpr Storage initStorage() { - return Storage{0}; - } - - Storage storage_ = 0; - -public: - template - class Ref { - Bitfield& bitfield_; - - public: - Ref(Bitfield& bitfield) : bitfield_(bitfield) {} - Ref& operator=(TypeAt value) { - bitfield_.storage_ = (bitfield_.storage_ & ~BitTraits::mask(Idx)) | - ((value << BitTraits::shift(Idx)) & BitTraits::mask(Idx)); - return *this; - } - operator TypeAt() const { - return const_cast(bitfield_).at(); - } - }; - - constexpr Bitfield() = default; - constexpr Bitfield(Fields... values) : storage_{initStorage<0>(values...)} {} - - template - constexpr TypeAt at() const { - return static_cast>( - (storage_ & BitTraits::mask(Idx)) >> BitTraits::shift(Idx)); - } - - template - Ref at() { - return {*this}; - } -}; - -} // namespace yoga -} // namespace facebook diff --git a/doric-Qt/doric/yoga/CompactValue.h b/doric-Qt/doric/yoga/CompactValue.h index be933a16..f398668e 100644 --- a/doric-Qt/doric/yoga/CompactValue.h +++ b/doric-Qt/doric/yoga/CompactValue.h @@ -125,8 +125,8 @@ 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 { diff --git a/doric-Qt/doric/yoga/Utils.cpp b/doric-Qt/doric/yoga/Utils.cpp index 761f3515..eaa74b06 100644 --- a/doric-Qt/doric/yoga/Utils.cpp +++ b/doric-Qt/doric/yoga/Utils.cpp @@ -6,6 +6,7 @@ */ #include "Utils.h" +#include using namespace facebook; @@ -52,6 +53,13 @@ bool YGFloatsEqual(const float a, const float b) { return yoga::isUndefined(a) && yoga::isUndefined(b); } +bool YGDoubleEqual(const double a, const double b) { + if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) { + return fabs(a - b) < 0.0001; + } + return yoga::isUndefined(a) && yoga::isUndefined(b); +} + float YGFloatSanitize(const float val) { return yoga::isUndefined(val) ? 0 : val; } @@ -65,3 +73,7 @@ YGFloatOptional YGFloatOptionalMax(YGFloatOptional op1, YGFloatOptional op2) { } return op1.isUndefined() ? op2 : op1; } + +void throwLogicalErrorWithMessage(const char* message) { + throw std::logic_error(message); +} diff --git a/doric-Qt/doric/yoga/Utils.h b/doric-Qt/doric/yoga/Utils.h index bce8dfca..57e1d45d 100644 --- a/doric-Qt/doric/yoga/Utils.h +++ b/doric-Qt/doric/yoga/Utils.h @@ -64,6 +64,8 @@ inline bool YGValueEqual( // difference between two floats is less than 0.0001f or both are undefined. bool YGFloatsEqual(const float a, const float b); +bool YGDoubleEqual(const double a, const double b); + float YGFloatMax(const float a, const float b); YGFloatOptional YGFloatOptionalMax( @@ -141,3 +143,5 @@ inline YGFloatOptional YGResolveValueMargin( const float ownerSize) { return value.isAuto() ? YGFloatOptional{0} : YGResolveValue(value, ownerSize); } + +void throwLogicalErrorWithMessage(const char* message); diff --git a/doric-Qt/doric/yoga/YGEnums.cpp b/doric-Qt/doric/yoga/YGEnums.cpp index 3c130129..c01d3d94 100644 --- a/doric-Qt/doric/yoga/YGEnums.cpp +++ b/doric-Qt/doric/yoga/YGEnums.cpp @@ -179,6 +179,8 @@ const char* YGOverflowToString(const YGOverflow value) { const char* YGPositionTypeToString(const YGPositionType value) { switch (value) { + case YGPositionTypeStatic: + return "static"; case YGPositionTypeRelative: return "relative"; case YGPositionTypeAbsolute: diff --git a/doric-Qt/doric/yoga/YGEnums.h b/doric-Qt/doric/yoga/YGEnums.h index 4241281d..3dc458dc 100644 --- a/doric-Qt/doric/yoga/YGEnums.h +++ b/doric-Qt/doric/yoga/YGEnums.h @@ -128,7 +128,11 @@ YG_ENUM_SEQ_DECL( YGOverflowHidden, YGOverflowScroll) -YG_ENUM_SEQ_DECL(YGPositionType, YGPositionTypeRelative, YGPositionTypeAbsolute) +YG_ENUM_SEQ_DECL( + YGPositionType, + YGPositionTypeStatic, + YGPositionTypeRelative, + YGPositionTypeAbsolute) YG_ENUM_DECL( YGPrintOptions, diff --git a/doric-Qt/doric/yoga/YGLayout.h b/doric-Qt/doric/yoga/YGLayout.h index 658a31f2..b7604d8e 100644 --- a/doric-Qt/doric/yoga/YGLayout.h +++ b/doric-Qt/doric/yoga/YGLayout.h @@ -6,10 +6,12 @@ */ #pragma once -#include "Bitfield.h" +#include "BitUtils.h" #include "YGFloatOptional.h" #include "Yoga-internal.h" +using namespace facebook::yoga; + struct YGLayout { std::array position = {}; std::array dimensions = {{YGUndefined, YGUndefined}}; @@ -18,12 +20,14 @@ struct YGLayout { std::array padding = {}; private: - static constexpr size_t directionIdx = 0; - static constexpr size_t didUseLegacyFlagIdx = 1; - static constexpr size_t doesLegacyStretchFlagAffectsLayoutIdx = 2; - static constexpr size_t hadOverflowIdx = 3; - facebook::yoga::Bitfield flags_ = - {YGDirectionInherit, false, false, false}; + static constexpr size_t directionOffset = 0; + static constexpr size_t didUseLegacyFlagOffset = + directionOffset + facebook::yoga::detail::bitWidthFn(); + static constexpr size_t doesLegacyStretchFlagAffectsLayoutOffset = + didUseLegacyFlagOffset + 1; + static constexpr size_t hadOverflowOffset = + doesLegacyStretchFlagAffectsLayoutOffset + 1; + uint8_t flags = 0; public: uint32_t computedFlexBasisGeneration = 0; @@ -32,7 +36,7 @@ public: // Instead of recomputing the entire layout every single time, we cache some // information to break early when nothing changed uint32_t generationCount = 0; - YGDirection lastOwnerDirection = (YGDirection) -1; + YGDirection lastOwnerDirection = YGDirectionInherit; uint32_t nextCachedMeasurementsIndex = 0; std::array @@ -41,27 +45,41 @@ public: YGCachedMeasurement cachedLayout = YGCachedMeasurement(); - YGDirection direction() const { return flags_.at(); } - decltype(flags_)::Ref direction() { - return flags_.at(); + YGDirection direction() const { + return facebook::yoga::detail::getEnumData( + flags, directionOffset); } - bool didUseLegacyFlag() const { return flags_.at(); } - decltype(flags_)::Ref didUseLegacyFlag() { - return flags_.at(); + void setDirection(YGDirection direction) { + facebook::yoga::detail::setEnumData( + flags, directionOffset, direction); + } + + bool didUseLegacyFlag() const { + return facebook::yoga::detail::getBooleanData( + flags, didUseLegacyFlagOffset); + } + + void setDidUseLegacyFlag(bool val) { + facebook::yoga::detail::setBooleanData(flags, didUseLegacyFlagOffset, val); } bool doesLegacyStretchFlagAffectsLayout() const { - return flags_.at(); - } - decltype(flags_)::Ref - doesLegacyStretchFlagAffectsLayout() { - return flags_.at(); + return facebook::yoga::detail::getBooleanData( + flags, doesLegacyStretchFlagAffectsLayoutOffset); } - bool hadOverflow() const { return flags_.at(); } - decltype(flags_)::Ref hadOverflow() { - return flags_.at(); + void setDoesLegacyStretchFlagAffectsLayout(bool val) { + facebook::yoga::detail::setBooleanData( + flags, doesLegacyStretchFlagAffectsLayoutOffset, val); + } + + bool hadOverflow() const { + return facebook::yoga::detail::getBooleanData(flags, hadOverflowOffset); + } + void setHadOverflow(bool hadOverflow) { + facebook::yoga::detail::setBooleanData( + flags, hadOverflowOffset, hadOverflow); } bool operator==(YGLayout layout) const; diff --git a/doric-Qt/doric/yoga/YGNode.cpp b/doric-Qt/doric/yoga/YGNode.cpp index 1d49b007..f4c14bf3 100644 --- a/doric-Qt/doric/yoga/YGNode.cpp +++ b/doric-Qt/doric/yoga/YGNode.cpp @@ -16,7 +16,7 @@ using facebook::yoga::detail::CompactValue; YGNode::YGNode(YGNode&& node) { context_ = node.context_; - flags_ = node.flags_; + flags = node.flags; measure_ = node.measure_; baseline_ = node.baseline_; print_ = node.print_; @@ -29,7 +29,7 @@ YGNode::YGNode(YGNode&& node) { config_ = node.config_; resolvedDimensions_ = node.resolvedDimensions_; for (auto c : children_) { - c->setOwner(c); + c->setOwner(this); } } @@ -42,7 +42,7 @@ YGNode::YGNode(const YGNode& node, YGConfigRef config) : YGNode{node} { void YGNode::print(void* printContext) { if (print_.noContext != nullptr) { - if (flags_.at()) { + if (facebook::yoga::detail::getBooleanData(flags, printUsesContext_)) { print_.withContext(this, printContext); } else { print_.noContext(this); @@ -50,89 +50,111 @@ void YGNode::print(void* printContext) { } } +CompactValue YGNode::computeEdgeValueForRow( + const YGStyle::Edges& edges, + YGEdge rowEdge, + YGEdge edge, + CompactValue defaultValue) { + if (!edges[rowEdge].isUndefined()) { + return edges[rowEdge]; + } else if (!edges[edge].isUndefined()) { + return edges[edge]; + } else if (!edges[YGEdgeHorizontal].isUndefined()) { + return edges[YGEdgeHorizontal]; + } else if (!edges[YGEdgeAll].isUndefined()) { + return edges[YGEdgeAll]; + } else { + return defaultValue; + } +} + +CompactValue YGNode::computeEdgeValueForColumn( + const YGStyle::Edges& edges, + YGEdge edge, + CompactValue defaultValue) { + if (!edges[edge].isUndefined()) { + return edges[edge]; + } else if (!edges[YGEdgeVertical].isUndefined()) { + return edges[YGEdgeVertical]; + } else if (!edges[YGEdgeAll].isUndefined()) { + return edges[YGEdgeAll]; + } else { + return defaultValue; + } +} + YGFloatOptional YGNode::getLeadingPosition( const YGFlexDirection axis, const float axisSize) const { - if (YGFlexDirectionIsRow(axis)) { - auto leadingPosition = YGComputedEdgeValue( - style_.position(), YGEdgeStart, CompactValue::ofUndefined()); - if (!leadingPosition.isUndefined()) { - return YGResolveValue(leadingPosition, axisSize); - } - } - - auto leadingPosition = YGComputedEdgeValue( - style_.position(), leading[axis], CompactValue::ofUndefined()); - - return leadingPosition.isUndefined() - ? YGFloatOptional{0} - : YGResolveValue(leadingPosition, axisSize); + auto leadingPosition = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.position(), + YGEdgeStart, + leading[axis], + CompactValue::ofZero()) + : computeEdgeValueForColumn( + style_.position(), leading[axis], CompactValue::ofZero()); + return YGResolveValue(leadingPosition, axisSize); } YGFloatOptional YGNode::getTrailingPosition( const YGFlexDirection axis, const float axisSize) const { - if (YGFlexDirectionIsRow(axis)) { - auto trailingPosition = YGComputedEdgeValue( - style_.position(), YGEdgeEnd, CompactValue::ofUndefined()); - if (!trailingPosition.isUndefined()) { - return YGResolveValue(trailingPosition, axisSize); - } - } - - auto trailingPosition = YGComputedEdgeValue( - style_.position(), trailing[axis], CompactValue::ofUndefined()); - - return trailingPosition.isUndefined() - ? YGFloatOptional{0} - : YGResolveValue(trailingPosition, axisSize); + auto trailingPosition = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.position(), + YGEdgeEnd, + trailing[axis], + CompactValue::ofZero()) + : computeEdgeValueForColumn( + style_.position(), trailing[axis], CompactValue::ofZero()); + return YGResolveValue(trailingPosition, axisSize); } bool YGNode::isLeadingPositionDefined(const YGFlexDirection axis) const { - return (YGFlexDirectionIsRow(axis) && - !YGComputedEdgeValue( - style_.position(), YGEdgeStart, CompactValue::ofUndefined()) - .isUndefined()) || - !YGComputedEdgeValue( - style_.position(), leading[axis], CompactValue::ofUndefined()) - .isUndefined(); + auto leadingPosition = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.position(), + YGEdgeStart, + leading[axis], + CompactValue::ofUndefined()) + : computeEdgeValueForColumn( + style_.position(), leading[axis], CompactValue::ofUndefined()); + return !leadingPosition.isUndefined(); } bool YGNode::isTrailingPosDefined(const YGFlexDirection axis) const { - return (YGFlexDirectionIsRow(axis) && - !YGComputedEdgeValue( - style_.position(), YGEdgeEnd, CompactValue::ofUndefined()) - .isUndefined()) || - !YGComputedEdgeValue( - style_.position(), trailing[axis], CompactValue::ofUndefined()) - .isUndefined(); + auto trailingPosition = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.position(), + YGEdgeEnd, + trailing[axis], + CompactValue::ofUndefined()) + : computeEdgeValueForColumn( + style_.position(), trailing[axis], CompactValue::ofUndefined()); + return !trailingPosition.isUndefined(); } 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()), - widthSize); + auto leadingMargin = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.margin(), YGEdgeStart, leading[axis], CompactValue::ofZero()) + : computeEdgeValueForColumn( + style_.margin(), leading[axis], CompactValue::ofZero()); + return YGResolveValueMargin(leadingMargin, widthSize); } 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()), - widthSize); + auto trailingMargin = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.margin(), YGEdgeEnd, trailing[axis], CompactValue::ofZero()) + : computeEdgeValueForColumn( + style_.margin(), trailing[axis], CompactValue::ofZero()); + return YGResolveValueMargin(trailingMargin, widthSize); } YGFloatOptional YGNode::getMarginForAxis( @@ -147,15 +169,14 @@ YGSize YGNode::measure( float height, YGMeasureMode heightMode, void* layoutContext) { - - return flags_.at() + return facebook::yoga::detail::getBooleanData(flags, measureUsesContext_) ? 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 flags_.at() + return facebook::yoga::detail::getBooleanData(flags, baselineUsesContext_) ? baseline_.withContext(this, width, height, layoutContext) : baseline_.noContext(this, width, height); } @@ -166,7 +187,7 @@ void YGNode::setMeasureFunc(decltype(YGNode::measure_) measureFunc) { if (measureFunc.noContext == nullptr) { // TODO: t18095186 Move nodeType to opt-in function and mark appropriate // places in Litho - flags_.at() = YGNodeTypeDefault; + setNodeType(YGNodeTypeDefault); } else { YGAssertWithNode( this, @@ -182,14 +203,14 @@ void YGNode::setMeasureFunc(decltype(YGNode::measure_) measureFunc) { } void YGNode::setMeasureFunc(YGMeasureFunc measureFunc) { - flags_.at() = false; + facebook::yoga::detail::setBooleanData(flags, measureUsesContext_, false); decltype(YGNode::measure_) m; m.noContext = measureFunc; setMeasureFunc(m); } YOGA_EXPORT void YGNode::setMeasureFunc(MeasureWithContextFn measureFunc) { - flags_.at() = true; + facebook::yoga::detail::setBooleanData(flags, measureUsesContext_, true); decltype(YGNode::measure_) m; m.withContext = measureFunc; setMeasureFunc(m); @@ -208,10 +229,10 @@ void YGNode::insertChild(YGNodeRef child, uint32_t index) { } void YGNode::setDirty(bool isDirty) { - if (isDirty == flags_.at()) { + if (isDirty == facebook::yoga::detail::getBooleanData(flags, isDirty_)) { return; } - flags_.at() = isDirty; + facebook::yoga::detail::setBooleanData(flags, isDirty_, isDirty); if (isDirty && dirtied_) { dirtied_(this); } @@ -232,7 +253,7 @@ void YGNode::removeChild(uint32_t index) { } void YGNode::setLayoutDirection(YGDirection direction) { - layout_.direction() = direction; + layout_.setDirection(direction); } void YGNode::setLayoutMargin(float margin, int index) { @@ -270,7 +291,7 @@ void YGNode::setLayoutMeasuredDimension(float measuredDimension, int index) { } void YGNode::setLayoutHadOverflow(bool hadOverflow) { - layout_.hadOverflow() = hadOverflow; + layout_.setHadOverflow(hadOverflow); } void YGNode::setLayoutDimension(float dimension, int index) { @@ -307,6 +328,9 @@ void YGNode::setPosition( const YGFlexDirection crossAxis = YGFlexDirectionCross(mainAxis, directionRespectingRoot); + // Here we should check for `YGPositionTypeStatic` and in this case zero inset + // properties (left, right, top, bottom, begin, end). + // https://www.w3.org/TR/css-position-3/#valdef-position-static const YGFloatOptional relativePositionMain = relativePosition(mainAxis, mainSize); const YGFloatOptional relativePositionCross = @@ -351,7 +375,9 @@ YGValue YGNode::resolveFlexBasisPtr() const { return flexBasis; } if (!style_.flex().isUndefined() && style_.flex().unwrap() > 0.0f) { - return flags_.at() ? YGValueAuto : YGValueZero; + return facebook::yoga::detail::getBooleanData(flags, useWebDefaults_) + ? YGValueAuto + : YGValueZero; } return YGValueAuto; } @@ -390,7 +416,7 @@ void YGNode::cloneChildrenIfNeeded(void* cloneContext) { } void YGNode::markDirtyAndPropogate() { - if (!flags_.at()) { + if (!facebook::yoga::detail::getBooleanData(flags, isDirty_)) { setDirty(true); setLayoutComputedFlexBasis(YGFloatOptional()); if (owner_) { @@ -400,7 +426,7 @@ void YGNode::markDirtyAndPropogate() { } void YGNode::markDirtyAndPropogateDownwards() { - flags_.at() = true; + facebook::yoga::detail::setBooleanData(flags, isDirty_, true); for_each(children_.begin(), children_.end(), [](YGNodeRef childNode) { childNode->markDirtyAndPropogateDownwards(); }); @@ -427,83 +453,64 @@ float YGNode::resolveFlexShrink() const { if (!style_.flexShrink().isUndefined()) { return style_.flexShrink().unwrap(); } - if (!flags_.at() && !style_.flex().isUndefined() && - style_.flex().unwrap() < 0.0f) { + if (!facebook::yoga::detail::getBooleanData(flags, useWebDefaults_) && + !style_.flex().isUndefined() && style_.flex().unwrap() < 0.0f) { return -style_.flex().unwrap(); } - return flags_.at() ? kWebDefaultFlexShrink - : kDefaultFlexShrink; + return facebook::yoga::detail::getBooleanData(flags, useWebDefaults_) + ? kWebDefaultFlexShrink + : kDefaultFlexShrink; } bool YGNode::isNodeFlexible() { return ( - (style_.positionType() == YGPositionTypeRelative) && + (style_.positionType() != YGPositionTypeAbsolute) && (resolveFlexGrow() != 0 || resolveFlexShrink() != 0)); } float YGNode::getLeadingBorder(const YGFlexDirection axis) const { - YGValue leadingBorder; - if (YGFlexDirectionIsRow(axis) && - !style_.border()[YGEdgeStart].isUndefined()) { - leadingBorder = style_.border()[YGEdgeStart]; - if (leadingBorder.value >= 0) { - return leadingBorder.value; - } - } - - leadingBorder = YGComputedEdgeValue( - style_.border(), leading[axis], CompactValue::ofZero()); - return YGFloatMax(leadingBorder.value, 0.0f); + YGValue leadingBorder = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.border(), YGEdgeStart, leading[axis], CompactValue::ofZero()) + : computeEdgeValueForColumn( + style_.border(), leading[axis], CompactValue::ofZero()); + return fmaxf(leadingBorder.value, 0.0f); } -float YGNode::getTrailingBorder(const YGFlexDirection flexDirection) const { - YGValue trailingBorder; - if (YGFlexDirectionIsRow(flexDirection) && - !style_.border()[YGEdgeEnd].isUndefined()) { - trailingBorder = style_.border()[YGEdgeEnd]; - if (trailingBorder.value >= 0.0f) { - return trailingBorder.value; - } - } - - trailingBorder = YGComputedEdgeValue( - style_.border(), trailing[flexDirection], CompactValue::ofZero()); - return YGFloatMax(trailingBorder.value, 0.0f); +float YGNode::getTrailingBorder(const YGFlexDirection axis) const { + YGValue trailingBorder = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.border(), YGEdgeEnd, trailing[axis], CompactValue::ofZero()) + : computeEdgeValueForColumn( + style_.border(), trailing[axis], CompactValue::ofZero()); + return fmaxf(trailingBorder.value, 0.0f); } YGFloatOptional YGNode::getLeadingPadding( const YGFlexDirection axis, const float widthSize) const { - const YGFloatOptional paddingEdgeStart = - YGResolveValue(style_.padding()[YGEdgeStart], widthSize); - if (YGFlexDirectionIsRow(axis) && - !style_.padding()[YGEdgeStart].isUndefined() && - !paddingEdgeStart.isUndefined() && paddingEdgeStart.unwrap() >= 0.0f) { - return paddingEdgeStart; - } - - YGFloatOptional resolvedValue = YGResolveValue( - YGComputedEdgeValue( - style_.padding(), leading[axis], CompactValue::ofZero()), - widthSize); - return YGFloatOptionalMax(resolvedValue, YGFloatOptional(0.0f)); + auto leadingPadding = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.padding(), + YGEdgeStart, + leading[axis], + CompactValue::ofZero()) + : computeEdgeValueForColumn( + style_.padding(), leading[axis], CompactValue::ofZero()); + return YGFloatOptionalMax( + YGResolveValue(leadingPadding, widthSize), YGFloatOptional(0.0f)); } 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); - - return YGFloatOptionalMax(resolvedValue, YGFloatOptional(0.0f)); + auto trailingPadding = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.padding(), YGEdgeEnd, trailing[axis], CompactValue::ofZero()) + : computeEdgeValueForColumn( + style_.padding(), trailing[axis], CompactValue::ofZero()); + return YGFloatOptionalMax( + YGResolveValue(trailingPadding, widthSize), YGFloatOptional(0.0f)); } YGFloatOptional YGNode::getLeadingPaddingAndBorder( @@ -536,11 +543,11 @@ bool YGNode::didUseLegacyFlag() { void YGNode::setLayoutDoesLegacyFlagAffectsLayout( bool doesLegacyFlagAffectsLayout) { - layout_.doesLegacyStretchFlagAffectsLayout() = doesLegacyFlagAffectsLayout; + layout_.setDoesLegacyStretchFlagAffectsLayout(doesLegacyFlagAffectsLayout); } void YGNode::setLayoutDidUseLegacyFlag(bool didUseLegacyFlag) { - layout_.didUseLegacyFlag() = didUseLegacyFlag; + layout_.setDidUseLegacyFlag(didUseLegacyFlag); } bool YGNode::isLayoutTreeEqualToNode(const YGNode& node) const { @@ -577,7 +584,8 @@ void YGNode::reset() { clearChildren(); - auto webDefaults = flags_.at(); + auto webDefaults = + facebook::yoga::detail::getBooleanData(flags, useWebDefaults_); *this = YGNode{getConfig()}; if (webDefaults) { useWebDefaults(); diff --git a/doric-Qt/doric/yoga/YGNode.h b/doric-Qt/doric/yoga/YGNode.h index 2967a1e2..4b6e6277 100644 --- a/doric-Qt/doric/yoga/YGNode.h +++ b/doric-Qt/doric/yoga/YGNode.h @@ -6,9 +6,12 @@ */ #pragma once + +#ifdef __cplusplus + #include #include -#include "Bitfield.h" +#include "BitUtils.h" #include "CompactValue.h" #include "YGConfig.h" #include "YGLayout.h" @@ -35,10 +38,7 @@ private: static constexpr size_t useWebDefaults_ = 7; void* context_ = nullptr; - using Flags = facebook::yoga:: - Bitfield; - Flags flags_ = - {true, false, false, YGNodeTypeDefault, false, false, false, false}; + uint8_t flags = 1; uint8_t reserved_ = 0; union { YGMeasureFunc noContext; @@ -70,13 +70,13 @@ private: void setBaselineFunc(decltype(baseline_)); void useWebDefaults() { - flags_.at() = true; + facebook::yoga::detail::setBooleanData(flags, useWebDefaults_, true); style_.flexDirection() = YGFlexDirectionRow; style_.alignContent() = YGAlignStretch; } // DANGER DANGER DANGER! - // If the the node assigned to has children, we'd either have to deallocate + // If the node assigned to has children, we'd either have to deallocate // them (potentially incorrect) or ignore them (danger of leaks). Only ever // use this after checking that there are no children. // DO NOT CHANGE THE VISIBILITY OF THIS METHOD! @@ -114,9 +114,13 @@ public: void print(void*); - bool getHasNewLayout() const { return flags_.at(); } + bool getHasNewLayout() const { + return facebook::yoga::detail::getBooleanData(flags, hasNewLayout_); + } - YGNodeType getNodeType() const { return flags_.at(); } + YGNodeType getNodeType() const { + return facebook::yoga::detail::getEnumData(flags, nodeType_); + } bool hasMeasureFunc() const noexcept { return measure_.noContext != nullptr; } @@ -142,7 +146,9 @@ public: uint32_t getLineIndex() const { return lineIndex_; } - bool isReferenceBaseline() { return flags_.at(); } + bool isReferenceBaseline() { + return facebook::yoga::detail::getBooleanData(flags, isReferenceBaseline_); + } // returns the YGNodeRef that owns this YGNode. An owner is used to identify // the YogaTree that a YGNode belongs to. This method will return the parent @@ -175,7 +181,9 @@ public: YGConfigRef getConfig() const { return config_; } - bool isDirty() const { return flags_.at(); } + bool isDirty() const { + return facebook::yoga::detail::getBooleanData(flags, isDirty_); + } std::array getResolvedDimensions() const { return resolvedDimensions_; @@ -185,6 +193,17 @@ public: return resolvedDimensions_[index]; } + static CompactValue computeEdgeValueForColumn( + const YGStyle::Edges& edges, + YGEdge edge, + CompactValue defaultValue); + + static CompactValue computeEdgeValueForRow( + const YGStyle::Edges& edges, + YGEdge rowEdge, + YGEdge edge, + CompactValue defaultValue); + // Methods related to positions, margin, padding and border YGFloatOptional getLeadingPosition( const YGFlexDirection axis, @@ -223,19 +242,22 @@ public: void setPrintFunc(YGPrintFunc printFunc) { print_.noContext = printFunc; - flags_.at() = false; + facebook::yoga::detail::setBooleanData(flags, printUsesContext_, false); } void setPrintFunc(PrintWithContextFn printFunc) { print_.withContext = printFunc; - flags_.at() = true; + facebook::yoga::detail::setBooleanData(flags, printUsesContext_, true); } void setPrintFunc(std::nullptr_t) { setPrintFunc(YGPrintFunc{nullptr}); } void setHasNewLayout(bool hasNewLayout) { - flags_.at() = hasNewLayout; + facebook::yoga::detail::setBooleanData(flags, hasNewLayout_, hasNewLayout); } - void setNodeType(YGNodeType nodeType) { flags_.at() = nodeType; } + void setNodeType(YGNodeType nodeType) { + return facebook::yoga::detail::setEnumData( + flags, nodeType_, nodeType); + } void setMeasureFunc(YGMeasureFunc measureFunc); void setMeasureFunc(MeasureWithContextFn); @@ -244,11 +266,11 @@ public: } void setBaselineFunc(YGBaselineFunc baseLineFunc) { - flags_.at() = false; + facebook::yoga::detail::setBooleanData(flags, baselineUsesContext_, false); baseline_.noContext = baseLineFunc; } void setBaselineFunc(BaselineWithContextFn baseLineFunc) { - flags_.at() = true; + facebook::yoga::detail::setBooleanData(flags, baselineUsesContext_, true); baseline_.withContext = baseLineFunc; } void setBaselineFunc(std::nullptr_t) { @@ -264,7 +286,8 @@ public: void setLineIndex(uint32_t lineIndex) { lineIndex_ = lineIndex; } void setIsReferenceBaseline(bool isReferenceBaseline) { - flags_.at() = isReferenceBaseline; + facebook::yoga::detail::setBooleanData( + flags, isReferenceBaseline_, isReferenceBaseline); } void setOwner(YGNodeRef owner) { owner_ = owner; } @@ -321,3 +344,5 @@ public: bool isLayoutTreeEqualToNode(const YGNode& node) const; void reset(); }; + +#endif diff --git a/doric-Qt/doric/yoga/YGNodePrint.cpp b/doric-Qt/doric/yoga/YGNodePrint.cpp index 26efa485..72d147db 100644 --- a/doric-Qt/doric/yoga/YGNodePrint.cpp +++ b/doric-Qt/doric/yoga/YGNodePrint.cpp @@ -104,10 +104,13 @@ static void appendEdgeIfNotUndefined( const string& str, const YGStyle::Edges& edges, const YGEdge edge) { - appendNumberIfNotUndefined( - base, - str, - YGComputedEdgeValue(edges, edge, detail::CompactValue::ofUndefined())); + // TODO: this doesn't take RTL / YGEdgeStart / YGEdgeEnd into account + auto value = (edge == YGEdgeLeft || edge == YGEdgeRight) + ? YGNode::computeEdgeValueForRow( + edges, edge, edge, detail::CompactValue::ofUndefined()) + : YGNode::computeEdgeValueForColumn( + edges, edge, detail::CompactValue::ofUndefined()); + appendNumberIfNotUndefined(base, str, value); } void YGNodeToString( diff --git a/doric-Qt/doric/yoga/YGStyle.h b/doric-Qt/doric/yoga/YGStyle.h index b066b346..aab7599c 100644 --- a/doric-Qt/doric/yoga/YGStyle.h +++ b/doric-Qt/doric/yoga/YGStyle.h @@ -6,16 +6,19 @@ */ #pragma once + +#ifdef __cplusplus + #include #include #include #include -#include "Bitfield.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 @@ -27,6 +30,19 @@ public: using Dimensions = Values; using Edges = Values; + template + struct BitfieldRef { + YGStyle& style; + size_t offset; + operator T() const { + return facebook::yoga::detail::getEnumData(style.flags, offset); + } + BitfieldRef& operator=(T x) { + facebook::yoga::detail::setEnumData(style.flags, offset, x); + return *this; + } + }; + template struct Ref { YGStyle& style; @@ -60,43 +76,35 @@ public: CompactValue operator[](Idx idx) const { return (style.*Prop)[idx]; } }; - YGStyle() = default; + YGStyle() { + alignContent() = YGAlignFlexStart; + alignItems() = YGAlignStretch; + } ~YGStyle() = default; private: - static constexpr size_t directionIdx = 0; - static constexpr size_t flexDirectionIdx = 1; - static constexpr size_t justifyContentIdx = 2; - static constexpr size_t alignContentIdx = 3; - static constexpr size_t alignItemsIdx = 4; - static constexpr size_t alignSelfIdx = 5; - static constexpr size_t positionTypeIdx = 6; - static constexpr size_t flexWrapIdx = 7; - static constexpr size_t overflowIdx = 8; - static constexpr size_t displayIdx = 9; - using Flags = facebook::yoga::Bitfield< - uint32_t, - YGDirection, - YGFlexDirection, - YGJustify, - YGAlign, - YGAlign, - YGAlign, - YGPositionType, - YGWrap, - YGOverflow, - YGDisplay>; + static constexpr size_t directionOffset = 0; + static constexpr size_t flexdirectionOffset = + directionOffset + facebook::yoga::detail::bitWidthFn(); + static constexpr size_t justifyContentOffset = flexdirectionOffset + + facebook::yoga::detail::bitWidthFn(); + static constexpr size_t alignContentOffset = + justifyContentOffset + facebook::yoga::detail::bitWidthFn(); + static constexpr size_t alignItemsOffset = + alignContentOffset + facebook::yoga::detail::bitWidthFn(); + static constexpr size_t alignSelfOffset = + alignItemsOffset + facebook::yoga::detail::bitWidthFn(); + static constexpr size_t positionTypeOffset = + alignSelfOffset + facebook::yoga::detail::bitWidthFn(); + static constexpr size_t flexWrapOffset = + positionTypeOffset + facebook::yoga::detail::bitWidthFn(); + static constexpr size_t overflowOffset = + flexWrapOffset + facebook::yoga::detail::bitWidthFn(); + static constexpr size_t displayOffset = + overflowOffset + facebook::yoga::detail::bitWidthFn(); + + uint32_t flags = 0; - Flags flags_ = {YGDirectionInherit, - YGFlexDirectionColumn, - YGJustifyFlexStart, - YGAlignFlexStart, - YGAlignStretch, - YGAlignAuto, - YGPositionTypeRelative, - YGWrapNoWrap, - YGOverflowVisible, - YGDisplayFlex}; YGFloatOptional flex_ = {}; YGFloatOptional flexGrow_ = {}; YGFloatOptional flexShrink_ = {}; @@ -115,45 +123,68 @@ public: // for library users needing a type using ValueRepr = std::remove_reference::type; - YGDirection direction() const { return flags_.at(); } - Flags::Ref direction() { return flags_.at(); } + YGDirection direction() const { + return facebook::yoga::detail::getEnumData( + flags, directionOffset); + } + BitfieldRef direction() { return {*this, directionOffset}; } YGFlexDirection flexDirection() const { - return flags_.at(); + return facebook::yoga::detail::getEnumData( + flags, flexdirectionOffset); } - Flags::Ref flexDirection() { - return flags_.at(); + BitfieldRef flexDirection() { + return {*this, flexdirectionOffset}; } - YGJustify justifyContent() const { return flags_.at(); } - Flags::Ref justifyContent() { - return flags_.at(); + YGJustify justifyContent() const { + return facebook::yoga::detail::getEnumData( + flags, justifyContentOffset); + } + BitfieldRef justifyContent() { + return {*this, justifyContentOffset}; } - YGAlign alignContent() const { return flags_.at(); } - Flags::Ref alignContent() { - return flags_.at(); + YGAlign alignContent() const { + return facebook::yoga::detail::getEnumData( + flags, alignContentOffset); + } + BitfieldRef alignContent() { return {*this, alignContentOffset}; } + + YGAlign alignItems() const { + return facebook::yoga::detail::getEnumData( + flags, alignItemsOffset); + } + BitfieldRef alignItems() { return {*this, alignItemsOffset}; } + + YGAlign alignSelf() const { + return facebook::yoga::detail::getEnumData(flags, alignSelfOffset); + } + BitfieldRef alignSelf() { return {*this, alignSelfOffset}; } + + YGPositionType positionType() const { + return facebook::yoga::detail::getEnumData( + flags, positionTypeOffset); + } + BitfieldRef positionType() { + return {*this, positionTypeOffset}; } - YGAlign alignItems() const { return flags_.at(); } - Flags::Ref alignItems() { return flags_.at(); } - - YGAlign alignSelf() const { return flags_.at(); } - Flags::Ref alignSelf() { return flags_.at(); } - - YGPositionType positionType() const { return flags_.at(); } - Flags::Ref positionType() { - return flags_.at(); + YGWrap flexWrap() const { + return facebook::yoga::detail::getEnumData(flags, flexWrapOffset); } + BitfieldRef flexWrap() { return {*this, flexWrapOffset}; } - YGWrap flexWrap() const { return flags_.at(); } - Flags::Ref flexWrap() { return flags_.at(); } + YGOverflow overflow() const { + return facebook::yoga::detail::getEnumData( + flags, overflowOffset); + } + BitfieldRef overflow() { return {*this, overflowOffset}; } - YGOverflow overflow() const { return flags_.at(); } - Flags::Ref overflow() { return flags_.at(); } - - YGDisplay display() const { return flags_.at(); } - Flags::Ref display() { return flags_.at(); } + YGDisplay display() const { + return facebook::yoga::detail::getEnumData(flags, displayOffset); + } + BitfieldRef display() { return {*this, displayOffset}; } YGFloatOptional flex() const { return flex_; } Ref flex() { return {*this}; } @@ -201,3 +232,5 @@ YOGA_EXPORT bool operator==(const YGStyle& lhs, const YGStyle& rhs); YOGA_EXPORT inline bool operator!=(const YGStyle& lhs, const YGStyle& rhs) { return !(lhs == rhs); } + +#endif diff --git a/doric-Qt/doric/yoga/YGValue.h b/doric-Qt/doric/yoga/YGValue.h index aaa10c3f..a2000978 100644 --- a/doric-Qt/doric/yoga/YGValue.h +++ b/doric-Qt/doric/yoga/YGValue.h @@ -11,6 +11,13 @@ #include "YGEnums.h" #include "YGMacros.h" +#if defined(_MSC_VER) && defined(__clang__) +#define COMPILING_WITH_CLANG_ON_WINDOWS +#endif +#if defined(COMPILING_WITH_CLANG_ON_WINDOWS) +#include +constexpr float YGUndefined = std::numeric_limits::quiet_NaN(); +#else YG_EXTERN_C_BEGIN // Not defined in MSVC++ @@ -20,6 +27,7 @@ static const uint32_t __nan = 0x7fc00000; #endif #define YGUndefined NAN +#endif typedef struct YGValue { float value; @@ -30,7 +38,10 @@ YOGA_EXPORT extern const YGValue YGValueAuto; YOGA_EXPORT extern const YGValue YGValueUndefined; YOGA_EXPORT extern const YGValue YGValueZero; +#if !defined(COMPILING_WITH_CLANG_ON_WINDOWS) YG_EXTERN_C_END +#endif +#undef COMPILING_WITH_CLANG_ON_WINDOWS #ifdef __cplusplus diff --git a/doric-Qt/doric/yoga/Yoga-internal.h b/doric-Qt/doric/yoga/Yoga-internal.h index 0b3368a0..acd173be 100644 --- a/doric-Qt/doric/yoga/Yoga-internal.h +++ b/doric-Qt/doric/yoga/Yoga-internal.h @@ -33,6 +33,10 @@ inline bool isUndefined(float value) { return std::isnan(value); } +inline bool isUndefined(double value) { + return std::isnan(value); +} + } // namespace yoga } // namespace facebook @@ -54,10 +58,10 @@ struct YGCachedMeasurement { float computedHeight; YGCachedMeasurement() - : availableWidth(0), - availableHeight(0), - widthMeasureMode((YGMeasureMode) -1), - heightMeasureMode((YGMeasureMode) -1), + : availableWidth(-1), + availableHeight(-1), + widthMeasureMode(YGMeasureModeUndefined), + heightMeasureMode(YGMeasureModeUndefined), computedWidth(-1), computedHeight(-1) {} @@ -144,8 +148,3 @@ static const float kDefaultFlexShrink = 0.0f; static const float kWebDefaultFlexShrink = 1.0f; 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); diff --git a/doric-Qt/doric/yoga/Yoga.cpp b/doric-Qt/doric/yoga/Yoga.cpp index 016ab0ac..33f70e82 100644 --- a/doric-Qt/doric/yoga/Yoga.cpp +++ b/doric-Qt/doric/yoga/Yoga.cpp @@ -106,38 +106,12 @@ static int YGDefaultLog( #undef YG_UNUSED #endif -YOGA_EXPORT bool YGFloatIsUndefined(const float value) { +static inline bool YGDoubleIsUndefined(const double value) { return facebook::yoga::isUndefined(value); } -detail::CompactValue YGComputedEdgeValue( - const YGStyle::Edges& edges, - YGEdge edge, - detail::CompactValue defaultValue) { - if (!edges[edge].isUndefined()) { - return edges[edge]; - } - - if ((edge == YGEdgeTop || edge == YGEdgeBottom) && - !edges[YGEdgeVertical].isUndefined()) { - return edges[YGEdgeVertical]; - } - - if ((edge == YGEdgeLeft || edge == YGEdgeRight || edge == YGEdgeStart || - edge == YGEdgeEnd) && - !edges[YGEdgeHorizontal].isUndefined()) { - return edges[YGEdgeHorizontal]; - } - - if (!edges[YGEdgeAll].isUndefined()) { - return edges[YGEdgeAll]; - } - - if (edge == YGEdgeStart || edge == YGEdgeEnd) { - return detail::CompactValue::ofUndefined(); - } - - return defaultValue; +YOGA_EXPORT bool YGFloatIsUndefined(const float value) { + return facebook::yoga::isUndefined(value); } YOGA_EXPORT void* YGNodeGetContext(YGNodeRef node) { @@ -249,9 +223,6 @@ YOGA_EXPORT YGNodeRef YGNodeClone(YGNodeRef oldNode) { static YGConfigRef YGConfigClone(const YGConfig& oldConfig) { const YGConfigRef config = new YGConfig(oldConfig); YGAssert(config != nullptr, "Could not allocate memory for config"); - if (config == nullptr) { - abort(); - } gConfigInstanceCount++; return config; } @@ -386,6 +357,14 @@ YOGA_EXPORT void YGNodeInsertChild( owner->markDirtyAndPropogate(); } +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) { @@ -1126,7 +1105,7 @@ static bool YGIsBaselineLayout(const YGNodeRef node) { const uint32_t childCount = YGNodeGetChildCount(node); for (uint32_t i = 0; i < childCount; i++) { const YGNodeRef child = YGNodeGetChild(node, i); - if (child->getStyle().positionType() == YGPositionTypeRelative && + if (child->getStyle().positionType() != YGPositionTypeAbsolute && child->getStyle().alignSelf() == YGAlignBaseline) { return true; } @@ -1655,8 +1634,8 @@ static void YGNodeAbsoluteLayoutChild( static void YGNodeWithMeasureFuncSetMeasuredDimensions( const YGNodeRef node, - const float availableWidth, - const float availableHeight, + float availableWidth, + float availableHeight, const YGMeasureMode widthMeasureMode, const YGMeasureMode heightMeasureMode, const float ownerWidth, @@ -1669,40 +1648,40 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions( node->hasMeasureFunc(), "Expected node to have custom measure function"); - const float paddingAndBorderAxisRow = - YGNodePaddingAndBorderForAxis(node, YGFlexDirectionRow, availableWidth); - const float paddingAndBorderAxisColumn = YGNodePaddingAndBorderForAxis( - node, YGFlexDirectionColumn, availableWidth); - const float marginAxisRow = - node->getMarginForAxis(YGFlexDirectionRow, availableWidth).unwrap(); - const float marginAxisColumn = - node->getMarginForAxis(YGFlexDirectionColumn, availableWidth).unwrap(); + if (widthMeasureMode == YGMeasureModeUndefined) { + availableWidth = YGUndefined; + } + if (heightMeasureMode == YGMeasureModeUndefined) { + availableHeight = YGUndefined; + } + + const auto& padding = node->getLayout().padding; + const auto& border = node->getLayout().border; + const float paddingAndBorderAxisRow = padding[YGEdgeLeft] + + padding[YGEdgeRight] + border[YGEdgeLeft] + border[YGEdgeRight]; + const float paddingAndBorderAxisColumn = padding[YGEdgeTop] + + padding[YGEdgeBottom] + border[YGEdgeTop] + border[YGEdgeBottom]; // We want to make sure we don't call measure with negative size const float innerWidth = YGFloatIsUndefined(availableWidth) ? availableWidth - : YGFloatMax(0, availableWidth - marginAxisRow - paddingAndBorderAxisRow); + : YGFloatMax(0, availableWidth - paddingAndBorderAxisRow); const float innerHeight = YGFloatIsUndefined(availableHeight) ? availableHeight - : YGFloatMax( - 0, availableHeight - marginAxisColumn - paddingAndBorderAxisColumn); + : YGFloatMax(0, availableHeight - 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), + node, YGFlexDirectionRow, availableWidth, ownerWidth, ownerWidth), YGDimensionWidth); node->setLayoutMeasuredDimension( YGNodeBoundAxis( node, YGFlexDirectionColumn, - availableHeight - marginAxisColumn, + availableHeight, ownerHeight, ownerWidth), YGDimensionHeight); @@ -1739,7 +1718,7 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions( (widthMeasureMode == YGMeasureModeUndefined || widthMeasureMode == YGMeasureModeAtMost) ? measuredSize.width + paddingAndBorderAxisRow - : availableWidth - marginAxisRow, + : availableWidth, ownerWidth, ownerWidth), YGDimensionWidth); @@ -1751,7 +1730,7 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions( (heightMeasureMode == YGMeasureModeUndefined || heightMeasureMode == YGMeasureModeAtMost) ? measuredSize.height + paddingAndBorderAxisColumn - : availableHeight - marginAxisColumn, + : availableHeight, ownerHeight, ownerWidth), YGDimensionHeight); @@ -1768,37 +1747,28 @@ static void YGNodeEmptyContainerSetMeasuredDimensions( const YGMeasureMode heightMeasureMode, const float ownerWidth, const float ownerHeight) { - const float paddingAndBorderAxisRow = - YGNodePaddingAndBorderForAxis(node, YGFlexDirectionRow, ownerWidth); - const float paddingAndBorderAxisColumn = - YGNodePaddingAndBorderForAxis(node, YGFlexDirectionColumn, ownerWidth); - const float marginAxisRow = - node->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap(); - const float marginAxisColumn = - node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth).unwrap(); + const auto& padding = node->getLayout().padding; + const auto& border = node->getLayout().border; + float width = availableWidth; + if (widthMeasureMode == YGMeasureModeUndefined || + widthMeasureMode == YGMeasureModeAtMost) { + width = padding[YGEdgeLeft] + padding[YGEdgeRight] + border[YGEdgeLeft] + + border[YGEdgeRight]; + } node->setLayoutMeasuredDimension( - YGNodeBoundAxis( - node, - YGFlexDirectionRow, - (widthMeasureMode == YGMeasureModeUndefined || - widthMeasureMode == YGMeasureModeAtMost) - ? paddingAndBorderAxisRow - : availableWidth - marginAxisRow, - ownerWidth, - ownerWidth), + YGNodeBoundAxis(node, YGFlexDirectionRow, width, ownerWidth, ownerWidth), YGDimensionWidth); + float height = availableHeight; + if (heightMeasureMode == YGMeasureModeUndefined || + heightMeasureMode == YGMeasureModeAtMost) { + height = padding[YGEdgeTop] + padding[YGEdgeBottom] + border[YGEdgeTop] + + border[YGEdgeBottom]; + } node->setLayoutMeasuredDimension( YGNodeBoundAxis( - node, - YGFlexDirectionColumn, - (heightMeasureMode == YGMeasureModeUndefined || - heightMeasureMode == YGMeasureModeAtMost) - ? paddingAndBorderAxisColumn - : availableHeight - marginAxisColumn, - ownerHeight, - ownerWidth), + node, YGFlexDirectionColumn, height, ownerHeight, ownerWidth), YGDimensionHeight); } @@ -1816,11 +1786,6 @@ static bool YGNodeFixedSizeSetMeasuredDimensions( heightMeasureMode == YGMeasureModeAtMost && availableHeight <= 0.0f) || (widthMeasureMode == YGMeasureModeExactly && heightMeasureMode == YGMeasureModeExactly)) { - auto marginAxisColumn = - node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth).unwrap(); - auto marginAxisRow = - node->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap(); - node->setLayoutMeasuredDimension( YGNodeBoundAxis( node, @@ -1829,7 +1794,7 @@ static bool YGNodeFixedSizeSetMeasuredDimensions( (widthMeasureMode == YGMeasureModeAtMost && availableWidth < 0.0f) ? 0.0f - : availableWidth - marginAxisRow, + : availableWidth, ownerWidth, ownerWidth), YGDimensionWidth); @@ -1842,7 +1807,7 @@ static bool YGNodeFixedSizeSetMeasuredDimensions( (heightMeasureMode == YGMeasureModeAtMost && availableHeight < 0.0f) ? 0.0f - : availableHeight - marginAxisColumn, + : availableHeight, ownerHeight, ownerWidth), YGDimensionHeight); @@ -1866,19 +1831,11 @@ static void YGZeroOutLayoutRecursivly( static float YGNodeCalculateAvailableInnerDim( const YGNodeConstRef node, - YGFlexDirection axis, - float availableDim, - float ownerDim) { - YGFlexDirection direction = - YGFlexDirectionIsRow(axis) ? YGFlexDirectionRow : YGFlexDirectionColumn; - YGDimension dimension = - YGFlexDirectionIsRow(axis) ? YGDimensionWidth : YGDimensionHeight; - - const float margin = node->getMarginForAxis(direction, ownerDim).unwrap(); - const float paddingAndBorder = - YGNodePaddingAndBorderForAxis(node, direction, ownerDim); - - float availableInnerDim = availableDim - margin - paddingAndBorder; + const YGDimension dimension, + const float availableDim, + const float paddingAndBorder, + const float ownerDim) { + float availableInnerDim = availableDim - paddingAndBorder; // Max dimension overrides predefined dimension value; Min dimension in turn // overrides both of the above if (!YGFloatIsUndefined(availableInnerDim)) { @@ -2328,7 +2285,8 @@ static void YGDistributeFreeSpaceFirstPass( // first and second passes. deltaFreeSpace += boundMainSize - childFlexBasis; collectedFlexItemsValues.totalFlexShrinkScaledFactors -= - flexShrinkScaledFactor; + (-currentRelativeChild->resolveFlexShrink() * + currentRelativeChild->getLayout().computedFlexBasis.unwrap()); } } } else if ( @@ -2490,7 +2448,7 @@ static void YGJustifyMainAxis( i < collectedFlexItemsValues.endOfLineIndex; i++) { const YGNodeRef child = node->getChild(i); - if (child->getStyle().positionType() == YGPositionTypeRelative) { + if (child->getStyle().positionType() != YGPositionTypeAbsolute) { if (child->marginLeadingValue(mainAxis).unit == YGUnitAuto) { numberOfAutoMarginsOnCurrentLine++; } @@ -2574,7 +2532,7 @@ static void YGJustifyMainAxis( // Now that we placed the element, we need to update the variables. // We need to do that only for relative elements. Absolute elements do not // take part in that phase. - if (childStyle.positionType() == YGPositionTypeRelative) { + if (childStyle.positionType() != YGPositionTypeAbsolute) { if (child->marginLeadingValue(mainAxis).unit == YGUnitAuto) { collectedFlexItemsValues.mainDim += collectedFlexItemsValues.remainingFreeSpace / @@ -2764,16 +2722,22 @@ static void YGNodelayoutImpl( const YGEdge startEdge = direction == YGDirectionLTR ? YGEdgeLeft : YGEdgeRight; const YGEdge endEdge = direction == YGDirectionLTR ? YGEdgeRight : YGEdgeLeft; - node->setLayoutMargin( - node->getLeadingMargin(flexRowDirection, ownerWidth).unwrap(), startEdge); - node->setLayoutMargin( - node->getTrailingMargin(flexRowDirection, ownerWidth).unwrap(), endEdge); - node->setLayoutMargin( - node->getLeadingMargin(flexColumnDirection, ownerWidth).unwrap(), - YGEdgeTop); - node->setLayoutMargin( - node->getTrailingMargin(flexColumnDirection, ownerWidth).unwrap(), - YGEdgeBottom); + + const float marginRowLeading = + node->getLeadingMargin(flexRowDirection, ownerWidth).unwrap(); + node->setLayoutMargin(marginRowLeading, startEdge); + const float marginRowTrailing = + node->getTrailingMargin(flexRowDirection, ownerWidth).unwrap(); + node->setLayoutMargin(marginRowTrailing, endEdge); + const float marginColumnLeading = + node->getLeadingMargin(flexColumnDirection, ownerWidth).unwrap(); + node->setLayoutMargin(marginColumnLeading, YGEdgeTop); + const float marginColumnTrailing = + node->getTrailingMargin(flexColumnDirection, ownerWidth).unwrap(); + node->setLayoutMargin(marginColumnTrailing, YGEdgeBottom); + + const float marginAxisRow = marginRowLeading + marginRowTrailing; + const float marginAxisColumn = marginColumnLeading + marginColumnTrailing; node->setLayoutBorder(node->getLeadingBorder(flexRowDirection), startEdge); node->setLayoutBorder(node->getTrailingBorder(flexRowDirection), endEdge); @@ -2796,8 +2760,8 @@ static void YGNodelayoutImpl( if (node->hasMeasureFunc()) { YGNodeWithMeasureFuncSetMeasuredDimensions( node, - availableWidth, - availableHeight, + availableWidth - marginAxisRow, + availableHeight - marginAxisColumn, widthMeasureMode, heightMeasureMode, ownerWidth, @@ -2812,8 +2776,8 @@ static void YGNodelayoutImpl( if (childCount == 0) { YGNodeEmptyContainerSetMeasuredDimensions( node, - availableWidth, - availableHeight, + availableWidth - marginAxisRow, + availableHeight - marginAxisColumn, widthMeasureMode, heightMeasureMode, ownerWidth, @@ -2826,8 +2790,8 @@ static void YGNodelayoutImpl( if (!performLayout && YGNodeFixedSizeSetMeasuredDimensions( node, - availableWidth, - availableHeight, + availableWidth - marginAxisRow, + availableHeight - marginAxisColumn, widthMeasureMode, heightMeasureMode, ownerWidth, @@ -2851,12 +2815,14 @@ static void YGNodelayoutImpl( const float mainAxisownerSize = isMainAxisRow ? ownerWidth : ownerHeight; const float crossAxisownerSize = isMainAxisRow ? ownerHeight : ownerWidth; - const float leadingPaddingAndBorderCross = - node->getLeadingPaddingAndBorder(crossAxis, ownerWidth).unwrap(); const float paddingAndBorderAxisMain = YGNodePaddingAndBorderForAxis(node, mainAxis, ownerWidth); + const float leadingPaddingAndBorderCross = + node->getLeadingPaddingAndBorder(crossAxis, ownerWidth).unwrap(); + const float trailingPaddingAndBorderCross = + node->getTrailingPaddingAndBorder(crossAxis, ownerWidth).unwrap(); const float paddingAndBorderAxisCross = - YGNodePaddingAndBorderForAxis(node, crossAxis, ownerWidth); + leadingPaddingAndBorderCross + trailingPaddingAndBorderCross; YGMeasureMode measureModeMainDim = isMainAxisRow ? widthMeasureMode : heightMeasureMode; @@ -2868,35 +2834,20 @@ static void YGNodelayoutImpl( const float paddingAndBorderAxisColumn = isMainAxisRow ? paddingAndBorderAxisCross : paddingAndBorderAxisMain; - const float marginAxisRow = - node->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap(); - const float marginAxisColumn = - node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth).unwrap(); - - const auto& minDimensions = node->getStyle().minDimensions(); - const auto& maxDimensions = node->getStyle().maxDimensions(); - const float minInnerWidth = - YGResolveValue(minDimensions[YGDimensionWidth], ownerWidth).unwrap() - - paddingAndBorderAxisRow; - const float maxInnerWidth = - YGResolveValue(maxDimensions[YGDimensionWidth], ownerWidth).unwrap() - - paddingAndBorderAxisRow; - const float minInnerHeight = - YGResolveValue(minDimensions[YGDimensionHeight], ownerHeight).unwrap() - - paddingAndBorderAxisColumn; - const float maxInnerHeight = - YGResolveValue(maxDimensions[YGDimensionHeight], ownerHeight).unwrap() - - paddingAndBorderAxisColumn; - - const float minInnerMainDim = isMainAxisRow ? minInnerWidth : minInnerHeight; - const float maxInnerMainDim = isMainAxisRow ? maxInnerWidth : maxInnerHeight; - // STEP 2: DETERMINE AVAILABLE SIZE IN MAIN AND CROSS DIRECTIONS float availableInnerWidth = YGNodeCalculateAvailableInnerDim( - node, YGFlexDirectionRow, availableWidth, ownerWidth); + node, + YGDimensionWidth, + availableWidth - marginAxisRow, + paddingAndBorderAxisRow, + ownerWidth); float availableInnerHeight = YGNodeCalculateAvailableInnerDim( - node, YGFlexDirectionColumn, availableHeight, ownerHeight); + node, + YGDimensionHeight, + availableHeight - marginAxisColumn, + paddingAndBorderAxisColumn, + ownerHeight); float availableInnerMainDim = isMainAxisRow ? availableInnerWidth : availableInnerHeight; @@ -2968,6 +2919,28 @@ static void YGNodelayoutImpl( // If we don't measure with exact main dimension we want to ensure we don't // violate min and max if (measureModeMainDim != YGMeasureModeExactly) { + const auto& minDimensions = node->getStyle().minDimensions(); + const auto& maxDimensions = node->getStyle().maxDimensions(); + const float minInnerWidth = + YGResolveValue(minDimensions[YGDimensionWidth], ownerWidth).unwrap() - + paddingAndBorderAxisRow; + const float maxInnerWidth = + YGResolveValue(maxDimensions[YGDimensionWidth], ownerWidth).unwrap() - + paddingAndBorderAxisRow; + const float minInnerHeight = + YGResolveValue(minDimensions[YGDimensionHeight], ownerHeight) + .unwrap() - + paddingAndBorderAxisColumn; + const float maxInnerHeight = + YGResolveValue(maxDimensions[YGDimensionHeight], ownerHeight) + .unwrap() - + paddingAndBorderAxisColumn; + + const float minInnerMainDim = + isMainAxisRow ? minInnerWidth : minInnerHeight; + const float maxInnerMainDim = + isMainAxisRow ? maxInnerWidth : maxInnerHeight; + if (!YGFloatIsUndefined(minInnerMainDim) && collectedFlexItemsValues.sizeConsumedOnCurrentLine < minInnerMainDim) { @@ -3296,7 +3269,7 @@ static void YGNodelayoutImpl( if (child->getStyle().display() == YGDisplayNone) { continue; } - if (child->getStyle().positionType() == YGPositionTypeRelative) { + if (child->getStyle().positionType() != YGPositionTypeAbsolute) { if (child->getLineIndex() != i) { break; } @@ -3338,7 +3311,7 @@ static void YGNodelayoutImpl( if (child->getStyle().display() == YGDisplayNone) { continue; } - if (child->getStyle().positionType() == YGPositionTypeRelative) { + if (child->getStyle().positionType() != YGPositionTypeAbsolute) { switch (YGNodeAlignItem(node, child)) { case YGAlignFlexStart: { child->setLayoutPosition( @@ -3516,8 +3489,8 @@ static void YGNodelayoutImpl( YGNodeBoundAxisWithinMinAndMax( node, crossAxis, - YGFloatOptional{totalLineCrossDim + - paddingAndBorderAxisCross}, + YGFloatOptional{ + totalLineCrossDim + paddingAndBorderAxisCross}, crossAxisownerSize) .unwrap()), paddingAndBorderAxisCross), @@ -3529,7 +3502,7 @@ static void YGNodelayoutImpl( if (performLayout && node->getStyle().flexWrap() == YGWrapWrapReverse) { for (uint32_t i = 0; i < childCount; i++) { const YGNodeRef child = YGNodeGetChild(node, i); - if (child->getStyle().positionType() == YGPositionTypeRelative) { + if (child->getStyle().positionType() != YGPositionTypeAbsolute) { child->setLayoutPosition( node->getLayout().measuredDimensions[dim[crossAxis]] - child->getLayout().position[pos[crossAxis]] - @@ -3542,7 +3515,8 @@ static void YGNodelayoutImpl( if (performLayout) { // STEP 10: SIZING AND POSITIONING ABSOLUTE CHILDREN for (auto child : node->getChildren()) { - if (child->getStyle().positionType() != YGPositionTypeAbsolute) { + if (child->getStyle().display() == YGDisplayNone || + child->getStyle().positionType() != YGPositionTypeAbsolute) { continue; } YGNodeAbsoluteLayoutChild( @@ -3646,14 +3620,14 @@ static inline bool YGMeasureModeNewMeasureSizeIsStricterAndStillValid( } YOGA_EXPORT float YGRoundValueToPixelGrid( - const float value, - const float pointScaleFactor, + const double value, + const double pointScaleFactor, const bool forceCeil, const bool forceFloor) { - double scaledValue = ((double) value) * pointScaleFactor; + double scaledValue = value * pointScaleFactor; // We want to calculate `fractial` such that `floor(scaledValue) = scaledValue // - fractial`. - float fractial = fmodf(scaledValue, 1.0f); + double fractial = fmod(scaledValue, 1.0); if (fractial < 0) { // This branch is for handling negative numbers for `value`. // @@ -3672,28 +3646,28 @@ YOGA_EXPORT float YGRoundValueToPixelGrid( // - Finding the `floor`: -2.2 - fractial2 = -2.2 - 0.8 = -3 ++fractial; } - if (YGFloatsEqual(fractial, 0)) { + if (YGDoubleEqual(fractial, 0)) { // First we check if the value is already rounded scaledValue = scaledValue - fractial; - } else if (YGFloatsEqual(fractial, 1.0f)) { - scaledValue = scaledValue - fractial + 1.0f; + } else if (YGDoubleEqual(fractial, 1.0)) { + scaledValue = scaledValue - fractial + 1.0; } else if (forceCeil) { // Next we check if we need to use forced rounding - scaledValue = scaledValue - fractial + 1.0f; + scaledValue = scaledValue - fractial + 1.0; } else if (forceFloor) { scaledValue = scaledValue - fractial; } else { // Finally we just round the value scaledValue = scaledValue - fractial + - (!YGFloatIsUndefined(fractial) && - (fractial > 0.5f || YGFloatsEqual(fractial, 0.5f)) - ? 1.0f - : 0.0f); + (!YGDoubleIsUndefined(fractial) && + (fractial > 0.5 || YGDoubleEqual(fractial, 0.5)) + ? 1.0 + : 0.0); } - return (YGFloatIsUndefined(scaledValue) || - YGFloatIsUndefined(pointScaleFactor)) + return (YGDoubleIsUndefined(scaledValue) || + YGDoubleIsUndefined(pointScaleFactor)) ? YGUndefined - : scaledValue / pointScaleFactor; + : (float) (scaledValue / pointScaleFactor); } YOGA_EXPORT bool YGNodeCanUseCachedMeasurement( @@ -3803,8 +3777,10 @@ bool YGLayoutNodeInternal( if (needToVisitNode) { // Invalidate the cached results. layout->nextCachedMeasurementsIndex = 0; - layout->cachedLayout.widthMeasureMode = (YGMeasureMode) -1; - layout->cachedLayout.heightMeasureMode = (YGMeasureMode) -1; + layout->cachedLayout.availableWidth = -1; + layout->cachedLayout.availableHeight = -1; + layout->cachedLayout.widthMeasureMode = YGMeasureModeUndefined; + layout->cachedLayout.heightMeasureMode = YGMeasureModeUndefined; layout->cachedLayout.computedWidth = -1; layout->cachedLayout.computedHeight = -1; } @@ -4061,24 +4037,24 @@ YOGA_EXPORT void YGConfigSetPointScaleFactor( static void YGRoundToPixelGrid( const YGNodeRef node, - const float pointScaleFactor, - const float absoluteLeft, - const float absoluteTop) { + const double pointScaleFactor, + const double absoluteLeft, + const double absoluteTop) { if (pointScaleFactor == 0.0f) { return; } - const float nodeLeft = node->getLayout().position[YGEdgeLeft]; - const float nodeTop = node->getLayout().position[YGEdgeTop]; + const double nodeLeft = node->getLayout().position[YGEdgeLeft]; + const double nodeTop = node->getLayout().position[YGEdgeTop]; - const float nodeWidth = node->getLayout().dimensions[YGDimensionWidth]; - const float nodeHeight = node->getLayout().dimensions[YGDimensionHeight]; + const double nodeWidth = node->getLayout().dimensions[YGDimensionWidth]; + const double nodeHeight = node->getLayout().dimensions[YGDimensionHeight]; - const float absoluteNodeLeft = absoluteLeft + nodeLeft; - const float absoluteNodeTop = absoluteTop + nodeTop; + const double absoluteNodeLeft = absoluteLeft + nodeLeft; + const double absoluteNodeTop = absoluteTop + nodeTop; - const float absoluteNodeRight = absoluteNodeLeft + nodeWidth; - const float absoluteNodeBottom = absoluteNodeTop + nodeHeight; + const double absoluteNodeRight = absoluteNodeLeft + nodeWidth; + const double absoluteNodeBottom = absoluteNodeTop + nodeHeight; // If a node has a custom measure function we never want to round down its // size as this could lead to unwanted text truncation. @@ -4096,11 +4072,11 @@ static void YGRoundToPixelGrid( // whole number, we don't have any fraction To verify if the result is close // to whole number we want to check both floor and ceil numbers const bool hasFractionalWidth = - !YGFloatsEqual(fmodf(nodeWidth * pointScaleFactor, 1.0), 0) && - !YGFloatsEqual(fmodf(nodeWidth * pointScaleFactor, 1.0), 1.0); + !YGDoubleEqual(fmod(nodeWidth * pointScaleFactor, 1.0), 0) && + !YGDoubleEqual(fmod(nodeWidth * pointScaleFactor, 1.0), 1.0); const bool hasFractionalHeight = - !YGFloatsEqual(fmodf(nodeHeight * pointScaleFactor, 1.0), 0) && - !YGFloatsEqual(fmodf(nodeHeight * pointScaleFactor, 1.0), 1.0); + !YGDoubleEqual(fmod(nodeHeight * pointScaleFactor, 1.0), 0) && + !YGDoubleEqual(fmod(nodeHeight * pointScaleFactor, 1.0), 1.0); node->setLayoutDimension( YGRoundValueToPixelGrid( @@ -4321,6 +4297,7 @@ YOGA_EXPORT void YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour( void YGAssert(const bool condition, const char* message) { if (!condition) { Log::log(YGNodeRef{nullptr}, YGLogLevelFatal, nullptr, "%s\n", message); + throwLogicalErrorWithMessage(message); } } @@ -4330,6 +4307,7 @@ void YGAssertWithNode( const char* message) { if (!condition) { Log::log(node, YGLogLevelFatal, nullptr, "%s\n", message); + throwLogicalErrorWithMessage(message); } } @@ -4339,6 +4317,7 @@ void YGAssertWithConfig( const char* message) { if (!condition) { Log::log(config, YGLogLevelFatal, nullptr, "%s\n", message); + throwLogicalErrorWithMessage(message); } } diff --git a/doric-Qt/doric/yoga/Yoga.h b/doric-Qt/doric/yoga/Yoga.h index 68ed0a62..86cd65e2 100644 --- a/doric-Qt/doric/yoga/Yoga.h +++ b/doric-Qt/doric/yoga/Yoga.h @@ -69,6 +69,11 @@ WIN_EXPORT void YGNodeInsertChild( 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); WIN_EXPORT YGNodeRef YGNodeGetChild(YGNodeRef node, uint32_t index); @@ -102,7 +107,7 @@ WIN_EXPORT void YGNodeMarkDirty(YGNodeRef node); // Marks the current node and all its descendants as dirty. // -// Intended to be used for Uoga benchmarks. Don't use in production, as calling +// Intended to be used for Yoga benchmarks. Don't use in production, as calling // `YGCalculateLayout` will cause the recalculation of each and every node. WIN_EXPORT void YGNodeMarkDirtyAndPropogateToDescendants(YGNodeRef node); @@ -347,8 +352,8 @@ WIN_EXPORT void YGConfigSetContext(YGConfigRef config, void* context); WIN_EXPORT void* YGConfigGetContext(YGConfigRef config); WIN_EXPORT float YGRoundValueToPixelGrid( - float value, - float pointScaleFactor, + double value, + double pointScaleFactor, bool forceCeil, bool forceFloor); diff --git a/doric-Qt/doric/yoga/event/event.cpp b/doric-Qt/doric/yoga/event/event.cpp index 2b07e381..3af3e83a 100644 --- a/doric-Qt/doric/yoga/event/event.cpp +++ b/doric-Qt/doric/yoga/event/event.cpp @@ -8,7 +8,6 @@ #include "event.h" #include #include -#include namespace facebook { namespace yoga { diff --git a/doric-Qt/doric/yoga/event/event.h b/doric-Qt/doric/yoga/event/event.h index 309dacb5..404ec376 100644 --- a/doric-Qt/doric/yoga/event/event.h +++ b/doric-Qt/doric/yoga/event/event.h @@ -11,6 +11,7 @@ #include #include #include +#include struct YGConfig; struct YGNode; diff --git a/doric-Qt/doric/yoga/log.cpp b/doric-Qt/doric/yoga/log.cpp index fe6fbbc6..eb3da039 100644 --- a/doric-Qt/doric/yoga/log.cpp +++ b/doric-Qt/doric/yoga/log.cpp @@ -26,10 +26,6 @@ void vlog( va_list args) { YGConfig* logConfig = config != nullptr ? config : YGConfigGetDefault(); logConfig->log(logConfig, node, level, context, format, args); - - if (level == YGLogLevelFatal) { - abort(); - } } } // namespace