objc2_ui_kit/generated/
UIPencilInteraction.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-core-foundation")]
7use objc2_core_foundation::*;
8use objc2_foundation::*;
9
10use crate::*;
11
12/// Preferred actions available to the user in Settings.
13///
14/// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uipencilpreferredaction?language=objc)
15// NS_ENUM
16#[repr(transparent)]
17#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
18pub struct UIPencilPreferredAction(pub NSInteger);
19impl UIPencilPreferredAction {
20    /// No action, or the user has disabled pencil interactions in Accessibility settings
21    #[doc(alias = "UIPencilPreferredActionIgnore")]
22    pub const Ignore: Self = Self(0);
23    /// Switch between the current tool and eraser
24    #[doc(alias = "UIPencilPreferredActionSwitchEraser")]
25    pub const SwitchEraser: Self = Self(1);
26    /// Switch between the current tool and the previously used tool
27    #[doc(alias = "UIPencilPreferredActionSwitchPrevious")]
28    pub const SwitchPrevious: Self = Self(2);
29    /// Show and hide the color palette
30    #[doc(alias = "UIPencilPreferredActionShowColorPalette")]
31    pub const ShowColorPalette: Self = Self(3);
32    /// Show the ink attributes palette
33    #[doc(alias = "UIPencilPreferredActionShowInkAttributes")]
34    pub const ShowInkAttributes: Self = Self(4);
35    /// Show a contextual palette of markup tools, or undo/redo options if tools are not available
36    #[doc(alias = "UIPencilPreferredActionShowContextualPalette")]
37    pub const ShowContextualPalette: Self = Self(5);
38    /// The user has selected a system shortcut to run
39    #[doc(alias = "UIPencilPreferredActionRunSystemShortcut")]
40    pub const RunSystemShortcut: Self = Self(6);
41}
42
43unsafe impl Encode for UIPencilPreferredAction {
44    const ENCODING: Encoding = NSInteger::ENCODING;
45}
46
47unsafe impl RefEncode for UIPencilPreferredAction {
48    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
49}
50
51/// The phase of an interaction gesture performed on the pencil.
52///
53/// If the gesture is discrete, the phase will be ``UIPencilInteractionPhaseEnded``
54///
55/// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uipencilinteractionphase?language=objc)
56// NS_ENUM
57#[repr(transparent)]
58#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
59pub struct UIPencilInteractionPhase(pub NSUInteger);
60impl UIPencilInteractionPhase {
61    /// A continuous gesture on the pencil began
62    #[doc(alias = "UIPencilInteractionPhaseBegan")]
63    pub const Began: Self = Self(0);
64    /// A continuous gesture on the pencil changed
65    #[doc(alias = "UIPencilInteractionPhaseChanged")]
66    pub const Changed: Self = Self(1);
67    /// A continuous gesture on the pencil ended, or a discrete gesture on the pencil recognized
68    #[doc(alias = "UIPencilInteractionPhaseEnded")]
69    pub const Ended: Self = Self(2);
70    /// A continuous gesture on the pencil was cancelled
71    #[doc(alias = "UIPencilInteractionPhaseCancelled")]
72    pub const Cancelled: Self = Self(3);
73}
74
75unsafe impl Encode for UIPencilInteractionPhase {
76    const ENCODING: Encoding = NSUInteger::ENCODING;
77}
78
79unsafe impl RefEncode for UIPencilInteractionPhase {
80    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
81}
82
83extern_class!(
84    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uipencilinteraction?language=objc)
85    #[unsafe(super(NSObject))]
86    #[thread_kind = MainThreadOnly]
87    #[derive(Debug, PartialEq, Eq, Hash)]
88    pub struct UIPencilInteraction;
89);
90
91unsafe impl NSObjectProtocol for UIPencilInteraction {}
92
93#[cfg(feature = "UIInteraction")]
94unsafe impl UIInteraction for UIPencilInteraction {}
95
96impl UIPencilInteraction {
97    extern_methods!(
98        /// The user’s preferred double-tap action as set in Settings app
99        #[unsafe(method(preferredTapAction))]
100        #[unsafe(method_family = none)]
101        pub unsafe fn preferredTapAction(mtm: MainThreadMarker) -> UIPencilPreferredAction;
102
103        /// The user’s preferred squeeze action as set in Settings app
104        #[unsafe(method(preferredSqueezeAction))]
105        #[unsafe(method_family = none)]
106        pub unsafe fn preferredSqueezeAction(mtm: MainThreadMarker) -> UIPencilPreferredAction;
107
108        /// The user's preference for drawing with pencil only as set in Settings app or the system tool picker
109        #[unsafe(method(prefersPencilOnlyDrawing))]
110        #[unsafe(method_family = none)]
111        pub unsafe fn prefersPencilOnlyDrawing(mtm: MainThreadMarker) -> bool;
112
113        /// The user's preference for if hovering with pencil should show a preview of the current drawing tool as set in Settings app
114        #[unsafe(method(prefersHoverToolPreview))]
115        #[unsafe(method_family = none)]
116        pub unsafe fn prefersHoverToolPreview(mtm: MainThreadMarker) -> bool;
117
118        /// Initialize an interaction and set the provided delegate
119        #[unsafe(method(initWithDelegate:))]
120        #[unsafe(method_family = init)]
121        pub unsafe fn initWithDelegate(
122            this: Allocated<Self>,
123            delegate: &ProtocolObject<dyn UIPencilInteractionDelegate>,
124        ) -> Retained<Self>;
125
126        /// The interaction's delegate
127        #[unsafe(method(delegate))]
128        #[unsafe(method_family = none)]
129        pub unsafe fn delegate(
130            &self,
131        ) -> Option<Retained<ProtocolObject<dyn UIPencilInteractionDelegate>>>;
132
133        /// This is a [weak property][objc2::topics::weak_property].
134        /// Setter for [`delegate`][Self::delegate].
135        #[unsafe(method(setDelegate:))]
136        #[unsafe(method_family = none)]
137        pub unsafe fn setDelegate(
138            &self,
139            delegate: Option<&ProtocolObject<dyn UIPencilInteractionDelegate>>,
140        );
141
142        /// Whether the interaction is enabled or not
143        #[unsafe(method(isEnabled))]
144        #[unsafe(method_family = none)]
145        pub unsafe fn isEnabled(&self) -> bool;
146
147        /// Setter for [`isEnabled`][Self::isEnabled].
148        #[unsafe(method(setEnabled:))]
149        #[unsafe(method_family = none)]
150        pub unsafe fn setEnabled(&self, enabled: bool);
151    );
152}
153
154/// Methods declared on superclass `NSObject`.
155impl UIPencilInteraction {
156    extern_methods!(
157        #[unsafe(method(init))]
158        #[unsafe(method_family = init)]
159        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
160
161        #[unsafe(method(new))]
162        #[unsafe(method_family = new)]
163        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
164    );
165}
166
167extern_class!(
168    /// An object that describes the hover pose of the pencil while performing a gesture on the pencil
169    ///
170    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uipencilhoverpose?language=objc)
171    #[unsafe(super(NSObject))]
172    #[thread_kind = MainThreadOnly]
173    #[derive(Debug, PartialEq, Eq, Hash)]
174    pub struct UIPencilHoverPose;
175);
176
177unsafe impl NSObjectProtocol for UIPencilHoverPose {}
178
179impl UIPencilHoverPose {
180    extern_methods!(
181        #[unsafe(method(new))]
182        #[unsafe(method_family = new)]
183        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
184
185        #[unsafe(method(init))]
186        #[unsafe(method_family = init)]
187        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
188
189        #[cfg(feature = "objc2-core-foundation")]
190        /// The hover location of the pencil in the interaction's view while performing the associated action. If the pencil is removed from hover range during a continuous interaction,
191        /// this will be the last reported location.
192        #[unsafe(method(location))]
193        #[unsafe(method_family = none)]
194        pub unsafe fn location(&self) -> CGPoint;
195
196        #[cfg(feature = "objc2-core-foundation")]
197        /// The normalized distance from the screen of the hovering pencil. This value will be 1 at the maximum distance from the screen and will approach 0 as the pencil gets
198        /// closer to the screen.
199        #[unsafe(method(zOffset))]
200        #[unsafe(method_family = none)]
201        pub unsafe fn zOffset(&self) -> CGFloat;
202
203        #[cfg(feature = "objc2-core-foundation")]
204        /// The azimuth angle in radians of the pencil in the interaction's view while performing the associated action. Zero radians points along the positive X axis.
205        #[unsafe(method(azimuthAngle))]
206        #[unsafe(method_family = none)]
207        pub unsafe fn azimuthAngle(&self) -> CGFloat;
208
209        #[cfg(feature = "objc2-core-foundation")]
210        /// The azimuth unit vector of the pencil in the interaction's view while performing the associated action. The unit vector points in the direction of the azimuth angle.
211        #[unsafe(method(azimuthUnitVector))]
212        #[unsafe(method_family = none)]
213        pub unsafe fn azimuthUnitVector(&self) -> CGVector;
214
215        #[cfg(feature = "objc2-core-foundation")]
216        /// The altitude angle in radians of the pencil while performing the associated action. Zero radians indicates that the stylus is parallel to the screen surface, while `M_PI/2`
217        /// radians indicates that it is normal to the screen surface.
218        #[unsafe(method(altitudeAngle))]
219        #[unsafe(method_family = none)]
220        pub unsafe fn altitudeAngle(&self) -> CGFloat;
221
222        #[cfg(feature = "objc2-core-foundation")]
223        /// The roll angle in radians of the pencil while performing the associated action. For pencils that don't support roll, this value will be 0.
224        #[unsafe(method(rollAngle))]
225        #[unsafe(method_family = none)]
226        pub unsafe fn rollAngle(&self) -> CGFloat;
227    );
228}
229
230extern_class!(
231    /// An object that describes a tap performed on the pencil
232    ///
233    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uipencilinteractiontap?language=objc)
234    #[unsafe(super(NSObject))]
235    #[thread_kind = MainThreadOnly]
236    #[derive(Debug, PartialEq, Eq, Hash)]
237    pub struct UIPencilInteractionTap;
238);
239
240unsafe impl NSObjectProtocol for UIPencilInteractionTap {}
241
242impl UIPencilInteractionTap {
243    extern_methods!(
244        #[unsafe(method(new))]
245        #[unsafe(method_family = new)]
246        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
247
248        #[unsafe(method(init))]
249        #[unsafe(method_family = init)]
250        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
251
252        /// The time in seconds from system start up when this tap occured
253        #[unsafe(method(timestamp))]
254        #[unsafe(method_family = none)]
255        pub unsafe fn timestamp(&self) -> NSTimeInterval;
256
257        /// The hover pose of the pencil while performing a tap. Returns `nil` if the pencil was not in hover range or if hover is not supported on the device.
258        #[unsafe(method(hoverPose))]
259        #[unsafe(method_family = none)]
260        pub unsafe fn hoverPose(&self) -> Option<Retained<UIPencilHoverPose>>;
261    );
262}
263
264extern_class!(
265    /// An object that describes a squeeze performed on the pencil
266    ///
267    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uipencilinteractionsqueeze?language=objc)
268    #[unsafe(super(NSObject))]
269    #[thread_kind = MainThreadOnly]
270    #[derive(Debug, PartialEq, Eq, Hash)]
271    pub struct UIPencilInteractionSqueeze;
272);
273
274unsafe impl NSObjectProtocol for UIPencilInteractionSqueeze {}
275
276impl UIPencilInteractionSqueeze {
277    extern_methods!(
278        #[unsafe(method(new))]
279        #[unsafe(method_family = new)]
280        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
281
282        #[unsafe(method(init))]
283        #[unsafe(method_family = init)]
284        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
285
286        /// The time in seconds from system start up when this squeeze occured
287        #[unsafe(method(timestamp))]
288        #[unsafe(method_family = none)]
289        pub unsafe fn timestamp(&self) -> NSTimeInterval;
290
291        /// The phase of the squeeze
292        #[unsafe(method(phase))]
293        #[unsafe(method_family = none)]
294        pub unsafe fn phase(&self) -> UIPencilInteractionPhase;
295
296        /// The hover pose of the pencil while performing a squeeze. Returns `nil` if the pencil was not in hover range or if hover is not supported on the device.
297        #[unsafe(method(hoverPose))]
298        #[unsafe(method_family = none)]
299        pub unsafe fn hoverPose(&self) -> Option<Retained<UIPencilHoverPose>>;
300    );
301}
302
303extern_protocol!(
304    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uipencilinteractiondelegate?language=objc)
305    pub unsafe trait UIPencilInteractionDelegate: NSObjectProtocol + MainThreadOnly {
306        /// Called when the user taps on the side of the pencil if the interaction's view is in a visible view hierarchy.
307        ///
308        /// The delegate may do anything in this method.  To perform the user's preferred tap action (as set in Settings), consult the ``preferredTapAction`` class property
309        /// of ``UIPencilInteraction``.
310        ///
311        /// - Note: If ``pencilInteraction(_:didReceiveTap:)`` is implemented, this method will not be called.
312        #[deprecated = "Use pencilInteraction(_:didReceiveTap:) instead"]
313        #[optional]
314        #[unsafe(method(pencilInteractionDidTap:))]
315        #[unsafe(method_family = none)]
316        unsafe fn pencilInteractionDidTap(&self, interaction: &UIPencilInteraction);
317
318        /// Called when the user taps on the side of the pencil if the interaction's view is in a visible view hierarchy.
319        ///
320        /// The delegate may do anything in this method.  To perform the user's preferred tap action (as set in Settings), consult the ``preferredTapAction`` class property
321        /// of ``UIPencilInteraction``.
322        ///
323        /// - Note: If both this method and the deprecated ``pencilInteractionDidTap(_:)`` are implemented, then only this method will be called.
324        #[optional]
325        #[unsafe(method(pencilInteraction:didReceiveTap:))]
326        #[unsafe(method_family = none)]
327        unsafe fn pencilInteraction_didReceiveTap(
328            &self,
329            interaction: &UIPencilInteraction,
330            tap: &UIPencilInteractionTap,
331        );
332
333        /// Called when the user squeezes side of the pencil if the interaction's view is in a visible view hierarchy.
334        ///
335        /// The delegate may do anything in this method.  To perform the user's preferred squeeze action (as set in Settings), consult the ``preferredSqueezeAction`` class
336        /// property of ``UIPencilInteraction``.
337        #[optional]
338        #[unsafe(method(pencilInteraction:didReceiveSqueeze:))]
339        #[unsafe(method_family = none)]
340        unsafe fn pencilInteraction_didReceiveSqueeze(
341            &self,
342            interaction: &UIPencilInteraction,
343            squeeze: &UIPencilInteractionSqueeze,
344        );
345    }
346);