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
91extern_conformance!(
92    unsafe impl NSObjectProtocol for UIPencilInteraction {}
93);
94
95#[cfg(feature = "UIInteraction")]
96extern_conformance!(
97    unsafe impl UIInteraction for UIPencilInteraction {}
98);
99
100impl UIPencilInteraction {
101    extern_methods!(
102        /// The user’s preferred double-tap action as set in Settings app
103        #[unsafe(method(preferredTapAction))]
104        #[unsafe(method_family = none)]
105        pub fn preferredTapAction(mtm: MainThreadMarker) -> UIPencilPreferredAction;
106
107        /// The user’s preferred squeeze action as set in Settings app
108        #[unsafe(method(preferredSqueezeAction))]
109        #[unsafe(method_family = none)]
110        pub fn preferredSqueezeAction(mtm: MainThreadMarker) -> UIPencilPreferredAction;
111
112        /// The user's preference for drawing with pencil only as set in Settings app or the system tool picker
113        #[unsafe(method(prefersPencilOnlyDrawing))]
114        #[unsafe(method_family = none)]
115        pub fn prefersPencilOnlyDrawing(mtm: MainThreadMarker) -> bool;
116
117        /// The user's preference for if hovering with pencil should show a preview of the current drawing tool as set in Settings app
118        #[unsafe(method(prefersHoverToolPreview))]
119        #[unsafe(method_family = none)]
120        pub fn prefersHoverToolPreview(mtm: MainThreadMarker) -> bool;
121
122        /// Initialize an interaction and set the provided delegate
123        #[unsafe(method(initWithDelegate:))]
124        #[unsafe(method_family = init)]
125        pub fn initWithDelegate(
126            this: Allocated<Self>,
127            delegate: &ProtocolObject<dyn UIPencilInteractionDelegate>,
128        ) -> Retained<Self>;
129
130        /// The interaction's delegate
131        #[unsafe(method(delegate))]
132        #[unsafe(method_family = none)]
133        pub fn delegate(&self)
134            -> Option<Retained<ProtocolObject<dyn UIPencilInteractionDelegate>>>;
135
136        /// Setter for [`delegate`][Self::delegate].
137        ///
138        /// This is a [weak property][objc2::topics::weak_property].
139        #[unsafe(method(setDelegate:))]
140        #[unsafe(method_family = none)]
141        pub fn setDelegate(
142            &self,
143            delegate: Option<&ProtocolObject<dyn UIPencilInteractionDelegate>>,
144        );
145
146        /// Whether the interaction is enabled or not
147        #[unsafe(method(isEnabled))]
148        #[unsafe(method_family = none)]
149        pub fn isEnabled(&self) -> bool;
150
151        /// Setter for [`isEnabled`][Self::isEnabled].
152        #[unsafe(method(setEnabled:))]
153        #[unsafe(method_family = none)]
154        pub fn setEnabled(&self, enabled: bool);
155    );
156}
157
158/// Methods declared on superclass `NSObject`.
159impl UIPencilInteraction {
160    extern_methods!(
161        #[unsafe(method(init))]
162        #[unsafe(method_family = init)]
163        pub fn init(this: Allocated<Self>) -> Retained<Self>;
164
165        #[unsafe(method(new))]
166        #[unsafe(method_family = new)]
167        pub fn new(mtm: MainThreadMarker) -> Retained<Self>;
168    );
169}
170
171extern_class!(
172    /// An object that describes the hover pose of the pencil while performing a gesture on the pencil
173    ///
174    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uipencilhoverpose?language=objc)
175    #[unsafe(super(NSObject))]
176    #[thread_kind = MainThreadOnly]
177    #[derive(Debug, PartialEq, Eq, Hash)]
178    pub struct UIPencilHoverPose;
179);
180
181extern_conformance!(
182    unsafe impl NSObjectProtocol for UIPencilHoverPose {}
183);
184
185impl UIPencilHoverPose {
186    extern_methods!(
187        #[unsafe(method(new))]
188        #[unsafe(method_family = new)]
189        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
190
191        #[unsafe(method(init))]
192        #[unsafe(method_family = init)]
193        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
194
195        #[cfg(feature = "objc2-core-foundation")]
196        /// 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,
197        /// this will be the last reported location.
198        #[unsafe(method(location))]
199        #[unsafe(method_family = none)]
200        pub fn location(&self) -> CGPoint;
201
202        #[cfg(feature = "objc2-core-foundation")]
203        /// 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
204        /// closer to the screen.
205        #[unsafe(method(zOffset))]
206        #[unsafe(method_family = none)]
207        pub fn zOffset(&self) -> CGFloat;
208
209        #[cfg(feature = "objc2-core-foundation")]
210        /// 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.
211        #[unsafe(method(azimuthAngle))]
212        #[unsafe(method_family = none)]
213        pub fn azimuthAngle(&self) -> CGFloat;
214
215        #[cfg(feature = "objc2-core-foundation")]
216        /// 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.
217        #[unsafe(method(azimuthUnitVector))]
218        #[unsafe(method_family = none)]
219        pub fn azimuthUnitVector(&self) -> CGVector;
220
221        #[cfg(feature = "objc2-core-foundation")]
222        /// 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`
223        /// radians indicates that it is normal to the screen surface.
224        #[unsafe(method(altitudeAngle))]
225        #[unsafe(method_family = none)]
226        pub fn altitudeAngle(&self) -> CGFloat;
227
228        #[cfg(feature = "objc2-core-foundation")]
229        /// 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.
230        #[unsafe(method(rollAngle))]
231        #[unsafe(method_family = none)]
232        pub fn rollAngle(&self) -> CGFloat;
233    );
234}
235
236extern_class!(
237    /// An object that describes a tap performed on the pencil
238    ///
239    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uipencilinteractiontap?language=objc)
240    #[unsafe(super(NSObject))]
241    #[thread_kind = MainThreadOnly]
242    #[derive(Debug, PartialEq, Eq, Hash)]
243    pub struct UIPencilInteractionTap;
244);
245
246extern_conformance!(
247    unsafe impl NSObjectProtocol for UIPencilInteractionTap {}
248);
249
250impl UIPencilInteractionTap {
251    extern_methods!(
252        #[unsafe(method(new))]
253        #[unsafe(method_family = new)]
254        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
255
256        #[unsafe(method(init))]
257        #[unsafe(method_family = init)]
258        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
259
260        /// The time in seconds from system start up when this tap occured
261        #[unsafe(method(timestamp))]
262        #[unsafe(method_family = none)]
263        pub fn timestamp(&self) -> NSTimeInterval;
264
265        /// 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.
266        #[unsafe(method(hoverPose))]
267        #[unsafe(method_family = none)]
268        pub fn hoverPose(&self) -> Option<Retained<UIPencilHoverPose>>;
269    );
270}
271
272extern_class!(
273    /// An object that describes a squeeze performed on the pencil
274    ///
275    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uipencilinteractionsqueeze?language=objc)
276    #[unsafe(super(NSObject))]
277    #[thread_kind = MainThreadOnly]
278    #[derive(Debug, PartialEq, Eq, Hash)]
279    pub struct UIPencilInteractionSqueeze;
280);
281
282extern_conformance!(
283    unsafe impl NSObjectProtocol for UIPencilInteractionSqueeze {}
284);
285
286impl UIPencilInteractionSqueeze {
287    extern_methods!(
288        #[unsafe(method(new))]
289        #[unsafe(method_family = new)]
290        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
291
292        #[unsafe(method(init))]
293        #[unsafe(method_family = init)]
294        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
295
296        /// The time in seconds from system start up when this squeeze occured
297        #[unsafe(method(timestamp))]
298        #[unsafe(method_family = none)]
299        pub fn timestamp(&self) -> NSTimeInterval;
300
301        /// The phase of the squeeze
302        #[unsafe(method(phase))]
303        #[unsafe(method_family = none)]
304        pub fn phase(&self) -> UIPencilInteractionPhase;
305
306        /// 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.
307        #[unsafe(method(hoverPose))]
308        #[unsafe(method_family = none)]
309        pub fn hoverPose(&self) -> Option<Retained<UIPencilHoverPose>>;
310    );
311}
312
313extern_protocol!(
314    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uipencilinteractiondelegate?language=objc)
315    pub unsafe trait UIPencilInteractionDelegate: NSObjectProtocol + MainThreadOnly {
316        /// Called when the user taps on the side of the pencil if the interaction's view is in a visible view hierarchy.
317        ///
318        /// 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
319        /// of ``UIPencilInteraction``.
320        ///
321        /// - Note: If ``pencilInteraction(_:didReceiveTap:)`` is implemented, this method will not be called.
322        #[deprecated = "Use pencilInteraction(_:didReceiveTap:) instead"]
323        #[optional]
324        #[unsafe(method(pencilInteractionDidTap:))]
325        #[unsafe(method_family = none)]
326        fn pencilInteractionDidTap(&self, interaction: &UIPencilInteraction);
327
328        /// Called when the user taps on the side of the pencil if the interaction's view is in a visible view hierarchy.
329        ///
330        /// 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
331        /// of ``UIPencilInteraction``.
332        ///
333        /// - Note: If both this method and the deprecated ``pencilInteractionDidTap(_:)`` are implemented, then only this method will be called.
334        #[optional]
335        #[unsafe(method(pencilInteraction:didReceiveTap:))]
336        #[unsafe(method_family = none)]
337        fn pencilInteraction_didReceiveTap(
338            &self,
339            interaction: &UIPencilInteraction,
340            tap: &UIPencilInteractionTap,
341        );
342
343        /// Called when the user squeezes side of the pencil if the interaction's view is in a visible view hierarchy.
344        ///
345        /// The delegate may do anything in this method.  To perform the user's preferred squeeze action (as set in Settings), consult the ``preferredSqueezeAction`` class
346        /// property of ``UIPencilInteraction``.
347        #[optional]
348        #[unsafe(method(pencilInteraction:didReceiveSqueeze:))]
349        #[unsafe(method_family = none)]
350        fn pencilInteraction_didReceiveSqueeze(
351            &self,
352            interaction: &UIPencilInteraction,
353            squeeze: &UIPencilInteractionSqueeze,
354        );
355    }
356);