1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:27:29 +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.Events;
using osu.Framework.Input.States; using osu.Framework.Input.States;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Input.Bindings; using osu.Game.Input.Bindings;
@ -18,13 +17,22 @@ namespace osu.Game.Tests.Visual.UserInterface
public partial class TestSceneOsuDropdown : ThemeComparisonTestScene public partial class TestSceneOsuDropdown : ThemeComparisonTestScene
{ {
protected override Drawable CreateContent() => protected override Drawable CreateContent() =>
new OsuEnumDropdown<BeatmapOnlineStatus> new OsuEnumDropdown<TestEnum>
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
Width = 150 Width = 150
}; };
private enum TestEnum
{
[System.ComponentModel.Description("Option")]
Option,
[System.ComponentModel.Description("Really lonnnnnnng option")]
ReallyLongOption,
}
[Test] [Test]
// todo: this can be written much better if ThemeComparisonTestScene has a manual input manager // todo: this can be written much better if ThemeComparisonTestScene has a manual input manager
public void TestBackAction() 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))); AddStep("press back", () => dropdown().OnPressed(new KeyBindingPressEvent<GlobalAction>(new InputState(), GlobalAction.Back)));
AddAssert("closed", () => dropdown().ChildrenOfType<Menu>().Single().State == MenuState.Closed); 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) : base(item)
{ {
Foreground.Padding = new MarginPadding(2); Foreground.Padding = new MarginPadding(2);
Foreground.AutoSizeAxes = Axes.Y;
Foreground.RelativeSizeAxes = Axes.X;
Masking = true; Masking = true;
CornerRadius = corner_radius; CornerRadius = corner_radius;
@ -247,11 +249,12 @@ namespace osu.Game.Graphics.UserInterface
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
}, },
Label = new OsuSpriteText Label = new TruncatingSpriteText
{ {
X = 15, Padding = new MarginPadding { Left = 15 },
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
RelativeSizeAxes = Axes.X,
}, },
}; };
} }