press esc to change bg color

This commit is contained in:
Chance 2025-03-24 18:08:00 -04:00 committed by BitSyndicate
parent 49a442ce38
commit 5f3236caa2
Signed by: bitsyndicate
GPG key ID: 443E4198D6BBA6DE
2 changed files with 39 additions and 8 deletions

View file

@ -42,6 +42,28 @@ impl ApplicationHandler for App<'_> {
debug!("Window closed, exiting");
std::process::exit(0)
}
WindowEvent::KeyboardInput { device_id, event, is_synthetic } => {
match event.physical_key {
winit::keyboard::PhysicalKey::Code(code) => {
if event.state.is_pressed() == false {
return;
}
if code == winit::keyboard::KeyCode::Escape {
// event_loop.exit();
debug!("Window closed, exiting");
if let Some(ctx) = &mut self.ctx {
match ctx.bg_color() {
wgpu::Color::WHITE => ctx.change_bg_color(wgpu::Color::BLACK),
wgpu::Color::BLACK => ctx.change_bg_color(wgpu::Color::WHITE),
_ => ctx.change_bg_color(wgpu::Color::WHITE),
}
// std::process::exit(0)
}
}
}
_ => {}
}
}
WindowEvent::RedrawRequested => {
if let Some(ctx) = &mut self.ctx {
ctx.draw();