Skip to content

Skip initial autosize transform in CompositeDrawable #6560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#nullable disable

using System;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
Expand Down Expand Up @@ -89,6 +90,29 @@ public void TestClearTransformsOnDelayedAutoSize()
AddUntilStep("container still autosized", () => container.Size == new Vector2(100));
}

[Test]
public void TestSkipInitialAutoSizeTransform()
{
Container container = null;
Drawable child = null;

AddStep("create hierarchy", () =>
{
Child = container = new Container
{
Masking = true,
AutoSizeAxes = Axes.Both,
AutoSizeDuration = 1000,
SkipInitialAutoSizeTransform = true,
Child = child = new Box { Size = new Vector2(100) },
};
});

AddAssert("no AutoSize transform present", () => container.Transforms.All(it => it.TargetMember != "baseSize"));
AddStep("update child size", () => child.Size = new Vector2(200));
AddAssert("autoSize transform present", () => container.Transforms.Any(it => it.TargetMember == "baseSize"));
}

private partial class SortableComposite : CompositeDrawable
{
public SortableComposite()
Expand Down
15 changes: 15 additions & 0 deletions osu.Framework/Graphics/Containers/CompositeDrawable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,13 @@ public override bool UpdateSubTree()
UpdateAfterChildren();

updateChildrenSizeDependencies();

if (SkipInitialAutoSizeTransform && !didInitialAutosize)
{
FinishTransforms(false, nameof(baseSize));
didInitialAutosize = true;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be moved inside updateChildrenSizeDependencies and potentially not do the transform in the first place rather than immediately terminating it? Feels weird to have laid out flat in the main update process.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original thought behind placing it there was that updateChildrenSizeDependencies can also get called from outside the update loop, so putting it here would make sure that the component had the chance to do a full update before finishing the transform.
I'm fine with moving it into updateChildrenSizeDependencies though.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up moving it into autoSizeResizeTo instead, seemed like a more convenient place to do this to me.


UpdateAfterAutoSize();
return true;
}
Expand All @@ -955,6 +962,8 @@ private void updateChild(Drawable c)
c.UpdateSubTree();
}

private bool didInitialAutosize;

/// <summary>
/// Updates all masking calculations for this <see cref="CompositeDrawable"/> and its <see cref="AliveInternalChildren"/>.
/// This occurs post-<see cref="UpdateSubTree"/> to ensure that all <see cref="Drawable"/> updates have taken place.
Expand Down Expand Up @@ -1824,6 +1833,12 @@ protected set
/// </summary>
public Easing AutoSizeEasing { get; protected set; }

/// <summary>
/// Whether the first resize should be instantaneously when autosize gets applied for the first time and <see cref="AutoSizeDuration"/>
/// is non-zero.
/// </summary>
public bool SkipInitialAutoSizeTransform { get; protected set; }

/// <summary>
/// Fired after this <see cref="CompositeDrawable"/>'s <see cref="Size"/> is updated through autosize.
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions osu.Framework/Graphics/Containers/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,16 @@ public void ChangeChildDepth(T child, float newDepth)
set => base.AutoSizeEasing = value;
}

/// <summary>
/// Whether the first resize should be instantaneously when autosize gets applied for the first time and <see cref="AutoSizeDuration"/>
/// is non-zero.
/// </summary>
public new bool SkipInitialAutoSizeTransform
{
get => base.SkipInitialAutoSizeTransform;
set => base.SkipInitialAutoSizeTransform = value;
}

public struct Enumerator : IEnumerator<T>
{
private Container<T> container;
Expand Down
Loading