winit-sonoma-fix/examples/touchpad_gestures.rs
Jim Eckerlein d448d3e14f
Add smart magnify gesture support for macOS (#2554)
* Add smart magnification gesture

* Deliver position of smart magnification event

* Document smart magnification event

* Revert "Deliver position of smart magnification event"

This reverts commit ac0e61a9a4e67bf54fc80230660051d366846bd4.

* Remove mention of touchpad from smart magnification event

* Update change log

* Mention minimum macOS version supporting smart magnification

* Improve doc
2023-01-21 17:35:07 +01:00

47 lines
1.4 KiB
Rust

use simple_logger::SimpleLogger;
use winit::{
event::{Event, WindowEvent},
event_loop::{ControlFlow, EventLoop},
window::WindowBuilder,
};
fn main() {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();
let _window = WindowBuilder::new()
.with_title("Touchpad gestures")
.build(&event_loop)
.unwrap();
println!("Only supported on macOS at the moment.");
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;
if let Event::WindowEvent { event, .. } = event {
match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::TouchpadMagnify { delta, .. } => {
if delta > 0.0 {
println!("Zoomed in {}", delta);
} else {
println!("Zoomed out {}", delta);
}
}
WindowEvent::SmartMagnify { .. } => {
println!("Smart zoom");
}
WindowEvent::TouchpadRotate { delta, .. } => {
if delta > 0.0 {
println!("Rotated counterclockwise {}", delta);
} else {
println!("Rotated clockwise {}", delta);
}
}
_ => (),
}
}
});
}