press esc to change bg color
This commit is contained in:
parent
0f4e41ae48
commit
eeb9f730eb
2 changed files with 39 additions and 8 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue