mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-25 06:41:31 +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
46 lines
1.4 KiB
Rust
46 lines
1.4 KiB
Rust
use winit::{
|
|
dpi::LogicalSize,
|
|
event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
|
|
event_loop::{ControlFlow, EventLoop},
|
|
window::WindowBuilder,
|
|
};
|
|
|
|
fn main() {
|
|
simple_logger::init().unwrap();
|
|
let event_loop = EventLoop::new();
|
|
|
|
let mut resizable = false;
|
|
|
|
let window = WindowBuilder::new()
|
|
.with_title("Hit space to toggle resizability.")
|
|
.with_inner_size(LogicalSize::new(400.0, 200.0))
|
|
.with_resizable(resizable)
|
|
.build(&event_loop)
|
|
.unwrap();
|
|
|
|
event_loop.run(move |event, _, control_flow| {
|
|
*control_flow = ControlFlow::Wait;
|
|
|
|
match event {
|
|
Event::WindowEvent { event, .. } => match event {
|
|
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
|
WindowEvent::KeyboardInput {
|
|
input:
|
|
KeyboardInput {
|
|
virtual_keycode: Some(VirtualKeyCode::Space),
|
|
state: ElementState::Released,
|
|
..
|
|
},
|
|
..
|
|
} => {
|
|
resizable = !resizable;
|
|
println!("Resizable: {}", resizable);
|
|
window.set_resizable(resizable);
|
|
}
|
|
_ => (),
|
|
},
|
|
_ => (),
|
|
};
|
|
});
|
|
}
|