mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 20:25:39 +08:00
Add support for setting fixed size of status pill
This commit is contained in:
parent
5ab3337a10
commit
feedd53a53
@ -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<BeatmapSetOnlineStatusPill> statusPills => this.ChildrenOfType<BeatmapSetOnlineStatusPill>();
|
||||
|
||||
[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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,31 @@ namespace osu.Game.Beatmaps.Drawables
|
||||
set => statusText.Padding = value;
|
||||
}
|
||||
|
||||
private float? fixedWidth;
|
||||
|
||||
/// <summary>
|
||||
/// When set to a non-<see langword="null"/> value, the pill will be forcibly sized to the given width.
|
||||
/// When set to a <see langword="null"/> value, the pill will autosize to its contents.
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user