2023-06-18 22:50:13 +10:00
|
|
|
#![allow(clippy::single_match)]
|
|
|
|
|
|
|
|
// Limit this example to only compatible platforms.
|
|
|
|
#[cfg(any(
|
|
|
|
windows_platform,
|
|
|
|
macos_platform,
|
|
|
|
x11_platform,
|
|
|
|
wayland_platform,
|
|
|
|
android_platform,
|
|
|
|
))]
|
|
|
|
fn main() -> std::process::ExitCode {
|
|
|
|
use std::{process::ExitCode, thread::sleep, time::Duration};
|
|
|
|
|
|
|
|
use simple_logger::SimpleLogger;
|
|
|
|
use winit::{
|
|
|
|
event::{Event, WindowEvent},
|
2023-07-24 09:37:51 +10:00
|
|
|
event_loop::{ControlFlow, EventLoop},
|
2023-06-18 22:50:13 +10:00
|
|
|
platform::pump_events::{EventLoopExtPumpEvents, PumpStatus},
|
|
|
|
window::WindowBuilder,
|
|
|
|
};
|
|
|
|
|
|
|
|
#[path = "util/fill.rs"]
|
|
|
|
mod fill;
|
|
|
|
|
2023-08-14 05:20:09 +10:00
|
|
|
let mut event_loop = EventLoop::new().unwrap();
|
2023-06-18 22:50:13 +10:00
|
|
|
|
|
|
|
SimpleLogger::new().init().unwrap();
|
|
|
|
let window = WindowBuilder::new()
|
|
|
|
.with_title("A fantastic window!")
|
|
|
|
.build(&event_loop)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
'main: loop {
|
2023-07-24 09:37:51 +10:00
|
|
|
let timeout = Some(Duration::ZERO);
|
|
|
|
let status = event_loop.pump_events(timeout, |event, _, control_flow| {
|
|
|
|
*control_flow = ControlFlow::Wait;
|
|
|
|
|
2023-06-18 22:50:13 +10:00
|
|
|
if let Event::WindowEvent { event, .. } = &event {
|
|
|
|
// Print only Window events to reduce noise
|
|
|
|
println!("{event:?}");
|
|
|
|
}
|
|
|
|
|
|
|
|
match event {
|
|
|
|
Event::WindowEvent {
|
|
|
|
event: WindowEvent::CloseRequested,
|
|
|
|
window_id,
|
|
|
|
} if window_id == window.id() => control_flow.set_exit(),
|
2023-07-29 02:37:56 +10:00
|
|
|
Event::AboutToWait => {
|
2023-06-18 22:50:13 +10:00
|
|
|
window.request_redraw();
|
|
|
|
}
|
2023-08-28 00:15:09 +10:00
|
|
|
Event::WindowEvent {
|
|
|
|
event: WindowEvent::RedrawRequested,
|
|
|
|
..
|
|
|
|
} => {
|
2023-06-18 22:50:13 +10:00
|
|
|
fill::fill_window(&window);
|
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if let PumpStatus::Exit(exit_code) = status {
|
|
|
|
break 'main ExitCode::from(exit_code as u8);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sleep for 1/60 second to simulate application work
|
|
|
|
//
|
|
|
|
// Since `pump_events` doesn't block it will be important to
|
|
|
|
// throttle the loop in the app somehow.
|
|
|
|
println!("Update()");
|
|
|
|
sleep(Duration::from_millis(16));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(any(ios_platform, wasm_platform, orbital_platform))]
|
|
|
|
fn main() {
|
|
|
|
println!("This platform doesn't support pump_events.");
|
|
|
|
}
|