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::*;

/// Specifies the style used to display a
/// `CPBarButton.`
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/carplay/cpbarbuttonstyle?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CPBarButtonStyle(pub NSInteger);
impl CPBarButtonStyle {
    #[doc(alias = "CPBarButtonStyleNone")]
    pub const None: Self = Self(0);
    #[doc(alias = "CPBarButtonStyleRounded")]
    pub const Rounded: Self = Self(1);
}

unsafe impl Encode for CPBarButtonStyle {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

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

/// Specifies the type of a
/// `CPBarButton.`
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/carplay/cpbarbuttontype?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CPBarButtonType(pub NSUInteger);
impl CPBarButtonType {
    #[doc(alias = "CPBarButtonTypeText")]
    pub const Text: Self = Self(0);
    #[doc(alias = "CPBarButtonTypeImage")]
    pub const Image: Self = Self(1);
}

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

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

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

extern_class!(
    /// A button for placement in a navigation bar.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/carplay/cpbarbutton?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct CPBarButton;
);

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

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

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

impl CPBarButton {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[cfg(all(feature = "block2", feature = "objc2-ui-kit"))]
        /// Convenience initializer that creates a bar button that renders with an image.
        ///
        /// # Safety
        ///
        /// `handler` must be a valid pointer or null.
        #[unsafe(method(initWithImage:handler:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithImage_handler(
            this: Allocated<Self>,
            image: &UIImage,
            handler: CPBarButtonHandler,
        ) -> Retained<Self>;

        #[cfg(feature = "block2")]
        /// Convenience initializer that creates a bar button that displays a text label.
        ///
        /// # Safety
        ///
        /// `handler` must be a valid pointer or null.
        #[unsafe(method(initWithTitle:handler:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithTitle_handler(
            this: Allocated<Self>,
            title: &NSString,
            handler: CPBarButtonHandler,
        ) -> Retained<Self>;

        /// A Boolean value indicating whether the button is enabled.
        ///
        ///
        /// Set the value of this property to
        /// `YES`to enable the button or
        /// `NO`to disable it. The default value of this property is
        /// `YES.`
        #[unsafe(method(isEnabled))]
        #[unsafe(method_family = none)]
        pub unsafe fn isEnabled(&self) -> bool;

        /// Setter for [`isEnabled`][Self::isEnabled].
        #[unsafe(method(setEnabled:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setEnabled(&self, enabled: bool);

        /// The style used to display this button.
        ///
        /// Defaults to
        /// `CPBarButtonStyleNone.`
        #[unsafe(method(buttonStyle))]
        #[unsafe(method_family = none)]
        pub unsafe fn buttonStyle(&self) -> CPBarButtonStyle;

        /// Setter for [`buttonStyle`][Self::buttonStyle].
        #[unsafe(method(setButtonStyle:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setButtonStyle(&self, button_style: CPBarButtonStyle);

        #[cfg(feature = "objc2-ui-kit")]
        /// The image displayed on the button.
        ///
        ///
        /// Animated images are not supported. If an animated image is assigned, only the first image will be used.
        ///
        ///
        /// Note: If both an image and title are specified, the title will take precedence.
        /// To use an image, ensure that the button's title is nil.
        #[unsafe(method(image))]
        #[unsafe(method_family = none)]
        pub unsafe fn image(&self) -> Option<Retained<UIImage>>;

        #[cfg(feature = "objc2-ui-kit")]
        /// Setter for [`image`][Self::image].
        #[unsafe(method(setImage:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setImage(&self, image: Option<&UIImage>);

        /// The title displayed on the button.
        ///
        ///
        /// Note: If both an image and title are specified, the title will take precedence.
        /// To use an image, ensure that the button's title is nil.
        #[unsafe(method(title))]
        #[unsafe(method_family = none)]
        pub unsafe fn title(&self) -> Option<Retained<NSString>>;

        /// Setter for [`title`][Self::title].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setTitle:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setTitle(&self, title: Option<&NSString>);

        #[cfg(feature = "block2")]
        /// # Safety
        ///
        /// `handler` must be a valid pointer or null.
        #[deprecated]
        #[unsafe(method(initWithType:handler:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithType_handler(
            this: Allocated<Self>,
            r#type: CPBarButtonType,
            handler: CPBarButtonHandler,
        ) -> Retained<Self>;

        #[deprecated]
        #[unsafe(method(buttonType))]
        #[unsafe(method_family = none)]
        pub unsafe fn buttonType(&self) -> CPBarButtonType;
    );
}