2019-12-22 17:04:11 +11:00
|
|
|
extern crate winit;
|
|
|
|
|
|
|
|
use winit::event::{Event, VirtualKeyCode, WindowEvent};
|
|
|
|
use winit::event_loop::{ControlFlow, EventLoop};
|
|
|
|
use winit::window::WindowBuilder;
|
|
|
|
|
|
|
|
fn main() {
|
2020-01-07 07:28:58 +11:00
|
|
|
simple_logger::init().unwrap();
|
2019-12-22 17:04:11 +11:00
|
|
|
let event_loop = EventLoop::new();
|
|
|
|
|
|
|
|
let window = WindowBuilder::new()
|
|
|
|
.with_title("A fantastic window!")
|
|
|
|
.build(&event_loop)
|
|
|
|
.unwrap();
|
|
|
|
|
2020-01-05 18:12:03 +11:00
|
|
|
event_loop.run(move |event, _, control_flow| {
|
|
|
|
*control_flow = ControlFlow::Wait;
|
2019-12-22 17:04:11 +11:00
|
|
|
|
2020-01-05 18:12:03 +11:00
|
|
|
match event {
|
|
|
|
Event::WindowEvent {
|
|
|
|
event: WindowEvent::CloseRequested,
|
|
|
|
..
|
|
|
|
} => *control_flow = ControlFlow::Exit,
|
|
|
|
|
|
|
|
// Keyboard input event to handle minimize via a hotkey
|
|
|
|
Event::WindowEvent {
|
|
|
|
event: WindowEvent::KeyboardInput { input, .. },
|
|
|
|
window_id,
|
|
|
|
} => {
|
|
|
|
if window_id == window.id() {
|
|
|
|
// Pressing the 'M' key will minimize the window
|
|
|
|
if input.virtual_keycode == Some(VirtualKeyCode::M) {
|
|
|
|
window.set_minimized(true);
|
|
|
|
}
|
2019-12-22 17:04:11 +11:00
|
|
|
}
|
|
|
|
}
|
2020-01-05 18:12:03 +11:00
|
|
|
_ => (),
|
2019-12-22 17:04:11 +11:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|