objc2_ui_kit/generated/
UIEvent.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ptr::NonNull;
4use objc2::__framework_prelude::*;
5use objc2_foundation::*;
6
7use crate::*;
8
9/// [Apple's documentation](https://developer.apple.com/documentation/uikit/uieventtype?language=objc)
10// NS_ENUM
11#[repr(transparent)]
12#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
13pub struct UIEventType(pub NSInteger);
14impl UIEventType {
15    #[doc(alias = "UIEventTypeTouches")]
16    pub const Touches: Self = Self(0);
17    #[doc(alias = "UIEventTypeMotion")]
18    pub const Motion: Self = Self(1);
19    #[doc(alias = "UIEventTypeRemoteControl")]
20    pub const RemoteControl: Self = Self(2);
21    #[doc(alias = "UIEventTypePresses")]
22    pub const Presses: Self = Self(3);
23    #[doc(alias = "UIEventTypeScroll")]
24    pub const Scroll: Self = Self(10);
25    #[doc(alias = "UIEventTypeHover")]
26    pub const Hover: Self = Self(11);
27    #[doc(alias = "UIEventTypeTransform")]
28    pub const Transform: Self = Self(14);
29}
30
31unsafe impl Encode for UIEventType {
32    const ENCODING: Encoding = NSInteger::ENCODING;
33}
34
35unsafe impl RefEncode for UIEventType {
36    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
37}
38
39/// [Apple's documentation](https://developer.apple.com/documentation/uikit/uieventsubtype?language=objc)
40// NS_ENUM
41#[repr(transparent)]
42#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
43pub struct UIEventSubtype(pub NSInteger);
44impl UIEventSubtype {
45    #[doc(alias = "UIEventSubtypeNone")]
46    pub const None: Self = Self(0);
47    #[doc(alias = "UIEventSubtypeMotionShake")]
48    pub const MotionShake: Self = Self(1);
49    #[doc(alias = "UIEventSubtypeRemoteControlPlay")]
50    pub const RemoteControlPlay: Self = Self(100);
51    #[doc(alias = "UIEventSubtypeRemoteControlPause")]
52    pub const RemoteControlPause: Self = Self(101);
53    #[doc(alias = "UIEventSubtypeRemoteControlStop")]
54    pub const RemoteControlStop: Self = Self(102);
55    #[doc(alias = "UIEventSubtypeRemoteControlTogglePlayPause")]
56    pub const RemoteControlTogglePlayPause: Self = Self(103);
57    #[doc(alias = "UIEventSubtypeRemoteControlNextTrack")]
58    pub const RemoteControlNextTrack: Self = Self(104);
59    #[doc(alias = "UIEventSubtypeRemoteControlPreviousTrack")]
60    pub const RemoteControlPreviousTrack: Self = Self(105);
61    #[doc(alias = "UIEventSubtypeRemoteControlBeginSeekingBackward")]
62    pub const RemoteControlBeginSeekingBackward: Self = Self(106);
63    #[doc(alias = "UIEventSubtypeRemoteControlEndSeekingBackward")]
64    pub const RemoteControlEndSeekingBackward: Self = Self(107);
65    #[doc(alias = "UIEventSubtypeRemoteControlBeginSeekingForward")]
66    pub const RemoteControlBeginSeekingForward: Self = Self(108);
67    #[doc(alias = "UIEventSubtypeRemoteControlEndSeekingForward")]
68    pub const RemoteControlEndSeekingForward: Self = Self(109);
69}
70
71unsafe impl Encode for UIEventSubtype {
72    const ENCODING: Encoding = NSInteger::ENCODING;
73}
74
75unsafe impl RefEncode for UIEventSubtype {
76    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
77}
78
79/// Set of buttons pressed for the current event
80/// Raw format of: 1
81/// <
82/// <
83/// (buttonNumber - 1)
84/// UIEventButtonMaskPrimary = 1
85/// <
86/// <
87/// 0
88///
89/// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uieventbuttonmask?language=objc)
90// NS_OPTIONS
91#[repr(transparent)]
92#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
93pub struct UIEventButtonMask(pub NSInteger);
94bitflags::bitflags! {
95    impl UIEventButtonMask: NSInteger {
96        #[doc(alias = "UIEventButtonMaskPrimary")]
97        const Primary = 1<<0;
98        #[doc(alias = "UIEventButtonMaskSecondary")]
99        const Secondary = 1<<1;
100    }
101}
102
103unsafe impl Encode for UIEventButtonMask {
104    const ENCODING: Encoding = NSInteger::ENCODING;
105}
106
107unsafe impl RefEncode for UIEventButtonMask {
108    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
109}
110
111impl UIEventButtonMask {
112    /// Convenience initializer for a button mask where `buttonNumber` is a one-based index of the button on the input device
113    /// .button(1) == .primary
114    /// .button(2) == .secondary
115    #[doc(alias = "UIEventButtonMaskForButtonNumber")]
116    #[inline]
117    pub unsafe fn for_button_number(button_number: NSInteger) -> UIEventButtonMask {
118        extern "C-unwind" {
119            fn UIEventButtonMaskForButtonNumber(button_number: NSInteger) -> UIEventButtonMask;
120        }
121        unsafe { UIEventButtonMaskForButtonNumber(button_number) }
122    }
123}
124
125extern_class!(
126    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uievent?language=objc)
127    #[unsafe(super(NSObject))]
128    #[thread_kind = MainThreadOnly]
129    #[derive(Debug, PartialEq, Eq, Hash)]
130    pub struct UIEvent;
131);
132
133extern_conformance!(
134    unsafe impl NSObjectProtocol for UIEvent {}
135);
136
137impl UIEvent {
138    extern_methods!(
139        #[unsafe(method(type))]
140        #[unsafe(method_family = none)]
141        pub unsafe fn r#type(&self) -> UIEventType;
142
143        #[unsafe(method(subtype))]
144        #[unsafe(method_family = none)]
145        pub unsafe fn subtype(&self) -> UIEventSubtype;
146
147        #[unsafe(method(timestamp))]
148        #[unsafe(method_family = none)]
149        pub unsafe fn timestamp(&self) -> NSTimeInterval;
150
151        #[cfg(feature = "UICommand")]
152        #[unsafe(method(modifierFlags))]
153        #[unsafe(method_family = none)]
154        pub unsafe fn modifierFlags(&self) -> UIKeyModifierFlags;
155
156        #[unsafe(method(buttonMask))]
157        #[unsafe(method_family = none)]
158        pub unsafe fn buttonMask(&self) -> UIEventButtonMask;
159
160        #[cfg(feature = "UITouch")]
161        #[unsafe(method(allTouches))]
162        #[unsafe(method_family = none)]
163        pub unsafe fn allTouches(&self) -> Option<Retained<NSSet<UITouch>>>;
164
165        #[cfg(all(
166            feature = "UIResponder",
167            feature = "UITouch",
168            feature = "UIView",
169            feature = "UIWindow"
170        ))]
171        #[unsafe(method(touchesForWindow:))]
172        #[unsafe(method_family = none)]
173        pub unsafe fn touchesForWindow(
174            &self,
175            window: &UIWindow,
176        ) -> Option<Retained<NSSet<UITouch>>>;
177
178        #[cfg(all(feature = "UIResponder", feature = "UITouch", feature = "UIView"))]
179        #[unsafe(method(touchesForView:))]
180        #[unsafe(method_family = none)]
181        pub unsafe fn touchesForView(&self, view: &UIView) -> Option<Retained<NSSet<UITouch>>>;
182
183        #[cfg(all(feature = "UIGestureRecognizer", feature = "UITouch"))]
184        #[unsafe(method(touchesForGestureRecognizer:))]
185        #[unsafe(method_family = none)]
186        pub unsafe fn touchesForGestureRecognizer(
187            &self,
188            gesture: &UIGestureRecognizer,
189        ) -> Option<Retained<NSSet<UITouch>>>;
190
191        #[cfg(feature = "UITouch")]
192        #[unsafe(method(coalescedTouchesForTouch:))]
193        #[unsafe(method_family = none)]
194        pub unsafe fn coalescedTouchesForTouch(
195            &self,
196            touch: &UITouch,
197        ) -> Option<Retained<NSArray<UITouch>>>;
198
199        #[cfg(feature = "UITouch")]
200        #[unsafe(method(predictedTouchesForTouch:))]
201        #[unsafe(method_family = none)]
202        pub unsafe fn predictedTouchesForTouch(
203            &self,
204            touch: &UITouch,
205        ) -> Option<Retained<NSArray<UITouch>>>;
206    );
207}
208
209/// Methods declared on superclass `NSObject`.
210impl UIEvent {
211    extern_methods!(
212        #[unsafe(method(init))]
213        #[unsafe(method_family = init)]
214        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
215
216        #[unsafe(method(new))]
217        #[unsafe(method_family = new)]
218        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
219    );
220}
221
222extern "C-unwind" {
223    #[deprecated = "renamed to `UIEventButtonMask::for_button_number`"]
224    pub fn UIEventButtonMaskForButtonNumber(button_number: NSInteger) -> UIEventButtonMask;
225}