mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-26 22:53:15 -04:00
Add smart magnification gesture
This commit is contained in:
@@ -29,6 +29,9 @@ fn main() {
|
||||
println!("Zoomed out {}", delta);
|
||||
}
|
||||
}
|
||||
WindowEvent::TouchpadSmartMagnify { .. } => {
|
||||
println!("Smart zoom");
|
||||
}
|
||||
WindowEvent::TouchpadRotate { delta, .. } => {
|
||||
if delta > 0.0 {
|
||||
println!("Rotated counterclockwise {}", delta);
|
||||
|
||||
11
src/event.rs
11
src/event.rs
@@ -444,6 +444,13 @@ pub enum WindowEvent<'a> {
|
||||
phase: TouchPhase,
|
||||
},
|
||||
|
||||
/// Touchpad smart magnification event.
|
||||
///
|
||||
/// ## Platform-specific
|
||||
///
|
||||
/// - Only available on **macOS**.
|
||||
TouchpadSmartMagnify { device_id: DeviceId },
|
||||
|
||||
/// Touchpad rotation event with two-finger rotation gesture.
|
||||
///
|
||||
/// Positive delta values indicate rotation counterclockwise and
|
||||
@@ -590,6 +597,9 @@ impl Clone for WindowEvent<'static> {
|
||||
delta: *delta,
|
||||
phase: *phase,
|
||||
},
|
||||
TouchpadSmartMagnify { device_id } => TouchpadSmartMagnify {
|
||||
device_id: *device_id,
|
||||
},
|
||||
TouchpadRotate {
|
||||
device_id,
|
||||
delta,
|
||||
@@ -696,6 +706,7 @@ impl<'a> WindowEvent<'a> {
|
||||
delta,
|
||||
phase,
|
||||
}),
|
||||
TouchpadSmartMagnify { device_id } => Some(TouchpadSmartMagnify { device_id }),
|
||||
TouchpadRotate {
|
||||
device_id,
|
||||
delta,
|
||||
|
||||
@@ -859,6 +859,20 @@ declare_class!(
|
||||
AppState::queue_event(EventWrapper::StaticEvent(window_event));
|
||||
}
|
||||
|
||||
#[sel(smartMagnifyWithEvent:)]
|
||||
fn smart_magnify_with_event(&self, _event: &NSEvent) {
|
||||
trace_scope!("smartMagnifyWithEvent:");
|
||||
|
||||
let window_event = Event::WindowEvent {
|
||||
window_id: self.window_id(),
|
||||
event: WindowEvent::TouchpadSmartMagnify {
|
||||
device_id: DEVICE_ID,
|
||||
},
|
||||
};
|
||||
|
||||
AppState::queue_event(EventWrapper::StaticEvent(window_event));
|
||||
}
|
||||
|
||||
#[sel(rotateWithEvent:)]
|
||||
fn rotate_with_event(&self, event: &NSEvent) {
|
||||
trace_scope!("rotateWithEvent:");
|
||||
|
||||
Reference in New Issue
Block a user