|
1 | 1 | use std::marker::PhantomData; |
2 | 2 |
|
3 | 3 | use crate::input::{ |
4 | | - Axis, ButtonState, EdgeFlags, KeyAction, Keycode, MetaState, MotionAction, MotionEventFlags, |
5 | | - Pointer, PointersIter, Source, ToolType, |
| 4 | + Axis, Button, ButtonState, EdgeFlags, KeyAction, Keycode, MetaState, MotionAction, |
| 5 | + MotionEventFlags, Pointer, PointersIter, Source, ToolType, |
6 | 6 | }; |
7 | 7 |
|
8 | 8 | /// A motion event |
@@ -54,10 +54,24 @@ impl<'a> MotionEvent<'a> { |
54 | 54 | // XXX: we use `AMotionEvent_getAction` directly since we have our own |
55 | 55 | // `MotionAction` enum that we share between backends, which may also |
56 | 56 | // capture unknown variants added in new versions of Android. |
57 | | - let action = unsafe { ndk_sys::AMotionEvent_getAction(self.ndk_event.ptr().as_ptr()) as u32 }; |
| 57 | + let action = |
| 58 | + unsafe { ndk_sys::AMotionEvent_getAction(self.ndk_event.ptr().as_ptr()) as u32 }; |
58 | 59 | action.into() |
59 | 60 | } |
60 | 61 |
|
| 62 | + /// Returns which button has been modified during a press or release action. |
| 63 | + /// |
| 64 | + /// For actions other than [`MotionAction::ButtonPress`] and |
| 65 | + /// [`MotionAction::ButtonRelease`] the returned value is undefined. |
| 66 | + /// |
| 67 | + /// See [the MotionEvent docs](https://developer.android.com/reference/android/view/MotionEvent#getActionButton()) |
| 68 | + #[inline] |
| 69 | + pub fn action_button(&self) -> Button { |
| 70 | + let action_button = |
| 71 | + unsafe { ndk_sys::AMotionEvent_getActionButton(self.ndk_event.ptr().as_ptr()) as u32 }; |
| 72 | + action_button.into() |
| 73 | + } |
| 74 | + |
61 | 75 | /// Returns the pointer index of an `Up` or `Down` event. |
62 | 76 | /// |
63 | 77 | /// Pointer indices can change per motion event. For an identifier that stays the same, see |
|
0 commit comments