2020-09-09 17:58:30 -08:00
|
|
|
use simple_logger::SimpleLogger;
|
2019-06-21 11:33:15 -04:00
|
|
|
use winit::{
|
2019-06-19 16:49:43 -04:00
|
|
|
dpi::LogicalSize,
|
2019-06-21 11:33:15 -04:00
|
|
|
event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
|
|
|
|
event_loop::{ControlFlow, EventLoop},
|
|
|
|
window::WindowBuilder,
|
|
|
|
};
|
2018-06-11 16:47:50 -06:00
|
|
|
|
|
|
|
fn main() {
|
2020-09-09 17:58:30 -08:00
|
|
|
SimpleLogger::new().init().unwrap();
|
2019-02-05 10:30:33 -05:00
|
|
|
let event_loop = EventLoop::new();
|
2018-06-11 16:47:50 -06:00
|
|
|
|
|
|
|
let mut resizable = false;
|
|
|
|
|
2019-02-05 10:30:33 -05:00
|
|
|
let window = WindowBuilder::new()
|
2018-06-11 16:47:50 -06:00
|
|
|
.with_title("Hit space to toggle resizability.")
|
2019-06-19 16:49:43 -04:00
|
|
|
.with_inner_size(LogicalSize::new(400.0, 200.0))
|
2018-06-11 16:47:50 -06:00
|
|
|
.with_resizable(resizable)
|
2019-02-05 10:30:33 -05:00
|
|
|
.build(&event_loop)
|
2018-06-11 16:47:50 -06:00
|
|
|
.unwrap();
|
|
|
|
|
2019-02-05 10:30:33 -05:00
|
|
|
event_loop.run(move |event, _, control_flow| {
|
|
|
|
*control_flow = ControlFlow::Wait;
|
2020-01-05 02:12:03 -05:00
|
|
|
|
2018-06-11 16:47:50 -06:00
|
|
|
match event {
|
2019-06-24 12:14:55 -04:00
|
|
|
Event::WindowEvent { event, .. } => match event {
|
|
|
|
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
|
|
|
WindowEvent::KeyboardInput {
|
|
|
|
input:
|
|
|
|
KeyboardInput {
|
|
|
|
virtual_keycode: Some(VirtualKeyCode::Space),
|
|
|
|
state: ElementState::Released,
|
|
|
|
..
|
|
|
|
},
|
|
|
|
..
|
|
|
|
} => {
|
|
|
|
resizable = !resizable;
|
|
|
|
println!("Resizable: {}", resizable);
|
|
|
|
window.set_resizable(resizable);
|
2018-06-11 16:47:50 -06:00
|
|
|
}
|
2019-06-24 12:14:55 -04:00
|
|
|
_ => (),
|
2018-06-11 16:47:50 -06:00
|
|
|
},
|
|
|
|
_ => (),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|