2019-07-11 08:54:54 +10:00
|
|
|
use instant::Instant;
|
|
|
|
use std::time::Duration;
|
2020-09-10 11:58:30 +10:00
|
|
|
|
|
|
|
use simple_logger::SimpleLogger;
|
2019-06-22 01:33:15 +10:00
|
|
|
use winit::{
|
|
|
|
event::{Event, StartCause, WindowEvent},
|
|
|
|
event_loop::{ControlFlow, EventLoop},
|
|
|
|
window::WindowBuilder,
|
|
|
|
};
|
2019-02-06 02:30:33 +11: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();
|
|
|
|
|
|
|
|
let _window = WindowBuilder::new()
|
|
|
|
.with_title("A fantastic window!")
|
|
|
|
.build(&event_loop)
|
|
|
|
.unwrap();
|
|
|
|
|
2019-06-20 12:06:09 +10:00
|
|
|
let timer_length = Duration::new(1, 0);
|
|
|
|
|
2019-02-06 02:30:33 +11:00
|
|
|
event_loop.run(move |event, _, control_flow| {
|
2019-11-23 11:11:04 +11:00
|
|
|
println!("{:?}", event);
|
2019-02-06 02:30:33 +11:00
|
|
|
|
|
|
|
match event {
|
2019-06-22 01:33:15 +10:00
|
|
|
Event::NewEvents(StartCause::Init) => {
|
|
|
|
*control_flow = ControlFlow::WaitUntil(Instant::now() + timer_length)
|
2019-06-25 02:14:55 +10:00
|
|
|
}
|
2019-06-22 01:33:15 +10:00
|
|
|
Event::NewEvents(StartCause::ResumeTimeReached { .. }) => {
|
2019-06-20 12:06:09 +10:00
|
|
|
*control_flow = ControlFlow::WaitUntil(Instant::now() + timer_length);
|
2019-02-06 02:30:33 +11:00
|
|
|
println!("\nTimer\n");
|
2019-06-25 02:14:55 +10:00
|
|
|
}
|
2019-02-06 02:30:33 +11:00
|
|
|
Event::WindowEvent {
|
|
|
|
event: WindowEvent::CloseRequested,
|
|
|
|
..
|
|
|
|
} => *control_flow = ControlFlow::Exit,
|
2019-06-22 01:33:15 +10:00
|
|
|
_ => (),
|
2019-02-06 02:30:33 +11:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|