objc2-game-controller 0.3.2

Bindings to the GameController framework
Documentation
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;

use crate::*;

/// Set this block if you want to be notified when the value on this button changes.
///
///
/// Parameter `button`: the element that has been modified.
///
/// Parameter `value`: the value the button was set to at the time the valueChangedHandler fired.
///
/// Parameter `pressed`: the pressed state of the button at the time the valueChangedHandler fired.
///
/// See: value
///
/// See: pressed
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccontrollerbuttonvaluechangedhandler?language=objc)
#[cfg(all(feature = "GCControllerElement", feature = "block2"))]
pub type GCControllerButtonValueChangedHandler =
    *mut block2::DynBlock<dyn Fn(NonNull<GCControllerButtonInput>, c_float, Bool)>;

/// Set this block if you want to be notified when the touched state on this button changes.
///
///
/// Parameter `button`: the element that has been modified.
///
/// Parameter `value`: the value the button was set to at the time the valueChangedHandler fired.
///
/// Parameter `pressed`: the pressed state of the button at the time the valueChangedHandler fired.
///
/// Parameter `touched`: the touched state of the button at the time the valueChangedHandler fired.
///
/// See: value
///
/// See: pressed
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccontrollerbuttontouchedchangedhandler?language=objc)
#[cfg(all(feature = "GCControllerElement", feature = "block2"))]
pub type GCControllerButtonTouchedChangedHandler =
    *mut block2::DynBlock<dyn Fn(NonNull<GCControllerButtonInput>, c_float, Bool, Bool)>;

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccontrollerbuttoninput?language=objc)
    #[unsafe(super(GCControllerElement, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[cfg(feature = "GCControllerElement")]
    pub struct GCControllerButtonInput;
);

#[cfg(feature = "GCControllerElement")]
extern_conformance!(
    unsafe impl NSObjectProtocol for GCControllerButtonInput {}
);

#[cfg(feature = "GCControllerElement")]
impl GCControllerButtonInput {
    extern_methods!(
        #[cfg(feature = "block2")]
        /// # Safety
        ///
        /// The returned block's argument 1 must be a valid pointer.
        #[unsafe(method(valueChangedHandler))]
        #[unsafe(method_family = none)]
        pub unsafe fn valueChangedHandler(&self) -> GCControllerButtonValueChangedHandler;

        #[cfg(feature = "block2")]
        /// Setter for [`valueChangedHandler`][Self::valueChangedHandler].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        ///
        /// # Safety
        ///
        /// `value_changed_handler` must be a valid pointer or null.
        #[unsafe(method(setValueChangedHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setValueChangedHandler(
            &self,
            value_changed_handler: GCControllerButtonValueChangedHandler,
        );

        #[cfg(feature = "block2")]
        /// Set this block if you want to be notified when only the pressed state on this button changes. This
        /// will get called less often than the valueChangedHandler with the additional feature of the pressed state
        /// being different to the last time it was called.
        ///
        /// # Safety
        ///
        /// The returned block's argument 1 must be a valid pointer.
        #[unsafe(method(pressedChangedHandler))]
        #[unsafe(method_family = none)]
        pub unsafe fn pressedChangedHandler(&self) -> GCControllerButtonValueChangedHandler;

        #[cfg(feature = "block2")]
        /// Setter for [`pressedChangedHandler`][Self::pressedChangedHandler].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        ///
        /// # Safety
        ///
        /// `pressed_changed_handler` must be a valid pointer or null.
        #[unsafe(method(setPressedChangedHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setPressedChangedHandler(
            &self,
            pressed_changed_handler: GCControllerButtonValueChangedHandler,
        );

        #[cfg(feature = "block2")]
        /// # Safety
        ///
        /// The returned block's argument 1 must be a valid pointer.
        #[unsafe(method(touchedChangedHandler))]
        #[unsafe(method_family = none)]
        pub unsafe fn touchedChangedHandler(&self) -> GCControllerButtonTouchedChangedHandler;

        #[cfg(feature = "block2")]
        /// Setter for [`touchedChangedHandler`][Self::touchedChangedHandler].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        ///
        /// # Safety
        ///
        /// `touched_changed_handler` must be a valid pointer or null.
        #[unsafe(method(setTouchedChangedHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setTouchedChangedHandler(
            &self,
            touched_changed_handler: GCControllerButtonTouchedChangedHandler,
        );

        /// 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].
        ///
        /// See: valueChangedHandler
        ///
        /// See: pressed
        #[unsafe(method(value))]
        #[unsafe(method_family = none)]
        pub unsafe fn value(&self) -> c_float;

        /// Buttons are mostly used in a digital sense, thus we have a recommended method for checking for pressed state instead of
        /// interpreting the value.
        ///
        /// As a general guideline a button is pressed if the value exceeds 0. However there may be hysterisis applied
        /// to counter noisy input values, thus incidental values around the threshold value may not trigger a change
        /// in pressed state.
        ///
        /// Others buttons may support two-stage actuation, where the button reports a value between 0 and 1 but is only considered
        /// pressed when its value is greater than some threshold other than 0.
        ///
        /// See: pressedChangedHandler
        ///
        /// See: value
        #[unsafe(method(isPressed))]
        #[unsafe(method_family = none)]
        pub unsafe fn isPressed(&self) -> bool;

        /// Some buttons feature capacitive touch capabilities where the user can touch the button
        /// without pressing it. In such cases, a button will be touched before it is pressed.
        ///
        /// For buttons without capacitive sensing, the touched state is true if the value exceeds 0.
        ///
        ///
        /// See: touchChangedHandler
        ///
        /// See: pressed
        #[unsafe(method(isTouched))]
        #[unsafe(method_family = none)]
        pub unsafe fn isTouched(&self) -> bool;

        /// Sets the normalized value for the button input. Will update the pressed state of the button.
        ///
        ///
        /// Parameter `value`: the value to set the input to.
        ///
        /// Note: If the controller's snapshot flag is set to NO, this method has no effect.
        ///
        /// See: value
        #[unsafe(method(setValue:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setValue(&self, value: c_float);
    );
}

/// Methods declared on superclass `NSObject`.
#[cfg(feature = "GCControllerElement")]
impl GCControllerButtonInput {
    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>;
    );
}