-
-
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.
Handle individual windows closing properly
- Loading branch information
Showing
4 changed files
with
33 additions
and
11 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
use crate::WindowCloseRequested; | ||
use crate::{Window, WindowCloseRequested, Windows}; | ||
use bevy_app::{AppExit, EventReader, EventWriter}; | ||
use bevy_ecs::prelude::{Res, ResMut}; | ||
|
||
pub fn exit_on_window_close_system( | ||
mut app_exit_events: EventWriter<AppExit>, | ||
mut window_close_requested_events: EventReader<WindowCloseRequested>, | ||
) { | ||
if window_close_requested_events.iter().next().is_some() { | ||
pub fn exit_on_all_closed(mut app_exit_events: EventWriter<AppExit>, windows: Res<Windows>) { | ||
if windows.iter().count() == 0 { | ||
app_exit_events.send(AppExit); | ||
} | ||
} | ||
|
||
pub fn close_when_requested( | ||
mut windows: ResMut<Windows>, | ||
mut closed: EventReader<WindowCloseRequested>, | ||
) { | ||
for event in closed.iter() { | ||
windows.get_mut(event.id).map(Window::close); | ||
} | ||
} |