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::Block<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::Block<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")]
56unsafe impl NSObjectProtocol for GCControllerButtonInput {}
57
58#[cfg(feature = "GCControllerElement")]
59impl GCControllerButtonInput {
60    extern_methods!(
61        #[cfg(feature = "block2")]
62        #[unsafe(method(valueChangedHandler))]
63        #[unsafe(method_family = none)]
64        pub unsafe fn valueChangedHandler(&self) -> GCControllerButtonValueChangedHandler;
65
66        #[cfg(feature = "block2")]
67        /// Setter for [`valueChangedHandler`][Self::valueChangedHandler].
68        #[unsafe(method(setValueChangedHandler:))]
69        #[unsafe(method_family = none)]
70        pub unsafe fn setValueChangedHandler(
71            &self,
72            value_changed_handler: GCControllerButtonValueChangedHandler,
73        );
74
75        #[cfg(feature = "block2")]
76        /// Set this block if you want to be notified when only the pressed state on this button changes. This
77        /// will get called less often than the valueChangedHandler with the additional feature of the pressed state
78        /// being different to the last time it was called.
79        #[unsafe(method(pressedChangedHandler))]
80        #[unsafe(method_family = none)]
81        pub unsafe fn pressedChangedHandler(&self) -> GCControllerButtonValueChangedHandler;
82
83        #[cfg(feature = "block2")]
84        /// Setter for [`pressedChangedHandler`][Self::pressedChangedHandler].
85        #[unsafe(method(setPressedChangedHandler:))]
86        #[unsafe(method_family = none)]
87        pub unsafe fn setPressedChangedHandler(
88            &self,
89            pressed_changed_handler: GCControllerButtonValueChangedHandler,
90        );
91
92        #[cfg(feature = "block2")]
93        #[unsafe(method(touchedChangedHandler))]
94        #[unsafe(method_family = none)]
95        pub unsafe fn touchedChangedHandler(&self) -> GCControllerButtonTouchedChangedHandler;
96
97        #[cfg(feature = "block2")]
98        /// Setter for [`touchedChangedHandler`][Self::touchedChangedHandler].
99        #[unsafe(method(setTouchedChangedHandler:))]
100        #[unsafe(method_family = none)]
101        pub unsafe fn setTouchedChangedHandler(
102            &self,
103            touched_changed_handler: GCControllerButtonTouchedChangedHandler,
104        );
105
106        /// 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].
107        ///
108        /// See: valueChangedHandler
109        ///
110        /// See: pressed
111        #[unsafe(method(value))]
112        #[unsafe(method_family = none)]
113        pub unsafe fn value(&self) -> c_float;
114
115        /// Buttons are mostly used in a digital sense, thus we have a recommended method for checking for pressed state instead of
116        /// interpreting the value.
117        ///
118        /// As a general guideline a button is pressed if the value exceeds 0. However there may be hysterisis applied
119        /// to counter noisy input values, thus incidental values around the threshold value may not trigger a change
120        /// in pressed state.
121        ///
122        /// Others buttons may support two-stage actuation, where the button reports a value between 0 and 1 but is only considered
123        /// pressed when its value is greater than some threshold other than 0.
124        ///
125        /// See: pressedChangedHandler
126        ///
127        /// See: value
128        #[unsafe(method(isPressed))]
129        #[unsafe(method_family = none)]
130        pub unsafe fn isPressed(&self) -> bool;
131
132        /// Some buttons feature capacitive touch capabilities where the user can touch the button
133        /// without pressing it. In such cases, a button will be touched before it is pressed.
134        ///
135        /// For buttons without capacitive sensing, the touched state is true if the value exceeds 0.
136        ///
137        ///
138        /// See: touchChangedHandler
139        ///
140        /// See: pressed
141        #[unsafe(method(isTouched))]
142        #[unsafe(method_family = none)]
143        pub unsafe fn isTouched(&self) -> bool;
144
145        /// Sets the normalized value for the button input. Will update the pressed state of the button.
146        ///
147        ///
148        /// Parameter `value`: the value to set the input to.
149        ///
150        /// Note: If the controller's snapshot flag is set to NO, this method has no effect.
151        ///
152        /// See: value
153        #[unsafe(method(setValue:))]
154        #[unsafe(method_family = none)]
155        pub unsafe fn setValue(&self, value: c_float);
156    );
157}
158
159/// Methods declared on superclass `NSObject`.
160#[cfg(feature = "GCControllerElement")]
161impl GCControllerButtonInput {
162    extern_methods!(
163        #[unsafe(method(init))]
164        #[unsafe(method_family = init)]
165        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
166
167        #[unsafe(method(new))]
168        #[unsafe(method_family = new)]
169        pub unsafe fn new() -> Retained<Self>;
170    );
171}