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 `dpad`: the direction pad collection whose axis have been modified.
///
/// Parameter `xValue`: the value the x axis was set to at the time the valueChangedHandler fired.
///
/// Parameter `yValue`: the value the y axis was set to at the time the valueChangedHandler fired.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccontrollerdirectionpadvaluechangedhandler?language=objc)
#[cfg(all(feature = "GCControllerElement", feature = "block2"))]
pub type GCControllerDirectionPadValueChangedHandler =
    *mut block2::DynBlock<dyn Fn(NonNull<GCControllerDirectionPad>, c_float, c_float)>;

extern_class!(
    /// A direction pad is a common grouping of 2 axis inputs where the input can also be interpreted as 2 sets of mutually exclusive button pairs.
    /// Only one button in each pair, {up, down} and {left, right}, can be pressed at any one time.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccontrollerdirectionpad?language=objc)
    #[unsafe(super(GCControllerElement, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[cfg(feature = "GCControllerElement")]
    pub struct GCControllerDirectionPad;
);

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

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

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

        #[cfg(feature = "GCControllerAxisInput")]
        #[unsafe(method(xAxis))]
        #[unsafe(method_family = none)]
        pub unsafe fn xAxis(&self) -> Retained<GCControllerAxisInput>;

        #[cfg(feature = "GCControllerAxisInput")]
        #[unsafe(method(yAxis))]
        #[unsafe(method_family = none)]
        pub unsafe fn yAxis(&self) -> Retained<GCControllerAxisInput>;

        #[cfg(feature = "GCControllerButtonInput")]
        #[unsafe(method(up))]
        #[unsafe(method_family = none)]
        pub unsafe fn up(&self) -> Retained<GCControllerButtonInput>;

        #[cfg(feature = "GCControllerButtonInput")]
        #[unsafe(method(down))]
        #[unsafe(method_family = none)]
        pub unsafe fn down(&self) -> Retained<GCControllerButtonInput>;

        #[cfg(feature = "GCControllerButtonInput")]
        #[unsafe(method(left))]
        #[unsafe(method_family = none)]
        pub unsafe fn left(&self) -> Retained<GCControllerButtonInput>;

        #[cfg(feature = "GCControllerButtonInput")]
        #[unsafe(method(right))]
        #[unsafe(method_family = none)]
        pub unsafe fn right(&self) -> Retained<GCControllerButtonInput>;

        /// Sets the normalized value for the direction pad's axis inputs. Will update the states of the direction pad's button inputs as well.
        ///
        ///
        /// Parameter `xAxis`: the value to set the xAxis of the touchpad to.
        ///
        /// Parameter `yAxis`: the value to set the yAxis of the touchpad to.
        ///
        /// Note: If the controller's snapshot flag is set to NO, this method has no effect.
        ///
        /// See: value
        ///
        /// See: pressed
        #[unsafe(method(setValueForXAxis:yAxis:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setValueForXAxis_yAxis(&self, x_axis: c_float, y_axis: c_float);
    );
}

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