use bevy::prelude::*; use bevy_ui_navigation::prelude::{ DefaultNavigationPlugins, FocusState, Focusable, NavEvent, NavRequest, NavRequestSystem, }; /// This example illustrates how to make a button "lock". To lock the UI, press /// 'A' on controller or 'left click' on mouse when the button with the lock is /// focused. /// /// To leave lock mode, press 'escape' on keyboard or 'start' on controller. /// This will emit a `NavRequest::Unlock` in the default input systems. Allowing /// the focus to change again. /// /// It is also possible to lock focus using the `NavRequest::Lock` request. /// Here, we emit one when the "l" key is pressed. fn main() { App::new() .add_plugins((DefaultPlugins, DefaultNavigationPlugins)) .init_resource::() .add_systems(Startup, setup) .add_systems( Update, ( extra_lock_key.before(NavRequestSystem), (print_nav_events, button_system).after(NavRequestSystem), ), ) .run(); } fn print_nav_events(mut events: EventReader) { for event in events.read() { println!("{:?}", event); } } fn extra_lock_key(mut requests: EventWriter, input: Res>) { if input.just_pressed(KeyCode::L) { requests.send(NavRequest::Lock); } } #[allow(clippy::type_complexity)] fn button_system( mut interaction_query: Query< (&Focusable, &mut BackgroundColor), (Changed, With