diff --git a/ash-window/Cargo.toml b/ash-window/Cargo.toml index 7c4d45ff1..704546465 100644 --- a/ash-window/Cargo.toml +++ b/ash-window/Cargo.toml @@ -22,7 +22,7 @@ raw-window-handle = "0.3.4" raw-window-metal = "0.1" [dev-dependencies] -winit = "0.19.4" +winit = "0.26" ash = { path = "../ash", version = "0.37", default-features = false, features = ["linked"] } [[example]] diff --git a/ash-window/examples/winit.rs b/ash-window/examples/winit.rs index f309efecb..78a16957e 100644 --- a/ash-window/examples/winit.rs +++ b/ash-window/examples/winit.rs @@ -7,12 +7,18 @@ use ash::vk; use std::error::Error; +use winit::{ + dpi::PhysicalSize, + event::{Event, VirtualKeyCode, WindowEvent}, + event_loop::{ControlFlow, EventLoop}, + window::WindowBuilder, +}; fn main() -> Result<(), Box> { - let mut events_loop = winit::EventsLoop::new(); - let window = winit::WindowBuilder::new() - .with_dimensions((800, 600).into()) - .build(&events_loop)?; + let event_loop = EventLoop::new(); + let window = WindowBuilder::new() + .with_inner_size(PhysicalSize::::from((800, 600))) + .build(&event_loop)?; unsafe { let entry = ash::Entry::linked(); @@ -29,21 +35,26 @@ fn main() -> Result<(), Box> { let surface_fn = ash::extensions::khr::Surface::new(&entry, &instance); println!("surface: {:?}", surface); - let mut running = true; - while running { - events_loop.poll_events(|event| { - if let winit::Event::WindowEvent { - event: winit::WindowEvent::CloseRequested, - .. - } = event - { - running = false; - } - }); - } - - surface_fn.destroy_surface(surface, None); + event_loop.run(move |event, _, control_flow| match event { + winit::event::Event::WindowEvent { + event: + WindowEvent::CloseRequested + | WindowEvent::KeyboardInput { + input: + winit::event::KeyboardInput { + virtual_keycode: Some(VirtualKeyCode::Escape), + .. + }, + .. + }, + window_id: _, + } => { + *control_flow = ControlFlow::Exit; + } + Event::LoopDestroyed => { + surface_fn.destroy_surface(surface, None); + } + _ => {} + }) } - - Ok(()) }