diff --git a/.rive_head b/.rive_head index 5ba69c37..f2ccbcf9 100644 --- a/.rive_head +++ b/.rive_head @@ -1 +1 @@ -edc91a599a7f182007e488b232d64e0166f43139 +95cad5c6055750ff6b1c033f903967e6b9c22bb6 diff --git a/include/rive/layout_component.hpp b/include/rive/layout_component.hpp index 668b938e..9fa80b50 100644 --- a/include/rive/layout_component.hpp +++ b/include/rive/layout_component.hpp @@ -76,6 +76,8 @@ class LayoutComponent : public LayoutComponentBase, public ProxyDrawing, public float m_heightOverride = NAN; int m_heightUnitValueOverride = -1; bool m_parentIsRow = true; + bool m_widthIntrinsicallySizeOverride = false; + bool m_heightIntrinsicallySizeOverride = false; #ifdef WITH_RIVE_LAYOUT protected: @@ -116,6 +118,8 @@ class LayoutComponent : public LayoutComponentBase, public ProxyDrawing, public // width/height and unit values. void widthOverride(float width, int unitValue = 1, bool isRow = true); void heightOverride(float height, int unitValue = 1, bool isRow = true); + void widthIntrinsicallySizeOverride(bool intrinsic); + void heightIntrinsicallySizeOverride(bool intrinsic); virtual bool canHaveOverrides() { return false; } bool mainAxisIsRow(); bool mainAxisIsColumn(); diff --git a/src/layout_component.cpp b/src/layout_component.cpp index ca2b1b61..c1443f28 100644 --- a/src/layout_component.cpp +++ b/src/layout_component.cpp @@ -149,6 +149,24 @@ void LayoutComponent::heightOverride(float height, int unitValue, bool isRow) markLayoutNodeDirty(); } +void LayoutComponent::widthIntrinsicallySizeOverride(bool intrinsic) +{ + m_widthIntrinsicallySizeOverride = intrinsic; + // If we have an intrinsically sized override, set units to auto + // otherwise set to points + m_widthUnitValueOverride = intrinsic ? 3 : 1; + markLayoutNodeDirty(); +} + +void LayoutComponent::heightIntrinsicallySizeOverride(bool intrinsic) +{ + m_heightIntrinsicallySizeOverride = intrinsic; + // If we have an intrinsically sized override, set units to auto + // otherwise set to points + m_heightUnitValueOverride = intrinsic ? 3 : 1; + markLayoutNodeDirty(); +} + #ifdef WITH_RIVE_LAYOUT StatusCode LayoutComponent::onAddedDirty(CoreContext* context) { @@ -298,7 +316,14 @@ void LayoutComponent::syncStyle() realWidthScaleType = LayoutScaleType::fixed; break; case YGUnitAuto: - realWidthScaleType = LayoutScaleType::fill; + if (m_widthIntrinsicallySizeOverride) + { + realWidthScaleType = LayoutScaleType::hug; + } + else + { + realWidthScaleType = LayoutScaleType::fill; + } break; default: break; @@ -314,7 +339,14 @@ void LayoutComponent::syncStyle() realHeightScaleType = LayoutScaleType::fixed; break; case YGUnitAuto: - realHeightScaleType = LayoutScaleType::fill; + if (m_heightIntrinsicallySizeOverride) + { + realHeightScaleType = LayoutScaleType::hug; + } + else + { + realHeightScaleType = LayoutScaleType::fill; + } break; default: break; diff --git a/src/nested_artboard_layout.cpp b/src/nested_artboard_layout.cpp index 501ffd67..384981bc 100644 --- a/src/nested_artboard_layout.cpp +++ b/src/nested_artboard_layout.cpp @@ -94,13 +94,19 @@ void NestedArtboardLayout::updateWidthOverride() if (instanceWidthScaleType() == 0) // LayoutScaleType::fixed { // If we're set to fixed, pass the unit value (points|percent) + artboardInstance()->widthIntrinsicallySizeOverride(false); artboardInstance()->widthOverride(actualInstanceWidth(), instanceWidthUnitsValue(), isRow); } else if (instanceWidthScaleType() == 1) // LayoutScaleType::fill { // If we're set to fill, pass auto + artboardInstance()->widthIntrinsicallySizeOverride(false); artboardInstance()->widthOverride(actualInstanceWidth(), 3, isRow); } + else if (instanceWidthScaleType() == 2) + { + artboardInstance()->widthIntrinsicallySizeOverride(true); + } } void NestedArtboardLayout::updateHeightOverride() @@ -114,6 +120,7 @@ void NestedArtboardLayout::updateHeightOverride() if (instanceHeightScaleType() == 0) // LayoutScaleType::fixed { // If we're set to fixed, pass the unit value (points|percent) + artboardInstance()->heightIntrinsicallySizeOverride(false); artboardInstance()->heightOverride(actualInstanceHeight(), instanceHeightUnitsValue(), isRow); @@ -121,8 +128,13 @@ void NestedArtboardLayout::updateHeightOverride() else if (instanceHeightScaleType() == 1) // LayoutScaleType::fill { // If we're set to fill, pass auto + artboardInstance()->heightIntrinsicallySizeOverride(false); artboardInstance()->heightOverride(actualInstanceHeight(), 3, isRow); } + else if (instanceWidthScaleType() == 2) + { + artboardInstance()->heightIntrinsicallySizeOverride(true); + } } void NestedArtboardLayout::instanceWidthChanged() { updateWidthOverride(); }