mirror of
https://github.com/ppy/osu
synced 2025-01-18 20:10:49 +00: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
|
||||
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
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.Overlays;
|
||||
using osuTK.Input;
|
||||
@ -99,7 +103,10 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
Origin = Anchor.Centre,
|
||||
Text = "Fixed width"
|
||||
});
|
||||
AddAssert("draw width is 200", () => toggleButton.DrawWidth, () => Is.EqualTo(200).Within(Precision.FLOAT_EPSILON));
|
||||
|
||||
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
|
||||
{
|
||||
@ -107,7 +114,14 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
Origin = Anchor.Centre,
|
||||
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");
|
||||
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]
|
||||
|
@ -97,7 +97,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
backgroundLayer = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
CornerRadius = corner_radius,
|
||||
Masking = true,
|
||||
BorderThickness = 2,
|
||||
@ -128,10 +128,12 @@ namespace osu.Game.Graphics.UserInterface
|
||||
if (width != null)
|
||||
{
|
||||
Width = width.Value;
|
||||
backgroundLayer.RelativeSizeAxes = Axes.Both;
|
||||
}
|
||||
else
|
||||
{
|
||||
AutoSizeAxes = Axes.X;
|
||||
backgroundLayer.AutoSizeAxes = Axes.X;
|
||||
text.Margin = new MarginPadding { Horizontal = 15 };
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user