Merge pull request #27982 from Joehuu/chevron-all-context-menus

Add chevron to distinguish all menus with submenus
This commit is contained in:
Dean Herbert 2024-04-24 22:39:56 +08:00 committed by GitHub
commit 29a6349fbe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 27 deletions

View File

@ -77,21 +77,21 @@ private static MenuItem[] makeMenu()
new OsuMenuItem(@"Some option"), new OsuMenuItem(@"Some option"),
new OsuMenuItem(@"Highlighted option", MenuItemType.Highlighted), new OsuMenuItem(@"Highlighted option", MenuItemType.Highlighted),
new OsuMenuItem(@"Another option"), new OsuMenuItem(@"Another option"),
new OsuMenuItem(@"Nested option >") new OsuMenuItem(@"Nested option")
{ {
Items = new MenuItem[] Items = new MenuItem[]
{ {
new OsuMenuItem(@"Sub-One"), new OsuMenuItem(@"Sub-One"),
new OsuMenuItem(@"Sub-Two"), new OsuMenuItem(@"Sub-Two"),
new OsuMenuItem(@"Sub-Three"), new OsuMenuItem(@"Sub-Three"),
new OsuMenuItem(@"Sub-Nested option >") new OsuMenuItem(@"Sub-Nested option")
{ {
Items = new MenuItem[] Items = new MenuItem[]
{ {
new OsuMenuItem(@"Double Sub-One"), new OsuMenuItem(@"Double Sub-One"),
new OsuMenuItem(@"Double Sub-Two"), new OsuMenuItem(@"Double Sub-Two"),
new OsuMenuItem(@"Double Sub-Three"), new OsuMenuItem(@"Double Sub-Three"),
new OsuMenuItem(@"Sub-Sub-Nested option >") new OsuMenuItem(@"Sub-Sub-Nested option")
{ {
Items = new MenuItem[] Items = new MenuItem[]
{ {

View File

@ -3,6 +3,7 @@
#nullable disable #nullable disable
using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -12,6 +13,7 @@
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
namespace osu.Game.Graphics.UserInterface namespace osu.Game.Graphics.UserInterface
@ -40,6 +42,27 @@ private void load()
AddInternal(hoverClickSounds = new HoverClickSounds()); AddInternal(hoverClickSounds = new HoverClickSounds());
updateTextColour(); updateTextColour();
bool hasSubmenu = Item.Items.Any();
// Only add right chevron if direction of menu items is vertical (i.e. width is relative size, see `DrawableMenuItem.SetFlowDirection()`).
if (hasSubmenu && RelativeSizeAxes == Axes.X)
{
AddInternal(new SpriteIcon
{
Margin = new MarginPadding(6),
Size = new Vector2(8),
Icon = FontAwesome.Solid.ChevronRight,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
});
text.Padding = new MarginPadding
{
// Add some padding for the chevron above.
Right = 5,
};
}
} }
protected override void LoadComplete() protected override void LoadComplete()

View File

@ -1,7 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -185,17 +184,6 @@ public EditorMenuItem(MenuItem item)
{ {
} }
private bool hasSubmenu => Item.Items.Any();
protected override TextContainer CreateTextContainer() => base.CreateTextContainer().With(c =>
{
c.Padding = new MarginPadding
{
// Add some padding for the chevron below.
Right = hasSubmenu ? 5 : 0,
};
});
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider) private void load(OverlayColourProvider colourProvider)
{ {
@ -203,18 +191,6 @@ private void load(OverlayColourProvider colourProvider)
BackgroundColourHover = colourProvider.Background1; BackgroundColourHover = colourProvider.Background1;
Foreground.Padding = new MarginPadding { Vertical = 2 }; Foreground.Padding = new MarginPadding { Vertical = 2 };
if (hasSubmenu)
{
AddInternal(new SpriteIcon
{
Margin = new MarginPadding(6),
Size = new Vector2(8),
Icon = FontAwesome.Solid.ChevronRight,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
});
}
} }
} }
} }