objc2-app-kit 0.3.2

Bindings to the AppKit 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
//! 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::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsstackviewgravity?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSStackViewGravity(pub NSInteger);
impl NSStackViewGravity {
    #[doc(alias = "NSStackViewGravityTop")]
    pub const Top: Self = Self(1);
    #[doc(alias = "NSStackViewGravityLeading")]
    pub const Leading: Self = Self(1);
    #[doc(alias = "NSStackViewGravityCenter")]
    pub const Center: Self = Self(2);
    #[doc(alias = "NSStackViewGravityBottom")]
    pub const Bottom: Self = Self(3);
    #[doc(alias = "NSStackViewGravityTrailing")]
    pub const Trailing: Self = Self(3);
}

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

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

/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsstackviewdistribution?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSStackViewDistribution(pub NSInteger);
impl NSStackViewDistribution {
    /// Default value. NSStackView will not have any special distribution behavior, relying on behavior described by gravity areas and set hugging priorities along the stacking axis.
    #[doc(alias = "NSStackViewDistributionGravityAreas")]
    pub const GravityAreas: Self = Self(-1);
    /// The effective hugging priority in the stacking axis is NSLayoutPriorityRequired, causing the stacked views to tightly fill the container along the stacking axis.
    #[doc(alias = "NSStackViewDistributionFill")]
    pub const Fill: Self = Self(0);
    /// Stacked views will have sizes maintained to be equal as much as possible along the stacking axis. The effective hugging priority in the stacking axis is NSLayoutPriorityRequired.
    #[doc(alias = "NSStackViewDistributionFillEqually")]
    pub const FillEqually: Self = Self(1);
    /// Stacked views will have sizes maintained to be equal, proportionally to their intrinsicContentSizes, as much as possible. The effective hugging priority in the stacking axis is NSLayoutPriorityRequired.
    #[doc(alias = "NSStackViewDistributionFillProportionally")]
    pub const FillProportionally: Self = Self(2);
    /// The space separating stacked views along the stacking axis are maintained to be equal as much as possible while still maintaining the minimum spacing.
    #[doc(alias = "NSStackViewDistributionEqualSpacing")]
    pub const EqualSpacing: Self = Self(3);
    /// Equal center-to-center spacing of the items is maintained as much as possible while still maintaining the minimum spacing between each view.
    #[doc(alias = "NSStackViewDistributionEqualCentering")]
    pub const EqualCentering: Self = Self(4);
}

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

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

/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsstackviewvisibilitypriority?language=objc)
// NS_TYPED_EXTENSIBLE_ENUM
pub type NSStackViewVisibilityPriority = c_float;

/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsstackviewvisibilityprioritymusthold?language=objc)
pub static NSStackViewVisibilityPriorityMustHold: NSStackViewVisibilityPriority = 1000 as _;

/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsstackviewvisibilityprioritydetachonlyifnecessary?language=objc)
pub static NSStackViewVisibilityPriorityDetachOnlyIfNecessary: NSStackViewVisibilityPriority =
    900 as _;

/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsstackviewvisibilityprioritynotvisible?language=objc)
pub static NSStackViewVisibilityPriorityNotVisible: NSStackViewVisibilityPriority = 0 as _;

/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsstackviewspacingusedefault?language=objc)
#[cfg(feature = "objc2-core-foundation")]
pub static NSStackViewSpacingUseDefault: CGFloat = c_float::MAX as _;

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsstackview?language=objc)
    #[unsafe(super(NSView, NSResponder, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[cfg(all(feature = "NSResponder", feature = "NSView"))]
    pub struct NSStackView;
);

#[cfg(all(
    feature = "NSAccessibilityProtocols",
    feature = "NSResponder",
    feature = "NSView"
))]
extern_conformance!(
    unsafe impl NSAccessibility for NSStackView {}
);

#[cfg(all(
    feature = "NSAccessibilityProtocols",
    feature = "NSResponder",
    feature = "NSView"
))]
extern_conformance!(
    unsafe impl NSAccessibilityElementProtocol for NSStackView {}
);

#[cfg(all(feature = "NSAnimation", feature = "NSResponder", feature = "NSView"))]
extern_conformance!(
    unsafe impl NSAnimatablePropertyContainer for NSStackView {}
);

