objc2-car-play 0.3.2

Bindings to the CarPlay framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
#[cfg(feature = "dispatch2")]
use dispatch2::*;
use objc2::__framework_prelude::*;
#[cfg(feature = "objc2-core-foundation")]
use objc2_core_foundation::*;
use objc2_foundation::*;
#[cfg(feature = "objc2-ui-kit")]
use objc2_ui_kit::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/carplay/cplistitemaccessorytype?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CPListItemAccessoryType(pub NSInteger);
impl CPListItemAccessoryType {
    #[doc(alias = "CPListItemAccessoryTypeNone")]
    pub const None: Self = Self(0);
    #[doc(alias = "CPListItemAccessoryTypeDisclosureIndicator")]
    pub const DisclosureIndicator: Self = Self(1);
    #[doc(alias = "CPListItemAccessoryTypeCloud")]
    pub const Cloud: Self = Self(2);
}

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

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

/// [Apple's documentation](https://developer.apple.com/documentation/carplay/cplistitemplayingindicatorlocation?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CPListItemPlayingIndicatorLocation(pub NSInteger);
impl CPListItemPlayingIndicatorLocation {
    #[doc(alias = "CPListItemPlayingIndicatorLocationLeading")]
    pub const Leading: Self = Self(0);
    #[doc(alias = "CPListItemPlayingIndicatorLocationTrailing")]
    pub const Trailing: Self = Self(1);
}

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

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

extern_class!(
    /// `CPListItem`describes a single object appearing in a list template.
    /// Each
    /// `CPListItem`is displayed as a single cell in the list.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/carplay/cplistitem?language=objc)
    #[unsafe(super(NSObject))]
    #[thread_kind = MainThreadOnly]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct CPListItem;
);

#[cfg(feature = "CPListItemTypes")]
extern_conformance!(
    unsafe impl CPListTemplateItem for CPListItem {}
);

#[cfg(feature = "CPListItemTypes")]
extern_conformance!(
    unsafe impl CPSelectableListItem for CPListItem {}
);

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

impl CPListItem {
    extern_methods!(
        #[cfg(feature = "objc2-ui-kit")]
        /// Initialize a list item with text, detailtext, an image, an accessory type, and an accessory image.
        ///
        ///
        /// Note: The maximum size of the image is given by +[CPListItem maximumImageSize].
        ///
        /// When providing an image, your app should provide a
        /// `UIImage`that is display-ready. If necessary for the image, provide
        /// light and dark styles by using an asset from your asset catalog, prepared with light and dark styles
        /// or by using
        /// `UIImageAsset`to combine two
        /// `UIImage`instances into a single image with
        /// both styles.
        ///
        /// UIImageAsset is used to combine multiple UIImages with different trait collections into a single UIImage.
        ///
        /// If you specify an
        /// `accessoryImage,`your
        /// `accessoryType`will be set to
        /// `CPListItemAccessoryTypeNone.`
        /// To properly size your list images, your app should consider the display scale of the car screen.
        /// See -[CPInterfaceController carTraitCollection].
        #[unsafe(method(initWithText:detailText:image:accessoryImage:accessoryType:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithText_detailText_image_accessoryImage_accessoryType(
            this: Allocated<Self>,
            text: Option<&NSString>,
            detail_text: Option<&NSString>,
            image: Option<&UIImage>,
            accessory_image: Option<&UIImage>,
            accessory_type: CPListItemAccessoryType,
        ) -> Retained<Self>;

