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
25unsafe impl NSObjectProtocol for UIIndirectScribbleInteraction {}
26
27#[cfg(feature = "UIInteraction")]
28unsafe impl UIInteraction for UIIndirectScribbleInteraction {}
29
30impl UIIndirectScribbleInteraction {
31    extern_methods!(
32        #[unsafe(method(init))]
33        #[unsafe(method_family = init)]
34        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
35
36        #[unsafe(method(new))]
37        #[unsafe(method_family = new)]
38        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
39
40        #[unsafe(method(initWithDelegate:))]
41        #[unsafe(method_family = init)]
42        pub unsafe fn initWithDelegate(
43            this: Allocated<Self>,
44            delegate: &ProtocolObject<dyn UIIndirectScribbleInteractionDelegate>,
45        ) -> Retained<Self>;
46
47        /// The delegate for the interaction, to supply and customize writable elements in the interaction's view.
48        #[unsafe(method(delegate))]
49        #[unsafe(method_family = none)]
50        pub unsafe fn delegate(
51            &self,
52        ) -> Option<Retained<ProtocolObject<dyn UIIndirectScribbleInteractionDelegate>>>;
53
54        /// : Indicates if the user is actively writing. It will be set to YES in between calls to -indirectScribbleInteraction:willBeginWritingInElement: and -indirectScribbleInteraction:didFinishWritingInElement: calls.
55        #[unsafe(method(isHandlingWriting))]
56        #[unsafe(method_family = none)]
57        pub unsafe fn isHandlingWriting(&self) -> bool;
58    );
59}
60
61/// 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.
62///
63/// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uiscribbleelementidentifier?language=objc)
64pub type UIScribbleElementIdentifier = AnyObject;
65
66extern_protocol!(
67    /// 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.
68    ///
69    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uiindirectscribbleinteractiondelegate?language=objc)
70    pub unsafe trait UIIndirectScribbleInteractionDelegate:
71        NSObjectProtocol + MainThreadOnly
72    {
73        #[cfg(all(feature = "block2", feature = "objc2-core-foundation"))]
74        /// 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.
75        ///
76        /// Parameter `interaction`: The interaction asking for the elements.
77        ///
78        /// 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.
79        ///
80        /// 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.
81        #[unsafe(method(indirectScribbleInteraction:requestElementsInRect:completion:))]
82        #[unsafe(method_family = none)]
83        unsafe fn indirectScribbleInteraction_requestElementsInRect_completion(
84            &self,
85            interaction: &UIIndirectScribbleInteraction,
86            rect: CGRect,
87            completion: &block2::Block<dyn Fn(NonNull<NSArray<UIScribbleElementIdentifier>>)>,
88        );
89
90        /// Asks the delegate if an element is currently focused, according to the internal state of the interaction's view.
91        ///
92        /// Parameter `interaction`: The interaction asking for the focused state.
93        ///
94        /// Parameter `elementIdentifier`: The identifier of the element the interaction is asking about.
95        ///
96        /// Returns: Return YES if the element is the one currently focused.
97        #[unsafe(method(indirectScribbleInteraction:isElementFocused:))]
98        #[unsafe(method_family = none)]
99        unsafe fn indirectScribbleInteraction_isElementFocused(
100            &self,
101            interaction: &UIIndirectScribbleInteraction,
102            element_identifier: &UIScribbleElementIdentifier,
103        ) -> bool;
104
105        #[cfg(feature = "objc2-core-foundation")]
106        /// Asks the delegate to provide the frame of an element.
107        ///
108        /// Parameter `interaction`: The interaction asking for the element's frame.
109        ///
110        /// Parameter `elementIdentifier`: The identifier of the element the interaction is asking about.
111        ///
112        /// Returns: Frame for the element, in the interactions's view coordinate system.
113        #[unsafe(method(indirectScribbleInteraction:frameForElement:))]
114        #[unsafe(method_family = none)]
115        unsafe fn indirectScribbleInteraction_frameForElement(
116            &self,
117            interaction: &UIIndirectScribbleInteraction,
118            element_identifier: &UIScribbleElementIdentifier,
119        ) -> CGRect;
120
121        #[cfg(all(
122            feature = "UIResponder",
123            feature = "UITextInput",
124            feature = "UITextInputTraits",
125            feature = "block2",
126            feature = "objc2-core-foundation"
127        ))]
128        /// 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.
129        /// 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.
130        /// 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.
131        ///
132        /// Parameter `interaction`: The interaction that is requesting to focus an element.
133        ///
134        /// Parameter `elementIdentifier`: The identifier of the element that should be focused.
135        ///
136        /// 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.
137        #[unsafe(method(indirectScribbleInteraction:focusElementIfNeeded:referencePoint:completion:))]
138        #[unsafe(method_family = none)]
139        unsafe fn indirectScribbleInteraction_focusElementIfNeeded_referencePoint_completion(
140            &self,
141            interaction: &UIIndirectScribbleInteraction,
142            element_identifier: &UIScribbleElementIdentifier,
143            focus_reference_point: CGPoint,
144            completion: &block2::Block<dyn Fn(*mut UIResponder)>,
145        );
146
147        /// 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.
148        /// 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.
149        ///
150        /// Parameter `interaction`: The interaction asking about delaying focus.
151        ///
152        /// Parameter `elementIdentifier`: The identifier of the element the interaction is asking about.
153        ///
154        /// Returns: Return YES to delay focusing the element.
155        #[optional]
156        #[unsafe(method(indirectScribbleInteraction:shouldDelayFocusForElement:))]
157        #[unsafe(method_family = none)]
158        unsafe fn indirectScribbleInteraction_shouldDelayFocusForElement(
159            &self,
160            interaction: &UIIndirectScribbleInteraction,
161            element_identifier: &UIScribbleElementIdentifier,
162        ) -> bool;
163
164        /// 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.
165        ///
166        /// Parameter `interaction`: The interaction notifying about writing state changes.
167        ///
168        /// Parameter `elementIdentifier`: The identifier of the element the user is writing into.
169        #[optional]
170        #[unsafe(method(indirectScribbleInteraction:willBeginWritingInElement:))]
171        #[unsafe(method_family = none)]
172        unsafe fn indirectScribbleInteraction_willBeginWritingInElement(
173            &self,
174            interaction: &UIIndirectScribbleInteraction,
175            element_identifier: &UIScribbleElementIdentifier,
176        );
177
178        /// Will be called when the user finished writing into an element, after the last word has been transcribed and committed.
179        ///
180        /// Parameter `interaction`: The interaction notifying about writing state changes.
181        ///
182        /// Parameter `elementIdentifier`: The identifier of the element the user finished writing into.
183        #[optional]
184        #[unsafe(method(indirectScribbleInteraction:didFinishWritingInElement:))]
185        #[unsafe(method_family = none)]
186        unsafe fn indirectScribbleInteraction_didFinishWritingInElement(
187            &self,
188            interaction: &UIIndirectScribbleInteraction,
189            element_identifier: &UIScribbleElementIdentifier,
190        );
191    }
192);