1 // Limit this example to only compatible platforms.
2 #[cfg(any(
3     target_os = "windows",
4     target_os = "macos",
5     target_os = "linux",
6     target_os = "dragonfly",
7     target_os = "freebsd",
8     target_os = "netbsd",
9     target_os = "openbsd"
10 ))]
main()11 fn main() {
12     use std::{thread::sleep, time::Duration};
13     use winit::{
14         event::{Event, WindowEvent},
15         event_loop::{ControlFlow, EventLoop},
16         platform::desktop::EventLoopExtDesktop,
17         window::WindowBuilder,
18     };
19     let mut event_loop = EventLoop::new();
20 
21     simple_logger::init().unwrap();
22     let _window = WindowBuilder::new()
23         .with_title("A fantastic window!")
24         .build(&event_loop)
25         .unwrap();
26 
27     let mut quit = false;
28 
29     while !quit {
30         event_loop.run_return(|event, _, control_flow| {
31             *control_flow = ControlFlow::Wait;
32 
33             if let Event::WindowEvent { event, .. } = &event {
34                 // Print only Window events to reduce noise
35                 println!("{:?}", event);
36             }
37 
38             match event {
39                 Event::WindowEvent {
40                     event: WindowEvent::CloseRequested,
41                     ..
42                 } => {
43                     quit = true;
44                 }
45                 Event::MainEventsCleared => {
46                     *control_flow = ControlFlow::Exit;
47                 }
48                 _ => (),
49             }
50         });
51 
52         // Sleep for 1/60 second to simulate rendering
53         println!("rendering");
54         sleep(Duration::from_millis(16));
55     }
56 }
57 
58 #[cfg(any(target_os = "ios", target_os = "android", target_arch = "wasm32"))]
main()59 fn main() {
60     println!("This platform doesn't support run_return.");
61 }
62