Don't request redraw every frame

This commit is contained in:
Hanno Braun 2025-03-28 18:48:24 +01:00
parent 4390d6d088
commit 05e52cbdcc

View File

@ -82,6 +82,8 @@ impl ApplicationHandler for DisplayState {
window.handle_input_event(input_event); window.handle_input_event(input_event);
} }
let mut drawn = false;
match event { match event {
WindowEvent::Resized(size) => { WindowEvent::Resized(size) => {
window.on_screen_resize(size); window.on_screen_resize(size);
@ -135,18 +137,17 @@ impl ApplicationHandler for DisplayState {
WindowEvent::MouseWheel { .. } => window.add_focus_point(), WindowEvent::MouseWheel { .. } => window.add_focus_point(),
WindowEvent::RedrawRequested => { WindowEvent::RedrawRequested => {
window.draw(); window.draw();
drawn = true;
} }
_ => {} _ => {}
} }
}
fn about_to_wait(&mut self, _: &ActiveEventLoop) {
let Some(window) = &self.window else {
return;
};
if !drawn {
window.window().request_redraw(); window.window().request_redraw();
} }
}
fn about_to_wait(&mut self, _: &ActiveEventLoop) {}
} }
fn input_event(event: &WindowEvent, invert_zoom: bool) -> Option<InputEvent> { fn input_event(event: &WindowEvent, invert_zoom: bool) -> Option<InputEvent> {