objc2-ui-kit 0.3.2

Bindings to the UIKit 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
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
//! 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::*;
#[cfg(feature = "objc2-core-foundation")]
use objc2_core_foundation::*;
use objc2_foundation::*;
#[cfg(feature = "objc2-quartz-core")]
#[cfg(not(target_os = "watchos"))]
use objc2_quartz_core::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/uikit/uisegmentedcontrolstyle?language=objc)
// NS_ENUM
#[deprecated = "The segmentedControlStyle property no longer has any effect"]
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct UISegmentedControlStyle(pub NSInteger);
impl UISegmentedControlStyle {
    #[doc(alias = "UISegmentedControlStylePlain")]
    #[deprecated = "The segmentedControlStyle property no longer has any effect"]
    pub const Plain: Self = Self(0);
    #[doc(alias = "UISegmentedControlStyleBordered")]
    #[deprecated = "The segmentedControlStyle property no longer has any effect"]
    pub const Bordered: Self = Self(1);
    #[doc(alias = "UISegmentedControlStyleBar")]
    #[deprecated = "The segmentedControlStyle property no longer has any effect"]
    pub const Bar: Self = Self(2);
    #[doc(alias = "UISegmentedControlStyleBezeled")]
    #[deprecated = "The segmentedControlStyle property no longer has any effect"]
    pub const Bezeled: Self = Self(3);
}

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

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

/// [Apple's documentation](https://developer.apple.com/documentation/uikit/uisegmentedcontrolnosegment?language=objc)
pub const UISegmentedControlNoSegment: c_int = -1;

/// [Apple's documentation](https://developer.apple.com/documentation/uikit/uisegmentedcontrolsegment?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct UISegmentedControlSegment(pub NSInteger);
impl UISegmentedControlSegment {
    #[doc(alias = "UISegmentedControlSegmentAny")]
    pub const Any: Self = Self(0);
    #[doc(alias = "UISegmentedControlSegmentLeft")]
    pub const Left: Self = Self(1);
    #[doc(alias = "UISegmentedControlSegmentCenter")]
    pub const Center: Self = Self(2);
    #[doc(alias = "UISegmentedControlSegmentRight")]
    pub const Right: Self = Self(3);
    #[doc(alias = "UISegmentedControlSegmentAlone")]
    pub const Alone: Self = Self(4);
}

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

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

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uisegmentedcontrol?language=objc)
    #[unsafe(super(UIControl, UIView, UIResponder, NSObject))]
    #[thread_kind = MainThreadOnly]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[cfg(all(feature = "UIControl", feature = "UIResponder", feature = "UIView"))]
    pub struct UISegmentedControl;
);

#[cfg(all(
    feature = "UIControl",
    feature = "UIResponder",
    feature = "UIView",
    feature = "objc2-quartz-core"
))]
#[cfg(not(target_os = "watchos"))]
extern_conformance!(
    unsafe impl CALayerDelegate for UISegmentedControl {}
);

#[cfg(all(feature = "UIControl", feature = "UIResponder", feature = "UIView"))]
extern_conformance!(
    unsafe impl NSCoding for UISegmentedControl {}
);

#[cfg(all(feature = "UIControl", feature = "UIResponder", feature = "UIView"))]
extern_conformance!(
    unsafe impl NSObjectProtocol for UISegmentedControl {}
);

#[cfg(all(
    feature = "UIAppearance",
    feature = "UIControl",
    feature = "UIResponder",
    feature = "UIView"
))]
extern_conformance!(
    unsafe impl UIAppearance for UISegmentedControl {}
);

#[cfg(all(
    feature = "UIAppearance",
    feature = "UIControl",
    feature = "UIResponder",
    feature = "UIView"
))]
extern_conformance!(
    unsafe impl UIAppearanceContainer for UISegmentedControl {}
);

#[cfg(all(feature = "UIControl", feature = "UIResponder", feature = "UIView"))]
extern_conformance!(
    unsafe impl UICoordinateSpace for UISegmentedControl {}
);

#[cfg(all(
    feature = "UIControl",
    feature = "UIDynamicBehavior",
    feature = "UIResponder",
    feature = "UIView"
))]
extern_conformance!(
    unsafe impl UIDynamicItem for UISegmentedControl {}
);

#[cfg(all(
    feature = "UIControl",
    feature = "UIFocus",
    feature = "UIResponder",
    feature = "UIView"
))]
extern_conformance!(
    unsafe impl UIFocusEnvironment for UISegmentedControl {}
);

#[cfg(all(
    feature = "UIControl",
    feature = "UIFocus",
    feature = "UIResponder",
    feature = "UIView"
))]
extern_conformance!(
    unsafe impl UIFocusItem for UISegmentedControl {}
);

