Commit a0b2bb3 1 parent 02f922f commit a0b2bb3 Copy full SHA for a0b2bb3
File tree 2 files changed +34
-0
lines changed
2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ extern crate winit;
2
+ use std:: time:: { Duration , Instant } ;
3
+
4
+ fn main ( ) {
5
+ let events_loop = winit:: EventLoop :: new ( ) ;
6
+
7
+ let _window = winit:: WindowBuilder :: new ( )
8
+ . with_title ( "A fantastic window!" )
9
+ . build ( & events_loop)
10
+ . unwrap ( ) ;
11
+
12
+ events_loop. run ( move |event, _, control_flow| {
13
+ println ! ( "{:?}" , event) ;
14
+
15
+ match event {
16
+ winit:: Event :: NewEvents ( winit:: StartCause :: Init ) =>
17
+ * control_flow = winit:: ControlFlow :: WaitTimeout ( Duration :: new ( 1 , 0 ) ) ,
18
+ winit:: Event :: NewEvents ( winit:: StartCause :: TimeoutExpired { ..} ) => {
19
+ * control_flow = winit:: ControlFlow :: WaitTimeout ( Duration :: new ( 1 , 0 ) ) ;
20
+ println ! ( "\n Timer\n " ) ;
21
+ } ,
22
+ winit:: Event :: NewEvents ( winit:: StartCause :: WaitCancelled { start, requested_duration} ) => {
23
+ println ! ( "{:?}" , Instant :: now( ) - start) ;
24
+ * control_flow = winit:: ControlFlow :: WaitTimeout ( requested_duration. unwrap ( ) . checked_sub ( Instant :: now ( ) - start) . unwrap_or ( Duration :: new ( 0 , 0 ) ) ) ;
25
+ }
26
+ winit:: Event :: WindowEvent {
27
+ event : winit:: WindowEvent :: CloseRequested ,
28
+ ..
29
+ } => * control_flow = winit:: ControlFlow :: Exit ,
30
+ _ => ( )
31
+ }
32
+ } ) ;
33
+ }
Original file line number Diff line number Diff line change @@ -172,6 +172,7 @@ impl EventLoop {
172
172
173
173
let mut msg = mem:: uninitialized ( ) ;
174
174
175
+ event_handler ( Event :: NewEvents ( StartCause :: Init ) , & event_loop, & mut control_flow) ;
175
176
' main: loop {
176
177
macro_rules! call_event_handler {
177
178
( $event: expr) => { {
You can’t perform that action at this time.
0 commit comments