Skip to content

Commit

Permalink
Move react_to_resize
Browse files Browse the repository at this point in the history
  • Loading branch information
nicopap committed Jan 6, 2024
1 parent 4e6d8f7 commit 61d801b
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions crates/bevy_winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ pub fn winit_runner(mut app: App) {
});
}
WindowEvent::RedrawRequested => {
redraw_requested(
run_app_update_if_should(
&mut runner_state,
&mut app,
&mut focused_windows_state,
Expand Down Expand Up @@ -762,24 +762,7 @@ pub fn winit_runner(mut app: App) {
}
}

fn react_to_resize(
window: &mut Mut<'_, Window>,
size: winit::dpi::PhysicalSize<u32>,
event_writers: &mut WindowAndInputEventWriters<'_>,
window_entity: Entity,
) {
window
.resolution
.set_physical_resolution(size.width, size.height);

event_writers.window_resized.send(WindowResized {
window: window_entity,
width: window.width(),
height: window.height(),
});
}

fn redraw_requested(
fn run_app_update_if_should(
runner_state: &mut WinitAppRunnerState,
app: &mut App,
focused_windows_state: &mut SystemState<(Res<WinitSettings>, Query<&Window>)>,
Expand Down Expand Up @@ -814,13 +797,11 @@ fn redraw_requested(
let (config, windows) = focused_windows_state.get(&app.world);
let focused = windows.iter().any(|window| window.focused);
let should_update = match config.update_mode(focused) {
UpdateMode::Continuous | UpdateMode::Reactive { .. } => {
// `Reactive`: In order for `event_handler` to have been called, either
// we received a window or raw input event, the `wait` elapsed, or a
// redraw was requested (by the app or the OS). There are no other
// conditions, so we can just return `true` here.
true
}
// `Reactive`: In order for `event_handler` to have been called, either
// we received a window or raw input event, the `wait` elapsed, or a
// redraw was requested (by the app or the OS). There are no other
// conditions, so we can just return `true` here.
UpdateMode::Continuous | UpdateMode::Reactive { .. } => true,
UpdateMode::ReactiveLowPower { .. } => {
runner_state.wait_elapsed
|| runner_state.redraw_requested
Expand Down Expand Up @@ -898,3 +879,20 @@ fn redraw_requested(

create_window_system_state.apply(&mut app.world);
}

fn react_to_resize(
window: &mut Mut<'_, Window>,
size: winit::dpi::PhysicalSize<u32>,
event_writers: &mut WindowAndInputEventWriters<'_>,
window_entity: Entity,
) {
window
.resolution
.set_physical_resolution(size.width, size.height);

event_writers.window_resized.send(WindowResized {
window: window_entity,
width: window.width(),
height: window.height(),
});
}

0 comments on commit 61d801b

Please sign in to comment.