#[cfg(all(
    feature = "UIControl",
    feature = "UIFocus",
    feature = "UIResponder",
    feature = "UIView"
))]
extern_conformance!(
    unsafe impl UIFocusItemContainer for UISegmentedControl {}
);

#[cfg(all(feature = "UIControl", feature = "UIResponder", feature = "UIView"))]
extern_conformance!(
    unsafe impl UIResponderStandardEditActions for UISegmentedControl {}
);

#[cfg(all(
    feature = "UIControl",
    feature = "UIResponder",
    feature = "UITraitCollection",
    feature = "UIView"
))]
extern_conformance!(
    unsafe impl UITraitEnvironment for UISegmentedControl {}
);

#[cfg(all(feature = "UIControl", feature = "UIResponder", feature = "UIView"))]
impl UISegmentedControl {
    extern_methods!(
        #[cfg(feature = "objc2-core-foundation")]
        #[unsafe(method(initWithFrame:))]
        #[unsafe(method_family = init)]
        pub fn initWithFrame(this: Allocated<Self>, frame: CGRect) -> Retained<Self>;

        /// # Safety
        ///
        /// `coder` possibly has further requirements.
        #[unsafe(method(initWithCoder:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithCoder(
            this: Allocated<Self>,
            coder: &NSCoder,
        ) -> Option<Retained<Self>>;

