Skip to content

Commit

Permalink
ash-window: Upgrade winit example to 0.26
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijnS95 committed Jul 29, 2022
1 parent f5e1f93 commit 9f18e51
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
2 changes: 1 addition & 1 deletion ash-window/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
51 changes: 31 additions & 20 deletions ash-window/examples/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
{
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(())
}

0 comments on commit 9f18e51

Please sign in to comment.