-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Polish and improve docs for
bevy_input_focus
(#16887)
# Objective `bevy_input_focus` needs some love before we ship it to users. There's a few missing helper methods, the docs could be improved, and `AutoFocus` should be more generally available. ## Solution The changes here are broken down by commit, and should generally be uncontroversial. The ones to focus on during review are: - Make navigate take a & InputFocus argument: this makes the intended pattern clearer to users - Remove TabGroup requirement from `AutoFocus`: I want auto-focusing even with gamepad-style focus navigation! - Handle case where tab group is None more gracefully: I think we can try harder to provide something usable, and shouldn't just fail to navigate ## Testing The `tab_navigation` example continues to work.
- Loading branch information
1 parent
20049d4
commit d8796ae
Showing
3 changed files
with
110 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//! Contains the [`AutoFocus`] component and related machinery. | ||
use bevy_ecs::{component::ComponentId, prelude::*, world::DeferredWorld}; | ||
|
||
use crate::SetInputFocus; | ||
|
||
/// Indicates that this widget should automatically receive [`InputFocus`](crate::InputFocus). | ||
/// | ||
/// This can be useful for things like dialog boxes, the first text input in a form, | ||
/// or the first button in a game menu. | ||
/// | ||
/// The focus is swapped when this component is added | ||
/// or an entity with this component is spawned. | ||
#[derive(Debug, Default, Component, Copy, Clone)] | ||
#[component(on_add = on_auto_focus_added)] | ||
pub struct AutoFocus; | ||
|
||
fn on_auto_focus_added(mut world: DeferredWorld, entity: Entity, _: ComponentId) { | ||
world.set_input_focus(entity); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters