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