mirror of
https://github.com/ppy/osu.git
synced 2025-02-06 04:12:55 +08:00
Merge pull request #19538 from bdach/mod-overlay/sheared-button-broken-autosize
Fix broken sheared button autosizing logic
This commit is contained in:
commit
5501195ed7
@ -3,9 +3,13 @@
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Framework.Testing;
|
||||||
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
@ -99,7 +103,10 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Text = "Fixed width"
|
Text = "Fixed width"
|
||||||
});
|
});
|
||||||
|
AddAssert("draw width is 200", () => toggleButton.DrawWidth, () => Is.EqualTo(200).Within(Precision.FLOAT_EPSILON));
|
||||||
|
|
||||||
AddStep("change text", () => toggleButton.Text = "New text");
|
AddStep("change text", () => toggleButton.Text = "New text");
|
||||||
|
AddAssert("draw width is 200", () => toggleButton.DrawWidth, () => Is.EqualTo(200).Within(Precision.FLOAT_EPSILON));
|
||||||
|
|
||||||
AddStep("create auto-sizing button", () => Child = toggleButton = new ShearedToggleButton
|
AddStep("create auto-sizing button", () => Child = toggleButton = new ShearedToggleButton
|
||||||
{
|
{
|
||||||
@ -107,7 +114,14 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Text = "This button autosizes to its text!"
|
Text = "This button autosizes to its text!"
|
||||||
});
|
});
|
||||||
|
AddAssert("button is wider than text", () => toggleButton.DrawWidth, () => Is.GreaterThan(toggleButton.ChildrenOfType<SpriteText>().Single().DrawWidth));
|
||||||
|
|
||||||
|
float originalDrawWidth = 0;
|
||||||
|
AddStep("store button width", () => originalDrawWidth = toggleButton.DrawWidth);
|
||||||
|
|
||||||
AddStep("change text", () => toggleButton.Text = "New text");
|
AddStep("change text", () => toggleButton.Text = "New text");
|
||||||
|
AddAssert("button is wider than text", () => toggleButton.DrawWidth, () => Is.GreaterThan(toggleButton.ChildrenOfType<SpriteText>().Single().DrawWidth));
|
||||||
|
AddAssert("button width decreased", () => toggleButton.DrawWidth, () => Is.LessThan(originalDrawWidth));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -97,7 +97,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
{
|
{
|
||||||
backgroundLayer = new Container
|
backgroundLayer = new Container
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Y,
|
||||||
CornerRadius = corner_radius,
|
CornerRadius = corner_radius,
|
||||||
Masking = true,
|
Masking = true,
|
||||||
BorderThickness = 2,
|
BorderThickness = 2,
|
||||||
@ -128,10 +128,12 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
if (width != null)
|
if (width != null)
|
||||||
{
|
{
|
||||||
Width = width.Value;
|
Width = width.Value;
|
||||||
|
backgroundLayer.RelativeSizeAxes = Axes.Both;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.X;
|
AutoSizeAxes = Axes.X;
|
||||||
|
backgroundLayer.AutoSizeAxes = Axes.X;
|
||||||
text.Margin = new MarginPadding { Horizontal = 15 };
|
text.Margin = new MarginPadding { Horizontal = 15 };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user