From b07d223e2fecaaf9c768da456bb7c5e1638d7712 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Fri, 23 Aug 2024 10:23:05 +0200 Subject: [PATCH] Remove `TouchPhase` from Android touch handling --- src/platform_impl/android/mod.rs | 51 ++++++++++++++------------------ 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index 211a1a9eef..3309d79ceb 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -318,43 +318,37 @@ impl EventLoop { InputEvent::MotionEvent(motion_event) => { let window_id = window::WindowId(WindowId); let device_id = event::DeviceId(DeviceId(motion_event.device_id())); - - let phase = match motion_event.action() { - MotionAction::Down | MotionAction::PointerDown => { - Some(event::TouchPhase::Started) - }, - MotionAction::Up | MotionAction::PointerUp => Some(event::TouchPhase::Ended), - MotionAction::Move => Some(event::TouchPhase::Moved), - MotionAction::Cancel => Some(event::TouchPhase::Cancelled), - _ => { - None // TODO mouse events + let action = motion_event.action(); + + let pointers: Option< + Box>>, + > = match action { + MotionAction::Down + | MotionAction::PointerDown + | MotionAction::Up + | MotionAction::PointerUp => Some(Box::new(std::iter::once( + motion_event.pointer_at_index(motion_event.pointer_index()), + ))), + MotionAction::Move | MotionAction::Cancel => { + Some(Box::new(motion_event.pointers())) }, + // TODO mouse events + _ => None, }; - if let Some(phase) = phase { - let pointers: Box>> = - 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()) - }, - }; + if let Some(pointers) = pointers { for pointer in pointers { let position = PhysicalPosition { x: pointer.x() as _, y: pointer.y() as _ }; trace!( - "Input event {device_id:?}, {phase:?}, loc={position:?}, \ + "Input event {device_id:?}, {action:?}, loc={position:?}, \ pointer={pointer:?}" ); let finger_id = event::FingerId(FingerId(pointer.pointer_id())); let force = Some(Force::Normalized(pointer.pressure() as f64)); - match phase { - event::TouchPhase::Started => { + match action { + MotionAction::Down | MotionAction::PointerDown => { let event = event::WindowEvent::PointerEntered { device_id, position, @@ -369,7 +363,7 @@ impl EventLoop { }; app.window_event(&self.window_target, window_id, event); }, - event::TouchPhase::Moved => { + MotionAction::Move => { let event = event::WindowEvent::PointerMoved { device_id, position, @@ -377,8 +371,8 @@ impl EventLoop { }; app.window_event(&self.window_target, window_id, event); }, - event::TouchPhase::Ended | event::TouchPhase::Cancelled => { - if let event::TouchPhase::Ended = phase { + MotionAction::Up | MotionAction::PointerUp | MotionAction::Cancel => { + if let MotionAction::Up | MotionAction::PointerUp = action { let event = event::WindowEvent::PointerButton { device_id, state: event::ElementState::Released, @@ -395,6 +389,7 @@ impl EventLoop { }; app.window_event(&self.window_target, window_id, event); }, + _ => unreachable!(), } } }