Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

low_power example: pick nits #12437

Merged
merged 2 commits into from Mar 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 11 additions & 8 deletions examples/window/low_power.rs
Expand Up @@ -16,7 +16,7 @@ fn main() {
.insert_resource(WinitSettings::game())
// Power-saving reactive rendering for applications.
.insert_resource(WinitSettings::desktop_app())
// You can also customize update behavior with the fields of [`WinitConfig`]
// You can also customize update behavior with the fields of [`WinitSettings`]
.insert_resource(WinitSettings {
focused_mode: bevy::winit::UpdateMode::Continuous,
unfocused_mode: bevy::winit::UpdateMode::ReactiveLowPower {
Expand Down Expand Up @@ -61,13 +61,16 @@ fn update_winit(
use ExampleMode::*;
*winit_config = match *mode {
Game => {
// In the default `WinitConfig::game()` mode:
// In the default `WinitSettings::game()` mode:
// * When focused: the event loop runs as fast as possible
// * When not focused: the event loop runs as fast as possible
// * When not focused: the app will update when the window is directly interacted with
// (e.g. the mouse hovers over a visible part of the out of focus window), a
// [`RequestRedraw`] event is received, or one sixtieth of a second has passed
// without the app updating (60 Hz refresh rate max).
WinitSettings::game()
}
Application => {
// While in `WinitConfig::desktop_app()` mode:
// While in `WinitSettings::desktop_app()` mode:
// * When focused: the app will update any time a winit event (e.g. the window is
// moved/resized, the mouse moves, a button is pressed, etc.), a [`RequestRedraw`]
// event is received, or after 5 seconds if the app has not updated.
Expand All @@ -80,7 +83,7 @@ fn update_winit(
ApplicationWithRedraw => {
// Sending a `RequestRedraw` event is useful when you want the app to update the next
// frame regardless of any user input. For example, your application might use
// `WinitConfig::desktop_app()` to reduce power use, but UI animations need to play even
// `WinitSettings::desktop_app()` to reduce power use, but UI animations need to play even
// when there are no inputs, so you send redraw requests while the animation is playing.
event.send(RequestRedraw);
WinitSettings::desktop_app()
Expand All @@ -101,9 +104,9 @@ pub(crate) mod test_setup {
/// Switch between update modes when the mouse is clicked.
pub(crate) fn cycle_modes(
mut mode: ResMut<ExampleMode>,
mouse_button_input: Res<ButtonInput<KeyCode>>,
button_input: Res<ButtonInput<KeyCode>>,
) {
if mouse_button_input.just_pressed(KeyCode::Space) {
if button_input.just_pressed(KeyCode::Space) {
*mode = match *mode {
ExampleMode::Game => ExampleMode::Application,
ExampleMode::Application => ExampleMode::ApplicationWithRedraw,
Expand Down Expand Up @@ -173,7 +176,7 @@ pub(crate) mod test_setup {
commands.spawn((
TextBundle::from_sections([
TextSection::new(
"Press spacebar to cycle modes\n",
"Press space bar to cycle modes\n",
TextStyle {
font_size: 50.0,
..default()
Expand Down