Support pinch, double tap and rotation gestures on iOS (#3130)
This is off by default on iOS. Note that pinch delta may be NaN. Co-authored-by: Mads Marquart <mads@marquart.dk>
This commit is contained in:
parent
30775f4982
commit
6b29253797
10 changed files with 362 additions and 34 deletions
121
src/platform_impl/ios/uikit/gesture_recognizer.rs
Normal file
121
src/platform_impl/ios/uikit/gesture_recognizer.rs
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
use icrate::Foundation::{CGFloat, NSInteger, NSObject, NSUInteger};
|
||||
use objc2::{
|
||||
encode::{Encode, Encoding},
|
||||
extern_class, extern_methods, mutability, ClassType,
|
||||
};
|
||||
|
||||
// https://developer.apple.com/documentation/uikit/uigesturerecognizer
|
||||
extern_class!(
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
pub(crate) struct UIGestureRecognizer;
|
||||
|
||||
unsafe impl ClassType for UIGestureRecognizer {
|
||||
type Super = NSObject;
|
||||
type Mutability = mutability::InteriorMutable;
|
||||
}
|
||||
);
|
||||
|
||||
extern_methods!(
|
||||
unsafe impl UIGestureRecognizer {
|
||||
#[method(state)]
|
||||
pub fn state(&self) -> UIGestureRecognizerState;
|
||||
}
|
||||
);
|
||||
|
||||
unsafe impl Encode for UIGestureRecognizer {
|
||||
const ENCODING: Encoding = Encoding::Object;
|
||||
}
|
||||
|
||||
// https://developer.apple.com/documentation/uikit/uigesturerecognizer/state
|
||||
#[repr(transparent)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct UIGestureRecognizerState(NSInteger);
|
||||
|
||||
unsafe impl Encode for UIGestureRecognizerState {
|
||||
const ENCODING: Encoding = NSInteger::ENCODING;
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl UIGestureRecognizerState {
|
||||
pub const Possible: Self = Self(0);
|
||||
pub const Began: Self = Self(1);
|
||||
pub const Changed: Self = Self(2);
|
||||
pub const Ended: Self = Self(3);
|
||||
pub const Cancelled: Self = Self(4);
|
||||
pub const Failed: Self = Self(5);
|
||||
}
|
||||
|
||||
// https://developer.apple.com/documentation/uikit/uipinchgesturerecognizer
|
||||
extern_class!(
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
pub(crate) struct UIPinchGestureRecognizer;
|
||||
|
||||
unsafe impl ClassType for UIPinchGestureRecognizer {
|
||||
type Super = UIGestureRecognizer;
|
||||
type Mutability = mutability::InteriorMutable;
|
||||
}
|
||||
);
|
||||
|
||||
extern_methods!(
|
||||
unsafe impl UIPinchGestureRecognizer {
|
||||
#[method(scale)]
|
||||
pub fn scale(&self) -> CGFloat;
|
||||
|
||||
#[method(velocity)]
|
||||
pub fn velocity(&self) -> CGFloat;
|
||||
}
|
||||
);
|
||||
|
||||
unsafe impl Encode for UIPinchGestureRecognizer {
|
||||
const ENCODING: Encoding = Encoding::Object;
|
||||
}
|
||||
|
||||
// https://developer.apple.com/documentation/uikit/uirotationgesturerecognizer
|
||||
extern_class!(
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
pub(crate) struct UIRotationGestureRecognizer;
|
||||
|
||||
unsafe impl ClassType for UIRotationGestureRecognizer {
|
||||
type Super = UIGestureRecognizer;
|
||||
type Mutability = mutability::InteriorMutable;
|
||||
}
|
||||
);
|
||||
|
||||
extern_methods!(
|
||||
unsafe impl UIRotationGestureRecognizer {
|
||||
#[method(rotation)]
|
||||
pub fn rotation(&self) -> CGFloat;
|
||||
|
||||
#[method(velocity)]
|
||||
pub fn velocity(&self) -> CGFloat;
|
||||
}
|
||||
);
|
||||
|
||||
unsafe impl Encode for UIRotationGestureRecognizer {
|
||||
const ENCODING: Encoding = Encoding::Object;
|
||||
}
|
||||
|
||||
// https://developer.apple.com/documentation/uikit/uitapgesturerecognizer
|
||||
extern_class!(
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
pub(crate) struct UITapGestureRecognizer;
|
||||
|
||||
unsafe impl ClassType for UITapGestureRecognizer {
|
||||
type Super = UIGestureRecognizer;
|
||||
type Mutability = mutability::InteriorMutable;
|
||||
}
|
||||
);
|
||||
|
||||
extern_methods!(
|
||||
unsafe impl UITapGestureRecognizer {
|
||||
#[method(setNumberOfTapsRequired:)]
|
||||
pub fn setNumberOfTapsRequired(&self, number_of_taps_required: NSUInteger);
|
||||
|
||||
#[method(setNumberOfTouchesRequired:)]
|
||||
pub fn setNumberOfTouchesRequired(&self, number_of_touches_required: NSUInteger);
|
||||
}
|
||||
);
|
||||
|
||||
unsafe impl Encode for UITapGestureRecognizer {
|
||||
const ENCODING: Encoding = Encoding::Object;
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ mod application;
|
|||
mod coordinate_space;
|
||||
mod device;
|
||||
mod event;
|
||||
mod gesture_recognizer;
|
||||
mod responder;
|
||||
mod screen;
|
||||
mod screen_mode;
|
||||
|
|
@ -23,6 +24,10 @@ pub(crate) use self::application::UIApplication;
|
|||
pub(crate) use self::coordinate_space::UICoordinateSpace;
|
||||
pub(crate) use self::device::UIDevice;
|
||||
pub(crate) use self::event::UIEvent;
|
||||
pub(crate) use self::gesture_recognizer::{
|
||||
UIGestureRecognizer, UIGestureRecognizerState, UIPinchGestureRecognizer,
|
||||
UIRotationGestureRecognizer, UITapGestureRecognizer,
|
||||
};
|
||||
pub(crate) use self::responder::UIResponder;
|
||||
pub(crate) use self::screen::{UIScreen, UIScreenOverscanCompensation};
|
||||
pub(crate) use self::screen_mode::UIScreenMode;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use objc2::encode::{Encode, Encoding};
|
|||
use objc2::rc::Id;
|
||||
use objc2::{extern_class, extern_methods, msg_send_id, mutability, ClassType};
|
||||
|
||||
use super::{UICoordinateSpace, UIResponder, UIViewController};
|
||||
use super::{UICoordinateSpace, UIGestureRecognizer, UIResponder, UIViewController};
|
||||
|
||||
extern_class!(
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
|
|
@ -65,6 +65,12 @@ extern_methods!(
|
|||
|
||||
#[method(setNeedsDisplay)]
|
||||
pub fn setNeedsDisplay(&self);
|
||||
|
||||
#[method(addGestureRecognizer:)]
|
||||
pub fn addGestureRecognizer(&self, gestureRecognizer: &UIGestureRecognizer);
|
||||
|
||||
#[method(removeGestureRecognizer:)]
|
||||
pub fn removeGestureRecognizer(&self, gestureRecognizer: &UIGestureRecognizer);
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue