bevyengine/bevy
bevy_input_focus
The "which entity gets keyboard input" subsystem. Defines focus state, focus traversal (Tab / Shift+Tab), and the dispatch path that turns raw key events into per-entity events for the focused widget.
Purpose
Without focus tracking, every keyboard event would have to be matched against every potentially-listening entity. bevy_input_focus introduces:
InputFocusresource — the currently focused entity (anOption<Entity>).InputFocusVisible— whether to draw a focus ring (set on Tab keypress, cleared on mouse use).- Focus dispatch systems — translate
KeyboardInputevents into per-entity events delivered through observers. - Focus traversal — find the next/previous focusable entity in tab order.
Directory layout
crates/bevy_input_focus/src/
├── lib.rs # InputFocusPlugin, InputDispatchPlugin
├── focus.rs # InputFocus / InputFocusVisible
├── tab_navigation.rs # Tab / Shift+Tab traversal
├── directional_navigation.rs # Arrow-key directional nav
├── autofocus.rs # AutoFocus marker
└── …Key abstractions
| Type | File | Description |
|---|---|---|
InputFocus |
crates/bevy_input_focus/src/focus.rs |
Resource: focused entity. |
InputFocusVisible |
crates/bevy_input_focus/src/focus.rs |
Whether to render focus indicators. |
TabIndex |
crates/bevy_input_focus/src/tab_navigation.rs |
Per-entity tab order priority. |
AutoFocus |
crates/bevy_input_focus/src/autofocus.rs |
Marker: focus this entity on spawn. |
InputFocusPlugin, InputDispatchPlugin |
crates/bevy_input_focus/src/lib.rs |
Plugins. |
How it works
InputDispatchPlugin runs before user systems each frame. For each KeyboardInput event, it looks at InputFocus. If focus is Some(entity), the event is bubbled as an entity event up the parent chain via observers. Widgets register Observer<KeyboardInput> (or higher-level events) on themselves.
Tab traversal is a separate system that sees Tab / Shift+Tab and updates InputFocus to the next/previous entity in tab order.
Integration points
- Depends on:
bevy_app,bevy_ecs,bevy_input,bevy_window. - Depended on by:
bevy_ui,bevy_ui_widgets,bevy_feathers,bevy_a11y.
Entry points for modification
- Custom traversal order: edit
tab_navigation.rs. - Add focus group concept: the existing types support per-window focus; cross-window focus would go here.
- Directional navigation tweaks:
directional_navigation.rs.
See also
bevy_input— events this crate routes.bevy_ui,bevy_ui_widgets— consumers.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.