@@ -3,12 +3,23 @@ use bevy_app::{AppExit, EventReader, EventWriter};
3
3
use bevy_ecs:: prelude:: * ;
4
4
use bevy_input:: { keyboard:: KeyCode , Input } ;
5
5
6
+ /// Whether to exit the application when there are no open windows.
7
+ ///
8
+ /// By default, this system is added by the [`crate::WindowPlugin`].
9
+ /// To disable this behaviour, set `close_when_requested` (on the [`crate::WindowPlugin`]) to `false`.
10
+ /// Please ensure that you read the caveats documented on that field.
11
+
6
12
pub fn exit_on_all_closed ( mut app_exit_events : EventWriter < AppExit > , windows : Res < Windows > ) {
7
13
if windows. iter ( ) . count ( ) == 0 {
8
14
app_exit_events. send ( AppExit ) ;
9
15
}
10
16
}
11
17
18
+ /// Whether to close windows when they are requested to be closed (i.e. when the close button is pressed).
19
+ /// Not adding this system (without replacement) will lead to the close button having no effect.
20
+ ///
21
+ /// By default, this system is added by the [`crate::WindowPlugin`].
22
+ /// To disable this behaviour, set `close_when_requested` (on the [`crate::WindowPlugin`]) to `false`
12
23
pub fn close_when_requested (
13
24
mut windows : ResMut < Windows > ,
14
25
mut closed : EventReader < WindowCloseRequested > ,
@@ -18,13 +29,18 @@ pub fn close_when_requested(
18
29
}
19
30
}
20
31
32
+ // TODO: Consider using the kbd tag here for escape: <kbd>esc</kbd>
33
+ // Currently, it isn't rendered by vscode's hover markdown provider (and the contents are lost)
34
+ /// Close the focused window whenever the escape key is pressed
35
+ ///
36
+ /// This is useful for examples
21
37
pub fn close_on_esc (
22
38
mut focused : Local < Option < WindowId > > ,
23
39
mut focused_events : EventReader < WindowFocused > ,
24
40
mut windows : ResMut < Windows > ,
25
41
input : Res < Input < KeyCode > > ,
26
42
) {
27
- // Todo : Track this more generally
43
+ // TODO : Track this in e.g. a resource to ensure consistent behaviour across similar systems
28
44
for event in focused_events. iter ( ) {
29
45
* focused = event. focused . then ( || event. id ) ;
30
46
}
0 commit comments