From fdd15cd5eca51af229f51c11c867577ee5b6e871 Mon Sep 17 00:00:00 2001 From: Jamie Taylor Date: Fri, 29 Nov 2024 06:44:20 +0900 Subject: [PATCH] Add callback for when a submenu is opened --- osu.Framework/Graphics/UserInterface/Menu.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/osu.Framework/Graphics/UserInterface/Menu.cs b/osu.Framework/Graphics/UserInterface/Menu.cs index ac178cf5ba..bf7de99ca6 100644 --- a/osu.Framework/Graphics/UserInterface/Menu.cs +++ b/osu.Framework/Graphics/UserInterface/Menu.cs @@ -32,6 +32,12 @@ public abstract partial class Menu : CompositeDrawable, IStateful [CanBeNull] public event Action StateChanged; + /// + /// Invoked when a Sub- is opened. + /// + [CanBeNull] + public event Action OnSubmenuOpen; + /// /// Gets or sets the delay before opening sub-s when menu items are hovered. /// @@ -563,6 +569,8 @@ private void openSubmenuFor(DrawableMenuItem item) submenu.StateChanged += submenuStateChanged; } + bool submenuChanged = submenu.triggeringItem != item; + submenu.triggeringItem = item; submenu.positionLayout.Invalidate(); @@ -574,6 +582,10 @@ private void openSubmenuFor(DrawableMenuItem item) Schedule(delegate { GetContainingFocusManager().AsNonNull().ChangeFocus(submenu); }); else submenu.Open(); + + // Check if submenu has changed before firing, to prevent extraneous callbacks (e.g. re-hovering the triggeringItem of an already open submenu) + if (submenuChanged) + OnSubmenuOpen?.Invoke(submenu); } else submenu.Close();