objc2_ui_kit/generated/
UIFocus.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::*;
6#[cfg(feature = "objc2-core-foundation")]
7use objc2_core_foundation::*;
8use objc2_foundation::*;
9
10use crate::*;
11
12/// [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocusheading?language=objc)
13// NS_OPTIONS
14#[repr(transparent)]
15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
16pub struct UIFocusHeading(pub NSUInteger);
17bitflags::bitflags! {
18    impl UIFocusHeading: NSUInteger {
19        #[doc(alias = "UIFocusHeadingNone")]
20        const None = 0;
21        #[doc(alias = "UIFocusHeadingUp")]
22        const Up = 1<<0;
23        #[doc(alias = "UIFocusHeadingDown")]
24        const Down = 1<<1;
25        #[doc(alias = "UIFocusHeadingLeft")]
26        const Left = 1<<2;
27        #[doc(alias = "UIFocusHeadingRight")]
28        const Right = 1<<3;
29        #[doc(alias = "UIFocusHeadingNext")]
30        const Next = 1<<4;
31        #[doc(alias = "UIFocusHeadingPrevious")]
32        const Previous = 1<<5;
33        #[doc(alias = "UIFocusHeadingFirst")]
34        const First = 1<<8;
35        #[doc(alias = "UIFocusHeadingLast")]
36        const Last = 1<<9;
37    }
38}
39
40unsafe impl Encode for UIFocusHeading {
41    const ENCODING: Encoding = NSUInteger::ENCODING;
42}
43
44unsafe impl RefEncode for UIFocusHeading {
45    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
46}
47
48/// [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocusitemdeferralmode?language=objc)
49// NS_ENUM
50#[repr(transparent)]
51#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
52pub struct UIFocusItemDeferralMode(pub NSInteger);
53impl UIFocusItemDeferralMode {
54    /// Use the system default behavior.
55    #[doc(alias = "UIFocusItemDeferralModeAutomatic")]
56    pub const Automatic: Self = Self(0);
57    /// Always defer focus for this item, even if deferral is disabled right now.
58    /// This means a programmatic update to this item would result in focus
59    /// disappearing until the user interacts with the focus engine again.
60    #[doc(alias = "UIFocusItemDeferralModeAlways")]
61    pub const Always: Self = Self(1);
62    /// Never defer focus for this item. When a programmatic focus update
63    /// lands on this item, it will always be and appear focused even if focus
64    /// deferral is currently enabled.
65    #[doc(alias = "UIFocusItemDeferralModeNever")]
66    pub const Never: Self = Self(2);
67}
68
69unsafe impl Encode for UIFocusItemDeferralMode {
70    const ENCODING: Encoding = NSInteger::ENCODING;
71}
72
73unsafe impl RefEncode for UIFocusItemDeferralMode {
74    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
75}
76
77/// [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocussoundidentifier?language=objc)
78// NS_TYPED_EXTENSIBLE_ENUM
79pub type UIFocusSoundIdentifier = NSString;
80
81/// These are focus group priorities that the system uses and that clients can use to make an item
82/// more or less important than these system states. Any priority below 0 will be ignored.
83///
84/// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocusgrouppriority?language=objc)
85// NS_TYPED_EXTENSIBLE_ENUM
86pub type UIFocusGroupPriority = NSInteger;
87
88/// [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocusgrouppriorityignored?language=objc)
89pub static UIFocusGroupPriorityIgnored: UIFocusGroupPriority = 0;
90
91/// [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocusgroupprioritypreviouslyfocused?language=objc)
92pub static UIFocusGroupPriorityPreviouslyFocused: UIFocusGroupPriority = 1000;
93
94/// [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocusgrouppriorityprioritized?language=objc)
95pub static UIFocusGroupPriorityPrioritized: UIFocusGroupPriority = 2000;
96
97/// [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocusgroupprioritycurrentlyfocused?language=objc)
98pub static UIFocusGroupPriorityCurrentlyFocused: UIFocusGroupPriority = NSIntegerMax as _;
99
100extern_protocol!(
101    /// Objects conforming to UIFocusEnvironment influence and respond to focus behavior within a specific area of the screen that they control.
102    ///
103    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocusenvironment?language=objc)
104    pub unsafe trait UIFocusEnvironment: NSObjectProtocol + MainThreadOnly {
105        /// The preferred focus environments define where to search for the default focused item in an environment, such as when focus updates programmatically.
106        /// Starting from the target environment, each preferred focus environment is recursively searched in the order of the array until an eligible, focusable item is found.
107        /// Preferred focus environments can include focusable and non-focusable items, in addition to non-item environments. Returning an empty array is equivalent to returning an array containing only 'self'.
108        #[unsafe(method(preferredFocusEnvironments))]
109        #[unsafe(method_family = none)]
110        fn preferredFocusEnvironments(
111            &self,
112        ) -> Retained<NSArray<ProtocolObject<dyn UIFocusEnvironment>>>;
113
114        /// The parent focus environment of this environment, or nil if no parent exists.
115        /// NOTE: If you implement this method, you must return a non-nil value for parent focus environment, otherwise your focus environment will not participate in focus interactions.
116        #[unsafe(method(parentFocusEnvironment))]
117        #[unsafe(method_family = none)]
118        fn parentFocusEnvironment(
119            &self,
120        ) -> Option<Retained<ProtocolObject<dyn UIFocusEnvironment>>>;
121
122        /// The container of any child focus items in this focus environment, or nil if no container exists.
123        #[unsafe(method(focusItemContainer))]
124        #[unsafe(method_family = none)]
125        fn focusItemContainer(&self) -> Option<Retained<ProtocolObject<dyn UIFocusItemContainer>>>;
126
127        /// Marks this environment as needing a focus update, which if accepted will attempt to reset focus to this environment, or one of its preferred focus environments, on the next update cycle. If this environment does not currently contain the focused item, then calling this method has no effect. If a parent of this environment is also requesting focus, then this environment's request is rejected in favor of the parent's.
128        /// NOTE: If you provide your own implementation, it must call `[[UIFocusSystem focusSystemForEnvironment:self] requestFocusUpdateToEnvironment:self]`;
129        #[unsafe(method(setNeedsFocusUpdate))]
130        #[unsafe(method_family = none)]
131        fn setNeedsFocusUpdate(&self);
132
133        /// Forces focus to be updated immediately. If there is an environment that has requested a focus update via -setNeedsFocusUpdate, and the request was accepted, then focus will be updated to that environment or one of its preferred focus environments.
134        /// NOTE: If you provide your own implementation, it must call `[[UIFocusSystem focusSystemForEnvironment:self] updateFocusIfNeeded];`.
135        #[unsafe(method(updateFocusIfNeeded))]
136        #[unsafe(method_family = none)]
137        fn updateFocusIfNeeded(&self);
138
139        /// Asks whether the system should allow a focus update to occur.
140        #[unsafe(method(shouldUpdateFocusInContext:))]
141        #[unsafe(method_family = none)]
142        fn shouldUpdateFocusInContext(&self, context: &UIFocusUpdateContext) -> bool;
143
144        #[cfg(feature = "UIFocusAnimationCoordinator")]
145        /// Called when the screen’s focused item has been updated to a new item. Use the animation coordinator to schedule focus-related animations in response to the update.
146        #[unsafe(method(didUpdateFocusInContext:withAnimationCoordinator:))]
147        #[unsafe(method_family = none)]
148        fn didUpdateFocusInContext_withAnimationCoordinator(
149            &self,
150            context: &UIFocusUpdateContext,
151            coordinator: &UIFocusAnimationCoordinator,
152        );
153
154        /// Specifies an identifier corresponding to a sound that should be played for a focus update.
155        /// Return UIFocusSoundIdentifierNone to opt out of sounds, UIFocusSoundIdentifierDefault for the system
156        /// default sounds, a previously registered identifier for a custom sound, or nil to defer the decision
157        /// to the parent.
158        #[optional]
159        #[unsafe(method(soundIdentifierForFocusUpdateInContext:))]
160        #[unsafe(method_family = none)]
161        fn soundIdentifierForFocusUpdateInContext(
162            &self,
163            context: &UIFocusUpdateContext,
164        ) -> Option<Retained<UIFocusSoundIdentifier>>;
165
166        #[cfg(all(feature = "UIResponder", feature = "UIView"))]
167        #[deprecated]
168        #[optional]
169        #[unsafe(method(preferredFocusedView))]
170        #[unsafe(method_family = none)]
171        fn preferredFocusedView(&self) -> Option<Retained<UIView>>;
172
173        /// The identifier of the focus group that this view belongs to. If this is nil, subviews inherit their superview's focus group.
174        #[optional]
175        #[unsafe(method(focusGroupIdentifier))]
176        #[unsafe(method_family = none)]
177        fn focusGroupIdentifier(&self) -> Option<Retained<NSString>>;
178    }
179);
180
181extern_protocol!(
182    /// Objects conforming to UIFocusItem are considered capable of participating in focus. Only UIFocusItems can ever be focused.
183    ///
184    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocusitem?language=objc)
185    pub unsafe trait UIFocusItem: UIFocusEnvironment + MainThreadOnly {
186        /// Indicates whether or not this item is currently allowed to become focused.
187        /// Returning NO restricts the item from being focusable, even if it is visible in the user interface. For example, UIControls return NO if they are disabled.
188        #[unsafe(method(canBecomeFocused))]
189        #[unsafe(method_family = none)]
190        fn canBecomeFocused(&self) -> bool;
191
192        #[cfg(feature = "objc2-core-foundation")]
193        /// The geometric frame of this item, represented in the `coordinateSpace` of the UIFocusItemContainer in which it is contained.
194        #[unsafe(method(frame))]
195        #[unsafe(method_family = none)]
196        fn frame(&self) -> CGRect;
197
198        #[cfg(feature = "UIFocusEffect")]
199        /// Describes a visual effect to apply when this item is focused. When not implemented, the system may create a default effect for this item.
200        /// Returning nil indicates that the system should not apply any visual effects, and that the app will handle applying the appropriate visuals.
201        #[optional]
202        #[unsafe(method(focusEffect))]
203        #[unsafe(method_family = none)]
204        fn focusEffect(&self) -> Option<Retained<UIFocusEffect>>;
205
206        /// The priority this item has in its focus group. The higher the priority, the more likely it is to get picked when focus moves into this group.
207        /// Note: this method can only be used to increase an item's priority, not decrease it. For example if an item is currently selected, the actual priority of this item will be determined by MAX(focusGroupPriority, UIFocusGroupPrioritySelected).
208        #[optional]
209        #[unsafe(method(focusGroupPriority))]
210        #[unsafe(method_family = none)]
211        fn focusGroupPriority(&self) -> UIFocusGroupPriority;
212
213        /// If this property is present and returns `UIFocusItemDeferralModeNever`, the focus deferral will not be enabled again
214        /// after the user engagement timeout has expired if this item is currently focused and programmatic focus updates pointing
215        /// to this item will be executed immediatly. If it returns `UIFocusItemDeferralModeAlways` focus will always be deferred
216        /// when this item is supposed to be focused.
217        /// Does nothing when focus deferral is not supported on the platform.
218        #[optional]
219        #[unsafe(method(focusItemDeferralMode))]
220        #[unsafe(method_family = none)]
221        fn focusItemDeferralMode(&self) -> UIFocusItemDeferralMode;
222
223        /// If this returns YES, the focus item is considered transparent in terms of occlusion. Items that are behind it are focusable.
224        /// This value is ignored when the item is focusable, in which case the item is never considered transparent.
225        #[optional]
226        #[unsafe(method(isTransparentFocusItem))]
227        #[unsafe(method_family = none)]
228        fn isTransparentFocusItem(&self) -> bool;
229
230        #[cfg(feature = "UIFocusMovementHint")]
231        /// Called whenever this focus item is hinting to the user a focus movement might occur.
232        /// The provided object is mutated by the focus engine whenever the user's finger moves.
233        #[optional]
234        #[unsafe(method(didHintFocusMovement:))]
235        #[unsafe(method_family = none)]
236        fn didHintFocusMovement(&self, hint: &UIFocusMovementHint);
237    }
238);
239
240extern_protocol!(
241    /// Objects conforming to UIFocusItemContainer are responsible for providing which focus items they
242    /// contain and where they are.
243    ///
244    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocusitemcontainer?language=objc)
245    pub unsafe trait UIFocusItemContainer: NSObjectProtocol + MainThreadOnly {
246        #[cfg(feature = "UIView")]
247        /// The coordinate space of the focus items contained in this container. The focus items returned by focusItemsInRect: should report their frames in this coordinate space.
248        /// If you are implementing this protocol, you may find it convenient to return the UIScreen as your coordinate space, and ensure that your contained items report their frames in screen space.
249        /// Similarly, you might find that your focus items' containing UIView or UIWindow is the most convenient coordinate space to use.
250        /// You may also choose to implement your own object that conforms to UICoordinateSpace, if that is the most natural solution for your architecture.
251        #[unsafe(method(coordinateSpace))]
252        #[unsafe(method_family = none)]
253        fn coordinateSpace(&self) -> Retained<ProtocolObject<dyn UICoordinateSpace>>;
254
255        #[cfg(feature = "objc2-core-foundation")]
256        /// Returns an array of all focus items within this container that intersect with the provided rect. `rect` is expressed in `coordinateSpace`.
257        /// Note: starting in iOS
258        /// &
259        /// tvOS 16.0, UIView will return its subviews from this method. If you override this method in a UIView subclass, it will be your responsibility to call super and merge your array of custom focus items with UIView's default focus items.
260        #[unsafe(method(focusItemsInRect:))]
261        #[unsafe(method_family = none)]
262        fn focusItemsInRect(
263            &self,
264            rect: CGRect,
265        ) -> Retained<NSArray<ProtocolObject<dyn UIFocusItem>>>;
266    }
267);
268
269extern_protocol!(
270    /// Objects conforming to UIFocusItemScrollableContainer are updated accordingly to ensure the
271    /// focused item remains visible on the screen.
272    ///
273    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocusitemscrollablecontainer?language=objc)
274    pub unsafe trait UIFocusItemScrollableContainer:
275        UIFocusItemContainer + MainThreadOnly
276    {
277        #[cfg(feature = "objc2-core-foundation")]
278        /// The current content offset of this scrollable container. If the scrollable container has a `bounds` property, `bounds.origin` must be equal to `contentOffset`.
279        #[unsafe(method(contentOffset))]
280        #[unsafe(method_family = none)]
281        fn contentOffset(&self) -> CGPoint;
282
283        #[cfg(feature = "objc2-core-foundation")]
284        /// Setter for [`contentOffset`][Self::contentOffset].
285        #[unsafe(method(setContentOffset:))]
286        #[unsafe(method_family = none)]
287        fn setContentOffset(&self, content_offset: CGPoint);
288
289        #[cfg(feature = "objc2-core-foundation")]
290        /// The total size of the content contained by this container. If this size exceeds the size of
291        /// this container's visible size, then scrolling is possible.
292        #[unsafe(method(contentSize))]
293        #[unsafe(method_family = none)]
294        fn contentSize(&self) -> CGSize;
295
296        #[cfg(feature = "objc2-core-foundation")]
297        /// The visible size of this scrollable container.
298        #[unsafe(method(visibleSize))]
299        #[unsafe(method_family = none)]
300        fn visibleSize(&self) -> CGSize;
301    }
302);
303
304extern_class!(
305    /// UIFocusUpdateContexts provide information relevant to a specific focus update from one view to another. They are ephemeral objects that are usually discarded after the update is finished.
306    ///
307    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocusupdatecontext?language=objc)
308    #[unsafe(super(NSObject))]
309    #[thread_kind = MainThreadOnly]
310    #[derive(Debug, PartialEq, Eq, Hash)]
311    pub struct UIFocusUpdateContext;
312);
313
314extern_conformance!(
315    unsafe impl NSObjectProtocol for UIFocusUpdateContext {}
316);
317
318impl UIFocusUpdateContext {
319    extern_methods!(
320        /// The item that was focused before the update, i.e. where focus is updating from. May be nil if no item was focused, such as when focus is initially set.
321        #[unsafe(method(previouslyFocusedItem))]
322        #[unsafe(method_family = none)]
323        pub fn previouslyFocusedItem(&self) -> Option<Retained<ProtocolObject<dyn UIFocusItem>>>;
324
325        /// The item that is focused after the update, i.e. where focus is updating to. May be nil if no item is being focused, meaning focus is being lost.
326        #[unsafe(method(nextFocusedItem))]
327        #[unsafe(method_family = none)]
328        pub fn nextFocusedItem(&self) -> Option<Retained<ProtocolObject<dyn UIFocusItem>>>;
329
330        /// The focus heading in which the update is occurring.
331        #[unsafe(method(focusHeading))]
332        #[unsafe(method_family = none)]
333        pub fn focusHeading(&self) -> UIFocusHeading;
334    );
335}
336
337/// Methods declared on superclass `NSObject`.
338impl UIFocusUpdateContext {
339    extern_methods!(
340        #[unsafe(method(init))]
341        #[unsafe(method_family = init)]
342        pub fn init(this: Allocated<Self>) -> Retained<Self>;
343
344        #[unsafe(method(new))]
345        #[unsafe(method_family = new)]
346        pub fn new(mtm: MainThreadMarker) -> Retained<Self>;
347    );
348}
349
350extern "C" {
351    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocusdidupdatenotification?language=objc)
352    pub static UIFocusDidUpdateNotification: &'static NSNotificationName;
353}
354
355extern "C" {
356    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocusmovementdidfailnotification?language=objc)
357    pub static UIFocusMovementDidFailNotification: &'static NSNotificationName;
358}
359
360extern "C" {
361    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocusupdatecontextkey?language=objc)
362    pub static UIFocusUpdateContextKey: &'static NSString;
363}
364
365extern "C" {
366    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocusupdateanimationcoordinatorkey?language=objc)
367    pub static UIFocusUpdateAnimationCoordinatorKey: &'static NSString;
368}
369
370extern "C" {
371    /// Sound identifier for disabling sound during a focus update.
372    ///
373    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocussoundidentifiernone?language=objc)
374    pub static UIFocusSoundIdentifierNone: &'static UIFocusSoundIdentifier;
375}
376
377extern "C" {
378    /// Sound identifier for playing the default sound during a focus update.
379    ///
380    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocussoundidentifierdefault?language=objc)
381    pub static UIFocusSoundIdentifierDefault: &'static UIFocusSoundIdentifier;
382}