mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-25 14:51:30 +11:00
6a330a2894
* Fix bug causing RedrawRequested events to only get emitted every other iteration of the event loop. * Initialize simple_logger in examples. This PR's primary bug was discovered because a friend of mine reported that winit was emitting concerning log messages, which I'd never seen since none of the examples print out the log messages. This addresses that, to hopefully reduce the chance of bugs going unnoticed in the future. * Add changelog entry * Format
60 lines
1.7 KiB
Rust
60 lines
1.7 KiB
Rust
// 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"
|
|
))]
|
|
fn main() {
|
|
use std::{thread::sleep, time::Duration};
|
|
use winit::{
|
|
event::{Event, WindowEvent},
|
|
event_loop::{ControlFlow, EventLoop},
|
|
platform::desktop::EventLoopExtDesktop,
|
|
window::WindowBuilder,
|
|
};
|
|
let mut event_loop = EventLoop::new();
|
|
|
|
simple_logger::init().unwrap();
|
|
let _window = WindowBuilder::new()
|
|
.with_title("A fantastic window!")
|
|
.build(&event_loop)
|
|
.unwrap();
|
|
|
|
let mut quit = false;
|
|
|
|
while !quit {
|
|
event_loop.run_return(|event, _, control_flow| {
|
|
if let Event::WindowEvent { event, .. } = &event {
|
|
// Print only Window events to reduce noise
|
|
println!("{:?}", event);
|
|
}
|
|
|
|
match event {
|
|
Event::WindowEvent {
|
|
event: WindowEvent::CloseRequested,
|
|
..
|
|
} => {
|
|
quit = true;
|
|
}
|
|
Event::MainEventsCleared => {
|
|
*control_flow = ControlFlow::Exit;
|
|
}
|
|
_ => *control_flow = ControlFlow::Wait,
|
|
}
|
|
});
|
|
|
|
// Sleep for 1/60 second to simulate rendering
|
|
println!("rendering");
|
|
sleep(Duration::from_millis(16));
|
|
}
|
|
}
|
|
|
|
#[cfg(any(target_os = "ios", target_os = "android", target_arch = "wasm32"))]
|
|
fn main() {
|
|
println!("This platform doesn't support run_return.");
|
|
}
|