objc2-car-play 0.3.2

Bindings to the CarPlay 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 objc2_foundation::*;
#[cfg(feature = "objc2-ui-kit")]
use objc2_ui_kit::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/carplay/cpalertactionstyle?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CPAlertActionStyle(pub NSUInteger);
impl CPAlertActionStyle {
    #[doc(alias = "CPAlertActionStyleDefault")]
    pub const Default: Self = Self(0);
    #[doc(alias = "CPAlertActionStyleCancel")]
    pub const Cancel: Self = Self(1);
    #[doc(alias = "CPAlertActionStyleDestructive")]
    pub const Destructive: Self = Self(2);
}

unsafe impl Encode for CPAlertActionStyle {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for CPAlertActionStyle {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// [Apple's documentation](https://developer.apple.com/documentation/carplay/cpalertactionhandler?language=objc)
#[cfg(feature = "block2")]
pub type CPAlertActionHandler = *mut block2::DynBlock<dyn Fn(NonNull<CPAlertAction>)>;

extern_class!(
    /// `CPAlertAction`represents a single action that appears inside of a
    /// `CPActionSheetTemplate`or
    /// `CPAlertTemplate.`
    /// The style of the parent template and the style of the
    /// `CPAlertAction`will together
    /// determine the action's appearance.
    ///
    /// The action has a customizable title, style, and a block callback
    /// that is invoked when the user taps this button.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/carplay/cpalertaction?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct CPAlertAction;
);

extern_conformance!(
    unsafe impl NSCoding for CPAlertAction {}
);

extern_conformance!(
    unsafe impl NSObjectProtocol for CPAlertAction {}
);

extern_conformance!(
    unsafe impl NSSecureCoding for CPAlertAction {}
);

impl CPAlertAction {
    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>;

        #[cfg(feature = "block2")]
        /// Create an alert action with a title, display style, and a callback handler that is invoked
        /// when the user taps this action.
        ///
        /// # Safety
        ///
        /// `handler` must be a valid pointer.
        #[unsafe(method(initWithTitle:style:handler:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithTitle_style_handler(
            this: Allocated<Self>,
            title: &NSString,
            style: CPAlertActionStyle,
            handler: CPAlertActionHandler,
        ) -> Retained<Self>;

        #[cfg(all(feature = "block2", feature = "objc2-ui-kit"))]
        /// Create an alert action with a title, a custom action color, and a callback handler that is invoked
        /// when the user taps this action.
        ///
        /// The system will automatically determine if the provided color meets contrast requirements.
        /// If the provided color does not meet contrast requirements, the system default will be used.
        /// Font color will automatically be adjusted by the system to correspond with this color.
        /// Alpha values will be ignored.
        ///
        /// # Safety
        ///
        /// `handler` must be a valid pointer.
        #[unsafe(method(initWithTitle:color:handler:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithTitle_color_handler(
            this: Allocated<Self>,
            title: &NSString,
            color: &UIColor,
            handler: CPAlertActionHandler,
        ) -> Retained<Self>;

        #[unsafe(method(title))]
        #[unsafe(method_family = none)]
        pub unsafe fn title(&self) -> Retained<NSString>;

        #[unsafe(method(style))]
        #[unsafe(method_family = none)]
        pub unsafe fn style(&self) -> CPAlertActionStyle;

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

        #[cfg(feature = "objc2-ui-kit")]
        #[unsafe(method(color))]
        #[unsafe(method_family = none)]
        pub unsafe fn color(&self) -> Option<Retained<UIColor>>;
    );
}