        #[cfg(feature = "objc2-ui-kit")]
        /// Initialize a list item with text, detail text, and an image.
        ///
        /// Your app should provide a
        /// `UIImage`that is display-ready, containing
        /// two
        /// `UIImageAssets,`corresponding to night and day mode.
        ///
        ///
        /// Note: The maximum size of the image is given by +[CPListItem maximumImageSize].
        ///
        /// When providing an image, your app should provide a
        /// `UIImage`that is display-ready. If necessary for the image, provide
        /// light and dark styles by using an asset from your asset catalog, prepared with light and dark styles
        /// or by using
        /// `UIImageAsset`to combine two
        /// `UIImage`instances into a single image with
        /// both styles.
        ///
        /// UIImageAsset is used to combine multiple UIImages with different trait collections into a single UIImage.
        ///
        ///
        /// To properly size your list images, your app should size them to the display scale of the car screen.
        /// See -[CPInterfaceController carTraitCollection].
        #[unsafe(method(initWithText:detailText:image:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithText_detailText_image(
            this: Allocated<Self>,
            text: Option<&NSString>,
            detail_text: Option<&NSString>,
            image: Option<&UIImage>,
        ) -> Retained<Self>;

        /// Initialize a list item with text and detail text.
        #[unsafe(method(initWithText:detailText:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithText_detailText(
            this: Allocated<Self>,
            text: Option<&NSString>,
            detail_text: Option<&NSString>,
        ) -> Retained<Self>;

        /// A Boolean value indicating whether the list item is enabled.
        ///
        ///
        /// Set the value of this property to
        /// `YES`to enable the list item 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);

        /// An accessory image type to display in the trailing portion of this list item.
        ///
        ///
        /// Note: If you specify a custom accessoryImage, it will take priority over one of the
        /// built-in accessory types specified here.
        #[unsafe(method(accessoryType))]
        #[unsafe(method_family = none)]
        pub unsafe fn accessoryType(&self) -> CPListItemAccessoryType;

        /// Setter for [`accessoryType`][Self::accessoryType].
        #[unsafe(method(setAccessoryType:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setAccessoryType(&self, accessory_type: CPListItemAccessoryType);

        /// If YES, a cell displaying this list item will render with an explicit indicator to the trailing edge of the text
        ///
        /// Defaults to NO.
        #[unsafe(method(isExplicitContent))]
        #[unsafe(method_family = none)]
        pub unsafe fn isExplicitContent(&self) -> bool;

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

        #[cfg(feature = "objc2-core-foundation")]
        /// Set a fractional value between 0 and 1 to display a progress bar on this list item.
        #[unsafe(method(playbackProgress))]
        #[unsafe(method_family = none)]
        pub unsafe fn playbackProgress(&self) -> CGFloat;

        #[cfg(feature = "objc2-core-foundation")]
        /// Setter for [`playbackProgress`][Self::playbackProgress].
        #[unsafe(method(setPlaybackProgress:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setPlaybackProgress(&self, playback_progress: CGFloat);

        /// Indicate that this list item represents content that is currently playing. This list item
        /// will render with an icon indicating that this item is playing.
        #[unsafe(method(isPlaying))]
        #[unsafe(method_family = none)]
        pub unsafe fn isPlaying(&self) -> bool;

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

        /// Specify the location in the list item for the now playing indicator.
        ///
        /// Defaults to CPListItemPlayingIndicatorLocationLeading.
        #[unsafe(method(playingIndicatorLocation))]
        #[unsafe(method_family = none)]
        pub unsafe fn playingIndicatorLocation(&self) -> CPListItemPlayingIndicatorLocation;

        /// Setter for [`playingIndicatorLocation`][Self::playingIndicatorLocation].
        #[unsafe(method(setPlayingIndicatorLocation:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setPlayingIndicatorLocation(
            &self,
            playing_indicator_location: CPListItemPlayingIndicatorLocation,
        );

        #[cfg(feature = "objc2-core-foundation")]
        /// The expected image size for your
        /// `CPListItem.`To properly size your list images, your app should size them to the display scale of the car screen.
        /// See -[CPInterfaceController carTraitCollection].
        #[unsafe(method(maximumImageSize))]
        #[unsafe(method_family = none)]
        pub unsafe fn maximumImageSize(mtm: MainThreadMarker) -> CGSize;

        /// Update the detail text in this list item, reloading this item in the table if needed.
        #[unsafe(method(setDetailText:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setDetailText(&self, detail_text: Option<&NSString>);

        #[cfg(feature = "objc2-ui-kit")]
        /// Update the image in this list item, reloading this item in the table if needed.
        ///
        /// When providing an image, your app should provide a
        /// `UIImage`that is display-ready. If necessary for the image, provide
        /// light and dark styles by using an asset from your asset catalog, prepared with light and dark styles
        /// or by using
        /// `UIImageAsset`to combine two
        /// `UIImage`instances into a single image with
        /// both styles.
        ///
        /// UIImageAsset is used to combine multiple UIImages with different trait collections into a single UIImage.
        #[unsafe(method(setImage:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setImage(&self, image: Option<&UIImage>);

        #[cfg(feature = "objc2-ui-kit")]
        /// Update the accessory image in this list item, reloading this item in the table if needed.
        ///
        /// When providing an image, your app should provide a
        /// `UIImage`that is display-ready. If necessary for the image, provide
        /// light and dark styles by using an asset from your asset catalog, prepared with light and dark styles
        /// or by using
        /// `UIImageAsset`to combine two
        /// `UIImage`instances into a single image with
        /// both styles.
        ///
        /// UIImageAsset is used to combine multiple UIImages with different trait collections into a single UIImage.
        #[unsafe(method(setAccessoryImage:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setAccessoryImage(&self, accessory_image: Option<&UIImage>);

        /// Assign a new text label to this list item, automatically reloading this item in its list template.
        #[unsafe(method(setText:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setText(&self, text: &NSString);

        #[cfg(all(feature = "CPListItemTypes", feature = "block2", feature = "dispatch2"))]
        /// An optional action block, fired when the user selects this item in a list template.
        ///
        /// You must call the completion block after processing the user's selection.
        ///
        /// # Safety
        ///
        /// - The returned block's argument 1 must be a valid pointer.
        /// - The returned block's argument 2 must be a valid pointer.
        #[unsafe(method(handler))]
        #[unsafe(method_family = none)]
        pub unsafe fn handler(
            &self,
        ) -> *mut block2::DynBlock<
            dyn Fn(NonNull<ProtocolObject<dyn CPSelectableListItem>>, dispatch_block_t),
        >;

        #[cfg(all(feature = "CPListItemTypes", feature = "block2", feature = "dispatch2"))]
        /// Setter for [`handler`][Self::handler].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setHandler(
            &self,
            handler: Option<
                &block2::DynBlock<
                    dyn Fn(NonNull<ProtocolObject<dyn CPSelectableListItem>>, dispatch_block_t),
                >,
            >,
        );

        /// The primary text shown in a cell displaying this list item.
        #[unsafe(method(text))]
        #[unsafe(method_family = none)]
        pub unsafe fn text(&self) -> Option<Retained<NSString>>;

        /// Any custom user info related to this item.
        #[unsafe(method(userInfo))]
        #[unsafe(method_family = none)]
        pub unsafe fn userInfo(&self) -> Option<Retained<AnyObject>>;

        /// Setter for [`userInfo`][Self::userInfo].
        ///
        /// # Safety
        ///
        /// `user_info` should be of the correct type.
        #[unsafe(method(setUserInfo:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setUserInfo(&self, user_info: Option<&AnyObject>);

        /// Any extra text displayed below the primary text in a cell displaying this list item.
        #[unsafe(method(detailText))]
        #[unsafe(method_family = none)]
        pub unsafe fn detailText(&self) -> Option<Retained<NSString>>;

        #[cfg(feature = "objc2-ui-kit")]
        /// An image displayed on the leading side of a cell displaying this list item.
        ///
        /// When providing an image, your app should provide a
        /// `UIImage`that is display-ready. If necessary for the image, provide
        /// light and dark styles by using an asset from your asset catalog, prepared with light and dark styles
        /// or by using
        /// `UIImageAsset`to combine two
        /// `UIImage`instances into a single image with
        /// both styles.
        ///
        /// UIImageAsset is used to combine multiple UIImages with different trait collections into a single UIImage.
        ///
        ///
        /// Animated images are not supported. If an animated image is assigned, only the first image will be used.
        /// To properly size your list images, your app should size them to the display scale of the car screen.
        /// See -[CPInterfaceController carTraitCollection].
        #[unsafe(method(image))]
        #[unsafe(method_family = none)]
        pub unsafe fn image(&self) -> Option<Retained<UIImage>>;

        #[cfg(feature = "objc2-ui-kit")]
        /// An image displayed on the trailing side of a cell displaying this list item.
        ///
        /// When providing an image, your app should provide a
        /// `UIImage`that is display-ready. If necessary for the image, provide
        /// light and dark styles by using an asset from your asset catalog, prepared with light and dark styles
        /// or by using
        /// `UIImageAsset`to combine two
        /// `UIImage`instances into a single image with
        /// both styles.
        ///
        /// UIImageAsset is used to combine multiple UIImages with different trait collections into a single UIImage.
        ///
        ///
        /// Animated images are not supported. If an animated image is assigned, only the first image will be used.
        ///
        ///
        /// Note: If set, this property takes precedence over the
        /// `accessoryType.`
        #[unsafe(method(accessoryImage))]
        #[unsafe(method_family = none)]
        pub unsafe fn accessoryImage(&self) -> Option<Retained<UIImage>>;

        /// If YES, a cell displaying this list item will render with a disclosure indicator
        /// in the trailing side of the cell.
        ///
        ///
        /// Note: If set, this property takes precedence over showsCloudLabel.
        ///
        /// Defaults to NO.
        #[deprecated]
        #[unsafe(method(showsDisclosureIndicator))]
        #[unsafe(method_family = none)]
        pub unsafe fn showsDisclosureIndicator(&self) -> bool;

        /// If YES, a cell displaying this list item will render with an explicit label to the trailing edge of the text
        ///
        /// Defaults to NO.
        #[deprecated]
        #[unsafe(method(showsExplicitLabel))]
        #[unsafe(method_family = none)]
        pub unsafe fn showsExplicitLabel(&self) -> bool;

        /// Setter for [`showsExplicitLabel`][Self::showsExplicitLabel].
        #[deprecated]
        #[unsafe(method(setShowsExplicitLabel:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setShowsExplicitLabel(&self, shows_explicit_label: bool);
    );
}

/// Methods declared on superclass `NSObject`.
impl CPListItem {
    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(mtm: MainThreadMarker) -> Retained<Self>;
    );
}

/// Deprecated.
impl CPListItem {
    extern_methods!(
        #[cfg(feature = "objc2-ui-kit")]
        /// Initialize a list item with text, detailtext, an image, and a disclosure indicator.
        ///
        ///
        /// Note: The maximum size of the image is given by +[CPListItem maximumImageSize].
        ///
        ///
        /// To properly size your list images, your app should size them to the display scale of the car screen.
        /// See -[CPInterfaceController carTraitCollection].
        #[deprecated]
        #[unsafe(method(initWithText:detailText:image:showsDisclosureIndicator:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithText_detailText_image_showsDisclosureIndicator(
            this: Allocated<Self>,
            text: Option<&NSString>,
            detail_text: Option<&NSString>,
            image: Option<&UIImage>,
            shows_disclosure_indicator: bool,
        ) -> Retained<Self>;
    );
}