2019-07-25 14:56:24 -04:00
|
|
|
// Limit this example to only compatible platforms.
|
|
|
|
#[cfg(any(
|
|
|
|
target_os = "windows",
|
|
|
|
target_os = "macos",
|
|
|
|
target_os = "linux",
|
|
|
|
target_os = "dragonfly",
|
|
|
|
target_os = "freebsd",
|
|
|
|
target_os = "netbsd",
|
|
|
|
target_os = "openbsd"
|
|
|
|
))]
|
2019-02-05 10:30:33 -05:00
|
|
|
fn main() {
|
2019-11-10 11:24:43 -07:00
|
|
|
use std::{thread::sleep, time::Duration};
|
2020-09-09 17:58:30 -08:00
|
|
|
|
|
|
|
use simple_logger::SimpleLogger;
|
2019-07-11 00:54:54 +02:00
|
|
|
use winit::{
|
|
|
|
event::{Event, WindowEvent},
|
|
|
|
event_loop::{ControlFlow, EventLoop},
|
2020-11-12 20:49:44 +01:00
|
|
|
platform::run_return::EventLoopExtRunReturn,
|
2019-07-11 00:54:54 +02:00
|
|
|
window::WindowBuilder,
|
|
|
|
};
|
2019-02-05 10:30:33 -05:00
|
|
|
let mut event_loop = EventLoop::new();
|
|
|
|
|
2020-09-09 17:58:30 -08:00
|
|
|
SimpleLogger::new().init().unwrap();
|
2019-11-10 11:24:43 -07:00
|
|
|
let _window = WindowBuilder::new()
|
2019-02-05 10:30:33 -05:00
|
|
|
.with_title("A fantastic window!")
|
|
|
|
.build(&event_loop)
|
|
|
|
.unwrap();
|
|
|
|
|
2019-11-10 11:24:43 -07:00
|
|
|
let mut quit = false;
|
2019-02-05 10:30:33 -05:00
|
|
|
|
2019-11-10 11:24:43 -07:00
|
|
|
while !quit {
|
|
|
|
event_loop.run_return(|event, _, control_flow| {
|
2020-01-07 20:55:18 -07:00
|
|
|
*control_flow = ControlFlow::Wait;
|
|
|
|
|
2019-11-10 11:24:43 -07:00
|
|
|
if let Event::WindowEvent { event, .. } = &event {
|
|
|
|
// Print only Window events to reduce noise
|
|
|
|
println!("{:?}", event);
|
|
|
|
}
|
2019-02-05 10:30:33 -05:00
|
|
|
|
2019-11-10 11:24:43 -07:00
|
|
|
match event {
|
|
|
|
Event::WindowEvent {
|
|
|
|
event: WindowEvent::CloseRequested,
|
|
|
|
..
|
|
|
|
} => {
|
|
|
|
quit = true;
|
|
|
|
}
|
2019-12-22 00:47:39 -05:00
|
|
|
Event::MainEventsCleared => {
|
2019-11-10 11:24:43 -07:00
|
|
|
*control_flow = ControlFlow::Exit;
|
|
|
|
}
|
2020-01-07 20:55:18 -07:00
|
|
|
_ => (),
|
2019-11-10 11:24:43 -07:00
|
|
|
}
|
|
|
|
});
|
2019-02-05 10:30:33 -05:00
|
|
|
|
2019-11-10 11:24:43 -07:00
|
|
|
// Sleep for 1/60 second to simulate rendering
|
2020-01-05 02:12:03 -05:00
|
|
|
println!("rendering");
|
2019-11-10 11:24:43 -07:00
|
|
|
sleep(Duration::from_millis(16));
|
|
|
|
}
|
2019-02-05 10:30:33 -05:00
|
|
|
}
|
2019-07-11 00:54:54 +02:00
|
|
|
|
2019-09-24 19:44:43 -04:00
|
|
|
#[cfg(any(target_os = "ios", target_os = "android", target_arch = "wasm32"))]
|
2019-07-25 14:56:24 -04:00
|
|
|
fn main() {
|
|
|
|
println!("This platform doesn't support run_return.");
|
2019-07-11 00:54:54 +02:00
|
|
|
}
|