objc2_ui_kit/generated/
UIIndirectScribbleInteraction.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
12extern_class!(
13    /// An interaction that allows using Scribble to enter text by handwriting on a view that is not formally a text input. Use UIIndirectScribbleInteraction if your app has a view that looks to the user as a text input but does not implement UITextInput. It makes the view act as a container of one or more virtual "Text Input Elements", each of which defines an area the user can write into without having to tap first.
14    /// Some examples of when UIIndirectScribbleInteraction can be used:
15    /// - A view that looks like a search field or a text field that in reality is a button, but installs a real text field when tapped
16    /// - A view that contains multiple virtual text fields which the user can normally tap and type into, but are not full blown text fields all the time
17    ///
18    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uiindirectscribbleinteraction?language=objc)
19    #[unsafe(super(NSObject))]
20    #[thread_kind = MainThreadOnly]
21    #[derive(Debug, PartialEq, Eq, Hash)]
22    pub struct UIIndirectScribbleInteraction;
23);
24
25extern_conformance!(
26    unsafe impl NSObjectProtocol for UIIndirectScribbleInteraction {}
27);
28
29#[cfg(feature = "UIInteraction")]
30extern_conformance!(
31    unsafe impl UIInteraction for UIIndirectScribbleInteraction {}
32);
33
34impl UIIndirectScribbleInteraction {
35    extern_methods!(
36        #[unsafe(method(init))]
37        #[unsafe(method_family = init)]
38        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
39
40        #[unsafe(method(new))]
41        #[unsafe(method_family = new)]
42        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
43
44        #[unsafe(method(initWithDelegate:))]
45        #[unsafe(method_family = init)]
46        pub fn initWithDelegate(
47            this: Allocated<Self>,
48            delegate: &ProtocolObject<dyn UIIndirectScribbleInteractionDelegate>,
49        ) -> Retained<Self>;
50
51        /// The delegate for the interaction, to supply and customize writable elements in the interaction's view.
52        #[unsafe(method(delegate))]
53        #[unsafe(method_family = none)]
54        pub fn delegate(
55            &self,
56        ) -> Option<Retained<ProtocolObject<dyn UIIndirectScribbleInteractionDelegate>>>;
57
58        /// : Indicates if the user is actively writing. It will be set to YES in between calls to -indirectScribbleInteraction:willBeginWritingInElement: and -indirectScribbleInteraction:didFinishWritingInElement: calls.
59        #[unsafe(method(isHandlingWriting))]
60        #[unsafe(method_family = none)]
61        pub fn isHandlingWriting(&self) -> bool;
62    );
63}
64
65/// Element identifiers are used to identify writable elements in the interaction's view, and will be supplied in every delegate callback. Any object that conforms to NSCopying and that can be compared for equality can be used. It is recommended to use simple immutable values, like NSString, NSNumber, or NSUUID.
66///
67/// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uiscribbleelementidentifier?language=objc)
68pub type UIScribbleElementIdentifier = AnyObject;
69
70extern_protocol!(
71    /// The protocol to be implemented by the delegate of UIIndirectScribbleInteraction. It will be responsible for supplying a list of writable elements, focusing them, and ultimately providing a real UITextInput that will handle text editing operations.
72    ///
73    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uiindirectscribbleinteractiondelegate?language=objc)
74    pub unsafe trait UIIndirectScribbleInteractionDelegate:
75        NSObjectProtocol + MainThreadOnly
76    {
77        #[cfg(all(feature = "block2", feature = "objc2-core-foundation"))]
78        /// This method will be called to request the text input elements in a certain rect of the view, each of which represents an area where the user can start writing even if it's not a text input field itself.
79        ///
80        /// Parameter `interaction`: The interaction asking for the elements.
81        ///
82        /// Parameter `rect`: The rect around the area where the user is trying to write, in the interaction's view coordinate system. Only elements intersecting this rect should be returned.
83        ///
84        /// Parameter `completion`: You must call the completion handler, synchronously or asynchronously, with an array of identifiers of the available elements, or an empty array if no elements are available.
85        #[unsafe(method(indirectScribbleInteraction:requestElementsInRect:completion:))]
86        #[unsafe(method_family = none)]
87        fn indirectScribbleInteraction_requestElementsInRect_completion(
88            &self,
89            interaction: &UIIndirectScribbleInteraction,
90            rect: CGRect,
91            completion: &block2::DynBlock<dyn Fn(NonNull<NSArray<UIScribbleElementIdentifier>>)>,
92        );
93
94        /// Asks the delegate if an element is currently focused, according to the internal state of the interaction's view.
95        ///
96        /// Parameter `interaction`: The interaction asking for the focused state.
97        ///
98        /// Parameter `elementIdentifier`: The identifier of the element the interaction is asking about.
99        ///
100        /// Returns: Return YES if the element is the one currently focused.
101        ///
102        /// # Safety
103        ///
104        /// `element_identifier` should be of the correct type.
105        #[unsafe(method(indirectScribbleInteraction:isElementFocused:))]
106        #[unsafe(method_family = none)]
107        unsafe fn indirectScribbleInteraction_isElementFocused(
108            &self,
109            interaction: &UIIndirectScribbleInteraction,
110            element_identifier: &UIScribbleElementIdentifier,
111        ) -> bool;
112
113        #[cfg(feature = "objc2-core-foundation")]
114        /// Asks the delegate to provide the frame of an element.
115        ///
116        /// Parameter `interaction`: The interaction asking for the element's frame.
117        ///
118        /// Parameter `elementIdentifier`: The identifier of the element the interaction is asking about.
119        ///
120        /// Returns: Frame for the element, in the interactions's view coordinate system.
121        ///
122        /// # Safety
123        ///
124        /// `element_identifier` should be of the correct type.
125        #[unsafe(method(indirectScribbleInteraction:frameForElement:))]
126        #[unsafe(method_family = none)]
127        unsafe fn indirectScribbleInteraction_frameForElement(
128            &self,
129            interaction: &UIIndirectScribbleInteraction,
130            element_identifier: &UIScribbleElementIdentifier,
131        ) -> CGRect;
132
133        #[cfg(all(
134            feature = "UIResponder",
135            feature = "UITextInput",
136            feature = "UITextInputTraits",
137            feature = "block2",
138            feature = "objc2-core-foundation"
139        ))]
140        /// Asks the delegate to focus an element to handle text edits. In response, it should make the element the currently focused one, and make the corresponding UITextInput become first responder.
141        /// If the element was not focused already, text selection should be set to the character location closest to focusReferencePoint, to avoid any scrolling or shifting of content.
142        /// If the element was focused already, no changes in selection should be made and this call can be ignored, but you must still call the completion handler with a reference to the text input.
143        ///
144        /// Parameter `interaction`: The interaction that is requesting to focus an element.
145        ///
146        /// Parameter `elementIdentifier`: The identifier of the element that should be focused.
147        ///
148        /// Parameter `completion`: You must always call the completion handler, either synchronously or asynchronously. On success, the first parameter should be the text input that became first responder and that will handle text operations for this element. On failure, call the completion with a nil parameter.
149        ///
150        /// # Safety
151        ///
152        /// `element_identifier` should be of the correct type.
153        #[unsafe(method(indirectScribbleInteraction:focusElementIfNeeded:referencePoint:completion:))]
154        #[unsafe(method_family = none)]
155        unsafe fn indirectScribbleInteraction_focusElementIfNeeded_referencePoint_completion(
156            &self,
157            interaction: &UIIndirectScribbleInteraction,
158            element_identifier: &UIScribbleElementIdentifier,
159            focus_reference_point: CGPoint,
160            completion: &block2::DynBlock<dyn Fn(*mut UIResponder)>,
161        );
162
163        /// Allow the delegate to delay focusing an element. Normally, Scribble will focus the element as soon as the user begins writing, but if you return YES from this callback, it will wait until the user makes a brief pause. This is useful in cases where the element's frame will shift or transform when becoming focused, which can be disruptive to a user trying to handwrite into it.
164        /// Wherever possible it is preferable to adjust the UI behavior to avoid the layout changes, and only use delayed focus as a last resort, since transcription will happen all at once instead of incrementally.
165        ///
166        /// Parameter `interaction`: The interaction asking about delaying focus.
167        ///
168        /// Parameter `elementIdentifier`: The identifier of the element the interaction is asking about.
169        ///
170        /// Returns: Return YES to delay focusing the element.
171        ///
172        /// # Safety
173        ///
174        /// `element_identifier` should be of the correct type.
175        #[optional]
176        #[unsafe(method(indirectScribbleInteraction:shouldDelayFocusForElement:))]
177        #[unsafe(method_family = none)]
178        unsafe fn indirectScribbleInteraction_shouldDelayFocusForElement(
179            &self,
180            interaction: &UIIndirectScribbleInteraction,
181            element_identifier: &UIScribbleElementIdentifier,
182        ) -> bool;
183
184        /// Will be called when the user begins writing into an element. This call will always be paired with a corresponding call to indirectScribbleInteraction:didFinishWritingInElement:. It is recommended to use this call to hide custom placeholders or other UI elements that can interfere with writing.
185        ///
186        /// Parameter `interaction`: The interaction notifying about writing state changes.
187        ///
188        /// Parameter `elementIdentifier`: The identifier of the element the user is writing into.
189        ///
190        /// # Safety
191        ///
192        /// `element_identifier` should be of the correct type.
193        #[optional]
194        #[unsafe(method(indirectScribbleInteraction:willBeginWritingInElement:))]
195        #[unsafe(method_family = none)]
196        unsafe fn indirectScribbleInteraction_willBeginWritingInElement(
197            &self,
198            interaction: &UIIndirectScribbleInteraction,
199            element_identifier: &UIScribbleElementIdentifier,
200        );
201
202        /// Will be called when the user finished writing into an element, after the last word has been transcribed and committed.
203        ///
204        /// Parameter `interaction`: The interaction notifying about writing state changes.
205        ///
206        /// Parameter `elementIdentifier`: The identifier of the element the user finished writing into.
207        ///
208        /// # Safety
209        ///
210        /// `element_identifier` should be of the correct type.
211        #[optional]
212        #[unsafe(method(indirectScribbleInteraction:didFinishWritingInElement:))]
213        #[unsafe(method_family = none)]
214        unsafe fn indirectScribbleInteraction_didFinishWritingInElement(
215            &self,
216            interaction: &UIIndirectScribbleInteraction,
217            element_identifier: &UIScribbleElementIdentifier,
218        );
219    }
220);