#[cfg(all(feature = "NSAppearance", feature = "NSResponder", feature = "NSView"))]
extern_conformance!(
    unsafe impl NSAppearanceCustomization for NSStackView {}
);

#[cfg(all(feature = "NSResponder", feature = "NSView"))]
extern_conformance!(
    unsafe impl NSCoding for NSStackView {}
);

#[cfg(all(feature = "NSDragging", feature = "NSResponder", feature = "NSView"))]
extern_conformance!(
    unsafe impl NSDraggingDestination for NSStackView {}
);

#[cfg(all(feature = "NSResponder", feature = "NSView"))]
extern_conformance!(
    unsafe impl NSObjectProtocol for NSStackView {}
);

#[cfg(all(
    feature = "NSResponder",
    feature = "NSUserInterfaceItemIdentification",
    feature = "NSView"
))]
extern_conformance!(
    unsafe impl NSUserInterfaceItemIdentification for NSStackView {}
);

#[cfg(all(feature = "NSResponder", feature = "NSView"))]
impl NSStackView {
    extern_methods!(
        #[unsafe(method(stackViewWithViews:))]
        #[unsafe(method_family = none)]
        pub fn stackViewWithViews(views: &NSArray<NSView>, mtm: MainThreadMarker)
            -> Retained<Self>;

        #[unsafe(method(delegate))]
        #[unsafe(method_family = none)]
        pub fn delegate(&self) -> Option<Retained<ProtocolObject<dyn NSStackViewDelegate>>>;

        /// Setter for [`delegate`][Self::delegate].
        ///
        /// This is a [weak property][objc2::topics::weak_property].
        #[unsafe(method(setDelegate:))]
        #[unsafe(method_family = none)]
        pub fn setDelegate(&self, delegate: Option<&ProtocolObject<dyn NSStackViewDelegate>>);

        #[cfg(feature = "NSUserInterfaceLayout")]
        /// Orientation of the StackView, defaults to NSUserInterfaceLayoutOrientationHorizontal
        #[unsafe(method(orientation))]
        #[unsafe(method_family = none)]
        pub fn orientation(&self) -> NSUserInterfaceLayoutOrientation;

        #[cfg(feature = "NSUserInterfaceLayout")]
        /// Setter for [`orientation`][Self::orientation].
        #[unsafe(method(setOrientation:))]
        #[unsafe(method_family = none)]
        pub fn setOrientation(&self, orientation: NSUserInterfaceLayoutOrientation);

        #[cfg(feature = "NSLayoutConstraint")]
        /// Describes how subviews are aligned within the StackView, defaults to `NSLayoutAttributeCenterY` for horizontal stacks, `NSLayoutAttributeCenterX` for vertical stacks. Setting `NSLayoutAttributeNotAnAttribute` will cause the internal alignment constraints to not be created, and could result in an ambiguous layout. Setting an inapplicable attribute for the set orientation will result in the alignment being ignored (similar to its handling with NSLayoutAttributeNotAnAttribute). The alignment constraints are established at a priority of `NSLayoutPriorityDefaultLow` and are overridable for individual views using external constraints.
        #[unsafe(method(alignment))]
        #[unsafe(method_family = none)]
        pub fn alignment(&self) -> NSLayoutAttribute;

        #[cfg(feature = "NSLayoutConstraint")]
        /// Setter for [`alignment`][Self::alignment].
        #[unsafe(method(setAlignment:))]
        #[unsafe(method_family = none)]
        pub fn setAlignment(&self, alignment: NSLayoutAttribute);

        /// Default padding inside the StackView, around all of the subviews.
        #[unsafe(method(edgeInsets))]
        #[unsafe(method_family = none)]
        pub fn edgeInsets(&self) -> NSEdgeInsets;

        /// Setter for [`edgeInsets`][Self::edgeInsets].
        #[unsafe(method(setEdgeInsets:))]
        #[unsafe(method_family = none)]
        pub fn setEdgeInsets(&self, edge_insets: NSEdgeInsets);

        /// The spacing and sizing distribution of stacked views along the primary axis. Defaults to GravityAreas.
        #[unsafe(method(distribution))]
        #[unsafe(method_family = none)]
        pub fn distribution(&self) -> NSStackViewDistribution;

        /// Setter for [`distribution`][Self::distribution].
        #[unsafe(method(setDistribution:))]
        #[unsafe(method_family = none)]
        pub fn setDistribution(&self, distribution: NSStackViewDistribution);

        #[cfg(feature = "objc2-core-foundation")]
        /// Default (minimum) spacing between each view
        #[unsafe(method(spacing))]
        #[unsafe(method_family = none)]
        pub fn spacing(&self) -> CGFloat;

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

        #[cfg(feature = "objc2-core-foundation")]
        #[unsafe(method(setCustomSpacing:afterView:))]
        #[unsafe(method_family = none)]
        pub fn setCustomSpacing_afterView(&self, spacing: CGFloat, view: &NSView);

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

        /// If YES, when a stacked view's `hidden` property is set to YES, the view will be detached from the stack and reattached when set to NO. Similarly, if the view has a lowered visibility priority and is detached from the stack view, it will be set as `hidden` rather than removed from the view hierarchy. Defaults to YES for apps linked on the 10.11 SDK or later.
        #[unsafe(method(detachesHiddenViews))]
        #[unsafe(method_family = none)]
        pub fn detachesHiddenViews(&self) -> bool;

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

        /// The list of views that are arranged in a stack by the receiver. They are a subset of
        /// `-subviews,`with potential difference in ordering.
        #[unsafe(method(arrangedSubviews))]
        #[unsafe(method_family = none)]
        pub fn arrangedSubviews(&self) -> Retained<NSArray<NSView>>;

        /// Adds a view to the end of the arrangedSubviews list. If the view is not a subview of the receiver, it will be added as one.
        #[unsafe(method(addArrangedSubview:))]
        #[unsafe(method_family = none)]
        pub fn addArrangedSubview(&self, view: &NSView);

        /// Adds a view to the arrangedSubviews list at a specific index.
        /// If the view is already in the arrangedSubviews list, it will move the view to the specified index (but not change the subview index).
        /// If the view is not a subview of the receiver, it will be added as one (not necessarily at the same index).
        #[unsafe(method(insertArrangedSubview:atIndex:))]
        #[unsafe(method_family = none)]
        pub fn insertArrangedSubview_atIndex(&self, view: &NSView, index: NSInteger);

        /// Removes a subview from the list of arranged subviews without removing it as a subview of the receiver.
        /// Removing the view as a subview (either by -[view removeFromSuperview] or setting the receiver's subviews) will automatically remove it as an arranged subview.
        #[unsafe(method(removeArrangedSubview:))]
        #[unsafe(method_family = none)]
        pub fn removeArrangedSubview(&self, view: &NSView);

        /// The arrangedSubviews that are currently detached/hidden.
        #[unsafe(method(detachedViews))]
        #[unsafe(method_family = none)]
        pub fn detachedViews(&self) -> Retained<NSArray<NSView>>;

        #[unsafe(method(setVisibilityPriority:forView:))]
        #[unsafe(method_family = none)]
        pub fn setVisibilityPriority_forView(
            &self,
            priority: NSStackViewVisibilityPriority,
            view: &NSView,
        );

        #[unsafe(method(visibilityPriorityForView:))]
        #[unsafe(method_family = none)]
        pub fn visibilityPriorityForView(&self, view: &NSView) -> NSStackViewVisibilityPriority;

        #[cfg(feature = "NSLayoutConstraint")]
        #[unsafe(method(clippingResistancePriorityForOrientation:))]
        #[unsafe(method_family = none)]
        pub fn clippingResistancePriorityForOrientation(
            &self,
            orientation: NSLayoutConstraintOrientation,
        ) -> NSLayoutPriority;

        #[cfg(feature = "NSLayoutConstraint")]
        #[unsafe(method(setClippingResistancePriority:forOrientation:))]
        #[unsafe(method_family = none)]
        pub fn setClippingResistancePriority_forOrientation(
            &self,
            clipping_resistance_priority: NSLayoutPriority,
            orientation: NSLayoutConstraintOrientation,
        );

        #[cfg(feature = "NSLayoutConstraint")]
        #[unsafe(method(huggingPriorityForOrientation:))]
        #[unsafe(method_family = none)]
        pub fn huggingPriorityForOrientation(
            &self,
            orientation: NSLayoutConstraintOrientation,
        ) -> NSLayoutPriority;

        #[cfg(feature = "NSLayoutConstraint")]
        #[unsafe(method(setHuggingPriority:forOrientation:))]
        #[unsafe(method_family = none)]
        pub fn setHuggingPriority_forOrientation(
            &self,
            hugging_priority: NSLayoutPriority,
            orientation: NSLayoutConstraintOrientation,
        );
    );
}

