From 89b9fdcd77bde332d4acc2f48a948ea83ec8f4b9 Mon Sep 17 00:00:00 2001 From: neurotok Date: Mon, 8 Nov 2021 23:25:13 +0100 Subject: [PATCH 1/4] winit v0.25.0 --- examples/Cargo.toml | 2 +- examples/src/lib.rs | 63 ++++++++++++++++++++++++++++----------------- 2 files changed, 41 insertions(+), 24 deletions(-) diff --git a/examples/Cargo.toml b/examples/Cargo.toml index f81b2b775..a8d090a79 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -5,7 +5,7 @@ authors = ["maik klein "] edition = "2018" [dependencies] -winit = "0.19.5" +winit = "0.25.0" image = "0.10.4" ash = { path = "../ash" } ash-window = { path = "../ash-window" } diff --git a/examples/src/lib.rs b/examples/src/lib.rs index 9d5513bba..6ac8f998f 100644 --- a/examples/src/lib.rs +++ b/examples/src/lib.rs @@ -14,6 +14,13 @@ use std::default::Default; use std::ffi::{CStr, CString}; use std::ops::Drop; +use winit::{ + event::{DeviceEvent, ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent}, + event_loop::{ControlFlow, EventLoop}, + platform::run_return::EventLoopExtRunReturn, + window::WindowBuilder, +}; + // Simple offset_of macro akin to C++ offsetof #[macro_export] macro_rules! offset_of { @@ -139,8 +146,8 @@ pub struct ExampleBase { pub surface_loader: Surface, pub swapchain_loader: Swapchain, pub debug_utils_loader: DebugUtils, - pub window: winit::Window, - pub events_loop: RefCell, + pub window: winit::window::Window, + pub events_loop: RefCell>, pub debug_call_back: vk::DebugUtilsMessengerEXT, pub pdevice: vk::PhysicalDevice, @@ -173,32 +180,42 @@ pub struct ExampleBase { impl ExampleBase { pub fn render_loop(&self, f: F) { - use winit::*; - self.events_loop.borrow_mut().run_forever(|event| { - f(); - match event { - Event::WindowEvent { event, .. } => match event { - WindowEvent::KeyboardInput { input, .. } => { - if let Some(VirtualKeyCode::Escape) = input.virtual_keycode { - ControlFlow::Break - } else { - ControlFlow::Continue - } - } - WindowEvent::CloseRequested => winit::ControlFlow::Break, - _ => ControlFlow::Continue, - }, - _ => ControlFlow::Continue, - } - }); + self.events_loop + .borrow_mut() + .run_return(|event, _, control_flow| { + *control_flow = ControlFlow::Wait; + f(); + match event { + Event::WindowEvent { + event: WindowEvent::CloseRequested, + window_id, + } if window_id == self.window.id() => *control_flow = ControlFlow::Exit, + + Event::DeviceEvent { event, .. } => match event { + DeviceEvent::Key(KeyboardInput { + virtual_keycode: Some(keycode), + state, + .. + }) => match (keycode, state) { + (VirtualKeyCode::Escape, ElementState::Released) => { + *control_flow = ControlFlow::Exit + } + _ => (), + }, + _ => (), + }, + + _ => (), + } + }); } pub fn new(window_width: u32, window_height: u32) -> Self { unsafe { - let events_loop = winit::EventsLoop::new(); - let window = winit::WindowBuilder::new() + let events_loop = EventLoop::new(); + let window = WindowBuilder::new() .with_title("Ash - Example") - .with_dimensions(winit::dpi::LogicalSize::new( + .with_inner_size(winit::dpi::LogicalSize::new( f64::from(window_width), f64::from(window_height), )) From a58403f6791ad07011f10f37ad2dba2f81c4c578 Mon Sep 17 00:00:00 2001 From: neurotok Date: Tue, 9 Nov 2021 19:12:51 +0100 Subject: [PATCH 2/4] window event keyboard input --- examples/src/lib.rs | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/examples/src/lib.rs b/examples/src/lib.rs index 6ac8f998f..314411b46 100644 --- a/examples/src/lib.rs +++ b/examples/src/lib.rs @@ -15,7 +15,7 @@ use std::ffi::{CStr, CString}; use std::ops::Drop; use winit::{ - event::{DeviceEvent, ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent}, + event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent}, event_loop::{ControlFlow, EventLoop}, platform::run_return::EventLoopExtRunReturn, window::WindowBuilder, @@ -187,25 +187,22 @@ impl ExampleBase { f(); match event { Event::WindowEvent { - event: WindowEvent::CloseRequested, + ref event, window_id, - } if window_id == self.window.id() => *control_flow = ControlFlow::Exit, - - Event::DeviceEvent { event, .. } => match event { - DeviceEvent::Key(KeyboardInput { - virtual_keycode: Some(keycode), - state, + } if window_id == self.window.id() => match event { + WindowEvent::CloseRequested + | WindowEvent::KeyboardInput { + input: + KeyboardInput { + state: ElementState::Pressed, + virtual_keycode: Some(VirtualKeyCode::Escape), + .. + }, .. - }) => match (keycode, state) { - (VirtualKeyCode::Escape, ElementState::Released) => { - *control_flow = ControlFlow::Exit - } - _ => (), - }, - _ => (), + } => *control_flow = ControlFlow::Exit, + _ => {} }, - - _ => (), + _ => {} } }); } From fe2bee2cc205b2bbb2cf3eb9fbe3f182bc1f106f Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Tue, 21 Dec 2021 00:39:35 +0100 Subject: [PATCH 3/4] Remove window.id() match, simply nested matches with single if-let --- examples/src/lib.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/examples/src/lib.rs b/examples/src/lib.rs index 314411b46..b27d7bb65 100644 --- a/examples/src/lib.rs +++ b/examples/src/lib.rs @@ -185,11 +185,8 @@ impl ExampleBase { .run_return(|event, _, control_flow| { *control_flow = ControlFlow::Wait; f(); - match event { - Event::WindowEvent { - ref event, - window_id, - } if window_id == self.window.id() => match event { + if let Event::WindowEvent { + event: WindowEvent::CloseRequested | WindowEvent::KeyboardInput { input: @@ -199,10 +196,11 @@ impl ExampleBase { .. }, .. - } => *control_flow = ControlFlow::Exit, - _ => {} - }, - _ => {} + }, + .. + } = event + { + *control_flow = ControlFlow::Exit } }); } From 6c37338fa044f2703bc78583c17f8ec656bf82de Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Tue, 21 Dec 2021 00:45:18 +0100 Subject: [PATCH 4/4] examples: Rename events_loop to event_loop --- examples/src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/src/lib.rs b/examples/src/lib.rs index b27d7bb65..59be91739 100644 --- a/examples/src/lib.rs +++ b/examples/src/lib.rs @@ -147,7 +147,7 @@ pub struct ExampleBase { pub swapchain_loader: Swapchain, pub debug_utils_loader: DebugUtils, pub window: winit::window::Window, - pub events_loop: RefCell>, + pub event_loop: RefCell>, pub debug_call_back: vk::DebugUtilsMessengerEXT, pub pdevice: vk::PhysicalDevice, @@ -180,7 +180,7 @@ pub struct ExampleBase { impl ExampleBase { pub fn render_loop(&self, f: F) { - self.events_loop + self.event_loop .borrow_mut() .run_return(|event, _, control_flow| { *control_flow = ControlFlow::Wait; @@ -207,14 +207,14 @@ impl ExampleBase { pub fn new(window_width: u32, window_height: u32) -> Self { unsafe { - let events_loop = EventLoop::new(); + let event_loop = EventLoop::new(); let window = WindowBuilder::new() .with_title("Ash - Example") .with_inner_size(winit::dpi::LogicalSize::new( f64::from(window_width), f64::from(window_height), )) - .build(&events_loop) + .build(&event_loop) .unwrap(); let entry = Entry::new(); let app_name = CString::new("VulkanTriangle").unwrap(); @@ -528,7 +528,7 @@ impl ExampleBase { .unwrap(); ExampleBase { - events_loop: RefCell::new(events_loop), + event_loop: RefCell::new(event_loop), entry, instance, device,