diff --git a/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapSetOnlineStatusPill.cs b/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapSetOnlineStatusPill.cs index 7bbf3c629b..2d61385269 100644 --- a/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapSetOnlineStatusPill.cs +++ b/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapSetOnlineStatusPill.cs @@ -2,11 +2,16 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Collections.Generic; using System.Linq; +using NUnit.Framework; +using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Testing; using osu.Game.Beatmaps; using osu.Game.Beatmaps.Drawables; +using osu.Game.Overlays; using osu.Game.Tests.Visual.UserInterface; using osuTK; @@ -28,5 +33,16 @@ namespace osu.Game.Tests.Visual.Beatmaps Status = status }) }; + + private IEnumerable statusPills => this.ChildrenOfType(); + + [Test] + public void TestFixedWidth() + { + AddStep("create themed content", () => CreateThemedContent(OverlayColourScheme.Red)); + + AddStep("set fixed width", () => statusPills.ForEach(pill => pill.FixedWidth = 90)); + AddStep("unset fixed width", () => statusPills.ForEach(pill => pill.FixedWidth = null)); + } } } diff --git a/osu.Game/Beatmaps/Drawables/BeatmapSetOnlineStatusPill.cs b/osu.Game/Beatmaps/Drawables/BeatmapSetOnlineStatusPill.cs index bc8af90069..848bab6394 100644 --- a/osu.Game/Beatmaps/Drawables/BeatmapSetOnlineStatusPill.cs +++ b/osu.Game/Beatmaps/Drawables/BeatmapSetOnlineStatusPill.cs @@ -47,6 +47,31 @@ namespace osu.Game.Beatmaps.Drawables set => statusText.Padding = value; } + private float? fixedWidth; + + /// + /// When set to a non- value, the pill will be forcibly sized to the given width. + /// When set to a value, the pill will autosize to its contents. + /// + public float? FixedWidth + { + get => fixedWidth; + set + { + fixedWidth = value; + + if (fixedWidth == null) + { + AutoSizeAxes = Axes.Both; + } + else + { + AutoSizeAxes = Axes.Y; + Width = fixedWidth.Value; + } + } + } + private readonly OsuSpriteText statusText; private readonly Box background;