autodirectional navigation can get stuck if no focus
The auto directional navigator doesn't know what to do if focus is currently set to None. Consider a game which uses both a keyboard and gamepad; if the user accidentally brushes their hand across the trackpad, this could cause a background click, which steals focus from the current widget. The user can no longer navigate with the gamepad after this - they are stuck unless they use the trackpad again.
There's a couple of solutions, but the easiest is to have the directional navigator pick a default. That is, if you trigger a directional navigation and nothing is focused, you could:
- Look for a widget that has AutoFocus
- Look for the closest (or farthest) widget in the chosen direction
- Pick an arbitrary widget
This does mean that nothing will be focused until the user tries to navigate again. A different approach would be to let the user install an observer that attempts to ensure that focus is never None; this is more complicated because you probably don't want to enforce this rule in all contexts.
@alice-i-cecile
Source: bevyengine/bevy