2018-06-12 08:47:50 +10:00
|
|
|
extern crate winit;
|
2019-02-06 02:30:33 +11:00
|
|
|
use winit::window::WindowBuilder;
|
|
|
|
use winit::event::{Event, WindowEvent, VirtualKeyCode, ElementState, KeyboardInput};
|
|
|
|
use winit::event_loop::{EventLoop, ControlFlow};
|
2018-06-12 08:47:50 +10:00
|
|
|
|
|
|
|
fn main() {
|
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.")
|
2018-06-15 09:42:18 +10:00
|
|
|
.with_dimensions((400, 200).into())
|
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| {
|
|
|
|
*control_flow = ControlFlow::Wait;
|
2018-06-12 08:47:50 +10:00
|
|
|
match event {
|
2019-02-06 02:30:33 +11:00
|
|
|
Event::WindowEvent { event, .. } => match event {
|
|
|
|
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
|
|
|
WindowEvent::KeyboardInput {
|
2018-06-12 08:47:50 +10:00
|
|
|
input:
|
2019-02-06 02:30:33 +11:00
|
|
|
KeyboardInput {
|
|
|
|
virtual_keycode: Some(VirtualKeyCode::Space),
|
|
|
|
state: ElementState::Released,
|
2018-06-12 08:47:50 +10:00
|
|
|
..
|
|
|
|
},
|
|
|
|
..
|
|
|
|
} => {
|
|
|
|
resizable = !resizable;
|
|
|
|
println!("Resizable: {}", resizable);
|
|
|
|
window.set_resizable(resizable);
|
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
},
|
|
|
|
_ => (),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|