iOS: convert touch positions to physical (#1551)

This commit is contained in:
Francesca Lovebloom 2020-05-04 15:55:58 -07:00 committed by GitHub
parent b4c6cdf9a3
commit 007b195a5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View file

@ -2,6 +2,7 @@
- On Windows, fix window intermittently hanging when `ControlFlow` was set to `Poll`. - On Windows, fix window intermittently hanging when `ControlFlow` was set to `Poll`.
- On Windows, fix `WindowBuilder::with_maximized` being ignored. - 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) # 0.22.1 (2020-04-16)

View file

@ -6,6 +6,7 @@ use objc::{
}; };
use crate::{ use crate::{
dpi::PhysicalPosition,
event::{DeviceId as RootDeviceId, Event, Force, Touch, TouchPhase, WindowEvent}, event::{DeviceId as RootDeviceId, Event, Force, Touch, TouchPhase, WindowEvent},
platform::ios::MonitorHandleExtIOS, platform::ios::MonitorHandleExtIOS,
platform_impl::platform::{ platform_impl::platform::{
@ -209,7 +210,7 @@ unsafe fn get_view_class(root_view_class: &'static Class) -> &'static Class {
if touch == nil { if touch == nil {
break; 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 touch_type: UITouchType = msg_send![touch, type];
let force = if os_supports_force { let force = if os_supports_force {
let trait_collection: id = msg_send![object, traitCollection]; 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), _ => 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 { touch_events.push(EventWrapper::StaticEvent(Event::WindowEvent {
window_id: RootWindowId(window.into()), window_id: RootWindowId(window.into()),
event: WindowEvent::Touch(Touch { event: WindowEvent::Touch(Touch {
device_id: RootDeviceId(DeviceId { uiscreen }), device_id: RootDeviceId(DeviceId { uiscreen }),
id: touch_id, id: touch_id,
location: (location.x as f64, location.y as f64).into(), location: physical_location,
force, force,
phase, phase,
}), }),