        /// Initializes the segmented control with the given items. Items may be NSStrings, UIImages, or (as of iOS 14.0) UIActions. When constructing from a UIAction segments will prefer images over titles when both are provided. The segmented control is automatically sized to fit content.
        ///
        /// # Safety
        ///
        /// `items` generic should be of the correct type.
        #[unsafe(method(initWithItems:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithItems(
            this: Allocated<Self>,
            items: Option<&NSArray>,
        ) -> Retained<Self>;

        #[cfg(all(
            feature = "UIAction",
            feature = "UIMenuElement",
            feature = "objc2-core-foundation"
        ))]
        /// Initializes the segmented control with the given frame and segments constructed from the given UIActions. Segments will prefer images over titles when both are provided. Selecting a segment calls UIAction.actionHandler as well as handlers for the ValueChanged and PrimaryActionTriggered control events.
        #[unsafe(method(initWithFrame:actions:))]
        #[unsafe(method_family = init)]
        pub fn initWithFrame_actions(
            this: Allocated<Self>,
            frame: CGRect,
            actions: &NSArray<UIAction>,
        ) -> Retained<Self>;

        #[cfg(all(feature = "UIAction", feature = "UIMenuElement"))]
        /// Insert a segment with the given action at the given index. Segments will prefer images over titles when both are provided. When the segment is selected UIAction.actionHandler is called. If a segment already exists with the action's identifier that segment will either be updated (if the index is the same) or it will be removed (if different).
        #[unsafe(method(insertSegmentWithAction:atIndex:animated:))]
        #[unsafe(method_family = none)]
        pub fn insertSegmentWithAction_atIndex_animated(
            &self,
            action: &UIAction,
            segment: NSUInteger,
            animated: bool,
        );

        #[cfg(all(feature = "UIAction", feature = "UIMenuElement"))]
        /// Reconfigures the given segment with this action. Segments will prefer images over titles when both are provided. When the segment is selected UIAction.actionHandler is called. UIAction.identifier must either match the action of the existing segment at this index, or be unique within all actions associated with the segmented control, or this method will assert.
        #[unsafe(method(setAction:forSegmentAtIndex:))]
        #[unsafe(method_family = none)]
        pub fn setAction_forSegmentAtIndex(&self, action: &UIAction, segment: NSUInteger);

        #[cfg(all(feature = "UIAction", feature = "UIMenuElement"))]
        /// Fetch the action for the given segment, if one has been assigned to that segment
        #[unsafe(method(actionForSegmentAtIndex:))]
        #[unsafe(method_family = none)]
        pub fn actionForSegmentAtIndex(&self, segment: NSUInteger) -> Option<Retained<UIAction>>;

        #[cfg(feature = "UIAction")]
        /// Returns the index of the segment associated with the given actionIdentifier, or NSNotFound if the identifier could not be found.
        #[unsafe(method(segmentIndexForActionIdentifier:))]
        #[unsafe(method_family = none)]
        pub fn segmentIndexForActionIdentifier(
            &self,
            action_identifier: &UIActionIdentifier,
        ) -> NSInteger;

        #[deprecated = "The segmentedControlStyle property no longer has any effect"]
        #[unsafe(method(segmentedControlStyle))]
        #[unsafe(method_family = none)]
        pub fn segmentedControlStyle(&self) -> UISegmentedControlStyle;

        /// Setter for [`segmentedControlStyle`][Self::segmentedControlStyle].
        #[deprecated = "The segmentedControlStyle property no longer has any effect"]
        #[unsafe(method(setSegmentedControlStyle:))]
        #[unsafe(method_family = none)]
        pub fn setSegmentedControlStyle(&self, segmented_control_style: UISegmentedControlStyle);

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

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

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

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

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

        #[unsafe(method(insertSegmentWithTitle:atIndex:animated:))]
        #[unsafe(method_family = none)]
        pub fn insertSegmentWithTitle_atIndex_animated(
            &self,
            title: Option<&NSString>,
            segment: NSUInteger,
            animated: bool,
        );

        #[cfg(feature = "UIImage")]
        #[unsafe(method(insertSegmentWithImage:atIndex:animated:))]
        #[unsafe(method_family = none)]
        pub fn insertSegmentWithImage_atIndex_animated(
            &self,
            image: Option<&UIImage>,
            segment: NSUInteger,
            animated: bool,
        );

        #[unsafe(method(removeSegmentAtIndex:animated:))]
        #[unsafe(method_family = none)]
        pub fn removeSegmentAtIndex_animated(&self, segment: NSUInteger, animated: bool);

        #[unsafe(method(removeAllSegments))]
        #[unsafe(method_family = none)]
        pub fn removeAllSegments(&self);

        #[unsafe(method(setTitle:forSegmentAtIndex:))]
        #[unsafe(method_family = none)]
        pub fn setTitle_forSegmentAtIndex(&self, title: Option<&NSString>, segment: NSUInteger);

        #[unsafe(method(titleForSegmentAtIndex:))]
        #[unsafe(method_family = none)]
        pub fn titleForSegmentAtIndex(&self, segment: NSUInteger) -> Option<Retained<NSString>>;

        #[cfg(feature = "UIImage")]
        #[unsafe(method(setImage:forSegmentAtIndex:))]
        #[unsafe(method_family = none)]
        pub fn setImage_forSegmentAtIndex(&self, image: Option<&UIImage>, segment: NSUInteger);

        #[cfg(feature = "UIImage")]
        #[unsafe(method(imageForSegmentAtIndex:))]
        #[unsafe(method_family = none)]
        pub fn imageForSegmentAtIndex(&self, segment: NSUInteger) -> Option<Retained<UIImage>>;

        #[cfg(feature = "objc2-core-foundation")]
        #[unsafe(method(setWidth:forSegmentAtIndex:))]
        #[unsafe(method_family = none)]
        pub fn setWidth_forSegmentAtIndex(&self, width: CGFloat, segment: NSUInteger);

        #[cfg(feature = "objc2-core-foundation")]
        #[unsafe(method(widthForSegmentAtIndex:))]
        #[unsafe(method_family = none)]
        pub fn widthForSegmentAtIndex(&self, segment: NSUInteger) -> CGFloat;

        #[cfg(feature = "objc2-core-foundation")]
        #[unsafe(method(setContentOffset:forSegmentAtIndex:))]
        #[unsafe(method_family = none)]
        pub fn setContentOffset_forSegmentAtIndex(&self, offset: CGSize, segment: NSUInteger);

        #[cfg(feature = "objc2-core-foundation")]
        #[unsafe(method(contentOffsetForSegmentAtIndex:))]
        #[unsafe(method_family = none)]
        pub fn contentOffsetForSegmentAtIndex(&self, segment: NSUInteger) -> CGSize;

        #[unsafe(method(setEnabled:forSegmentAtIndex:))]
        #[unsafe(method_family = none)]
        pub fn setEnabled_forSegmentAtIndex(&self, enabled: bool, segment: NSUInteger);

        #[unsafe(method(isEnabledForSegmentAtIndex:))]
        #[unsafe(method_family = none)]
        pub fn isEnabledForSegmentAtIndex(&self, segment: NSUInteger) -> bool;

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

        /// Setter for [`selectedSegmentIndex`][Self::selectedSegmentIndex].
        #[unsafe(method(setSelectedSegmentIndex:))]
        #[unsafe(method_family = none)]
        pub fn setSelectedSegmentIndex(&self, selected_segment_index: NSInteger);

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

        #[cfg(feature = "UIColor")]
        /// Setter for [`selectedSegmentTintColor`][Self::selectedSegmentTintColor].
        #[unsafe(method(setSelectedSegmentTintColor:))]
        #[unsafe(method_family = none)]
        pub fn setSelectedSegmentTintColor(&self, selected_segment_tint_color: Option<&UIColor>);

        #[cfg(all(feature = "UIBarCommon", feature = "UIImage"))]
        #[unsafe(method(setBackgroundImage:forState:barMetrics:))]
        #[unsafe(method_family = none)]
        pub fn setBackgroundImage_forState_barMetrics(
            &self,
            background_image: Option<&UIImage>,
            state: UIControlState,
            bar_metrics: UIBarMetrics,
        );

        #[cfg(all(feature = "UIBarCommon", feature = "UIImage"))]
        #[unsafe(method(backgroundImageForState:barMetrics:))]
        #[unsafe(method_family = none)]
        pub fn backgroundImageForState_barMetrics(
            &self,
            state: UIControlState,
            bar_metrics: UIBarMetrics,
        ) -> Option<Retained<UIImage>>;

        #[cfg(all(feature = "UIBarCommon", feature = "UIImage"))]
        #[unsafe(method(setDividerImage:forLeftSegmentState:rightSegmentState:barMetrics:))]
        #[unsafe(method_family = none)]
        pub fn setDividerImage_forLeftSegmentState_rightSegmentState_barMetrics(
            &self,
            divider_image: Option<&UIImage>,
            left_state: UIControlState,
            right_state: UIControlState,
            bar_metrics: UIBarMetrics,
        );

        #[cfg(all(feature = "UIBarCommon", feature = "UIImage"))]
        #[unsafe(method(dividerImageForLeftSegmentState:rightSegmentState:barMetrics:))]
        #[unsafe(method_family = none)]
        pub fn dividerImageForLeftSegmentState_rightSegmentState_barMetrics(
            &self,
            left_state: UIControlState,
            right_state: UIControlState,
            bar_metrics: UIBarMetrics,
        ) -> Option<Retained<UIImage>>;

        /// # Safety
        ///
        /// `attributes` generic should be of the correct type.
        #[unsafe(method(setTitleTextAttributes:forState:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setTitleTextAttributes_forState(
            &self,
            attributes: Option<&NSDictionary<NSAttributedStringKey, AnyObject>>,
            state: UIControlState,
        );

        #[unsafe(method(titleTextAttributesForState:))]
        #[unsafe(method_family = none)]
        pub fn titleTextAttributesForState(
            &self,
            state: UIControlState,
        ) -> Option<Retained<NSDictionary<NSAttributedStringKey, AnyObject>>>;

        #[cfg(all(
            feature = "UIBarCommon",
            feature = "UIGeometry",
            feature = "objc2-core-foundation"
        ))]
        #[unsafe(method(setContentPositionAdjustment:forSegmentType:barMetrics:))]
        #[unsafe(method_family = none)]
        pub fn setContentPositionAdjustment_forSegmentType_barMetrics(
            &self,
            adjustment: UIOffset,
            left_center_right_or_alone: UISegmentedControlSegment,
            bar_metrics: UIBarMetrics,
        );

        #[cfg(all(
            feature = "UIBarCommon",
            feature = "UIGeometry",
            feature = "objc2-core-foundation"
        ))]
        #[unsafe(method(contentPositionAdjustmentForSegmentType:barMetrics:))]
        #[unsafe(method_family = none)]
        pub fn contentPositionAdjustmentForSegmentType_barMetrics(
            &self,
            left_center_right_or_alone: UISegmentedControlSegment,
            bar_metrics: UIBarMetrics,
        ) -> UIOffset;
    );
}

