objc2_ui_kit/generated/
UIScribbleInteraction.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::*;
8
9use crate::*;
10
11extern_class!(
12    /// An interaction that allows customizing the behavior of Scribble on text input views, or suppress it entirely in specific cases.
13    /// By default, Scribble allows the user to enter text by handwriting directly into any view that implements UITextInput and is editable. In apps with customized text fields, you can use UIScribbleInteraction's delegate callbacks to optimize the UI for a better writing experience. For example, you might want to hide custom placeholders when writing begins, or request delaying focusing the field if it moves when gaining focus.
14    /// In some cases it is necessary to suppress Scribble, for example if a text view also supports drawing with Apple Pencil. You may also need to suppress Scribble in views that handle Pencil events directly, like a drawing canvas, since nearby text fields could take over the Pencil events for writing.
15    ///
16    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uiscribbleinteraction?language=objc)
17    #[unsafe(super(NSObject))]
18    #[thread_kind = MainThreadOnly]
19    #[derive(Debug, PartialEq, Eq, Hash)]
20    pub struct UIScribbleInteraction;
21);
22
23extern_conformance!(
24    unsafe impl NSObjectProtocol for UIScribbleInteraction {}
25);
26
27#[cfg(feature = "UIInteraction")]
28extern_conformance!(
29    unsafe impl UIInteraction for UIScribbleInteraction {}
30);
31
32impl UIScribbleInteraction {
33    extern_methods!(
34        #[unsafe(method(init))]
35        #[unsafe(method_family = init)]
36        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
37
38        #[unsafe(method(new))]
39        #[unsafe(method_family = new)]
40        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
41
42        #[unsafe(method(initWithDelegate:))]
43        #[unsafe(method_family = init)]
44        pub fn initWithDelegate(
45            this: Allocated<Self>,
46            delegate: &ProtocolObject<dyn UIScribbleInteractionDelegate>,
47        ) -> Retained<Self>;
48
49        /// The delegate for the interaction, specified on init.
50        #[unsafe(method(delegate))]
51        #[unsafe(method_family = none)]
52        pub fn delegate(
53            &self,
54        ) -> Option<Retained<ProtocolObject<dyn UIScribbleInteractionDelegate>>>;
55
56        /// : Indicates if the user is actively writing. It will be set to YES in between calls to scribbleInteractionWillBeginWriting: and scribbleInteractionDidFinishWriting:
57        #[unsafe(method(isHandlingWriting))]
58        #[unsafe(method_family = none)]
59        pub fn isHandlingWriting(&self) -> bool;
60
61        /// A readonly class property that indicates the user is likely to use Apple Pencil and Scribble to enter text instead of the keyboard. In this case it is recommended to adjust the layout of UI elements that are not optimal for direct handwriting input. For example, small or resizable text fields that expect more than a few words could be made taller and reserve some whitespace at the bottom.
62        #[unsafe(method(isPencilInputExpected))]
63        #[unsafe(method_family = none)]
64        pub fn isPencilInputExpected(mtm: MainThreadMarker) -> bool;
65    );
66}
67
68extern_protocol!(
69    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uiscribbleinteractiondelegate?language=objc)
70    pub unsafe trait UIScribbleInteractionDelegate:
71        NSObjectProtocol + MainThreadOnly
72    {
73        #[cfg(feature = "objc2-core-foundation")]
74        /// Allows the delegate to prevent Scribble from starting at a specific location in the view. If not implemented, defaults to YES.
75        /// You can use this callback to temporarily suppress Scribble in text input views if your app supports drawing over text or other special interaction when using Apple Pencil. In cases like this, it's recommended to provide a UI affordance for the user to toggle between drawing and handwriting.
76        /// This callback can also return NO for views that handle Pencil events directly, like a drawing canvas, since nearby text fields could take over the Pencil events for writing.
77        ///
78        /// Parameter `interaction`: The interaction asking if it can begin handling user input.
79        ///
80        /// Parameter `location`: The location in the interaction's view coordinate system.
81        ///
82        /// Returns: Return NO to disallow writing at the specified location.
83        #[optional]
84        #[unsafe(method(scribbleInteraction:shouldBeginAtLocation:))]
85        #[unsafe(method_family = none)]
86        fn scribbleInteraction_shouldBeginAtLocation(
87            &self,
88            interaction: &UIScribbleInteraction,
89            location: CGPoint,
90        ) -> bool;
91
92        /// Allow the delegate to delay focusing (making first responder) the text input view. Normally, Scribble will focus the target input 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 text input view will shift or transform when becoming first responder, which can be disruptive to a user trying to handwrite into it.
93        /// 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.
94        ///
95        /// Parameter `interaction`: The interaction asking about delaying focus.
96        ///
97        /// Returns: Return YES to delay focusing the text input.
98        #[optional]
99        #[unsafe(method(scribbleInteractionShouldDelayFocus:))]
100        #[unsafe(method_family = none)]
101        fn scribbleInteractionShouldDelayFocus(&self, interaction: &UIScribbleInteraction) -> bool;
102
103        /// Will be called when the user begins writing into the interaction's view. This call will always be paired with a corresponding call to scribbleInteractionDidFinishWriting:. It is recommended to use this call to hide custom placeholders or other UI elements that can interfere with writing.
104        ///
105        /// Parameter `interaction`: The interaction notifying about writing state changes.
106        #[optional]
107        #[unsafe(method(scribbleInteractionWillBeginWriting:))]
108        #[unsafe(method_family = none)]
109        fn scribbleInteractionWillBeginWriting(&self, interaction: &UIScribbleInteraction);
110
111        /// Will be called when the user finished writing into the interaction's view, after the last word has been transcribed and committed.
112        ///
113        /// Parameter `interaction`: The interaction notifying about writing state changes.
114        #[optional]
115        #[unsafe(method(scribbleInteractionDidFinishWriting:))]
116        #[unsafe(method_family = none)]
117        fn scribbleInteractionDidFinishWriting(&self, interaction: &UIScribbleInteraction);
118    }
119);