Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples: Upgrade to winit 0.25 #487

Merged
merged 4 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["maik klein <maikklein@googlemail.com>"]
edition = "2018"

[dependencies]
winit = "0.19.5"
winit = "0.25.0"
image = "0.10.4"
ash = { path = "../ash" }
ash-window = { path = "../ash-window" }
62 changes: 37 additions & 25 deletions examples/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ use std::default::Default;
use std::ffi::{CStr, CString};
use std::ops::Drop;

use winit::{
event::{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 {
Expand Down Expand Up @@ -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<winit::EventsLoop>,
pub window: winit::window::Window,
pub event_loop: RefCell<EventLoop<()>>,
pub debug_call_back: vk::DebugUtilsMessengerEXT,

pub pdevice: vk::PhysicalDevice,
Expand Down Expand Up @@ -173,36 +180,41 @@ pub struct ExampleBase {

impl ExampleBase {
pub fn render_loop<F: Fn()>(&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.event_loop
.borrow_mut()
.run_return(|event, _, control_flow| {
*control_flow = ControlFlow::Wait;
f();
if let Event::WindowEvent {
event:
WindowEvent::CloseRequested
| WindowEvent::KeyboardInput {
input:
KeyboardInput {
state: ElementState::Pressed,
virtual_keycode: Some(VirtualKeyCode::Escape),
..
},
..
},
..
} = event
{
*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 event_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),
))
.build(&events_loop)
.build(&event_loop)
.unwrap();
let entry = Entry::new();
let app_name = CString::new("VulkanTriangle").unwrap();
Expand Down Expand Up @@ -516,7 +528,7 @@ impl ExampleBase {
.unwrap();

ExampleBase {
events_loop: RefCell::new(events_loop),
event_loop: RefCell::new(event_loop),
entry,
instance,
device,
Expand Down