/// Methods declared on superclass `UIControl`.
#[cfg(all(feature = "UIControl", feature = "UIResponder", feature = "UIView"))]
impl UISegmentedControl {
    extern_methods!(
        #[cfg(all(
            feature = "UIAction",
            feature = "UIMenuElement",
            feature = "objc2-core-foundation"
        ))]
        /// Initializes the control and adds primaryAction for the UIControlEventPrimaryActionTriggered control event. Subclasses of UIControl may alter or add behaviors around the usage of primaryAction, see subclass documentation of this initializer for additional information.
        #[unsafe(method(initWithFrame:primaryAction:))]
        #[unsafe(method_family = init)]
        pub fn initWithFrame_primaryAction(
            this: Allocated<Self>,
            frame: CGRect,
            primary_action: Option<&UIAction>,
        ) -> Retained<Self>;
    );
}

/// Methods declared on superclass `UIView`.
#[cfg(all(feature = "UIControl", feature = "UIResponder", feature = "UIView"))]
impl UISegmentedControl {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;
    );
}

/// Methods declared on superclass `NSObject`.
#[cfg(all(feature = "UIControl", feature = "UIResponder", feature = "UIView"))]
impl UISegmentedControl {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new(mtm: MainThreadMarker) -> Retained<Self>;
    );
}

/// SpringLoading.
#[cfg(all(feature = "UIControl", feature = "UIResponder", feature = "UIView"))]
impl UISegmentedControl {
    extern_methods!();
}

#[cfg(all(
    feature = "UIControl",
    feature = "UIResponder",
    feature = "UISpringLoadedInteractionSupporting",
    feature = "UIView"
))]
extern_conformance!(
    unsafe impl UISpringLoadedInteractionSupporting for UISegmentedControl {}
);