/// Methods declared on superclass `NSView`.
#[cfg(all(feature = "NSResponder", feature = "NSView"))]
impl NSStackView {
    extern_methods!(
        #[unsafe(method(initWithFrame:))]
        #[unsafe(method_family = init)]
        pub fn initWithFrame(this: Allocated<Self>, frame_rect: NSRect) -> 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>>;
    );
}

/// Methods declared on superclass `NSResponder`.
#[cfg(all(feature = "NSResponder", feature = "NSView"))]
impl NSStackView {
    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 = "NSResponder", feature = "NSView"))]
impl NSStackView {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new(mtm: MainThreadMarker) -> Retained<Self>;
    );
}

extern_protocol!(
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsstackviewdelegate?language=objc)
    pub unsafe trait NSStackViewDelegate: NSObjectProtocol + MainThreadOnly {
        #[cfg(all(feature = "NSResponder", feature = "NSView"))]
        #[optional]
        #[unsafe(method(stackView:willDetachViews:))]
        #[unsafe(method_family = none)]
        fn stackView_willDetachViews(&self, stack_view: &NSStackView, views: &NSArray<NSView>);

        #[cfg(all(feature = "NSResponder", feature = "NSView"))]
        #[optional]
        #[unsafe(method(stackView:didReattachViews:))]
        #[unsafe(method_family = none)]
        fn stackView_didReattachViews(&self, stack_view: &NSStackView, views: &NSArray<NSView>);
    }
);

