2019-06-22 01:33:15 +10:00
|
|
|
use winit::{
|
|
|
|
event::{Event, WindowEvent},
|
|
|
|
event_loop::{ControlFlow, EventLoop},
|
|
|
|
window::WindowBuilder,
|
|
|
|
};
|
2017-05-25 02:29:51 +10:00
|
|
|
|
|
|
|
fn main() {
|
2019-02-06 02:30:33 +11:00
|
|
|
let event_loop: EventLoop<i32> = EventLoop::new_user_event();
|
2017-05-25 02:29:51 +10:00
|
|
|
|
2019-02-06 02:30:33 +11:00
|
|
|
let _window = WindowBuilder::new()
|
2017-05-25 02:29:51 +10:00
|
|
|
.with_title("A fantastic window!")
|
2019-02-06 02:30:33 +11:00
|
|
|
.build(&event_loop)
|
2017-05-25 02:29:51 +10:00
|
|
|
.unwrap();
|
|
|
|
|
2019-02-06 02:30:33 +11:00
|
|
|
let proxy = event_loop.create_proxy();
|
2017-05-25 02:29:51 +10:00
|
|
|
|
|
|
|
std::thread::spawn(move || {
|
2019-02-06 02:30:33 +11:00
|
|
|
let mut counter = 0;
|
|
|
|
// Wake up the `event_loop` once every second.
|
2017-05-25 02:29:51 +10:00
|
|
|
loop {
|
|
|
|
std::thread::sleep(std::time::Duration::from_secs(1));
|
2019-02-06 02:30:33 +11:00
|
|
|
proxy.send_event(counter).unwrap();
|
|
|
|
counter += 1;
|
2017-05-25 02:29:51 +10:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-02-06 02:30:33 +11:00
|
|
|
event_loop.run(move |event, _, control_flow| {
|
2017-05-25 02:29:51 +10:00
|
|
|
println!("{:?}", event);
|
|
|
|
match event {
|
2019-06-22 01:33:15 +10:00
|
|
|
Event::WindowEvent {
|
|
|
|
event: WindowEvent::CloseRequested,
|
|
|
|
..
|
|
|
|
} => *control_flow = ControlFlow::Exit,
|
2019-02-06 02:30:33 +11:00
|
|
|
_ => *control_flow = ControlFlow::Wait,
|
2017-05-25 02:29:51 +10:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|