objc2_game_controller/generated/
GCStylus.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
9extern "C" {
10    /// A notification that posts after a stylus accessory connects to the device.
11    ///
12    /// Use this constant with `NSNotificationCenter` to listen for stylus
13    /// connection events.
14    ///
15    /// Connections of stylus accessories will be reflected in the `styli` array
16    /// of the `GCStylus` class when the notification posts.
17    ///
18    /// The `object` property of the notification will contain the `GCStylus` that
19    /// was connected.
20    ///
21    /// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcstylusdidconnectnotification?language=objc)
22    pub static GCStylusDidConnectNotification: &'static NSString;
23}
24
25extern "C" {
26    /// A notification that posts after a stylus accessory disconnects from the
27    /// device.
28    ///
29    /// Use this constant with `NSNotificationCenter` to listen for stylus
30    /// disconnection events.
31    ///
32    /// The `object` property of the notification will contain the `GCStylus` that
33    /// was disconnected.
34    ///
35    /// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcstylusdiddisconnectnotification?language=objc)
36    pub static GCStylusDidDisconnectNotification: &'static NSString;
37}
38
39extern_class!(
40    /// An object that represents a physical stylus connected to the device.
41    ///
42    /// Use the `styli` property to get the currently connect stylus accessories
43    /// when your application starts.  Register for `GCStylusDidConnectNotification`
44    /// and `GCStylusDidDisconnectNotification` to get notified when a stylus
45    /// connects of disconnects while your application is running.
46    ///
47    /// ```text
48    /// // Register for notifications
49    /// NotificationCenter.default.addObserver(self, selector: #selector(stylus(didConnect:)), name: NSNotification.Name.GCStylusDidConnect, object: nil)
50    /// NotificationCenter.default.addObserver(self, selector: #selector(stylus(didDisconnect:)), name: NSNotification.Name.GCStylusDidConnect, object: nil)
51    ///
52    /// // Query current stylus devices
53    /// for stylus in GCStylus.styluses {
54    /// ...
55    /// }
56    ///
57    /// // Later, handle connection
58    /// func stylus(didConnect notification: Notification) {
59    /// guard let stylus = notification.object as? GCStylus else { return }
60    /// ...
61    /// }
62    /// ```
63    ///
64    /// Check the `productCategory` to determine the type of stylus.  A spatial
65    /// stylus - capable of 6DoF tracking by Apple Vision Pro - has a
66    /// `GCProductCategorySpatialStylus` category.
67    ///
68    /// Use the `input` property to get the input profile of the stylus.  A spatial
69    /// stylus includes a pressure sensitive tip and an input cluster composed of
70    /// two buttons.
71    ///
72    /// - The primary button (`GCInputStylusPrimaryButton`) is the front button
73    /// (closest to the stylus tip) in the input cluster of the stylus.  This
74    /// button is frequently used grab virtual objects.
75    ///
76    /// - The secondary button (`GCInputStylusSecondaryButton`) is the middle
77    /// button in the input cluster.  It can measures pressure/force levels.
78    /// It's intended to be used for controlling in-air drawing, selection,
79    /// and generic interactions.
80    ///
81    /// - The tip is also represented as a button (`GCInputStylusTip`).
82    ///
83    /// ```text
84    /// guard let input = stylus.input else { return }
85    /// input.inputStateQueueDepth = 20
86    /// input.inputStateAvailableHandler = { input in
87    /// // This block will be enqueued for execution when the state of
88    /// // any stylus input changes.
89    ///
90    /// // Iterate through all input state changes since last execution of
91    /// // the block.
92    /// while let nextState = input.nextInputState() {
93    /// // Use the value of `pressedInput.isPressed` for binary
94    /// // interactions, such as object selection.
95    /// let primaryButtonPressed = nextState.buttons[.stylusPrimaryButton]?.pressedInput.isPressed
96    /// let secondaryButtonPressed = nextState.buttons[.stylusSecondaryButton]?.pressedInput.isPressed
97    /// // Use the normalized press value for analog actions such as
98    /// // controlling virtual ink flow.
99    /// let secondaryButtonPressure = nextState.buttons[.stylusSecondaryButton]?.pressedInput.value
100    /// let tipPressure = nextState.buttons[.stylusTip]?.pressedInput.value
101    ///
102    /// ...
103    /// }
104    /// }
105    /// ```
106    ///
107    /// Use the `haptics` property to get the haptics profile of the stylus.  A
108    /// spatial stylus may optionally support haptic feedback to a single
109    /// locality - `GCHapticsLocalityDefault`.
110    ///
111    /// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gcstylus?language=objc)
112    #[unsafe(super(NSObject))]
113    #[derive(Debug, PartialEq, Eq, Hash)]
114    pub struct GCStylus;
115);
116
117#[cfg(feature = "GCDevice")]
118extern_conformance!(
119    unsafe impl GCDevice for GCStylus {}
120);
121
122extern_conformance!(
123    unsafe impl NSObjectProtocol for GCStylus {}
124);
125
126impl GCStylus {
127    extern_methods!(
128        #[cfg(all(
129            feature = "GCDevicePhysicalInput",
130            feature = "GCDevicePhysicalInputState"
131        ))]
132        /// Gets the input profile for the stylus.
133        ///
134        /// The input profile is represented as an object conforming to the
135        /// `GCDevicePhysicalInput` protocol.  Use this object to discover available
136        /// inputs on the stylus, including buttons and pressure sensors, and get
137        /// notified when the state of those inputs change.
138        #[unsafe(method(input))]
139        #[unsafe(method_family = none)]
140        pub unsafe fn input(&self) -> Option<Retained<ProtocolObject<dyn GCDevicePhysicalInput>>>;
141
142        #[cfg(feature = "GCDeviceHaptics")]
143        /// Gets the haptics profile for the stylus, if supported.
144        ///
145        /// The haptics profile is represented as a `GCDeviceHaptics` instance, from
146        /// which you can create `CHHapticEngine` instances targeting the haptic
147        /// actuator(s) in the accessory.
148        ///
149        /// Not all stylus accessories support haptic feedback.  If the accessory
150        /// does not support haptic feedback, this property is `nil`.
151        ///
152        ///
153        /// Note: Haptics are a drain on the accessory's battery, and can be distracting when
154        /// used excessively. Use haptic feedback judiciously and in response to
155        /// meaningful user interactions.
156        #[unsafe(method(haptics))]
157        #[unsafe(method_family = none)]
158        pub unsafe fn haptics(&self) -> Option<Retained<GCDeviceHaptics>>;
159    );
160}
161
162/// Methods declared on superclass `NSObject`.
163impl GCStylus {
164    extern_methods!(
165        #[unsafe(method(init))]
166        #[unsafe(method_family = init)]
167        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
168
169        #[unsafe(method(new))]
170        #[unsafe(method_family = new)]
171        pub unsafe fn new() -> Retained<Self>;
172    );
173}
174
175/// Discovery.
176impl GCStylus {
177    extern_methods!(
178        /// Get the collection of stylus accessories currently connected to the device.
179        ///
180        /// This property returns an array of all currently connected stylus accessories.
181        /// The array is empty when no stylus accessories are connected.  The array
182        /// updates automatically as stylus accessories connect and disconnect.
183        ///
184        /// To be notified when the array changes, register for the
185        /// `GCStylusDidConnectNotification` and `GCStylusDidDisconnectNotification`.
186        #[unsafe(method(styli))]
187        #[unsafe(method_family = none)]
188        pub unsafe fn styli() -> Retained<NSArray<GCStylus>>;
189    );
190}