Skip to content

Commit 3f6300d

Browse files
authored
low_power example: pick nits (#12437)
# Objective - no-longer-extant type `WinitConfig` referenced in comments - `mouse_button_input` refers to `KeyCode` input - "spacebar" flagged as a typo by RustRover IDE ## Solution - replace `WinitConfig` with `WinitSettings` in comments - rename `mouse_button_input` to just `button_input` - change "spacebar" to "space bar"
1 parent 78c754c commit 3f6300d

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

examples/window/low_power.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn main() {
1616
.insert_resource(WinitSettings::game())
1717
// Power-saving reactive rendering for applications.
1818
.insert_resource(WinitSettings::desktop_app())
19-
// You can also customize update behavior with the fields of [`WinitConfig`]
19+
// You can also customize update behavior with the fields of [`WinitSettings`]
2020
.insert_resource(WinitSettings {
2121
focused_mode: bevy::winit::UpdateMode::Continuous,
2222
unfocused_mode: bevy::winit::UpdateMode::ReactiveLowPower {
@@ -61,13 +61,16 @@ fn update_winit(
6161
use ExampleMode::*;
6262
*winit_config = match *mode {
6363
Game => {
64-
// In the default `WinitConfig::game()` mode:
64+
// In the default `WinitSettings::game()` mode:
6565
// * When focused: the event loop runs as fast as possible
66-
// * When not focused: the event loop runs as fast as possible
66+
// * When not focused: the app will update when the window is directly interacted with
67+
// (e.g. the mouse hovers over a visible part of the out of focus window), a
68+
// [`RequestRedraw`] event is received, or one sixtieth of a second has passed
69+
// without the app updating (60 Hz refresh rate max).
6770
WinitSettings::game()
6871
}
6972
Application => {
70-
// While in `WinitConfig::desktop_app()` mode:
73+
// While in `WinitSettings::desktop_app()` mode:
7174
// * When focused: the app will update any time a winit event (e.g. the window is
7275
// moved/resized, the mouse moves, a button is pressed, etc.), a [`RequestRedraw`]
7376
// event is received, or after 5 seconds if the app has not updated.
@@ -80,7 +83,7 @@ fn update_winit(
8083
ApplicationWithRedraw => {
8184
// Sending a `RequestRedraw` event is useful when you want the app to update the next
8285
// frame regardless of any user input. For example, your application might use
83-
// `WinitConfig::desktop_app()` to reduce power use, but UI animations need to play even
86+
// `WinitSettings::desktop_app()` to reduce power use, but UI animations need to play even
8487
// when there are no inputs, so you send redraw requests while the animation is playing.
8588
event.send(RequestRedraw);
8689
WinitSettings::desktop_app()
@@ -101,9 +104,9 @@ pub(crate) mod test_setup {
101104
/// Switch between update modes when the mouse is clicked.
102105
pub(crate) fn cycle_modes(
103106
mut mode: ResMut<ExampleMode>,
104-
mouse_button_input: Res<ButtonInput<KeyCode>>,
107+
button_input: Res<ButtonInput<KeyCode>>,
105108
) {
106-
if mouse_button_input.just_pressed(KeyCode::Space) {
109+
if button_input.just_pressed(KeyCode::Space) {
107110
*mode = match *mode {
108111
ExampleMode::Game => ExampleMode::Application,
109112
ExampleMode::Application => ExampleMode::ApplicationWithRedraw,
@@ -173,7 +176,7 @@ pub(crate) mod test_setup {
173176
commands.spawn((
174177
TextBundle::from_sections([
175178
TextSection::new(
176-
"Press spacebar to cycle modes\n",
179+
"Press space bar to cycle modes\n",
177180
TextStyle {
178181
font_size: 50.0,
179182
..default()

0 commit comments

Comments
 (0)