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