2019-12-22 01:04:11 -05:00
|
|
|
extern crate winit;
|
|
|
|
|
2020-09-09 17:58:30 -08:00
|
|
|
use simple_logger::SimpleLogger;
|
2019-12-22 01:04:11 -05:00
|
|
|
use winit::event::{Event, VirtualKeyCode, WindowEvent};
|
2022-04-09 18:32:02 -07:00
|
|
|
use winit::event_loop::EventLoop;
|
2019-12-22 01:04:11 -05:00
|
|
|
use winit::window::WindowBuilder;
|
|
|
|
|
|
|
|
fn main() {
|
2020-09-09 17:58:30 -08:00
|
|
|
SimpleLogger::new().init().unwrap();
|
2019-12-22 01:04:11 -05:00
|
|
|
let event_loop = EventLoop::new();
|
|
|
|
|
|
|
|
let window = WindowBuilder::new()
|
|
|
|
.with_title("A fantastic window!")
|
|
|
|
.build(&event_loop)
|
|
|
|
.unwrap();
|
|
|
|
|
2020-01-05 02:12:03 -05:00
|
|
|
event_loop.run(move |event, _, control_flow| {
|
2022-04-09 18:32:02 -07:00
|
|
|
control_flow.set_wait();
|
2019-12-22 01:04:11 -05:00
|
|
|
|
2020-01-05 02:12:03 -05:00
|
|
|
match event {
|
|
|
|
Event::WindowEvent {
|
|
|
|
event: WindowEvent::CloseRequested,
|
|
|
|
..
|
2022-04-09 18:32:02 -07:00
|
|
|
} => control_flow.set_exit(),
|
2020-01-05 02:12:03 -05:00
|
|
|
|
|
|
|
// 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 01:04:11 -05:00
|
|
|
}
|
|
|
|
}
|
2020-01-05 02:12:03 -05:00
|
|
|
_ => (),
|
2019-12-22 01:04:11 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|