-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/rewrite-winit-loop
- Loading branch information
Showing
15 changed files
with
323 additions
and
52 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,32 @@ | ||
use bevy_ecs::prelude::*; | ||
use bevy_input::{keyboard::KeyCode, ButtonInput}; | ||
use bevy_window::Window; | ||
|
||
/// Close the focused window whenever the escape key (<kbd>Esc</kbd>) is pressed | ||
/// | ||
/// This is useful for examples or prototyping. | ||
/// | ||
/// # Example | ||
/// | ||
/// ```no_run | ||
/// # use bevy_app::prelude::*; | ||
/// # use bevy_dev_tools::close_on_esc; | ||
/// # | ||
/// App::new() | ||
/// .add_systems(Update, close_on_esc); | ||
/// ``` | ||
pub fn close_on_esc( | ||
mut commands: Commands, | ||
focused_windows: Query<(Entity, &Window)>, | ||
input: Res<ButtonInput<KeyCode>>, | ||
) { | ||
for (window, focus) in focused_windows.iter() { | ||
if !focus.focused { | ||
continue; | ||
} | ||
|
||
if input.just_pressed(KeyCode::Escape) { | ||
commands.entity(window).despawn(); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.