From 007b195a5ec4228daf4512f723c050eac7314fa6 Mon Sep 17 00:00:00 2001 From: Francesca Lovebloom Date: Mon, 4 May 2020 15:55:58 -0700 Subject: [PATCH] iOS: convert touch positions to physical (#1551) --- CHANGELOG.md | 1 + src/platform_impl/ios/view.rs | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9259fd5..d9c79649 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - On Windows, fix window intermittently hanging when `ControlFlow` was set to `Poll`. - On Windows, fix `WindowBuilder::with_maximized` being ignored. +- On iOS, touch positions are now properly converted to physical pixels. # 0.22.1 (2020-04-16) diff --git a/src/platform_impl/ios/view.rs b/src/platform_impl/ios/view.rs index 77f3fc59..5481b8ef 100644 --- a/src/platform_impl/ios/view.rs +++ b/src/platform_impl/ios/view.rs @@ -6,6 +6,7 @@ use objc::{ }; use crate::{ + dpi::PhysicalPosition, event::{DeviceId as RootDeviceId, Event, Force, Touch, TouchPhase, WindowEvent}, platform::ios::MonitorHandleExtIOS, platform_impl::platform::{ @@ -209,7 +210,7 @@ unsafe fn get_view_class(root_view_class: &'static Class) -> &'static Class { if touch == nil { break; } - let location: CGPoint = msg_send![touch, locationInView: nil]; + let logical_location: CGPoint = msg_send![touch, locationInView: nil]; let touch_type: UITouchType = msg_send![touch, type]; let force = if os_supports_force { let trait_collection: id = msg_send![object, traitCollection]; @@ -248,12 +249,19 @@ unsafe fn get_view_class(root_view_class: &'static Class) -> &'static Class { _ => panic!("unexpected touch phase: {:?}", phase as i32), }; + let physical_location = { + let scale_factor: CGFloat = msg_send![object, contentScaleFactor]; + PhysicalPosition::from_logical::<(f64, f64), f64>( + (logical_location.x as _, logical_location.y as _), + scale_factor, + ) + }; touch_events.push(EventWrapper::StaticEvent(Event::WindowEvent { window_id: RootWindowId(window.into()), event: WindowEvent::Touch(Touch { device_id: RootDeviceId(DeviceId { uiscreen }), id: touch_id, - location: (location.x as f64, location.y as f64).into(), + location: physical_location, force, phase, }),