2022-06-10 20:43:33 +10:00
|
|
|
#![allow(clippy::single_match)]
|
|
|
|
|
2020-09-10 11:58:30 +10:00
|
|
|
use simple_logger::SimpleLogger;
|
2019-06-22 01:33:15 +10:00
|
|
|
use winit::{
|
2019-06-20 06:49:43 +10:00
|
|
|
dpi::LogicalSize,
|
2019-06-22 01:33:15 +10:00
|
|
|
event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
|
2022-04-10 11:32:02 +10:00
|
|
|
event_loop::EventLoop,
|
2019-06-22 01:33:15 +10:00
|
|
|
window::WindowBuilder,
|
|
|
|
};
|
2018-06-12 08:47:50 +10:00
|
|
|
|
|
|
|
fn main() {
|
2020-09-10 11:58:30 +10:00
|
|
|
SimpleLogger::new().init().unwrap();
|
2019-02-06 02:30:33 +11:00
|
|
|
let event_loop = EventLoop::new();
|
2018-06-12 08:47:50 +10:00
|
|
|
|
|
|
|
let mut resizable = false;
|
|
|
|
|
2019-02-06 02:30:33 +11:00
|
|
|
let window = WindowBuilder::new()
|
2018-06-12 08:47:50 +10:00
|
|
|
.with_title("Hit space to toggle resizability.")
|
2022-07-01 21:07:10 +10:00
|
|
|
.with_inner_size(LogicalSize::new(600.0, 300.0))
|
|
|
|
.with_min_inner_size(LogicalSize::new(400.0, 200.0))
|
|
|
|
.with_max_inner_size(LogicalSize::new(800.0, 400.0))
|
2018-06-12 08:47:50 +10:00
|
|
|
.with_resizable(resizable)
|
2019-02-06 02:30:33 +11:00
|
|
|
.build(&event_loop)
|
2018-06-12 08:47:50 +10:00
|
|
|
.unwrap();
|
|
|
|
|
2019-02-06 02:30:33 +11:00
|
|
|
event_loop.run(move |event, _, control_flow| {
|
2022-04-10 11:32:02 +10:00
|
|
|
control_flow.set_wait();
|
2020-01-05 18:12:03 +11:00
|
|
|
|
2018-06-12 08:47:50 +10:00
|
|
|
match event {
|
2019-06-25 02:14:55 +10:00
|
|
|
Event::WindowEvent { event, .. } => match event {
|
2022-04-10 11:32:02 +10:00
|
|
|
WindowEvent::CloseRequested => control_flow.set_exit(),
|
2019-06-25 02:14:55 +10:00
|
|
|
WindowEvent::KeyboardInput {
|
|
|
|
input:
|
|
|
|
KeyboardInput {
|
|
|
|
virtual_keycode: Some(VirtualKeyCode::Space),
|
|
|
|
state: ElementState::Released,
|
|
|
|
..
|
|
|
|
},
|
|
|
|
..
|
|
|
|
} => {
|
|
|
|
resizable = !resizable;
|
|
|
|
println!("Resizable: {}", resizable);
|
|
|
|
window.set_resizable(resizable);
|
2018-06-12 08:47:50 +10:00
|
|
|
}
|
2019-06-25 02:14:55 +10:00
|
|
|
_ => (),
|
2018-06-12 08:47:50 +10:00
|
|
|
},
|
|
|
|
_ => (),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|