examples: Trigger event-loop exit on Escape key
In visual examples it is convenient to just press the escape key to exit the demo.
This commit is contained in:
parent
636a7148c8
commit
ab7688e2ed
5 changed files with 60 additions and 11 deletions
|
|
@ -1,7 +1,8 @@
|
|||
use std::num::NonZeroU32;
|
||||
use std::rc::Rc;
|
||||
use winit::event::{Event, WindowEvent};
|
||||
use winit::event::{Event, KeyEvent, WindowEvent};
|
||||
use winit::event_loop::{ControlFlow, EventLoop};
|
||||
use winit::keyboard::{Key, NamedKey};
|
||||
use winit::window::WindowBuilder;
|
||||
|
||||
const BUFFER_WIDTH: usize = 256;
|
||||
|
|
@ -58,7 +59,16 @@ fn main() {
|
|||
buffer.present().unwrap();
|
||||
}
|
||||
Event::WindowEvent {
|
||||
event: WindowEvent::CloseRequested,
|
||||
event:
|
||||
WindowEvent::CloseRequested
|
||||
| WindowEvent::KeyboardInput {
|
||||
event:
|
||||
KeyEvent {
|
||||
logical_key: Key::Named(NamedKey::Escape),
|
||||
..
|
||||
},
|
||||
..
|
||||
},
|
||||
window_id,
|
||||
} if window_id == window.id() => {
|
||||
elwt.exit();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue