From 8fb7aa5cef1c3bee28730dc771c7ddb16ba47c66 Mon Sep 17 00:00:00 2001 From: Marnix Kuijs <44985093+MarnixKuijs@users.noreply.github.com> Date: Wed, 2 Dec 2020 21:13:42 +0100 Subject: [PATCH] Android: Improved multi-touch (#1783) * Improved multi-touch * Update feature matrix * Generate cancelled events for all pointers * Changed back features matrix layout * Reduced code duplication * Updated changelog * Revert changelog update --- FEATURES.md | 2 +- src/platform_impl/android/mod.rs | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/FEATURES.md b/FEATURES.md index 1e77e9c5..dcd91ed3 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -202,7 +202,7 @@ Legend: |Cursor icon |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|✔️ | |Touch events |✔️ |❌ |✔️ |✔️ |✔️ |✔️ |❌ | |Touch pressure |✔️ |❌ |❌ |❌ |❌ |✔️ |❌ | -|Multitouch |✔️ |❌ |✔️ |✔️ |❓ |✔️ |❌ | +|Multitouch |✔️ |❌ |✔️ |✔️ |✔️ |✔️ |❌ | |Keyboard events |✔️ |✔️ |✔️ |✔️ |❓ |❌ |✔️ | |Drag & Drop |▢[#720] |▢[#720] |▢[#720] |❌[#306] |**N/A**|**N/A**|❓ | |Raw Device Events |▢[#750] |▢[#750] |▢[#750] |❌ |❌ |❌ |❓ | diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index ddd1eb96..b8df4515 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -193,14 +193,27 @@ impl EventLoop { } _ => None, // TODO mouse events }; - if let Some(phase) = phase { - for pointer in motion_event.pointers() { + let pointers: Box< + dyn Iterator>, + > = match phase { + event::TouchPhase::Started + | event::TouchPhase::Ended => Box::new( + std::iter::once(motion_event.pointer_at_index( + motion_event.pointer_index(), + )), + ), + event::TouchPhase::Moved + | event::TouchPhase::Cancelled => { + Box::new(motion_event.pointers()) + } + }; + + for pointer in pointers { let location = PhysicalPosition { x: pointer.x() as _, y: pointer.y() as _, }; - let event = event::Event::WindowEvent { window_id, event: event::WindowEvent::Touch(