ash-window: Upgrade winit example to 0.26

This commit is contained in:
Marijn Suijten 2022-07-29 19:42:10 +02:00 committed by GitHub
parent c66db26bc3
commit f4acfbe2cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 21 deletions

View file

@ -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]]

View file

@ -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<dyn Error>> {
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::<u32>::from((800, 600)))
.build(&event_loop)?;
unsafe {
let entry = ash::Entry::linked();
@ -29,21 +35,26 @@ fn main() -> Result<(), Box<dyn Error>> {
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_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),
..
} = event
{
running = false;
},
..
},
window_id: _,
} => {
*control_flow = ControlFlow::Exit;
}
});
}
Event::LoopDestroyed => {
surface_fn.destroy_surface(surface, None);
}
Ok(())
_ => {}
})
}
}