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 unsafe 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 unsafe 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 unsafe fn focusItemContainer(
126 &self,
127 ) -> Option<Retained<ProtocolObject<dyn UIFocusItemContainer>>>;
128
129 /// 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.
130 /// NOTE: If you provide your own implementation, it must call `[[UIFocusSystem focusSystemForEnvironment:self] requestFocusUpdateToEnvironment:self]`;
131 #[unsafe(method(setNeedsFocusUpdate))]
132 #[unsafe(method_family = none)]
133 unsafe fn setNeedsFocusUpdate(&self);
134
135 /// 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.
136 /// NOTE: If you provide your own implementation, it must call `[[UIFocusSystem focusSystemForEnvironment:self] updateFocusIfNeeded];`.
137 #[unsafe(method(updateFocusIfNeeded))]
138 #[unsafe(method_family = none)]
139 unsafe fn updateFocusIfNeeded(&self);
140
141 /// Asks whether the system should allow a focus update to occur.
142 #[unsafe(method(shouldUpdateFocusInContext:))]
143 #[unsafe(method_family = none)]
144 unsafe fn shouldUpdateFocusInContext(&self, context: &UIFocusUpdateContext) -> bool;
145
146 #[cfg(feature = "UIFocusAnimationCoordinator")]
147 /// 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.
148 #[unsafe(method(didUpdateFocusInContext:withAnimationCoordinator:))]
149 #[unsafe(method_family = none)]
150 unsafe fn didUpdateFocusInContext_withAnimationCoordinator(
151 &self,
152 context: &UIFocusUpdateContext,
153 coordinator: &UIFocusAnimationCoordinator,
154 );
155
156 /// Specifies an identifier corresponding to a sound that should be played for a focus update.
157 /// Return UIFocusSoundIdentifierNone to opt out of sounds, UIFocusSoundIdentifierDefault for the system
158 /// default sounds, a previously registered identifier for a custom sound, or nil to defer the decision
159 /// to the parent.
160 #[optional]
161 #[unsafe(method(soundIdentifierForFocusUpdateInContext:))]
162 #[unsafe(method_family = none)]
163 unsafe fn soundIdentifierForFocusUpdateInContext(
164 &self,
165 context: &UIFocusUpdateContext,
166 ) -> Option<Retained<UIFocusSoundIdentifier>>;
167
168 #[cfg(all(feature = "UIResponder", feature = "UIView"))]
169 #[deprecated]
170 #[optional]
171 #[unsafe(method(preferredFocusedView))]
172 #[unsafe(method_family = none)]
173 unsafe fn preferredFocusedView(&self) -> Option<Retained<UIView>>;
174
175 /// The identifier of the focus group that this view belongs to. If this is nil, subviews inherit their superview's focus group.
176 #[optional]
177 #[unsafe(method(focusGroupIdentifier))]
178 #[unsafe(method_family = none)]
179 unsafe fn focusGroupIdentifier(&self) -> Option<Retained<NSString>>;
180 }
181);
182
183extern_protocol!(
184 /// Objects conforming to UIFocusItem are considered capable of participating in focus. Only UIFocusItems can ever be focused.
185 ///
186 /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocusitem?language=objc)
187 pub unsafe trait UIFocusItem: UIFocusEnvironment + MainThreadOnly {
188 /// Indicates whether or not this item is currently allowed to become focused.
189 /// 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.
190 #[unsafe(method(canBecomeFocused))]
191 #[unsafe(method_family = none)]
192 unsafe fn canBecomeFocused(&self) -> bool;
193
194 #[cfg(feature = "objc2-core-foundation")]
195 /// The geometric frame of this item, represented in the `coordinateSpace` of the UIFocusItemContainer in which it is contained.
196 #[unsafe(method(frame))]
197 #[unsafe(method_family = none)]
198 unsafe fn frame(&self) -> CGRect;
199
200 #[cfg(feature = "UIFocusEffect")]
201 /// Describes a visual effect to apply when this item is focused. When not implemented, the system may create a default effect for this item.
202 /// Returning nil indicates that the system should not apply any visual effects, and that the app will handle applying the appropriate visuals.
203 #[optional]
204 #[unsafe(method(focusEffect))]
205 #[unsafe(method_family = none)]
206 unsafe fn focusEffect(&self) -> Option<Retained<UIFocusEffect>>;
207
208 /// 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.
209 /// 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).
210 #[optional]
211 #[unsafe(method(focusGroupPriority))]
212 #[unsafe(method_family = none)]
213 unsafe fn focusGroupPriority(&self) -> UIFocusGroupPriority;
214
215 /// If this property is present and returns `UIFocusItemDeferralModeNever`, the focus deferral will not be enabled again
216 /// after the user engagement timeout has expired if this item is currently focused and programmatic focus updates pointing
217 /// to this item will be executed immediatly. If it returns `UIFocusItemDeferralModeAlways` focus will always be deferred
218 /// when this item is supposed to be focused.
219 /// Does nothing when focus deferral is not supported on the platform.
220 #[optional]
221 #[unsafe(method(focusItemDeferralMode))]
222 #[unsafe(method_family = none)]
223 unsafe fn focusItemDeferralMode(&self) -> UIFocusItemDeferralMode;
224
225 /// If this returns YES, the focus item is considered transparent in terms of occlusion. Items that are behind it are focusable.
226 /// This value is ignored when the item is focusable, in which case the item is never considered transparent.
227 #[optional]
228 #[unsafe(method(isTransparentFocusItem))]
229 #[unsafe(method_family = none)]
230 unsafe fn isTransparentFocusItem(&self) -> bool;
231
232 #[cfg(feature = "UIFocusMovementHint")]
233 /// Called whenever this focus item is hinting to the user a focus movement might occur.
234 /// The provided object is mutated by the focus engine whenever the user's finger moves.
235 #[optional]
236 #[unsafe(method(didHintFocusMovement:))]
237 #[unsafe(method_family = none)]
238 unsafe fn didHintFocusMovement(&self, hint: &UIFocusMovementHint);
239 }
240);
241
242extern_protocol!(
243 /// Objects conforming to UIFocusItemContainer are responsible for providing which focus items they
244 /// contain and where they are.
245 ///
246 /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocusitemcontainer?language=objc)
247 pub unsafe trait UIFocusItemContainer: NSObjectProtocol + MainThreadOnly {
248 #[cfg(feature = "UIView")]
249 /// 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.
250 /// 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.
251 /// Similarly, you might find that your focus items' containing UIView or UIWindow is the most convenient coordinate space to use.
252 /// You may also choose to implement your own object that conforms to UICoordinateSpace, if that is the most natural solution for your architecture.
253 #[unsafe(method(coordinateSpace))]
254 #[unsafe(method_family = none)]
255 unsafe fn coordinateSpace(&self) -> Retained<ProtocolObject<dyn UICoordinateSpace>>;
256
257 #[cfg(feature = "objc2-core-foundation")]
258 /// Returns an array of all focus items within this container that intersect with the provided rect. `rect` is expressed in `coordinateSpace`.
259 /// Note: starting in iOS
260 /// &
261 /// 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.
262 #[unsafe(method(focusItemsInRect:))]
263 #[unsafe(method_family = none)]
264 unsafe fn focusItemsInRect(
265 &self,
266 rect: CGRect,
267 ) -> Retained<NSArray<ProtocolObject<dyn UIFocusItem>>>;
268 }
269);
270
271extern_protocol!(
272 /// Objects conforming to UIFocusItemScrollableContainer are updated accordingly to ensure the
273 /// focused item remains visible on the screen.
274 ///
275 /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocusitemscrollablecontainer?language=objc)
276 pub unsafe trait UIFocusItemScrollableContainer:
277 UIFocusItemContainer + MainThreadOnly
278 {
279 #[cfg(feature = "objc2-core-foundation")]
280 /// The current content offset of this scrollable container. If the scrollable container has a `bounds` property, `bounds.origin` must be equal to `contentOffset`.
281 #[unsafe(method(contentOffset))]
282 #[unsafe(method_family = none)]
283 unsafe fn contentOffset(&self) -> CGPoint;
284
285 #[cfg(feature = "objc2-core-foundation")]
286 /// Setter for [`contentOffset`][Self::contentOffset].
287 #[unsafe(method(setContentOffset:))]
288 #[unsafe(method_family = none)]
289 unsafe fn setContentOffset(&self, content_offset: CGPoint);
290
291 #[cfg(feature = "objc2-core-foundation")]
292 /// The total size of the content contained by this container. If this size exceeds the size of
293 /// this container's visible size, then scrolling is possible.
294 #[unsafe(method(contentSize))]
295 #[unsafe(method_family = none)]
296 unsafe fn contentSize(&self) -> CGSize;
297
298 #[cfg(feature = "objc2-core-foundation")]
299 /// The visible size of this scrollable container.
300 #[unsafe(method(visibleSize))]
301 #[unsafe(method_family = none)]
302 unsafe fn visibleSize(&self) -> CGSize;
303 }
304);
305
306extern_class!(
307 /// 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.
308 ///
309 /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocusupdatecontext?language=objc)
310 #[unsafe(super(NSObject))]
311 #[thread_kind = MainThreadOnly]
312 #[derive(Debug, PartialEq, Eq, Hash)]
313 pub struct UIFocusUpdateContext;
314);
315
316extern_conformance!(
317 unsafe impl NSObjectProtocol for UIFocusUpdateContext {}
318);
319
320impl UIFocusUpdateContext {
321 extern_methods!(
322 /// 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.
323 #[unsafe(method(previouslyFocusedItem))]
324 #[unsafe(method_family = none)]
325 pub unsafe fn previouslyFocusedItem(
326 &self,
327 ) -> Option<Retained<ProtocolObject<dyn UIFocusItem>>>;
328
329 /// 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.
330 #[unsafe(method(nextFocusedItem))]
331 #[unsafe(method_family = none)]
332 pub unsafe fn nextFocusedItem(&self) -> Option<Retained<ProtocolObject<dyn UIFocusItem>>>;
333
334 #[cfg(all(feature = "UIResponder", feature = "UIView"))]
335 /// The view that was focused before the update. May be nil if no view was focused, such as when setting initial focus.
336 /// If previouslyFocusedItem is not a view, this returns that item's containing view, otherwise they are equal.
337 /// NOTE: This property will be deprecated in a future release. Use previouslyFocusedItem instead.
338 #[unsafe(method(previouslyFocusedView))]
339 #[unsafe(method_family = none)]
340 pub unsafe fn previouslyFocusedView(&self) -> Option<Retained<UIView>>;
341
342 #[cfg(all(feature = "UIResponder", feature = "UIView"))]
343 /// The view that will be focused after the update. May be nil if no view will be focused.
344 /// If nextFocusedItem is not a view, this returns that item's containing view, otherwise they are equal.
345 /// NOTE: This property will be deprecated in a future release. Use nextFocusedItem instead.
346 #[unsafe(method(nextFocusedView))]
347 #[unsafe(method_family = none)]
348 pub unsafe fn nextFocusedView(&self) -> Option<Retained<UIView>>;
349
350 /// The focus heading in which the update is occurring.
351 #[unsafe(method(focusHeading))]
352 #[unsafe(method_family = none)]
353 pub unsafe fn focusHeading(&self) -> UIFocusHeading;
354 );
355}
356
357/// Methods declared on superclass `NSObject`.
358impl UIFocusUpdateContext {
359 extern_methods!(
360 #[unsafe(method(init))]
361 #[unsafe(method_family = init)]
362 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
363
364 #[unsafe(method(new))]
365 #[unsafe(method_family = new)]
366 pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
367 );
368}
369
370extern "C" {
371 /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocusdidupdatenotification?language=objc)
372 pub static UIFocusDidUpdateNotification: &'static NSNotificationName;
373}
374
375extern "C" {
376 /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocusmovementdidfailnotification?language=objc)
377 pub static UIFocusMovementDidFailNotification: &'static NSNotificationName;
378}
379
380extern "C" {
381 /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocusupdatecontextkey?language=objc)
382 pub static UIFocusUpdateContextKey: &'static NSString;
383}
384
385extern "C" {
386 /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocusupdateanimationcoordinatorkey?language=objc)
387 pub static UIFocusUpdateAnimationCoordinatorKey: &'static NSString;
388}
389
390extern "C" {
391 /// Sound identifier for disabling sound during a focus update.
392 ///
393 /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocussoundidentifiernone?language=objc)
394 pub static UIFocusSoundIdentifierNone: &'static UIFocusSoundIdentifier;
395}
396
397extern "C" {
398 /// Sound identifier for playing the default sound during a focus update.
399 ///
400 /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uifocussoundidentifierdefault?language=objc)
401 pub static UIFocusSoundIdentifierDefault: &'static UIFocusSoundIdentifier;
402}