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
14 use simple_logger::SimpleLogger;
15 use winit::{
16 event::{Event, WindowEvent},
17 event_loop::{ControlFlow, EventLoop},
18 platform::run_return::EventLoopExtRunReturn,
19 window::WindowBuilder,
20 };
21 let mut event_loop = EventLoop::new();
22
23 SimpleLogger::new().init().unwrap();
24 let _window = WindowBuilder::new()
25 .with_title("A fantastic window!")
26 .build(&event_loop)
27 .unwrap();
28
29 let mut quit = false;
30
31 while !quit {
32 event_loop.run_return(|event, _, control_flow| {
33 *control_flow = ControlFlow::Wait;
34
35 if let Event::WindowEvent { event, .. } = &event {
36 // Print only Window events to reduce noise
37 println!("{:?}", event);
38 }
39
40 match event {
41 Event::WindowEvent {
42 event: WindowEvent::CloseRequested,
43 ..
44 } => {
45 quit = true;
46 }
47 Event::MainEventsCleared => {
48 *control_flow = ControlFlow::Exit;
49 }
50 _ => (),
51 }
52 });
53
54 // Sleep for 1/60 second to simulate rendering
55 println!("rendering");
56 sleep(Duration::from_millis(16));
57 }
58 }
59
60 #[cfg(any(target_os = "ios", target_os = "android", target_arch = "wasm32"))]
main()61 fn main() {
62 println!("This platform doesn't support run_return.");
63 }
64