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 axis changes.
///
///
/// Parameter `axis`: the element that has been modified.
///
/// Parameter `value`: the value the axis was set to at the time the valueChangedHandler fired.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccontrolleraxisvaluechangedhandler?language=objc)
#[cfg(all(feature = "GCControllerElement", feature = "block2"))]
pub type GCControllerAxisValueChangedHandler =
    *mut block2::DynBlock<dyn Fn(NonNull<GCControllerAxisInput>, c_float)>;

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

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

#[cfg(feature = "GCControllerElement")]
impl GCControllerAxisInput {
    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) -> GCControllerAxisValueChangedHandler;

        #[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: GCControllerAxisValueChangedHandler,
        );

        /// A normalized value for the input, between -1 and 1 for axis inputs. The values are deadzoned and saturated before they are returned
        /// so there is no value ouside the range. Deadzoning does not remove values from the range, the full 0 to 1 magnitude of values
        /// are possible from the input.
        ///
        /// As an axis is often used in a digital sense, you can rely on a value of 0 meaning the axis is inside the deadzone.
        /// Any value greater than or less than zero is not in the deadzone.
        #[unsafe(method(value))]
        #[unsafe(method_family = none)]
        pub unsafe fn value(&self) -> c_float;

        /// Sets the normalized value for the input.
        ///
        ///
        /// 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 GCControllerAxisInput {
    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>;
    );
}