2022-06-10 20:43:33 +10:00
|
|
|
#![allow(clippy::single_match)]
|
|
|
|
|
2019-07-26 04:56:24 +10:00
|
|
|
// Limit this example to only compatible platforms.
|
|
|
|
#[cfg(any(
|
2022-12-25 18:57:27 +11:00
|
|
|
windows_platform,
|
|
|
|
macos_platform,
|
|
|
|
x11_platform,
|
|
|
|
wayland_platform,
|
2023-01-06 00:58:08 +11:00
|
|
|
android_platform,
|
|
|
|
orbital_platform,
|
2019-07-26 04:56:24 +10:00
|
|
|
))]
|
2019-02-06 02:30:33 +11:00
|
|
|
fn main() {
|
2019-11-11 05:24:43 +11:00
|
|
|
use std::{thread::sleep, time::Duration};
|
2020-09-10 11:58:30 +10:00
|
|
|
|
|
|
|
use simple_logger::SimpleLogger;
|
2019-07-11 08:54:54 +10:00
|
|
|
use winit::{
|
|
|
|
event::{Event, WindowEvent},
|
2022-04-10 11:32:02 +10:00
|
|
|
event_loop::EventLoop,
|
2020-11-13 06:49:44 +11:00
|
|
|
platform::run_return::EventLoopExtRunReturn,
|
2019-07-11 08:54:54 +10:00
|
|
|
window::WindowBuilder,
|
|
|
|
};
|
2019-02-06 02:30:33 +11:00
|
|
|
let mut event_loop = EventLoop::new();
|
|
|
|
|
2020-09-10 11:58:30 +10:00
|
|
|
SimpleLogger::new().init().unwrap();
|
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| {
|
2022-04-10 11:32:02 +10:00
|
|
|
control_flow.set_wait();
|
2020-01-08 14:55:18 +11:00
|
|
|
|
2019-11-11 05:24:43 +11:00
|
|
|
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;
|
|
|
|
}
|
2019-12-22 16:47:39 +11:00
|
|
|
Event::MainEventsCleared => {
|
2022-04-10 11:32:02 +10:00
|
|
|
control_flow.set_exit();
|
2019-11-11 05:24:43 +11:00
|
|
|
}
|
2020-01-08 14:55:18 +11:00
|
|
|
_ => (),
|
2019-11-11 05:24:43 +11:00
|
|
|
}
|
|
|
|
});
|
2019-02-06 02:30:33 +11:00
|
|
|
|
2019-11-11 05:24:43 +11:00
|
|
|
// Sleep for 1/60 second to simulate rendering
|
2020-01-05 18:12:03 +11:00
|
|
|
println!("rendering");
|
2019-11-11 05:24:43 +11:00
|
|
|
sleep(Duration::from_millis(16));
|
|
|
|
}
|
2019-02-06 02:30:33 +11:00
|
|
|
}
|
2019-07-11 08:54:54 +10:00
|
|
|
|
2022-12-25 18:57:27 +11:00
|
|
|
#[cfg(any(ios_platform, wasm_platform))]
|
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
|
|
|
}
|