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