mirror of https://github.com/ppy/osu
Fix sizing of OsuAnimatedButton and OsuClickableContainer (#4898)
Fix sizing of OsuAnimatedButton and OsuClickableContainer
This commit is contained in:
commit
b93446688c
|
@ -0,0 +1,50 @@
|
|||
// 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 osu.Framework.Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
|
||||
namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
/// <summary>
|
||||
/// An abstract test case which exposes small cells arranged in a grid.
|
||||
/// Useful for displaying multiple configurations of a tested component at a glance.
|
||||
/// </summary>
|
||||
public abstract class OsuGridTestScene : OsuTestScene
|
||||
{
|
||||
private readonly Drawable[,] cells;
|
||||
|
||||
/// <summary>
|
||||
/// The amount of rows in the grid.
|
||||
/// </summary>
|
||||
protected readonly int Rows;
|
||||
|
||||
/// <summary>
|
||||
/// The amount of columns in the grid.
|
||||
/// </summary>
|
||||
protected readonly int Cols;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a grid test case with the given dimensions.
|
||||
/// </summary>
|
||||
protected OsuGridTestScene(int rows, int cols)
|
||||
{
|
||||
Rows = rows;
|
||||
Cols = cols;
|
||||
|
||||
GridContainer testContainer;
|
||||
Add(testContainer = new GridContainer { RelativeSizeAxes = Axes.Both });
|
||||
|
||||
cells = new Drawable[rows, cols];
|
||||
for (int r = 0; r < rows; r++)
|
||||
for (int c = 0; c < cols; c++)
|
||||
cells[r, c] = new Container { RelativeSizeAxes = Axes.Both };
|
||||
|
||||
testContainer.Content = cells.ToJagged();
|
||||
}
|
||||
|
||||
protected Container Cell(int index) => (Container)cells[index / Cols, index % Cols];
|
||||
protected Container Cell(int row, int col) => (Container)cells[row, col];
|
||||
}
|
||||
}
|
|
@ -3,13 +3,12 @@
|
|||
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
public class TestSceneLoadingAnimation : GridTestScene //todo: this should be an OsuTestScene
|
||||
public class TestSceneLoadingAnimation : OsuGridTestScene
|
||||
{
|
||||
public TestSceneLoadingAnimation()
|
||||
: base(2, 2)
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
// 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.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
public class TestSceneOsuAnimatedButton : OsuGridTestScene
|
||||
{
|
||||
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
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -31,7 +31,7 @@ private void load()
|
|||
{
|
||||
if (AutoSizeAxes != Axes.None)
|
||||
{
|
||||
content.RelativeSizeAxes = RelativeSizeAxes;
|
||||
content.RelativeSizeAxes = (Axes.Both & ~AutoSizeAxes);
|
||||
content.AutoSizeAxes = AutoSizeAxes;
|
||||
}
|
||||
|
||||
|
|
|
@ -66,6 +66,7 @@ public Vector2 ButtonSize
|
|||
set
|
||||
{
|
||||
Content.RelativeSizeAxes = Axes.None;
|
||||
Content.AutoSizeAxes = Axes.None;
|
||||
Content.Size = value;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue