Fix sizing of OsuAnimatedButton and OsuClickableContainer

Was incorrect under some combinations of relative and autosize usage.
This commit is contained in:
Dean Herbert 2019-06-03 13:53:24 +09:00
parent e017350b80
commit 3ef17a54f6
3 changed files with 80 additions and 1 deletions

View File

@ -0,0 +1,73 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osuTK;
namespace osu.Game.Tests.Visual.UserInterface
{
public class TestSceneOsuAnimatedButton : GridTestScene
{
public TestSceneOsuAnimatedButton()
: base(3, 2)
{
Cell(0).Add(new BaseContainer("relative sized")
{
RelativeSizeAxes = Axes.Both,
});
Cell(1).Add(new BaseContainer("auto sized")
{
AutoSizeAxes = Axes.Both
});
Cell(2).Add(new BaseContainer("relative Y auto X")
{
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X
});
Cell(3).Add(new BaseContainer("relative X auto Y")
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y
});
Cell(4).Add(new BaseContainer("fixed")
{
Size = new Vector2(100),
});
Cell(5).Add(new BaseContainer("fixed")
{
Size = new Vector2(100, 50),
});
AddToggleStep("toggle enabled", toggle =>
{
for (int i = 0; i < 6; i++)
((BaseContainer)Cell(i).Child).Action = toggle ? () => { } : (Action)null;
});
}
public class BaseContainer : OsuAnimatedButton
{
public BaseContainer(string text)
{
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
Add(new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = text
});
}
}
}
}

View File

@ -31,7 +31,7 @@ private void load()
{
if (AutoSizeAxes != Axes.None)
{
content.RelativeSizeAxes = RelativeSizeAxes;
content.RelativeSizeAxes = (Axes.Both & ~AutoSizeAxes);
content.AutoSizeAxes = AutoSizeAxes;
}

View File

@ -74,6 +74,12 @@ public OsuAnimatedButton()
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
if (AutoSizeAxes != Axes.None)
{
content.RelativeSizeAxes = (Axes.Both & ~AutoSizeAxes);
content.AutoSizeAxes = AutoSizeAxes;
}
Enabled.BindValueChanged(enabled => this.FadeColour(enabled.NewValue ? Color4.White : colours.Gray9, 200, Easing.OutQuint), true);
}