From 1e1fffad83a42d6cb94e3b89c9519df15438eefb Mon Sep 17 00:00:00 2001 From: Benjamin Saunders Date: Sun, 22 Oct 2023 15:53:52 -0700 Subject: [PATCH] Update winit --- crates/yakui-vulkan/Cargo.toml | 2 +- crates/yakui-vulkan/examples/demo.rs | 188 +++++++++++++-------------- 2 files changed, 94 insertions(+), 96 deletions(-) diff --git a/crates/yakui-vulkan/Cargo.toml b/crates/yakui-vulkan/Cargo.toml index a8603ab6..f05fc58e 100644 --- a/crates/yakui-vulkan/Cargo.toml +++ b/crates/yakui-vulkan/Cargo.toml @@ -18,4 +18,4 @@ thunderdome = "0.6.0" ash-window = "0.12.0" image = "0.24.5" raw-window-handle = "0.5.0" -winit = "0.27.5" +winit = { version = "0.29.2", features = ["rwh_05"] } diff --git a/crates/yakui-vulkan/examples/demo.rs b/crates/yakui-vulkan/examples/demo.rs index 9a3b2452..c68e04bd 100644 --- a/crates/yakui-vulkan/examples/demo.rs +++ b/crates/yakui-vulkan/examples/demo.rs @@ -3,9 +3,9 @@ use yakui::geometry::{UVec2, Vec2}; use yakui_vulkan::*; use winit::{ - event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent}, + event::{ElementState, Event, KeyEvent, WindowEvent}, event_loop::ControlFlow, - platform::run_return::EventLoopExtRunReturn, + keyboard::{KeyCode, PhysicalKey}, }; use yakui::image; @@ -30,7 +30,7 @@ fn main() { use winit::dpi::PhysicalSize; let (width, height) = (500, 500); - let (mut event_loop, window) = init_winit(width, height); + let (event_loop, window) = init_winit(width, height); let mut vulkan_test = VulkanTest::new(width, height, &window); let mut yak = yakui::Yakui::new(); @@ -67,105 +67,103 @@ fn main() { let mut winit_initializing = true; - event_loop.run_return(|event, _, control_flow| { - *control_flow = ControlFlow::Poll; - match event { - Event::WindowEvent { - event: - WindowEvent::CloseRequested - | WindowEvent::KeyboardInput { - input: - KeyboardInput { - state: ElementState::Pressed, - virtual_keycode: Some(VirtualKeyCode::Escape), - .. - }, - .. - }, - .. - } => *control_flow = ControlFlow::Exit, - - Event::NewEvents(cause) => { - if cause == winit::event::StartCause::Init { - winit_initializing = true; - } else { - winit_initializing = false; - } + event_loop.set_control_flow(ControlFlow::Poll); + _ = event_loop.run(|event, elwt| match event { + Event::WindowEvent { + event: + WindowEvent::CloseRequested + | WindowEvent::KeyboardInput { + event: + KeyEvent { + state: ElementState::Pressed, + physical_key: PhysicalKey::Code(KeyCode::Escape), + .. + }, + .. + }, + .. + } => elwt.exit(), + + Event::NewEvents(cause) => { + if cause == winit::event::StartCause::Init { + winit_initializing = true; + } else { + winit_initializing = false; } + } - Event::MainEventsCleared => { - let vulkan_context = VulkanContext::new( - &vulkan_test.device, - vulkan_test.present_queue, - vulkan_test.device_memory_properties, - ); + Event::AboutToWait => { + let vulkan_context = VulkanContext::new( + &vulkan_test.device, + vulkan_test.present_queue, + vulkan_test.device_memory_properties, + ); - yak.start(); - gui(&gui_state); - yak.finish(); + yak.start(); + gui(&gui_state); + yak.finish(); - let paint = yak.paint(); + let paint = yak.paint(); - let index = vulkan_test.cmd_begin(); - unsafe { - yakui_vulkan.transfers_finished(&vulkan_context); - yakui_vulkan.transfer(paint, &vulkan_context, vulkan_test.draw_command_buffer); - } - vulkan_test.render_begin(index); - unsafe { - yakui_vulkan.paint( - paint, - &vulkan_context, - vulkan_test.draw_command_buffer, - vulkan_test.swapchain_info.surface_resolution, - ); - } - vulkan_test.render_end(index); - yakui_vulkan.transfers_submitted(); + let index = vulkan_test.cmd_begin(); + unsafe { + yakui_vulkan.transfers_finished(&vulkan_context); + yakui_vulkan.transfer(paint, &vulkan_context, vulkan_test.draw_command_buffer); } - Event::WindowEvent { - event: WindowEvent::Resized(size), - .. - } => { - if winit_initializing { - println!("Ignoring resize during init!"); - } else { - let PhysicalSize { width, height } = size; - vulkan_test.resized(width, height); - yak.set_surface_size([width as f32, height as f32].into()); - yak.set_unscaled_viewport(yakui_core::geometry::Rect::from_pos_size( - Default::default(), - [width as f32, height as f32].into(), - )); - } + vulkan_test.render_begin(index); + unsafe { + yakui_vulkan.paint( + paint, + &vulkan_context, + vulkan_test.draw_command_buffer, + vulkan_test.swapchain_info.surface_resolution, + ); } - Event::WindowEvent { - event: WindowEvent::ScaleFactorChanged { scale_factor, .. }, - .. - } => yak.set_scale_factor(scale_factor as _), - Event::WindowEvent { - event: - WindowEvent::KeyboardInput { - input: - KeyboardInput { - state: ElementState::Released, - virtual_keycode, - .. - }, - .. - }, - .. - } => match virtual_keycode { - Some(VirtualKeyCode::A) => { - gui_state.which_image = match &gui_state.which_image { - WhichImage::Monkey => WhichImage::Dog, - WhichImage::Dog => WhichImage::Monkey, - } - } - _ => {} - }, - _ => (), + vulkan_test.render_end(index); + yakui_vulkan.transfers_submitted(); } + Event::WindowEvent { + event: WindowEvent::Resized(size), + .. + } => { + if winit_initializing { + println!("Ignoring resize during init!"); + } else { + let PhysicalSize { width, height } = size; + vulkan_test.resized(width, height); + yak.set_surface_size([width as f32, height as f32].into()); + yak.set_unscaled_viewport(yakui_core::geometry::Rect::from_pos_size( + Default::default(), + [width as f32, height as f32].into(), + )); + } + } + Event::WindowEvent { + event: WindowEvent::ScaleFactorChanged { scale_factor, .. }, + .. + } => yak.set_scale_factor(scale_factor as _), + Event::WindowEvent { + event: + WindowEvent::KeyboardInput { + event: + KeyEvent { + state: ElementState::Released, + physical_key, + .. + }, + .. + }, + .. + } => match physical_key { + PhysicalKey::Code(KeyCode::KeyA) => { + gui_state.which_image = match &gui_state.which_image { + WhichImage::Monkey => WhichImage::Dog, + WhichImage::Dog => WhichImage::Monkey, + } + } + _ => {} + }, + _ => (), }); unsafe { @@ -700,7 +698,7 @@ fn init_winit( ) -> (winit::event_loop::EventLoop<()>, winit::window::Window) { use winit::{event_loop::EventLoopBuilder, window::WindowBuilder}; - let event_loop = EventLoopBuilder::new().build(); + let event_loop = EventLoopBuilder::new().build().unwrap(); let window = WindowBuilder::new() .with_title("Yakui Vulkan - Test")