/// NSStackViewGravityAreas.
#[cfg(all(feature = "NSResponder", feature = "NSView"))]
impl NSStackView {
    extern_methods!(
        #[unsafe(method(addView:inGravity:))]
        #[unsafe(method_family = none)]
        pub fn addView_inGravity(&self, view: &NSView, gravity: NSStackViewGravity);

        #[unsafe(method(insertView:atIndex:inGravity:))]
        #[unsafe(method_family = none)]
        pub fn insertView_atIndex_inGravity(
            &self,
            view: &NSView,
            index: NSUInteger,
            gravity: NSStackViewGravity,
        );

        #[unsafe(method(removeView:))]
        #[unsafe(method_family = none)]
        pub fn removeView(&self, view: &NSView);

        #[unsafe(method(viewsInGravity:))]
        #[unsafe(method_family = none)]
        pub fn viewsInGravity(&self, gravity: NSStackViewGravity) -> Retained<NSArray<NSView>>;

        #[unsafe(method(setViews:inGravity:))]
        #[unsafe(method_family = none)]
        pub fn setViews_inGravity(&self, views: &NSArray<NSView>, gravity: NSStackViewGravity);

        #[unsafe(method(views))]
        #[unsafe(method_family = none)]
        pub fn views(&self) -> Retained<NSArray<NSView>>;
    );
}

/// NSStackViewDeprecated.
#[cfg(all(feature = "NSResponder", feature = "NSView"))]
impl NSStackView {
    extern_methods!(
        #[deprecated = "Set -distribution to NSStackViewDistributionEqualSpacing instead."]
        #[unsafe(method(hasEqualSpacing))]
        #[unsafe(method_family = none)]
        pub fn hasEqualSpacing(&self) -> bool;

        /// Setter for [`hasEqualSpacing`][Self::hasEqualSpacing].
        #[deprecated = "Set -distribution to NSStackViewDistributionEqualSpacing instead."]
        #[unsafe(method(setHasEqualSpacing:))]
        #[unsafe(method_family = none)]
        pub fn setHasEqualSpacing(&self, has_equal_spacing: bool);
    );
}