1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-16 20:43:12 +08:00
Files
osu-lazer/osu.Game/Graphics/UserInterface/DrawableStatefulMenuItem.cs
T
Dean Herbert 1016bca280 Keep any stateful dropdown menu open on click (#37021)
Right click is a very obfuscated UX which most users won't find. This
makes more sense to the average user (probably).

Caveat: clicking away actually sends clicks to underlying UI. This is
not the case in macOS or windows (locally, same app; globally it still
sends clicks to other windows).

Coming from https://github.com/ppy/osu/discussions/36926.

---------

Co-authored-by: Bartłomiej Dach <dach.bartlomiej@gmail.com>
2026-03-21 22:18:02 +09:00

66 lines
2.0 KiB
C#

// 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.
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osuTK;
namespace osu.Game.Graphics.UserInterface
{
public partial class DrawableStatefulMenuItem : DrawableOsuMenuItem
{
protected new StatefulMenuItem Item => (StatefulMenuItem)base.Item;
public override bool CloseMenuOnClick => false;
public DrawableStatefulMenuItem(StatefulMenuItem item)
: base(item)
{
}
protected override TextContainer CreateTextContainer() => new ToggleTextContainer(Item);
private partial class ToggleTextContainer : TextContainer
{
private readonly StatefulMenuItem menuItem;
private readonly Bindable<object> state;
private readonly SpriteIcon stateIcon;
public ToggleTextContainer(StatefulMenuItem menuItem)
{
this.menuItem = menuItem;
state = menuItem.State.GetBoundCopy();
CheckboxContainer.Add(stateIcon = new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(10),
AlwaysPresent = true,
});
}
protected override void LoadComplete()
{
base.LoadComplete();
state.BindValueChanged(updateState, true);
}
private void updateState(ValueChangedEvent<object> state)
{
var icon = menuItem.GetIconForState(state.NewValue);
if (icon == null)
stateIcon.Alpha = 0;
else
{
stateIcon.Alpha = 1;
stateIcon.Icon = icon.Value;
}
}
}
}
}