Skip to content

Commit

Permalink
Run update on resize also (for simplicity)
Browse files Browse the repository at this point in the history
  • Loading branch information
hakolao committed Jan 22, 2024
1 parent ae6a77e commit 7d8440e
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions src/glass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ impl Glass {
let mut runner_state = RunnerState::default();
// Run update at start
runner_state.run_update = true;
runner_state.is_start = true;

match event_loop.run(move |event, event_loop| {
event_loop.set_control_flow(ControlFlow::Poll);
Expand All @@ -58,11 +57,8 @@ impl Glass {
if !event_loop.exiting() {
self.app.input(&mut context, event_loop, &event);
}
// We want to trigger one update before any render. Resizes (at app start trigger renders)
if !runner_state.is_start {
runner_state.run_update = false;
}
runner_state.render_without_update = false;

runner_state.run_update = false;

match event {
Event::WindowEvent {
Expand All @@ -79,7 +75,7 @@ impl Glass {
context.device_context.device(),
physical_size,
);
runner_state.render_without_update = true;
runner_state.run_update = true;
}
}
WindowEvent::ScaleFactorChanged {
Expand All @@ -90,7 +86,7 @@ impl Glass {
context.device_context.device(),
size,
);
runner_state.render_without_update = true;
runner_state.run_update = true;
}
WindowEvent::KeyboardInput {
event,
Expand Down Expand Up @@ -128,13 +124,8 @@ impl Glass {
}
_ => {}
}
if !event_loop.exiting() {
if runner_state.run_update {
self.run_update(event_loop, &mut context, &mut runner_state);
runner_state.is_start = false;
} else if runner_state.render_without_update {
self.render(&mut context);
}
if !event_loop.exiting() && runner_state.run_update {
self.run_update(event_loop, &mut context, &mut runner_state);
}
}) {
Err(e) => Err(GlassError::EventLoopError(e)),
Expand Down Expand Up @@ -206,10 +197,8 @@ impl Glass {

#[derive(Default)]
struct RunnerState {
is_start: bool,
run_update: bool,
request_window_close: bool,
render_without_update: bool,
remove_windows: Vec<WindowId>,
}

Expand Down

0 comments on commit 7d8440e

Please sign in to comment.