Add keyboard navgation to context menu child menus

#3676
This commit is contained in:
Wojtek Figat
2026-01-30 18:00:16 +01:00
parent e8c2f18a4d
commit 87ccaa9dd8
3 changed files with 21 additions and 3 deletions

View File

@@ -502,6 +502,7 @@ namespace FlaxEditor.GUI.ContextMenu
if (base.OnKeyDown(key))
return true;
// Keyboard navigation around the menu
switch (key)
{
case KeyboardKeys.ArrowDown:
@@ -526,6 +527,20 @@ namespace FlaxEditor.GUI.ContextMenu
}
}
break;
case KeyboardKeys.ArrowRight:
for (int i = 0; i < _panel.Children.Count; i++)
{
if (_panel.Children[i] is ContextMenuChildMenu item && item.Visible && item.IsFocused && !item.ContextMenu.IsOpened)
{
item.ShowChild(this);
item.ContextMenu._panel.Children.FirstOrDefault(x => x is ContextMenuButton && x.Visible)?.Focus();
break;
}
}
break;
case KeyboardKeys.ArrowLeft:
ParentCM?.RootWindow.Focus();
break;
}
return false;

View File

@@ -72,6 +72,11 @@ namespace FlaxEditor.GUI.ContextMenu
/// </summary>
public bool HasChildCMOpened => _childCM != null;
/// <summary>
/// Gets the parent context menu (if exists).
/// </summary>
public ContextMenuBase ParentCM => _parentCM;
/// <summary>
/// Gets the topmost context menu.
/// </summary>
@@ -81,9 +86,7 @@ namespace FlaxEditor.GUI.ContextMenu
{
var cm = this;
while (cm._parentCM != null && cm._isSubMenu)
{
cm = cm._parentCM;
}
return cm;
}
}

View File

@@ -29,7 +29,7 @@ namespace FlaxEditor.GUI.ContextMenu
CloseMenuOnClick = false;
}
private void ShowChild(ContextMenu parentContextMenu)
internal void ShowChild(ContextMenu parentContextMenu)
{
// Hide parent CM popups and set itself as child
var vAlign = parentContextMenu.ItemsAreaMargin.Top;