objc2_car_play/generated/
CPBarButton.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7#[cfg(feature = "objc2-ui-kit")]
8use objc2_ui_kit::*;
9
10use crate::*;
11
12/// Specifies the style used to display a
13/// `CPBarButton.`
14///
15/// See also [Apple's documentation](https://developer.apple.com/documentation/carplay/cpbarbuttonstyle?language=objc)
16// NS_ENUM
17#[repr(transparent)]
18#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
19pub struct CPBarButtonStyle(pub NSInteger);
20impl CPBarButtonStyle {
21    #[doc(alias = "CPBarButtonStyleNone")]
22    pub const None: Self = Self(0);
23    #[doc(alias = "CPBarButtonStyleRounded")]
24    pub const Rounded: Self = Self(1);
25}
26
27unsafe impl Encode for CPBarButtonStyle {
28    const ENCODING: Encoding = NSInteger::ENCODING;
29}
30
31unsafe impl RefEncode for CPBarButtonStyle {
32    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
33}
34
35/// Specifies the type of a
36/// `CPBarButton.`
37///
38/// See also [Apple's documentation](https://developer.apple.com/documentation/carplay/cpbarbuttontype?language=objc)
39// NS_ENUM
40#[repr(transparent)]
41#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
42pub struct CPBarButtonType(pub NSUInteger);
43impl CPBarButtonType {
44    #[doc(alias = "CPBarButtonTypeText")]
45    pub const Text: Self = Self(0);
46    #[doc(alias = "CPBarButtonTypeImage")]
47    pub const Image: Self = Self(1);
48}
49
50unsafe impl Encode for CPBarButtonType {
51    const ENCODING: Encoding = NSUInteger::ENCODING;
52}
53
54unsafe impl RefEncode for CPBarButtonType {
55    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
56}
57
58/// [Apple's documentation](https://developer.apple.com/documentation/carplay/cpbarbuttonhandler?language=objc)
59#[cfg(feature = "block2")]
60pub type CPBarButtonHandler = *mut block2::DynBlock<dyn Fn(NonNull<CPBarButton>)>;
61
62extern_class!(
63    /// A button for placement in a navigation bar.
64    ///
65    /// See also [Apple's documentation](https://developer.apple.com/documentation/carplay/cpbarbutton?language=objc)
66    #[unsafe(super(NSObject))]
67    #[derive(Debug, PartialEq, Eq, Hash)]
68    pub struct CPBarButton;
69);
70
71extern_conformance!(
72    unsafe impl NSCoding for CPBarButton {}
73);
74
75extern_conformance!(
76    unsafe impl NSObjectProtocol for CPBarButton {}
77);
78
79extern_conformance!(
80    unsafe impl NSSecureCoding for CPBarButton {}
81);
82
83impl CPBarButton {
84    extern_methods!(
85        #[unsafe(method(new))]
86        #[unsafe(method_family = new)]
87        pub unsafe fn new() -> Retained<Self>;
88
89        #[unsafe(method(init))]
90        #[unsafe(method_family = init)]
91        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
92
93        #[cfg(all(feature = "block2", feature = "objc2-ui-kit"))]
94        /// Convenience initializer that creates a bar button that renders with an image.
95        ///
96        /// # Safety
97        ///
98        /// `handler` must be a valid pointer or null.
99        #[unsafe(method(initWithImage:handler:))]
100        #[unsafe(method_family = init)]
101        pub unsafe fn initWithImage_handler(
102            this: Allocated<Self>,
103            image: &UIImage,
104            handler: CPBarButtonHandler,
105        ) -> Retained<Self>;
106
107        #[cfg(feature = "block2")]
108        /// Convenience initializer that creates a bar button that displays a text label.
109        ///
110        /// # Safety
111        ///
112        /// `handler` must be a valid pointer or null.
113        #[unsafe(method(initWithTitle:handler:))]
114        #[unsafe(method_family = init)]
115        pub unsafe fn initWithTitle_handler(
116            this: Allocated<Self>,
117            title: &NSString,
118            handler: CPBarButtonHandler,
119        ) -> Retained<Self>;
120
121        /// A Boolean value indicating whether the button is enabled.
122        ///
123        ///
124        /// Set the value of this property to
125        /// `YES`to enable the button or
126        /// `NO`to disable it. The default value of this property is
127        /// `YES.`
128        #[unsafe(method(isEnabled))]
129        #[unsafe(method_family = none)]
130        pub unsafe fn isEnabled(&self) -> bool;
131
132        /// Setter for [`isEnabled`][Self::isEnabled].
133        #[unsafe(method(setEnabled:))]
134        #[unsafe(method_family = none)]
135        pub unsafe fn setEnabled(&self, enabled: bool);
136
137        /// The style used to display this button.
138        ///
139        /// Defaults to
140        /// `CPBarButtonStyleNone.`
141        #[unsafe(method(buttonStyle))]
142        #[unsafe(method_family = none)]
143        pub unsafe fn buttonStyle(&self) -> CPBarButtonStyle;
144
145        /// Setter for [`buttonStyle`][Self::buttonStyle].
146        #[unsafe(method(setButtonStyle:))]
147        #[unsafe(method_family = none)]
148        pub unsafe fn setButtonStyle(&self, button_style: CPBarButtonStyle);
149
150        #[cfg(feature = "objc2-ui-kit")]
151        /// The image displayed on the button.
152        ///
153        ///
154        /// Animated images are not supported. If an animated image is assigned, only the first image will be used.
155        ///
156        ///
157        /// Note: If both an image and title are specified, the title will take precedence.
158        /// To use an image, ensure that the button's title is nil.
159        #[unsafe(method(image))]
160        #[unsafe(method_family = none)]
161        pub unsafe fn image(&self) -> Option<Retained<UIImage>>;
162
163        #[cfg(feature = "objc2-ui-kit")]
164        /// Setter for [`image`][Self::image].
165        #[unsafe(method(setImage:))]
166        #[unsafe(method_family = none)]
167        pub unsafe fn setImage(&self, image: Option<&UIImage>);
168
169        /// The title displayed on the button.
170        ///
171        ///
172        /// Note: If both an image and title are specified, the title will take precedence.
173        /// To use an image, ensure that the button's title is nil.
174        #[unsafe(method(title))]
175        #[unsafe(method_family = none)]
176        pub unsafe fn title(&self) -> Option<Retained<NSString>>;
177
178        /// Setter for [`title`][Self::title].
179        ///
180        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
181        #[unsafe(method(setTitle:))]
182        #[unsafe(method_family = none)]
183        pub unsafe fn setTitle(&self, title: Option<&NSString>);
184
185        #[cfg(feature = "block2")]
186        /// # Safety
187        ///
188        /// `handler` must be a valid pointer or null.
189        #[deprecated]
190        #[unsafe(method(initWithType:handler:))]
191        #[unsafe(method_family = init)]
192        pub unsafe fn initWithType_handler(
193            this: Allocated<Self>,
194            r#type: CPBarButtonType,
195            handler: CPBarButtonHandler,
196        ) -> Retained<Self>;
197
198        #[deprecated]
199        #[unsafe(method(buttonType))]
200        #[unsafe(method_family = none)]
201        pub unsafe fn buttonType(&self) -> CPBarButtonType;
202    );
203}