objc2_game_controller/generated/
GCControllerButtonInput.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
7use crate::*;
8
9/// Set this block if you want to be notified when the value on this button changes.
10///
11///
12/// Parameter `button`: the element that has been modified.
13///
14/// Parameter `value`: the value the button was set to at the time the valueChangedHandler fired.
15///
16/// Parameter `pressed`: the pressed state of the button at the time the valueChangedHandler fired.
17///
18/// See: value
19///
20/// See: pressed
21///
22/// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccontrollerbuttonvaluechangedhandler?language=objc)
23#[cfg(all(feature = "GCControllerElement", feature = "block2"))]
24pub type GCControllerButtonValueChangedHandler =
25    *mut block2::DynBlock<dyn Fn(NonNull<GCControllerButtonInput>, c_float, Bool)>;
26
27/// Set this block if you want to be notified when the touched state on this button changes.
28///
29///
30/// Parameter `button`: the element that has been modified.
31///
32/// Parameter `value`: the value the button was set to at the time the valueChangedHandler fired.
33///
34/// Parameter `pressed`: the pressed state of the button at the time the valueChangedHandler fired.
35///
36/// Parameter `touched`: the touched state of the button at the time the valueChangedHandler fired.
37///
38/// See: value
39///
40/// See: pressed
41///
42/// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccontrollerbuttontouchedchangedhandler?language=objc)
43#[cfg(all(feature = "GCControllerElement", feature = "block2"))]
44pub type GCControllerButtonTouchedChangedHandler =
45    *mut block2::DynBlock<dyn Fn(NonNull<GCControllerButtonInput>, c_float, Bool, Bool)>;
46
47extern_class!(
48    /// [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccontrollerbuttoninput?language=objc)
49    #[unsafe(super(GCControllerElement, NSObject))]
50    #[derive(Debug, PartialEq, Eq, Hash)]
51    #[cfg(feature = "GCControllerElement")]
52    pub struct GCControllerButtonInput;
53);
54
55#[cfg(feature = "GCControllerElement")]
56extern_conformance!(
57    unsafe impl NSObjectProtocol for GCControllerButtonInput {}
58);
59
60#[cfg(feature = "GCControllerElement")]
61impl GCControllerButtonInput {
62    extern_methods!(
63        #[cfg(feature = "block2")]
64        /// # Safety
65        ///
66        /// The returned block's argument 1 must be a valid pointer.
67        #[unsafe(method(valueChangedHandler))]
68        #[unsafe(method_family = none)]
69        pub unsafe fn valueChangedHandler(&self) -> GCControllerButtonValueChangedHandler;
70
71        #[cfg(feature = "block2")]
72        /// Setter for [`valueChangedHandler`][Self::valueChangedHandler].
73        ///
74        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
75        ///
76        /// # Safety
77        ///
78        /// `value_changed_handler` must be a valid pointer or null.
79        #[unsafe(method(setValueChangedHandler:))]
80        #[unsafe(method_family = none)]
81        pub unsafe fn setValueChangedHandler(
82            &self,
83            value_changed_handler: GCControllerButtonValueChangedHandler,
84        );
85
86        #[cfg(feature = "block2")]
87        /// Set this block if you want to be notified when only the pressed state on this button changes. This
88        /// will get called less often than the valueChangedHandler with the additional feature of the pressed state
89        /// being different to the last time it was called.
90        ///
91        /// # Safety
92        ///
93        /// The returned block's argument 1 must be a valid pointer.
94        #[unsafe(method(pressedChangedHandler))]
95        #[unsafe(method_family = none)]
96        pub unsafe fn pressedChangedHandler(&self) -> GCControllerButtonValueChangedHandler;
97
98        #[cfg(feature = "block2")]
99        /// Setter for [`pressedChangedHandler`][Self::pressedChangedHandler].
100        ///
101        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
102        ///
103        /// # Safety
104        ///
105        /// `pressed_changed_handler` must be a valid pointer or null.
106        #[unsafe(method(setPressedChangedHandler:))]
107        #[unsafe(method_family = none)]
108        pub unsafe fn setPressedChangedHandler(
109            &self,
110            pressed_changed_handler: GCControllerButtonValueChangedHandler,
111        );
112
113        #[cfg(feature = "block2")]
114        /// # Safety
115        ///
116        /// The returned block's argument 1 must be a valid pointer.
117        #[unsafe(method(touchedChangedHandler))]
118        #[unsafe(method_family = none)]
119        pub unsafe fn touchedChangedHandler(&self) -> GCControllerButtonTouchedChangedHandler;
120
121        #[cfg(feature = "block2")]
122        /// Setter for [`touchedChangedHandler`][Self::touchedChangedHandler].
123        ///
124        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
125        ///
126        /// # Safety
127        ///
128        /// `touched_changed_handler` must be a valid pointer or null.
129        #[unsafe(method(setTouchedChangedHandler:))]
130        #[unsafe(method_family = none)]
131        pub unsafe fn setTouchedChangedHandler(
132            &self,
133            touched_changed_handler: GCControllerButtonTouchedChangedHandler,
134        );
135
136        /// A normalized value for the input. Between 0 and 1 for button inputs. Values are saturated and thus never exceed the range of [0, 1].
137        ///
138        /// See: valueChangedHandler
139        ///
140        /// See: pressed
141        #[unsafe(method(value))]
142        #[unsafe(method_family = none)]
143        pub unsafe fn value(&self) -> c_float;
144
145        /// Buttons are mostly used in a digital sense, thus we have a recommended method for checking for pressed state instead of
146        /// interpreting the value.
147        ///
148        /// As a general guideline a button is pressed if the value exceeds 0. However there may be hysterisis applied
149        /// to counter noisy input values, thus incidental values around the threshold value may not trigger a change
150        /// in pressed state.
151        ///
152        /// Others buttons may support two-stage actuation, where the button reports a value between 0 and 1 but is only considered
153        /// pressed when its value is greater than some threshold other than 0.
154        ///
155        /// See: pressedChangedHandler
156        ///
157        /// See: value
158        #[unsafe(method(isPressed))]
159        #[unsafe(method_family = none)]
160        pub unsafe fn isPressed(&self) -> bool;
161
162        /// Some buttons feature capacitive touch capabilities where the user can touch the button
163        /// without pressing it. In such cases, a button will be touched before it is pressed.
164        ///
165        /// For buttons without capacitive sensing, the touched state is true if the value exceeds 0.
166        ///
167        ///
168        /// See: touchChangedHandler
169        ///
170        /// See: pressed
171        #[unsafe(method(isTouched))]
172        #[unsafe(method_family = none)]
173        pub unsafe fn isTouched(&self) -> bool;
174
175        /// Sets the normalized value for the button input. Will update the pressed state of the button.
176        ///
177        ///
178        /// Parameter `value`: the value to set the input to.
179        ///
180        /// Note: If the controller's snapshot flag is set to NO, this method has no effect.
181        ///
182        /// See: value
183        #[unsafe(method(setValue:))]
184        #[unsafe(method_family = none)]
185        pub unsafe fn setValue(&self, value: c_float);
186    );
187}
188
189/// Methods declared on superclass `NSObject`.
190#[cfg(feature = "GCControllerElement")]
191impl GCControllerButtonInput {
192    extern_methods!(
193        #[unsafe(method(init))]
194        #[unsafe(method_family = init)]
195        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
196
197        #[unsafe(method(new))]
198        #[unsafe(method_family = new)]
199        pub unsafe fn new() -> Retained<Self>;
200    );
201}