forked from unknownue/vulkan-tutorial-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
00_base_code.rs
61 lines (49 loc) · 1.96 KB
/
00_base_code.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use winit::event::{Event, VirtualKeyCode, ElementState, KeyboardInput, WindowEvent};
use winit::event_loop::{EventLoop, ControlFlow};
// Constants
const WINDOW_TITLE: &'static str = "00.Base Code";
const WINDOW_WIDTH: u32 = 800;
const WINDOW_HEIGHT: u32 = 600;
struct VulkanApp;
impl VulkanApp {
fn init_window(event_loop: &EventLoop<()>) -> winit::window::Window {
winit::window::WindowBuilder::new()
.with_title(WINDOW_TITLE)
.with_inner_size(winit::dpi::LogicalSize::new(WINDOW_WIDTH, WINDOW_HEIGHT))
.build(event_loop)
.expect("Failed to create window.")
}
pub fn main_loop(event_loop: EventLoop<()>) {
event_loop.run(move |event, _, control_flow| {
match event {
| Event::WindowEvent { event, .. } => {
match event {
| WindowEvent::CloseRequested => {
*control_flow = ControlFlow::Exit
},
| WindowEvent::KeyboardInput { input, .. } => {
match input {
| KeyboardInput { virtual_keycode, state, .. } => {
match (virtual_keycode, state) {
| (Some(VirtualKeyCode::Escape), ElementState::Pressed) => {
dbg!();
*control_flow = ControlFlow::Exit
},
| _ => {},
}
},
}
},
| _ => {},
}
},
_ => (),
}
})
}
}
fn main() {
let event_loop = EventLoop::new();
let _window = VulkanApp::init_window(&event_loop);
VulkanApp::main_loop(event_loop);
}