2019-07-26 04:56:24 +10: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-06 02:30:33 +11:00
|
|
|
fn main() {
|
2019-11-11 05:24:43 +11:00
|
|
|
use std::{thread::sleep, time::Duration};
|
2019-07-11 08:54:54 +10:00
|
|
|
use winit::{
|
|
|
|
event::{Event, WindowEvent},
|
|
|
|
event_loop::{ControlFlow, EventLoop},
|
|
|
|
platform::desktop::EventLoopExtDesktop,
|
|
|
|
window::WindowBuilder,
|
|
|
|
};
|
2019-02-06 02:30:33 +11:00
|
|
|
let mut event_loop = EventLoop::new();
|
|
|
|
|
2019-11-11 05:24:43 +11:00
|
|
|
let _window = WindowBuilder::new()
|
2019-02-06 02:30:33 +11:00
|
|
|
.with_title("A fantastic window!")
|
|
|
|
.build(&event_loop)
|
|
|
|
.unwrap();
|
|
|
|
|
2019-11-11 05:24:43 +11:00
|
|
|
let mut quit = false;
|
2019-02-06 02:30:33 +11:00
|
|
|
|
2019-11-11 05:24:43 +11:00
|
|
|
while !quit {
|
|
|
|
event_loop.run_return(|event, _, control_flow| {
|
|
|
|
if let Event::WindowEvent { event, .. } = &event {
|
|
|
|
// Print only Window events to reduce noise
|
|
|
|
println!("{:?}", event);
|
|
|
|
}
|
2019-02-06 02:30:33 +11:00
|
|
|
|
2019-11-11 05:24:43 +11:00
|
|
|
match event {
|
|
|
|
Event::WindowEvent {
|
|
|
|
event: WindowEvent::CloseRequested,
|
|
|
|
..
|
|
|
|
} => {
|
|
|
|
quit = true;
|
|
|
|
*control_flow = ControlFlow::Exit;
|
|
|
|
}
|
|
|
|
Event::EventsCleared => {
|
|
|
|
*control_flow = ControlFlow::Exit;
|
|
|
|
}
|
|
|
|
_ => *control_flow = ControlFlow::Wait,
|
|
|
|
}
|
|
|
|
});
|
2019-02-06 02:30:33 +11:00
|
|
|
|
2019-11-11 05:24:43 +11:00
|
|
|
// Sleep for 1/60 second to simulate rendering
|
|
|
|
sleep(Duration::from_millis(16));
|
|
|
|
}
|
2019-02-06 02:30:33 +11:00
|
|
|
}
|
2019-07-11 08:54:54 +10:00
|
|
|
|
2019-09-25 09:44:43 +10:00
|
|
|
#[cfg(any(target_os = "ios", target_os = "android", target_arch = "wasm32"))]
|
2019-07-26 04:56:24 +10:00
|
|
|
fn main() {
|
|
|
|
println!("This platform doesn't support run_return.");
|
2019-07-11 08:54:54 +10:00
|
|
|
}
|