Add Tab navigation for Editor UI
This commit is contained in:
@@ -24,6 +24,11 @@ namespace FlaxEditor.Windows
|
||||
/// </summary>
|
||||
protected virtual bool CanOpenContentFinder => true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this window can use UI navigation (tab/enter).
|
||||
/// </summary>
|
||||
protected virtual bool CanUseNavigation => true;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="EditorWindow"/> class.
|
||||
/// </summary>
|
||||
@@ -184,6 +189,32 @@ namespace FlaxEditor.Windows
|
||||
|
||||
#endregion
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool OnKeyDown(KeyboardKeys key)
|
||||
{
|
||||
if (base.OnKeyDown(key))
|
||||
return true;
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case KeyboardKeys.Return:
|
||||
if (CanUseNavigation && Root?.FocusedControl != null)
|
||||
{
|
||||
Root.SubmitFocused();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case KeyboardKeys.Tab:
|
||||
if (CanUseNavigation && Root != null)
|
||||
{
|
||||
Root.Navigate(NavDirection.Next);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnDestroy()
|
||||
{
|
||||
|
||||
@@ -323,12 +323,15 @@ namespace FlaxEditor.Windows
|
||||
/// <inheritdoc />
|
||||
protected override bool CanOpenContentFinder => false;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override bool CanUseNavigation => false;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnPlayBegin()
|
||||
{
|
||||
_gameStartTime = Time.UnscaledGameTime;
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnPlayEnd()
|
||||
{
|
||||
@@ -533,6 +536,22 @@ namespace FlaxEditor.Windows
|
||||
Screen.CursorVisible = true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Control OnNavigate(NavDirection direction, Vector2 location, Control caller, System.Collections.Generic.List<Control> visited)
|
||||
{
|
||||
// Block leaking UI navigation focus outside the game window
|
||||
if (IsFocused && caller != this)
|
||||
{
|
||||
// Pick the first UI control if game UI is not focused yet
|
||||
foreach (var child in _guiRoot.Children)
|
||||
{
|
||||
if (child.Visible)
|
||||
return child.OnNavigate(direction, Vector2.Zero, this, visited);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool OnMouseDown(Vector2 location, MouseButton button)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user