-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Click-to-focus doesn't work with directional navigation #25596
Copy link
Copy link
Open
Labels
A-UIGraphical user interfaces, styles, layouts, and widgetsGraphical user interfaces, styles, layouts, and widgetsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixesA "normal" level of difficulty; suitable for simple features or challenging fixesM-Migration-GuideA breaking change to Bevy's public API that needs to be noted in a migration guideA breaking change to Bevy's public API that needs to be noted in a migration guideS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!This issue is ready for an implementation PR. Go for it!X-UncontroversialThis work is generally agreed uponThis work is generally agreed upon
Description
Activity
Metadata
Metadata
Assignees
Labels
A-UIGraphical user interfaces, styles, layouts, and widgetsGraphical user interfaces, styles, layouts, and widgetsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixesA "normal" level of difficulty; suitable for simple features or challenging fixesM-Migration-GuideA breaking change to Bevy's public API that needs to be noted in a migration guideA breaking change to Bevy's public API that needs to be noted in a migration guideS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!This issue is ready for an implementation PR. Go for it!X-UncontroversialThis work is generally agreed uponThis work is generally agreed upon
Type
Projects
- StatusShow more project fieldsNeeds SME Triage
The
acquire_focus_tab_indexobserver which is installed byPointerFocusPlugininbevy_input_focusonly works withTabIndex, not other kinds of focusable entities. This means that when you click on a widget that uses directional navigation, it immediately loses focus; worse, the focus is set toNone, so you can't get back to it by navigating, since the directional system doesn't know where to start.The problem is that
TabIndexwas originally modeled after the HTMLtab-indexattribute, which has two different jobs: it indicates where the element should be in the tab order, but it also indicates that the element is focusable at all. Unfortunately, Bevy has two different focus navigation systems, and only one of them usesTabIndex.Worse, there's no single component in the directional nav framework that indicates "this widget is focusable" - we have
AutoDirectionalNavigationand we have the directional navigation override, but both of these indicate where the focus moves to when leaving the widget, not whether the widget can accept focus. Also,AutoDirectionalNavigationis inbevy_ui, which means that it's at a higher layer thanbevy_input_focus, which cannot depend on it.The right answer, I think, is to split
TabIndexinto two separate components:Focusable, which for now means that an entity can accept focus, andTabIndexwhich now only specifies the tab order.We can make
Focusablea required component for bothTabIndexandAutoDirectionalNavigation, avoiding the need to migrate all the examples. For the manual directional navigation examples we might need to addFocusableexplicitly.We can update the sequential navigator to consider an entity with only
Focusable(noTabIndex) to have an implicit tab index of zero. The acquire focus observer would then only useFocusable. All of the bevy feathers widgets which useTabIndex::default()would migration to just usingFocusable.We can also think about adding
Focusableto all the headless widgets; we couldn't do this before, because we didn't want to assume that the widgets were only meant to be used in a sequential navigation context, butFocusablecan work with either navigation type.Another benefit of this approach: we can make a widget temporarily non-focusable by removing the
Focusablemarker, without losing it's tab order, which we couldn't before.@alice-i-cecile @kfc35 @ickshonpe @gagnus