mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 00:40:09 +09:00
Add constructor argument to facilitate fixed width/autosizing
This commit is contained in:
@ -23,12 +23,11 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
|
|
||||||
AddStep("create button", () =>
|
AddStep("create button", () =>
|
||||||
{
|
{
|
||||||
Child = button = new ShearedToggleButton
|
Child = button = new ShearedToggleButton(200)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Text = "Toggle me",
|
Text = "Toggle me",
|
||||||
Width = 200
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -36,6 +35,28 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
AddToggleStep("toggle disabled", disabled => button.Active.Disabled = disabled);
|
AddToggleStep("toggle disabled", disabled => button.Active.Disabled = disabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestSizing()
|
||||||
|
{
|
||||||
|
ShearedToggleButton toggleButton = null;
|
||||||
|
|
||||||
|
AddStep("create fixed width button", () => Child = toggleButton = new ShearedToggleButton(200)
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Text = "Fixed width"
|
||||||
|
});
|
||||||
|
AddStep("change text", () => toggleButton.Text = "New text");
|
||||||
|
|
||||||
|
AddStep("create auto-sizing button", () => Child = toggleButton = new ShearedToggleButton
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Text = "This button autosizes to its text!"
|
||||||
|
});
|
||||||
|
AddStep("change text", () => toggleButton.Text = "New text");
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestDisabledState()
|
public void TestDisabledState()
|
||||||
{
|
{
|
||||||
|
@ -42,7 +42,17 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private OverlayColourProvider colourProvider { get; set; } = null!;
|
private OverlayColourProvider colourProvider { get; set; } = null!;
|
||||||
|
|
||||||
public ShearedToggleButton()
|
/// <summary>
|
||||||
|
/// Creates a new <see cref="ShearedToggleButton"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="width">
|
||||||
|
/// The width of the button.
|
||||||
|
/// <list type="bullet">
|
||||||
|
/// <item>If a non-<see langword="null"/> value is provided, this button will have a fixed width equal to the provided value.</item>
|
||||||
|
/// <item>If a <see langword="null"/> value is provided (or the argument is omitted entirely), the button will autosize in width to fit the text.</item>
|
||||||
|
/// </list>
|
||||||
|
/// </param>
|
||||||
|
public ShearedToggleButton(float? width = null)
|
||||||
{
|
{
|
||||||
Height = 50;
|
Height = 50;
|
||||||
Padding = new MarginPadding { Horizontal = shear * 50 };
|
Padding = new MarginPadding { Horizontal = shear * 50 };
|
||||||
@ -67,6 +77,16 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
Shear = new Vector2(-shear, 0)
|
Shear = new Vector2(-shear, 0)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (width != null)
|
||||||
|
{
|
||||||
|
Width = width.Value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.X;
|
||||||
|
text.Margin = new MarginPadding { Horizontal = 15 };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
|
Reference in New Issue
Block a user