Skip to content

Commit ff3b0d0

Browse files
committed
Add suggested docs
1 parent 6c1e61f commit ff3b0d0

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

crates/bevy_window/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@ use bevy_app::{prelude::*, Events};
2525
pub struct WindowPlugin {
2626
pub add_primary_window: bool,
2727
/// Whether to close the app when there are no open windows.
28+
/// If disabling this, consider ensuring that you send a [`bevy_app::AppExit`] event yourself
29+
/// when the app should exit; otherwise you will create headless processes, which would be
30+
/// surprising for your users.
31+
///
2832
/// This setting controls whether this plugin adds [`exit_on_all_closed`]
2933
pub exit_on_all_closed: bool,
3034
/// Whether to close windows when they are requested to be closed (i.e. when the close button is pressed)
35+
///
3136
/// This setting controls whether this plugin adds [`close_when_requested`]
3237
pub close_when_requested: bool,
3338
}

crates/bevy_window/src/system.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,23 @@ use bevy_app::{AppExit, EventReader, EventWriter};
33
use bevy_ecs::prelude::*;
44
use bevy_input::{keyboard::KeyCode, Input};
55

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+
612
pub fn exit_on_all_closed(mut app_exit_events: EventWriter<AppExit>, windows: Res<Windows>) {
713
if windows.iter().count() == 0 {
814
app_exit_events.send(AppExit);
915
}
1016
}
1117

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`
1223
pub fn close_when_requested(
1324
mut windows: ResMut<Windows>,
1425
mut closed: EventReader<WindowCloseRequested>,
@@ -18,13 +29,18 @@ pub fn close_when_requested(
1829
}
1930
}
2031

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
2137
pub fn close_on_esc(
2238
mut focused: Local<Option<WindowId>>,
2339
mut focused_events: EventReader<WindowFocused>,
2440
mut windows: ResMut<Windows>,
2541
input: Res<Input<KeyCode>>,
2642
) {
27-
// Todo: Track this more generally
43+
// TODO: Track this in e.g. a resource to ensure consistent behaviour across similar systems
2844
for event in focused_events.iter() {
2945
*focused = event.focused.then(|| event.id);
3046
}

0 commit comments

Comments
 (0)