1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 15:27:24 +08:00

Merge pull request #27178 from Joehuu/truncate-osu-dropdown-items

Truncate long dropdown menu item text and show tooltip
This commit is contained in:
Dean Herbert 2024-02-15 16:11:36 +08:00 committed by GitHub
commit 409dfd33e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 5 deletions

View File

@ -9,7 +9,6 @@ using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Framework.Input.States;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Graphics.UserInterface;
using osu.Game.Input.Bindings;
@ -18,13 +17,22 @@ namespace osu.Game.Tests.Visual.UserInterface
public partial class TestSceneOsuDropdown : ThemeComparisonTestScene
{
protected override Drawable CreateContent() =>
new OsuEnumDropdown<BeatmapOnlineStatus>
new OsuEnumDropdown<TestEnum>
{
Anchor = Anchor.Centre,
Origin = Anchor.TopCentre,
Width = 150
};
private enum TestEnum
{
[System.ComponentModel.Description("Option")]
Option,
[System.ComponentModel.Description("Really lonnnnnnng option")]
ReallyLongOption,
}
[Test]
// todo: this can be written much better if ThemeComparisonTestScene has a manual input manager
public void TestBackAction()
@ -43,7 +51,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AddStep("press back", () => dropdown().OnPressed(new KeyBindingPressEvent<GlobalAction>(new InputState(), GlobalAction.Back)));
AddAssert("closed", () => dropdown().ChildrenOfType<Menu>().Single().State == MenuState.Closed);
OsuEnumDropdown<BeatmapOnlineStatus> dropdown() => this.ChildrenOfType<OsuEnumDropdown<BeatmapOnlineStatus>>().First();
OsuEnumDropdown<TestEnum> dropdown() => this.ChildrenOfType<OsuEnumDropdown<TestEnum>>().First();
}
}
}

View File

@ -186,6 +186,8 @@ namespace osu.Game.Graphics.UserInterface
: base(item)
{
Foreground.Padding = new MarginPadding(2);
Foreground.AutoSizeAxes = Axes.Y;
Foreground.RelativeSizeAxes = Axes.X;
Masking = true;
CornerRadius = corner_radius;
@ -247,11 +249,12 @@ namespace osu.Game.Graphics.UserInterface
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
},
Label = new OsuSpriteText
Label = new TruncatingSpriteText
{
X = 15,
Padding = new MarginPadding { Left = 15 },
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
RelativeSizeAxes = Axes.X,
},
};
}