From c7ab5c858371b75694c66b2264f34da52458f84e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20Sch=C3=BCrz?= Date: Fri, 11 Apr 2025 15:56:31 +0200 Subject: [PATCH 01/12] Add `DampContinuously` method for Vector2 values --- osu.Framework/Utils/Interpolation.cs | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/osu.Framework/Utils/Interpolation.cs b/osu.Framework/Utils/Interpolation.cs index 68b077bf0a..3df9cbdd83 100644 --- a/osu.Framework/Utils/Interpolation.cs +++ b/osu.Framework/Utils/Interpolation.cs @@ -32,6 +32,21 @@ public static double Damp(double start, double final, double @base, double expon return Lerp(start, final, 1 - Math.Pow(@base, exponent)); } + /// + /// Interpolates between 2 vectors (start and final) using a given base and exponent. + /// + /// The start value. + /// The end value. + /// The base of the exponential. The valid range is [0, 1], where smaller values mean that the final value is achieved more quickly, and values closer to 1 results in slow convergence to the final value. + /// The exponent of the exponential. An exponent of 0 results in the start values, whereas larger exponents make the result converge to the final value. + public static Vector2 Damp(Vector2 start, Vector2 final, double @base, double exponent) + { + if (@base < 0 || @base > 1) + throw new ArgumentOutOfRangeException(nameof(@base), $"{nameof(@base)} has to lie in [0,1], but is {@base}."); + + return Vector2.Lerp(start, final, (float)(1 - Math.Pow(@base, exponent))); + } + /// /// Interpolate the current value towards the target value based on the elapsed time. /// If the current value is updated every frame using this function, the result is approximately frame-rate independent. @@ -50,6 +65,24 @@ public static double DampContinuously(double current, double target, double half return Damp(current, target, 0.5, exponent); } + /// + /// Interpolate the current value towards the target value based on the elapsed time. + /// If the current value is updated every frame using this function, the result is approximately frame-rate independent. + /// + /// + /// Because floating-point errors can accumulate over a long time, this function shouldn't be + /// used for things requiring accurate values. + /// + /// The current value. + /// The target value. + /// The time it takes to reach the middle value of the current and the target value. + /// The elapsed time of the current frame. + public static Vector2 DampContinuously(Vector2 current, Vector2 target, double halfTime, double elapsedTime) + { + double exponent = elapsedTime / halfTime; + return Damp(current, target, 0.5, exponent); + } + /// /// Interpolates between a set of points using a lagrange polynomial. /// From a9b8bbf9382d6a2aa790aa0bb1840bf6305a6932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20Sch=C3=BCrz?= Date: Fri, 11 Apr 2025 16:11:29 +0200 Subject: [PATCH 02/12] Use continuous damping for autoSize --- .../Visual/Layout/TestSceneLayoutDurations.cs | 1 - .../Graphics/Containers/CompositeDrawable.cs | 66 +++++++++---------- .../Graphics/Containers/Container.cs | 14 +--- .../Graphics/Containers/FlowContainer.cs | 6 +- 4 files changed, 35 insertions(+), 52 deletions(-) diff --git a/osu.Framework.Tests/Visual/Layout/TestSceneLayoutDurations.cs b/osu.Framework.Tests/Visual/Layout/TestSceneLayoutDurations.cs index 0d868976ce..519bc0391e 100644 --- a/osu.Framework.Tests/Visual/Layout/TestSceneLayoutDurations.cs +++ b/osu.Framework.Tests/Visual/Layout/TestSceneLayoutDurations.cs @@ -37,7 +37,6 @@ public void SetUp() => Schedule(() => autoSizeContainer = new Container { Clock = new FramedClock(manualClock), - AutoSizeEasing = Easing.None, Children = new[] { new Box diff --git a/osu.Framework/Graphics/Containers/CompositeDrawable.cs b/osu.Framework/Graphics/Containers/CompositeDrawable.cs index 3d9de04b5f..3a8e21567c 100644 --- a/osu.Framework/Graphics/Containers/CompositeDrawable.cs +++ b/osu.Framework/Graphics/Containers/CompositeDrawable.cs @@ -22,6 +22,7 @@ using osu.Framework.Statistics; using System.Threading.Tasks; using JetBrains.Annotations; +using osu.Framework.Caching; using osu.Framework.Development; using osu.Framework.Extensions.EnumExtensions; using osu.Framework.Extensions.ExceptionExtensions; @@ -1813,17 +1814,11 @@ protected set } /// - /// The duration which automatic sizing should take. If zero, then it is instantaneous. - /// Otherwise, this is equivalent to applying an automatic size via a resize transform. + /// The duration which automatic sizing should approximately take. If zero, then it is instantaneous. + /// AutoSize is being applied continuously so the actual amount of time taken depends on the overall change in value. /// public float AutoSizeDuration { get; protected set; } - /// - /// The type of easing which should be used for smooth automatic sizing when - /// is non-zero. - /// - public Easing AutoSizeEasing { get; protected set; } - /// /// Fired after this 's is updated through autosize. /// @@ -1940,12 +1935,7 @@ private void updateAutoSize() if (AutoSizeAxes == Axes.None) return; - Vector2 b = computeAutoSize() + Padding.Total; - - autoSizeResizeTo(new Vector2( - AutoSizeAxes.HasFlagFast(Axes.X) ? b.X : base.Width, - AutoSizeAxes.HasFlagFast(Axes.Y) ? b.Y : base.Height - ), AutoSizeDuration, AutoSizeEasing); + targetAutoSize.Value = computeAutoSize() + Padding.Total; //note that this is called before autoSize becomes valid. may be something to consider down the line. //might work better to add an OnRefresh event in Cached<> and invoke there. @@ -1963,6 +1953,9 @@ private void updateChildrenSizeDependencies() updateAutoSize(); childrenSizeDependencies.Validate(); } + + if (targetAutoSize.IsValid) + applyAutoSize(targetAutoSize.Value); } finally { @@ -1970,25 +1963,38 @@ private void updateChildrenSizeDependencies() } } - private void autoSizeResizeTo(Vector2 newSize, double duration = 0, Easing easing = Easing.None) + private void applyAutoSize(Vector2 targetSize) { - var currentTransform = TransformsForTargetMember(nameof(baseSize)).FirstOrDefault() as AutoSizeTransform; + targetSize = new Vector2( + AutoSizeAxes.HasFlagFast(Axes.X) ? targetSize.X : base.Width, + AutoSizeAxes.HasFlagFast(Axes.Y) ? targetSize.Y : base.Height + ); - if ((currentTransform?.EndValue ?? Size) != newSize) + if (AutoSizeDuration <= 0) { - if (duration == 0) - { - if (currentTransform != null) - ClearTransforms(false, nameof(baseSize)); - baseSize = newSize; - } - else - this.TransformTo(this.PopulateTransform(new AutoSizeTransform { Rewindable = false }, newSize, duration, easing)); + baseSize = targetSize; + targetAutoSize.Invalidate(); + return; + } + + Vector2 newSize = Interpolation.DampContinuously(baseSize, targetSize, AutoSizeDuration / 4, Time.Elapsed); + + if (Precision.AlmostEquals(newSize, targetSize, 0.5f)) + { + newSize = targetSize; + targetAutoSize.Invalidate(); } + + baseSize = newSize; } /// - /// A helper property for to change the size of s with . + /// When valid, holds the current target size computed for automatic sizing. + /// + private readonly Cached targetAutoSize = new Cached(); + + /// + /// A helper property for to change the size of s with . /// private Vector2 baseSize { @@ -2000,14 +2006,6 @@ private Vector2 baseSize } } - private class AutoSizeTransform : TransformCustom - { - public AutoSizeTransform() - : base(nameof(baseSize)) - { - } - } - #endregion } } diff --git a/osu.Framework/Graphics/Containers/Container.cs b/osu.Framework/Graphics/Containers/Container.cs index 2c996f04b1..3f7b90e31a 100644 --- a/osu.Framework/Graphics/Containers/Container.cs +++ b/osu.Framework/Graphics/Containers/Container.cs @@ -492,8 +492,8 @@ public void ChangeChildDepth(T child, float newDepth) } /// - /// The duration which automatic sizing should take. If zero, then it is instantaneous. - /// Otherwise, this is equivalent to applying an automatic size via a resize transform. + /// The duration which automatic sizing should approximately take. If zero, then it is instantaneous. + /// AutoSize is being applied continuously so the actual amount of time taken depends on the overall change in value. /// public new float AutoSizeDuration { @@ -501,16 +501,6 @@ public void ChangeChildDepth(T child, float newDepth) set => base.AutoSizeDuration = value; } - /// - /// The type of easing which should be used for smooth automatic sizing when - /// is non-zero. - /// - public new Easing AutoSizeEasing - { - get => base.AutoSizeEasing; - set => base.AutoSizeEasing = value; - } - public struct Enumerator : IEnumerator { private Container container; diff --git a/osu.Framework/Graphics/Containers/FlowContainer.cs b/osu.Framework/Graphics/Containers/FlowContainer.cs index 005202c749..5361970787 100644 --- a/osu.Framework/Graphics/Containers/FlowContainer.cs +++ b/osu.Framework/Graphics/Containers/FlowContainer.cs @@ -31,11 +31,7 @@ protected FlowContainer() /// /// The easing that should be used when children are moved to their position in the layout. /// - public Easing LayoutEasing - { - get => AutoSizeEasing; - set => AutoSizeEasing = value; - } + public Easing LayoutEasing { get; set; } /// /// The time it should take to move a child from its current position to its new layout position. From d05cb9d5f25b95d07a14f9a5496c4139aa532f85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20Sch=C3=BCrz?= Date: Fri, 11 Apr 2025 18:08:07 +0200 Subject: [PATCH 03/12] Apply autoSize immediately if duration is zero --- osu.Framework/Graphics/Containers/CompositeDrawable.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Framework/Graphics/Containers/CompositeDrawable.cs b/osu.Framework/Graphics/Containers/CompositeDrawable.cs index 3a8e21567c..44d47e0d4c 100644 --- a/osu.Framework/Graphics/Containers/CompositeDrawable.cs +++ b/osu.Framework/Graphics/Containers/CompositeDrawable.cs @@ -1937,6 +1937,9 @@ private void updateAutoSize() targetAutoSize.Value = computeAutoSize() + Padding.Total; + if (AutoSizeDuration <= 0) + applyAutoSize(targetAutoSize.Value); + //note that this is called before autoSize becomes valid. may be something to consider down the line. //might work better to add an OnRefresh event in Cached<> and invoke there. OnAutoSize?.Invoke(); From 792f14506d3228f3928ca0b503e4b58e20c9c8b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20Sch=C3=BCrz?= Date: Fri, 11 Apr 2025 18:15:13 +0200 Subject: [PATCH 04/12] Add test scene for autosize duration --- .../Containers/TestSceneCompositeDrawable.cs | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/osu.Framework.Tests/Visual/Containers/TestSceneCompositeDrawable.cs b/osu.Framework.Tests/Visual/Containers/TestSceneCompositeDrawable.cs index 8064c71d70..2ad11d7a84 100644 --- a/osu.Framework.Tests/Visual/Containers/TestSceneCompositeDrawable.cs +++ b/osu.Framework.Tests/Visual/Containers/TestSceneCompositeDrawable.cs @@ -89,6 +89,54 @@ public void TestClearTransformsOnDelayedAutoSize() AddUntilStep("container still autosized", () => container.Size == new Vector2(100)); } + [Test] + public void TestAutoSizeDuration() + { + Container parent = null; + Drawable child = null; + + AddStep("create hierarchy", () => + { + Child = parent = new Container + { + Masking = true, + AutoSizeAxes = Axes.Both, + AutoSizeDuration = 500, + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Color4.Yellow, + }, + new Container + { + Padding = new MarginPadding(50), + AutoSizeAxes = Axes.Both, + Child = child = new Box + { + Size = new Vector2(100), + Colour = Color4.Red, + } + } + } + }; + }); + + AddSliderStep("AutoSizeDuration", 0f, 1500f, 500f, value => + { + if (parent != null) parent.AutoSizeDuration = value; + }); + AddSliderStep("Width", 0f, 300f, 100f, value => + { + if (child != null) child.Width = value; + }); + AddSliderStep("Height", 0f, 300f, 100f, value => + { + if (child != null) child.Height = value; + }); + } + private partial class SortableComposite : CompositeDrawable { public SortableComposite() From e4023e55b83ce29dd3c7a07e0874f4dd47992a6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20Sch=C3=BCrz?= Date: Fri, 11 Apr 2025 18:20:39 +0200 Subject: [PATCH 05/12] Remove test that's no longer applicable --- .../Visual/Layout/TestSceneLayoutDurations.cs | 46 ++----------------- 1 file changed, 5 insertions(+), 41 deletions(-) diff --git a/osu.Framework.Tests/Visual/Layout/TestSceneLayoutDurations.cs b/osu.Framework.Tests/Visual/Layout/TestSceneLayoutDurations.cs index 519bc0391e..59e8bd9943 100644 --- a/osu.Framework.Tests/Visual/Layout/TestSceneLayoutDurations.cs +++ b/osu.Framework.Tests/Visual/Layout/TestSceneLayoutDurations.cs @@ -18,10 +18,9 @@ namespace osu.Framework.Tests.Visual.Layout public partial class TestSceneLayoutDurations : FrameworkTestScene { private ManualClock manualClock; - private Container autoSizeContainer; private FillFlowContainer fillFlowContainer; - private Box box1, box2; + private Box box; private const float duration = 1000; @@ -34,23 +33,6 @@ public void SetUp() => Schedule(() => Children = new Drawable[] { - autoSizeContainer = new Container - { - Clock = new FramedClock(manualClock), - Children = new[] - { - new Box - { - Colour = Color4.Red, - RelativeSizeAxes = Axes.Both - }, - box1 = new Box - { - Colour = Color4.Transparent, - Size = Vector2.Zero, - }, - } - }, fillFlowContainer = new FillFlowContainer { Clock = new FramedClock(manualClock), @@ -59,27 +41,20 @@ public void SetUp() => Schedule(() => Children = new Drawable[] { new Box { Colour = Color4.Red, Size = new Vector2(100) }, - box2 = new Box { Colour = Color4.Blue, Size = new Vector2(100) }, + box = new Box { Colour = Color4.Blue, Size = new Vector2(100) }, } } }; paused = false; - autoSizeContainer.FinishTransforms(); fillFlowContainer.FinishTransforms(); - autoSizeContainer.AutoSizeAxes = Axes.None; - autoSizeContainer.AutoSizeDuration = 0; - autoSizeContainer.Size = Vector2.Zero; - box1.Size = Vector2.Zero; - fillFlowContainer.LayoutDuration = 0; fillFlowContainer.Size = new Vector2(200, 200); }); private void check(float ratio) => - AddAssert($"Check @{ratio}", () => Precision.AlmostEquals(autoSizeContainer.Size, new Vector2(changed_value * ratio)) && - Precision.AlmostEquals(box2.Position, new Vector2(changed_value * (1 - ratio), changed_value * ratio))); + AddAssert($"Check @{ratio}", () => Precision.AlmostEquals(box.Position, new Vector2(changed_value * (1 - ratio), changed_value * ratio))); private void skipTo(float ratio) => AddStep($"skip to {ratio}", () => { manualClock.CurrentTime = duration * ratio; }); @@ -90,13 +65,8 @@ public void TestChangeAfterDuration() { paused = true; manualClock.CurrentTime = 0; - autoSizeContainer.FinishTransforms(); fillFlowContainer.FinishTransforms(); - autoSizeContainer.AutoSizeAxes = Axes.Both; - autoSizeContainer.AutoSizeDuration = duration; - box1.Size = new Vector2(100); - fillFlowContainer.LayoutDuration = duration; fillFlowContainer.Width = 100; }); @@ -115,14 +85,11 @@ public void TestInterruptExistingDuration() { paused = true; manualClock.CurrentTime = 0; - autoSizeContainer.FinishTransforms(); fillFlowContainer.FinishTransforms(); - autoSizeContainer.AutoSizeAxes = Axes.Both; - autoSizeContainer.AutoSizeDuration = duration; fillFlowContainer.LayoutDuration = duration; - box1.Size = new Vector2(changed_value); + box.Size = new Vector2(changed_value); fillFlowContainer.Width = changed_value; }); @@ -131,7 +98,6 @@ public void TestInterruptExistingDuration() AddStep("set duration 0", () => { - autoSizeContainer.AutoSizeDuration = 0; fillFlowContainer.LayoutDuration = 0; }); @@ -145,7 +111,6 @@ public void TestInterruptExistingDuration() AddStep("alter values", () => { - box1.Size = new Vector2(0); fillFlowContainer.Width = 200; }); @@ -161,11 +126,10 @@ public void TestInterruptExistingDuration() protected override void Update() { - if (autoSizeContainer != null) + if (fillFlowContainer != null) { if (!paused) manualClock.CurrentTime = Clock.CurrentTime; - autoSizeContainer.Children[0].Invalidate(); fillFlowContainer.Invalidate(); } From 20e67243a439a9e795da51feef3367e164733e58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20Sch=C3=BCrz?= Date: Fri, 11 Apr 2025 19:22:56 +0200 Subject: [PATCH 06/12] Make sure initial autosize is instant --- .../Graphics/Containers/CompositeDrawable.cs | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/osu.Framework/Graphics/Containers/CompositeDrawable.cs b/osu.Framework/Graphics/Containers/CompositeDrawable.cs index 44d47e0d4c..dc15ce178e 100644 --- a/osu.Framework/Graphics/Containers/CompositeDrawable.cs +++ b/osu.Framework/Graphics/Containers/CompositeDrawable.cs @@ -946,6 +946,7 @@ public override bool UpdateSubTree() UpdateAfterChildren(); updateChildrenSizeDependencies(); + applyAutoSize(); UpdateAfterAutoSize(); return true; } @@ -1933,12 +1934,15 @@ private Vector2 computeAutoSize() private void updateAutoSize() { if (AutoSizeAxes == Axes.None) + { + targetAutoSize.Invalidate(); return; + } targetAutoSize.Value = computeAutoSize() + Padding.Total; - if (AutoSizeDuration <= 0) - applyAutoSize(targetAutoSize.Value); + if (!didInitialAutoSize || AutoSizeDuration <= 0) + autoSizeResizeTo(targetAutoSize.Value, 0); //note that this is called before autoSize becomes valid. may be something to consider down the line. //might work better to add an OnRefresh event in Cached<> and invoke there. @@ -1956,9 +1960,6 @@ private void updateChildrenSizeDependencies() updateAutoSize(); childrenSizeDependencies.Validate(); } - - if (targetAutoSize.IsValid) - applyAutoSize(targetAutoSize.Value); } finally { @@ -1966,21 +1967,32 @@ private void updateChildrenSizeDependencies() } } - private void applyAutoSize(Vector2 targetSize) + private void applyAutoSize() + { + if (AutoSizeAxes == Axes.None) + return; + + if (targetAutoSize.IsValid) + autoSizeResizeTo(targetAutoSize.Value, AutoSizeDuration); + + didInitialAutoSize = true; + } + + private void autoSizeResizeTo(Vector2 targetSize, double duration) { targetSize = new Vector2( AutoSizeAxes.HasFlagFast(Axes.X) ? targetSize.X : base.Width, AutoSizeAxes.HasFlagFast(Axes.Y) ? targetSize.Y : base.Height ); - if (AutoSizeDuration <= 0) + if (duration <= 0) { baseSize = targetSize; targetAutoSize.Invalidate(); return; } - Vector2 newSize = Interpolation.DampContinuously(baseSize, targetSize, AutoSizeDuration / 4, Time.Elapsed); + Vector2 newSize = Interpolation.DampContinuously(baseSize, targetSize, duration / 4, Time.Elapsed); if (Precision.AlmostEquals(newSize, targetSize, 0.5f)) { @@ -1996,8 +2008,10 @@ private void applyAutoSize(Vector2 targetSize) /// private readonly Cached targetAutoSize = new Cached(); + private bool didInitialAutoSize; + /// - /// A helper property for to change the size of s with . + /// A helper property for to change the size of s with . /// private Vector2 baseSize { From 0b1ccff3c3bc3d3a0e8504c032fda9cc646626d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20Sch=C3=BCrz?= Date: Fri, 11 Apr 2025 19:23:16 +0200 Subject: [PATCH 07/12] Add method to finish autosize transform --- .../Containers/TestSceneCompositeDrawable.cs | 38 +++++++++++++++++++ .../Graphics/Containers/CompositeDrawable.cs | 8 ++++ .../Graphics/Containers/Container.cs | 2 + 3 files changed, 48 insertions(+) diff --git a/osu.Framework.Tests/Visual/Containers/TestSceneCompositeDrawable.cs b/osu.Framework.Tests/Visual/Containers/TestSceneCompositeDrawable.cs index 2ad11d7a84..3837dff7be 100644 --- a/osu.Framework.Tests/Visual/Containers/TestSceneCompositeDrawable.cs +++ b/osu.Framework.Tests/Visual/Containers/TestSceneCompositeDrawable.cs @@ -8,6 +8,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; +using osu.Framework.Utils; using osuTK; using osuTK.Graphics; @@ -137,6 +138,43 @@ public void TestAutoSizeDuration() }); } + [Test] + public void TestFinishAutoSizeTransforms() + { + Container parent = null; + Drawable child = null; + + AddStep("create hierarchy", () => + { + Child = parent = new Container + { + Masking = true, + AutoSizeAxes = Axes.Both, + AutoSizeDuration = 1000, + Name = "Parent", + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Color4.Yellow, + }, + child = new Box + { + Size = new Vector2(100), + Colour = Color4.Red, + Alpha = 0.5f, + } + } + }; + }); + AddAssert("size matches child", () => Precision.AlmostEquals(parent.ChildSize, child.DrawSize)); + AddStep("resize child", () => child.Size = new Vector2(200)); + AddAssert("size doesn't match child", () => !Precision.AlmostEquals(parent.ChildSize, child.DrawSize)); + AddStep("finish autosize transform", () => parent.FinishAutoSizeTransforms()); + AddAssert("size matches child", () => Precision.AlmostEquals(parent.ChildSize, child.DrawSize)); + } + private partial class SortableComposite : CompositeDrawable { public SortableComposite() diff --git a/osu.Framework/Graphics/Containers/CompositeDrawable.cs b/osu.Framework/Graphics/Containers/CompositeDrawable.cs index dc15ce178e..b731715f20 100644 --- a/osu.Framework/Graphics/Containers/CompositeDrawable.cs +++ b/osu.Framework/Graphics/Containers/CompositeDrawable.cs @@ -2003,6 +2003,14 @@ private void autoSizeResizeTo(Vector2 targetSize, double duration) baseSize = newSize; } + protected void FinishAutoSizeTransforms() + { + updateChildrenSizeDependencies(); + + if (targetAutoSize.IsValid) + autoSizeResizeTo(targetAutoSize.Value, 0); + } + /// /// When valid, holds the current target size computed for automatic sizing. /// diff --git a/osu.Framework/Graphics/Containers/Container.cs b/osu.Framework/Graphics/Containers/Container.cs index 3f7b90e31a..f0121e03b3 100644 --- a/osu.Framework/Graphics/Containers/Container.cs +++ b/osu.Framework/Graphics/Containers/Container.cs @@ -501,6 +501,8 @@ public void ChangeChildDepth(T child, float newDepth) set => base.AutoSizeDuration = value; } + public new void FinishAutoSizeTransforms() => base.FinishAutoSizeTransforms(); + public struct Enumerator : IEnumerator { private Container container; From ca36a469963604785ecda0f99e7f1aa6a73a6d2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20Sch=C3=BCrz?= Date: Fri, 11 Apr 2025 19:29:10 +0200 Subject: [PATCH 08/12] Fix wording in docs --- osu.Framework/Graphics/Containers/CompositeDrawable.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Framework/Graphics/Containers/CompositeDrawable.cs b/osu.Framework/Graphics/Containers/CompositeDrawable.cs index b731715f20..973a76e2d8 100644 --- a/osu.Framework/Graphics/Containers/CompositeDrawable.cs +++ b/osu.Framework/Graphics/Containers/CompositeDrawable.cs @@ -2012,7 +2012,7 @@ protected void FinishAutoSizeTransforms() } /// - /// When valid, holds the current target size computed for automatic sizing. + /// When valid, holds the current target size that should be approached when using automatic sizing and is non-zero. /// private readonly Cached targetAutoSize = new Cached(); From 0cb33967c621330f0a55403ea1f6f580ea492482 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20Sch=C3=BCrz?= Date: Fri, 11 Apr 2025 19:36:04 +0200 Subject: [PATCH 09/12] Remove early exit from method --- osu.Framework/Graphics/Containers/CompositeDrawable.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/osu.Framework/Graphics/Containers/CompositeDrawable.cs b/osu.Framework/Graphics/Containers/CompositeDrawable.cs index 973a76e2d8..83b2f0b453 100644 --- a/osu.Framework/Graphics/Containers/CompositeDrawable.cs +++ b/osu.Framework/Graphics/Containers/CompositeDrawable.cs @@ -1969,9 +1969,6 @@ private void updateChildrenSizeDependencies() private void applyAutoSize() { - if (AutoSizeAxes == Axes.None) - return; - if (targetAutoSize.IsValid) autoSizeResizeTo(targetAutoSize.Value, AutoSizeDuration); From 1d3fdfc1fab38e4a4dec668760d9e8abcfe830b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20Sch=C3=BCrz?= Date: Fri, 11 Apr 2025 19:40:40 +0200 Subject: [PATCH 10/12] Add doc comment --- osu.Framework/Graphics/Containers/CompositeDrawable.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Framework/Graphics/Containers/CompositeDrawable.cs b/osu.Framework/Graphics/Containers/CompositeDrawable.cs index 83b2f0b453..1f1f5bde19 100644 --- a/osu.Framework/Graphics/Containers/CompositeDrawable.cs +++ b/osu.Framework/Graphics/Containers/CompositeDrawable.cs @@ -2000,6 +2000,9 @@ private void autoSizeResizeTo(Vector2 targetSize, double duration) baseSize = newSize; } + /// + /// Immediately resizes to the current target size if is non-zero. + /// protected void FinishAutoSizeTransforms() { updateChildrenSizeDependencies(); From 3e5de2d6d3efebf778fe17a53f7410ed8ab42879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20Sch=C3=BCrz?= Date: Fri, 11 Apr 2025 19:42:02 +0200 Subject: [PATCH 11/12] Add doc comment to Container too --- osu.Framework/Graphics/Containers/Container.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Framework/Graphics/Containers/Container.cs b/osu.Framework/Graphics/Containers/Container.cs index f0121e03b3..f879f9742a 100644 --- a/osu.Framework/Graphics/Containers/Container.cs +++ b/osu.Framework/Graphics/Containers/Container.cs @@ -501,6 +501,9 @@ public void ChangeChildDepth(T child, float newDepth) set => base.AutoSizeDuration = value; } + /// + /// Immediately resizes to the current target size if is non-zero. + /// public new void FinishAutoSizeTransforms() => base.FinishAutoSizeTransforms(); public struct Enumerator : IEnumerator From 05250613df272e34f408b32f066d1e87b9f23c23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20Sch=C3=BCrz?= Date: Fri, 11 Apr 2025 19:43:14 +0200 Subject: [PATCH 12/12] Use `LayoutSize` for assertion instead of `DrawSize` --- .../Visual/Containers/TestSceneCompositeDrawable.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Framework.Tests/Visual/Containers/TestSceneCompositeDrawable.cs b/osu.Framework.Tests/Visual/Containers/TestSceneCompositeDrawable.cs index 3837dff7be..7c3e521bd5 100644 --- a/osu.Framework.Tests/Visual/Containers/TestSceneCompositeDrawable.cs +++ b/osu.Framework.Tests/Visual/Containers/TestSceneCompositeDrawable.cs @@ -168,11 +168,11 @@ public void TestFinishAutoSizeTransforms() } }; }); - AddAssert("size matches child", () => Precision.AlmostEquals(parent.ChildSize, child.DrawSize)); + AddAssert("size matches child", () => Precision.AlmostEquals(parent.ChildSize, child.LayoutSize)); AddStep("resize child", () => child.Size = new Vector2(200)); - AddAssert("size doesn't match child", () => !Precision.AlmostEquals(parent.ChildSize, child.DrawSize)); + AddAssert("size doesn't match child", () => !Precision.AlmostEquals(parent.ChildSize, child.LayoutSize)); AddStep("finish autosize transform", () => parent.FinishAutoSizeTransforms()); - AddAssert("size matches child", () => Precision.AlmostEquals(parent.ChildSize, child.DrawSize)); + AddAssert("size matches child", () => Precision.AlmostEquals(parent.ChildSize, child.LayoutSize)); } private partial class SortableComposite : CompositeDrawable