2016-03-27 04:07:52 +11:00
|
|
|
extern crate winit;
|
2014-09-12 16:50:54 +10:00
|
|
|
|
2018-04-25 06:20:40 +10:00
|
|
|
use std::collections::HashMap;
|
2019-02-06 02:30:33 +11:00
|
|
|
use winit::window::Window;
|
|
|
|
use winit::event::{Event, WindowEvent, ElementState, KeyboardInput};
|
|
|
|
use winit::event_loop::{EventLoop, ControlFlow};
|
2018-04-25 06:20:40 +10:00
|
|
|
|
2014-08-04 01:23:08 +10:00
|
|
|
fn main() {
|
2019-02-06 02:30:33 +11:00
|
|
|
let event_loop = EventLoop::new();
|
2014-08-04 01:23:08 +10:00
|
|
|
|
2018-04-25 06:20:40 +10:00
|
|
|
let mut windows = HashMap::new();
|
|
|
|
for _ in 0..3 {
|
2019-02-06 02:30:33 +11:00
|
|
|
let window = Window::new(&event_loop).unwrap();
|
2018-04-25 06:20:40 +10:00
|
|
|
windows.insert(window.id(), window);
|
|
|
|
}
|
2014-12-24 03:12:29 +11:00
|
|
|
|
2019-02-06 02:30:33 +11:00
|
|
|
event_loop.run(move |event, event_loop, control_flow| {
|
|
|
|
*control_flow = ControlFlow::Wait;
|
2015-06-16 21:48:08 +10:00
|
|
|
match event {
|
2019-02-06 02:30:33 +11:00
|
|
|
Event::WindowEvent { event, window_id } => {
|
|
|
|
match event {
|
|
|
|
WindowEvent::CloseRequested => {
|
|
|
|
println!("Window {:?} has received the signal to close", window_id);
|
2018-04-25 06:20:40 +10:00
|
|
|
|
2019-02-06 02:30:33 +11:00
|
|
|
// This drops the window, causing it to close.
|
|
|
|
windows.remove(&window_id);
|
2017-01-29 01:45:01 +11:00
|
|
|
|
2019-02-06 02:30:33 +11:00
|
|
|
if windows.is_empty() {
|
|
|
|
*control_flow = ControlFlow::Exit;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
WindowEvent::KeyboardInput { input: KeyboardInput { state: ElementState::Pressed, .. }, .. } => {
|
|
|
|
let window = Window::new(&event_loop).unwrap();
|
|
|
|
windows.insert(window.id(), window);
|
|
|
|
},
|
|
|
|
_ => ()
|
2017-01-29 01:45:01 +11:00
|
|
|
}
|
2018-04-25 06:20:40 +10:00
|
|
|
}
|
2017-01-29 01:45:01 +11:00
|
|
|
_ => (),
|
2015-06-16 21:48:08 +10:00
|
|
|
}
|
2017-01-29 01:45:01 +11:00
|
|
|
})
|
2014-08-04 01:23:08 +10:00
|
|
|
}
|