mirror of
https://github.com/rust-windowing/winit.git
synced 2026-09-01 14:20:05 -04:00
Deliver position of smart magnification event
This commit is contained in:
@@ -29,8 +29,8 @@ fn main() {
|
|||||||
println!("Zoomed out {}", delta);
|
println!("Zoomed out {}", delta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WindowEvent::TouchpadSmartMagnify { .. } => {
|
WindowEvent::TouchpadSmartMagnify { position, .. } => {
|
||||||
println!("Smart zoom");
|
println!("Smart zoom at {position:?}");
|
||||||
}
|
}
|
||||||
WindowEvent::TouchpadRotate { delta, .. } => {
|
WindowEvent::TouchpadRotate { delta, .. } => {
|
||||||
if delta > 0.0 {
|
if delta > 0.0 {
|
||||||
|
|||||||
19
src/event.rs
19
src/event.rs
@@ -449,7 +449,10 @@ pub enum WindowEvent<'a> {
|
|||||||
/// ## Platform-specific
|
/// ## Platform-specific
|
||||||
///
|
///
|
||||||
/// - Only available on **macOS**.
|
/// - Only available on **macOS**.
|
||||||
TouchpadSmartMagnify { device_id: DeviceId },
|
TouchpadSmartMagnify {
|
||||||
|
device_id: DeviceId,
|
||||||
|
position: PhysicalPosition<f64>,
|
||||||
|
},
|
||||||
|
|
||||||
/// Touchpad rotation event with two-finger rotation gesture.
|
/// Touchpad rotation event with two-finger rotation gesture.
|
||||||
///
|
///
|
||||||
@@ -597,8 +600,12 @@ impl Clone for WindowEvent<'static> {
|
|||||||
delta: *delta,
|
delta: *delta,
|
||||||
phase: *phase,
|
phase: *phase,
|
||||||
},
|
},
|
||||||
TouchpadSmartMagnify { device_id } => TouchpadSmartMagnify {
|
TouchpadSmartMagnify {
|
||||||
|
device_id,
|
||||||
|
position,
|
||||||
|
} => TouchpadSmartMagnify {
|
||||||
device_id: *device_id,
|
device_id: *device_id,
|
||||||
|
position: *position,
|
||||||
},
|
},
|
||||||
TouchpadRotate {
|
TouchpadRotate {
|
||||||
device_id,
|
device_id,
|
||||||
@@ -706,7 +713,13 @@ impl<'a> WindowEvent<'a> {
|
|||||||
delta,
|
delta,
|
||||||
phase,
|
phase,
|
||||||
}),
|
}),
|
||||||
TouchpadSmartMagnify { device_id } => Some(TouchpadSmartMagnify { device_id }),
|
TouchpadSmartMagnify {
|
||||||
|
device_id,
|
||||||
|
position,
|
||||||
|
} => Some(TouchpadSmartMagnify {
|
||||||
|
device_id,
|
||||||
|
position,
|
||||||
|
}),
|
||||||
TouchpadRotate {
|
TouchpadRotate {
|
||||||
device_id,
|
device_id,
|
||||||
delta,
|
delta,
|
||||||
|
|||||||
@@ -860,13 +860,22 @@ declare_class!(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[sel(smartMagnifyWithEvent:)]
|
#[sel(smartMagnifyWithEvent:)]
|
||||||
fn smart_magnify_with_event(&self, _event: &NSEvent) {
|
fn smart_magnify_with_event(&self, event: &NSEvent) {
|
||||||
trace_scope!("smartMagnifyWithEvent:");
|
trace_scope!("smartMagnifyWithEvent:");
|
||||||
|
|
||||||
|
let window_point = event.locationInWindow();
|
||||||
|
let view_point = self.convertPoint_fromView(window_point, None);
|
||||||
|
let view_rect = self.frame();
|
||||||
|
|
||||||
|
let x = view_point.x as f64;
|
||||||
|
let y = view_rect.size.height as f64 - view_point.y as f64;
|
||||||
|
let logical_position = LogicalPosition::new(x, y);
|
||||||
|
|
||||||
let window_event = Event::WindowEvent {
|
let window_event = Event::WindowEvent {
|
||||||
window_id: self.window_id(),
|
window_id: self.window_id(),
|
||||||
event: WindowEvent::TouchpadSmartMagnify {
|
event: WindowEvent::TouchpadSmartMagnify {
|
||||||
device_id: DEVICE_ID,
|
device_id: DEVICE_ID,
|
||||||
|
position: logical_position.to_physical(self.scale_factor()),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user