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
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;
use crate::*;
extern "C" {
/// A notification that posts after a stylus accessory connects to the device.
///
/// Use this constant with `NSNotificationCenter` to listen for stylus
/// connection events.
///
/// Connections of stylus accessories will be reflected in the `styli` array
/// of the `GCStylus` class when the notification posts.
///
/// The `object` property of the notification will contain the `GCStylus` that
/// was connected.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcstylusdidconnectnotification?language=objc)
pub static GCStylusDidConnectNotification: &'static NSString;
}
extern "C" {
/// A notification that posts after a stylus accessory disconnects from the
/// device.
///
/// Use this constant with `NSNotificationCenter` to listen for stylus
/// disconnection events.
///
/// The `object` property of the notification will contain the `GCStylus` that
/// was disconnected.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcstylusdiddisconnectnotification?language=objc)
pub static GCStylusDidDisconnectNotification: &'static NSString;
}
extern_class!(
/// An object that represents a physical stylus connected to the device.
///
/// Use the `styli` property to get the currently connect stylus accessories
/// when your application starts. Register for `GCStylusDidConnectNotification`
/// and `GCStylusDidDisconnectNotification` to get notified when a stylus
/// connects of disconnects while your application is running.
///
/// ```text
/// // Register for notifications
/// NotificationCenter.default.addObserver(self, selector: #selector(stylus(didConnect:)), name: NSNotification.Name.GCStylusDidConnect, object: nil)
/// NotificationCenter.default.addObserver(self, selector: #selector(stylus(didDisconnect:)), name: NSNotification.Name.GCStylusDidConnect, object: nil)
///
/// // Query current stylus devices
/// for stylus in GCStylus.styluses {
/// ...
/// }
///
/// // Later, handle connection
/// func stylus(didConnect notification: Notification) {
/// guard let stylus = notification.object as? GCStylus else { return }
/// ...
/// }
/// ```
///
/// Check the `productCategory` to determine the type of stylus. A spatial
/// stylus - capable of 6DoF tracking by Apple Vision Pro - has a
/// `GCProductCategorySpatialStylus` category.
///
/// Use the `input` property to get the input profile of the stylus. A spatial
/// stylus includes a pressure sensitive tip and an input cluster composed of
/// two buttons.
///
/// - The primary button (`GCInputStylusPrimaryButton`) is the front button
/// (closest to the stylus tip) in the input cluster of the stylus. This
/// button is frequently used grab virtual objects.
///
/// - The secondary button (`GCInputStylusSecondaryButton`) is the middle
/// button in the input cluster. It can measures pressure/force levels.
/// It's intended to be used for controlling in-air drawing, selection,
/// and generic interactions.
///
/// - The tip is also represented as a button (`GCInputStylusTip`).
///
/// ```text
/// guard let input = stylus.input else { return }
/// input.inputStateQueueDepth = 20
/// input.inputStateAvailableHandler = { input in
/// // This block will be enqueued for execution when the state of
/// // any stylus input changes.
///
/// // Iterate through all input state changes since last execution of
/// // the block.
/// while let nextState = input.nextInputState() {
/// // Use the value of `pressedInput.isPressed` for binary
/// // interactions, such as object selection.
/// let primaryButtonPressed = nextState.buttons[.stylusPrimaryButton]?.pressedInput.isPressed
/// let secondaryButtonPressed = nextState.buttons[.stylusSecondaryButton]?.pressedInput.isPressed
/// // Use the normalized press value for analog actions such as
/// // controlling virtual ink flow.
/// let secondaryButtonPressure = nextState.buttons[.stylusSecondaryButton]?.pressedInput.value
/// let tipPressure = nextState.buttons[.stylusTip]?.pressedInput.value
///
/// ...
/// }
/// }
/// ```
///
/// Use the `haptics` property to get the haptics profile of the stylus. A
/// spatial stylus may optionally support haptic feedback to a single
/// locality - `GCHapticsLocalityDefault`.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcstylus?language=objc)
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct GCStylus;
);
#[cfg(feature = "GCDevice")]
extern_conformance!(
unsafe impl GCDevice for GCStylus {}
);
extern_conformance!(
unsafe impl NSObjectProtocol for GCStylus {}
);
impl GCStylus {
extern_methods!(
#[cfg(all(
feature = "GCDevicePhysicalInput",
feature = "GCDevicePhysicalInputState"
))]
/// Gets the input profile for the stylus.
///
/// The input profile is represented as an object conforming to the
/// `GCDevicePhysicalInput` protocol. Use this object to discover available
/// inputs on the stylus, including buttons and pressure sensors, and get
/// notified when the state of those inputs change.
#[unsafe(method(input))]
#[unsafe(method_family = none)]
pub unsafe fn input(&self) -> Option<Retained<ProtocolObject<dyn GCDevicePhysicalInput>>>;
#[cfg(feature = "GCDeviceHaptics")]
/// Gets the haptics profile for the stylus, if supported.
///
/// The haptics profile is represented as a `GCDeviceHaptics` instance, from
/// which you can create `CHHapticEngine` instances targeting the haptic
/// actuator(s) in the accessory.
///
/// Not all stylus accessories support haptic feedback. If the accessory
/// does not support haptic feedback, this property is `nil`.
///
///
/// Note: Haptics are a drain on the accessory's battery, and can be distracting when
/// used excessively. Use haptic feedback judiciously and in response to
/// meaningful user interactions.
#[unsafe(method(haptics))]
#[unsafe(method_family = none)]
pub unsafe fn haptics(&self) -> Option<Retained<GCDeviceHaptics>>;
);
}
/// Methods declared on superclass `NSObject`.
impl GCStylus {
extern_methods!(
#[unsafe(method(init))]
#[unsafe(method_family = init)]
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
#[unsafe(method(new))]
#[unsafe(method_family = new)]
pub unsafe fn new() -> Retained<Self>;
);
}
/// Discovery.
impl GCStylus {
extern_methods!(
/// Get the collection of stylus accessories currently connected to the device.
///
/// This property returns an array of all currently connected stylus accessories.
/// The array is empty when no stylus accessories are connected. The array
/// updates automatically as stylus accessories connect and disconnect.
///
/// To be notified when the array changes, register for the
/// `GCStylusDidConnectNotification` and `GCStylusDidDisconnectNotification`.
#[unsafe(method(styli))]
#[unsafe(method_family = none)]
pub unsafe fn styli() -> Retained<NSArray<GCStylus>>;
);
}