- Implemented shift tab support for Container Controls

This commit is contained in:
Nils Hausfeld
2023-09-23 11:56:45 +02:00
parent 248304a78f
commit 963300c2cb
5 changed files with 35 additions and 8 deletions

View File

@@ -507,15 +507,19 @@ namespace FlaxEngine.GUI
// Perform automatic navigation based on the layout
var result = NavigationRaycast(direction, location, visited);
if (result == null && direction == NavDirection.Next)
var rightMostLocation = location;
if (result == null && (direction == NavDirection.Next || direction == NavDirection.Previous))
{
// Try wrap the navigation over the layout based on the direction
var visitedWrap = new List<Control>(visited);
result = NavigationWrap(direction, location, visitedWrap);
result = NavigationWrap(direction, location, visitedWrap, out rightMostLocation);
}
if (result != null)
{
result = result.OnNavigate(direction, result.PointFromParent(location), this, visited);
// HACK: only the 'previous' direction needs the rightMostLocation so i used a ternary conditional operator.
// The rightMostLocation can probably become a 'desired raycast origin' that gets calculated correctly in the NavigationWrap method.
var useLocation = direction == NavDirection.Previous ? rightMostLocation : location;
result = result.OnNavigate(direction, result.PointFromParent(useLocation), this, visited);
if (result != null)
return result;
}
@@ -551,8 +555,9 @@ namespace FlaxEngine.GUI
/// <param name="direction">The navigation direction.</param>
/// <param name="location">The navigation start location (in the control-space).</param>
/// <param name="visited">The list with visited controls. Used to skip recursive navigation calls when doing traversal across the UI hierarchy.</param>
/// <param name="rightMostLocation">Returns the rightmost location of the parent container for the raycast used by the child container</param>
/// <returns>The target navigation control or null if didn't performed any navigation.</returns>
protected virtual Control NavigationWrap(NavDirection direction, Float2 location, List<Control> visited)
protected virtual Control NavigationWrap(NavDirection direction, Float2 location, List<Control> visited, out Float2 rightMostLocation)
{
// This searches form a child that calls this navigation event (see Control.OnNavigate) to determinate the layout wrapping size based on that child size
var currentChild = RootWindow?.FocusedControl;
@@ -566,15 +571,22 @@ namespace FlaxEngine.GUI
case NavDirection.Next:
predictedLocation = new Float2(0, location.Y + layoutSize.Y);
break;
case NavDirection.Previous:
predictedLocation = new Float2(Size.X, location.Y - layoutSize.Y);
break;
}
if (new Rectangle(Float2.Zero, Size).Contains(ref predictedLocation))
{
var result = NavigationRaycast(direction, predictedLocation, visited);
if (result != null)
return result;
{
rightMostLocation = predictedLocation;
return result;
}
}
}
return Parent?.NavigationWrap(direction, PointToParent(ref location), visited);
rightMostLocation = location;
return Parent?.NavigationWrap(direction, PointToParent(ref location), visited, out rightMostLocation);
}
private static bool CanGetAutoFocus(Control c)
@@ -613,6 +625,10 @@ namespace FlaxEngine.GUI
uiDir1 = new Float2(1, 0);
uiDir2 = new Float2(0, 1);
break;
case NavDirection.Previous:
uiDir1 = new Float2(-1, 0);
uiDir2 = new Float2(0, -1);
break;
}
Control result = null;
var minDistance = float.MaxValue;

View File

@@ -634,6 +634,7 @@ namespace FlaxEngine.GUI
case NavDirection.Left: return new Float2(0, size.Y * 0.5f);
case NavDirection.Right: return new Float2(size.X, size.Y * 0.5f);
case NavDirection.Next: return Float2.Zero;
case NavDirection.Previous: return new Float2(Size.X, Size.Y);
default: return size * 0.5f;
}
}

View File

@@ -202,5 +202,10 @@ namespace FlaxEngine.GUI
/// The next item (right with layout wrapping).
/// </summary>
Next,
/// <summary>
/// The previous item (left with layout wrapping).
/// </summary>
Previous,
}
}