objc2_ui_kit/generated/UIWritingToolsCoordinator.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/// Constants that specify the reason you updated your view’s content
13/// outside of the Writing Tools workflow.
14///
15/// If you modify your view’s text storage while Writing Tools is active,
16/// report those changes to your ``UIWritingToolsCoordinator`` object
17/// so it can track them correctly. Call the
18/// ``UIWritingToolsCoordinator/updateRange(_:with:reason:forContextWithIdentifier:)``
19/// method to report changes that occur inside one of your context objects. Call the
20/// ``UIWritingToolsCoordinator/updateForReflowedTextInContextWithIdentifier(_:)``
21/// method for changes that affect the layout of your text, such as text insertions
22/// before a context object or changes to your view’s frame rectangle.
23///
24/// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uiwritingtoolscoordinatortextupdatereason?language=objc)
25// NS_ENUM
26#[repr(transparent)]
27#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
28pub struct UIWritingToolsCoordinatorTextUpdateReason(pub NSInteger);
29impl UIWritingToolsCoordinatorTextUpdateReason {
30 /// An operation that involved a person editing the text in your view.
31 ///
32 /// Specify this option when the changes come from the text input system.
33 #[doc(alias = "UIWritingToolsCoordinatorTextUpdateReasonTyping")]
34 pub const Typing: Self = Self(0);
35 /// An operation that changed the view’s text as part of an undo or
36 /// redo command.
37 ///
38 /// Specify this option when an undo or redo command initiated the
39 /// change to your view.
40 #[doc(alias = "UIWritingToolsCoordinatorTextUpdateReasonUndoRedo")]
41 pub const UndoRedo: Self = Self(1);
42}
43
44unsafe impl Encode for UIWritingToolsCoordinatorTextUpdateReason {
45 const ENCODING: Encoding = NSInteger::ENCODING;
46}
47
48unsafe impl RefEncode for UIWritingToolsCoordinatorTextUpdateReason {
49 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
50}
51
52/// The states that indicate the current activity, if any, Writing Tools
53/// is performing in your view.
54///
55/// Making changes to your view requires several different levels of
56/// interaction. Initially, Writing Tools displays its UI and collects
57/// information about what the person wants to do. When the person selects
58/// an operation, Writing Tools sends the relevant details to a large language
59/// model (LLM) and processes the results. It then works with the custom view to
60/// integrate any changes into the view’s text storage. During each
61/// of these activities, the coordinator reflects what’s happening in
62/// its ``UIWritingToolsCoordinator/state`` property. You can use
63/// the current state as a guide to making decisions in other parts of your view.
64///
65/// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uiwritingtoolscoordinatorstate?language=objc)
66// NS_ENUM
67#[repr(transparent)]
68#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
69pub struct UIWritingToolsCoordinatorState(pub NSInteger);
70impl UIWritingToolsCoordinatorState {
71 /// A state that indicates Writing Tools isn’t currently performing
72 /// any work on your view’s content.
73 ///
74 /// The coordinator starts in the `inactive` state, and transitions
75 /// immediately to the ``noninteractive`` or ``interactiveResting``
76 /// state when someone chooses an option from the Writing Tools UI.
77 /// After the coordinator finishes incorporating any changes for the
78 /// current operation, it returns to the `inactive` state and waits
79 /// for the person to choose a different option or dismiss the Writing Tools UI.
80 #[doc(alias = "UIWritingToolsCoordinatorStateInactive")]
81 pub const Inactive: Self = Self(0);
82 /// A state that indicates Writing Tools is handling interactions in
83 /// the system UI, instead of in your view.
84 ///
85 /// Writing Tools transitions to this state when the coordinator uses
86 /// the ``UIWritingToolsBehavior/limited`` experience or when someone chooses an
87 /// option that displays its results in the Writing Tools UI. When
88 /// the person accepts the changes from the tool or dismisses the
89 /// Writing Tools UI, the coordinator returns to the ``inactive``
90 /// state. If the person discards the change and selects a tool with
91 /// an interactive experience instead, the coordinator transitions
92 /// to the ``interactiveResting`` state.
93 #[doc(alias = "UIWritingToolsCoordinatorStateNoninteractive")]
94 pub const Noninteractive: Self = Self(1);
95 /// A state that indicates Writing Tools is in the resting state
96 /// for an inline editing experience.
97 ///
98 /// When someone initially selects a tool with an interactive experience,
99 /// the coordinator transitions briefly to this state and starts the
100 /// operation. The coordinator transitions swiftly to the ``interactiveStreaming``
101 /// state when it submits the request and delivers the results to your
102 /// view. When it finishes delivering the results, it transitions back
103 /// to the `interactiveResting` state and awaits further commands. If
104 /// the person accepts the changes or dismisses the Writing Tools UI,
105 /// the coordinator transitions from this state to the ``inactive`` state.
106 #[doc(alias = "UIWritingToolsCoordinatorStateInteractiveResting")]
107 pub const InteractiveResting: Self = Self(2);
108 /// A state that indicates Writing Tools is processing a request and
109 /// incorporating changes interactively into your view.
110 ///
111 /// The coordinator transitions swiftly from the ``interactiveResting``
112 /// state to this state at the start of an operation. In this state,
113 /// the coordinator submits the request for processing and delivers
114 /// the results back to your view. When the coordinator finishes delivering
115 /// the results, it transitions back to the ``interactiveResting`` state.
116 #[doc(alias = "UIWritingToolsCoordinatorStateInteractiveStreaming")]
117 pub const InteractiveStreaming: Self = Self(3);
118}
119
120unsafe impl Encode for UIWritingToolsCoordinatorState {
121 const ENCODING: Encoding = NSInteger::ENCODING;
122}
123
124unsafe impl RefEncode for UIWritingToolsCoordinatorState {
125 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
126}
127
128extern_class!(
129 /// An object that manages interactions between Writing Tools and
130 /// your custom text view.
131 ///
132 /// Add a `UIWritingToolsCoordinator` object to a custom view when you
133 /// want to add Writing Tools support to that view. The coordinator manages
134 /// interactions between your view and the Writing Tools UI and back-end
135 /// capabilities. When creating a coordinator, you supply a delegate object
136 /// to respond to requests from the system and provide needed information.
137 /// Your delegate delivers your view’s text to Writing Tools, incorporates
138 /// suggested changes back into your text storage, and supports the animations
139 /// that Writing Tools creates to show the state of an operation.
140 ///
141 /// Create the `UIWritingToolsCoordinator` object when setting up your UI, and
142 /// initialize it with a custom object that adopts the ``UIWritingToolsCoordinator/Delegate``
143 /// protocol. Add the coordinator to your view using the ``UIView/addInteraction(_:)``
144 /// method. When a coordinator is present on a view, the system adds UI elements
145 /// to initiate Writing Tools operations.
146 ///
147 /// When defining the delegate, choose an object from your app that has access
148 /// to your view and its text storage. You can adopt the ``UIWritingToolsCoordinator/Delegate``
149 /// protocol in the view itself, or in another type that your view uses to
150 /// manage content. During the interactions with Writing Tools, the delegate
151 /// gets and sets the contents of the view’s text storage and supports Writing Tools behaviors.
152 ///
153 /// > Note: You don’t need to create an `UIWritingToolsCoordinator` object
154 /// if you display text using a ``UITextView``,
155 /// <doc
156 /// ://com.apple.documentation/documentation/appkit/nstextview>,
157 /// <doc
158 /// ://com.apple.documentation/documentation/swiftui/text>,
159 /// <doc
160 /// ://com.apple.documentation/documentation/swiftui/textfield>, or
161 /// <doc
162 /// ://com.apple.documentation/documentation/swiftui/texteditor> view.
163 /// Those views already include the required support to handle Writing Tools
164 /// interactions.
165 ///
166 /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uiwritingtoolscoordinator?language=objc)
167 #[unsafe(super(NSObject))]
168 #[thread_kind = MainThreadOnly]
169 #[derive(Debug, PartialEq, Eq, Hash)]
170 pub struct UIWritingToolsCoordinator;
171);
172
173extern_conformance!(
174 unsafe impl NSObjectProtocol for UIWritingToolsCoordinator {}
175);
176
177#[cfg(feature = "UIInteraction")]
178extern_conformance!(
179 unsafe impl UIInteraction for UIWritingToolsCoordinator {}
180);
181
182impl UIWritingToolsCoordinator {
183 extern_methods!(
184 /// A Boolean value that indicates whether Writing Tools features are
185 /// currently available.
186 ///
187 /// The value of this property is `true` when Writing Tools features are
188 /// available, and `false` when they aren’t. Writing Tools support might
189 /// be unavailable because of device constraints or because the system isn’t
190 /// ready to process Writing Tools requests.
191 #[unsafe(method(isWritingToolsAvailable))]
192 #[unsafe(method_family = none)]
193 pub fn isWritingToolsAvailable(mtm: MainThreadMarker) -> bool;
194
195 /// Creates a writing tools coordinator and assigns the specified
196 /// delegate object to it.
197 ///
198 /// - Parameters:
199 /// - delegate: An object capable of handling Writing Tools interactions
200 /// for your view. The delegate must be able to modify your view’s text
201 /// storage and refresh the view’s layout and appearance.
202 ///
203 /// Create the coordinator object during your view’s initialization, and assign
204 /// the object to your view. Use the ``UIView/addInteraction(_:)``
205 /// method to add the object to your view.
206 #[unsafe(method(initWithDelegate:))]
207 #[unsafe(method_family = init)]
208 pub fn initWithDelegate(
209 this: Allocated<Self>,
210 delegate: Option<&ProtocolObject<dyn UIWritingToolsCoordinatorDelegate>>,
211 ) -> Retained<Self>;
212
213 /// The object that handles Writing Tools interactions for your view.
214 ///
215 /// Specify this object at initialization time when creating your `UIWritingToolsCoordinator`
216 /// object. The object must adopt the ``UIWritingToolsCoordinator/Delegate``
217 /// protocol, and be capable of modifying your view’s text storage and
218 /// refreshing the view’s layout and appearance.
219 #[unsafe(method(delegate))]
220 #[unsafe(method_family = none)]
221 pub fn delegate(
222 &self,
223 ) -> Option<Retained<ProtocolObject<dyn UIWritingToolsCoordinatorDelegate>>>;
224
225 #[cfg(all(feature = "UIResponder", feature = "UIView"))]
226 /// The view that Writing Tools uses to display visual effects during
227 /// the text-rewriting process.
228 ///
229 /// Writing Tools uses the view in this property to host the visual effects
230 /// it creates when making interactive changes to your view’s content.
231 /// These visual effects let people know the state of the text and provide
232 /// feedback about what’s happening to it. Set this property to a subview
233 /// that sits visually above, and covers, all of the text in your custom
234 /// text view. If you don’t assign a value to this property, the coordinator
235 /// uses the object in its ``UIInteraction/view`` property to host any visual effects.
236 ///
237 /// If you display your view’s text using multiple text containers, implement the
238 /// ``UIWritingToolsCoordinator/Delegate/writingToolsCoordinator(_:requestsSingleContainerSubrangesOf:in:completion:)``
239 /// method to request multiple previews.
240 #[unsafe(method(effectContainerView))]
241 #[unsafe(method_family = none)]
242 pub fn effectContainerView(&self) -> Option<Retained<UIView>>;
243
244 #[cfg(all(feature = "UIResponder", feature = "UIView"))]
245 /// Setter for [`effectContainerView`][Self::effectContainerView].
246 ///
247 /// This is a [weak property][objc2::topics::weak_property].
248 #[unsafe(method(setEffectContainerView:))]
249 #[unsafe(method_family = none)]
250 pub fn setEffectContainerView(&self, effect_container_view: Option<&UIView>);
251
252 #[cfg(all(feature = "UIResponder", feature = "UIView"))]
253 /// The view that Writing Tools uses to display background decorations
254 /// such as proofreading marks.
255 ///
256 /// Writing Tools uses the view in this property to host proofreading marks
257 /// and other visual elements that show any suggested changes. Set this
258 /// property to a subview situated visibly below the text in your custom
259 /// text view. It's also satisfactory to place this view visually in front
260 /// of the text. Make sure the size of the view is big enough to
261 /// cover all of the affected text. If you don’t assign a value to
262 /// this property, the coordinator uses the object in its ``UIInteraction/view``
263 /// property to host any visual elements.
264 ///
265 /// If you display your view’s text using multiple text containers, implement the
266 /// ``UIWritingToolsCoordinator/Delegate/writingToolsCoordinator(_:requestsSingleContainerSubrangesOf:in:completion:)``
267 /// and ``UIWritingToolsCoordinator/Delegate/writingToolsCoordinator(_:requestsDecorationContainerViewFor:in:completion:)``
268 /// methods to provide separate decoration views for each container.
269 #[unsafe(method(decorationContainerView))]
270 #[unsafe(method_family = none)]
271 pub fn decorationContainerView(&self) -> Option<Retained<UIView>>;
272
273 #[cfg(all(feature = "UIResponder", feature = "UIView"))]
274 /// Setter for [`decorationContainerView`][Self::decorationContainerView].
275 ///
276 /// This is a [weak property][objc2::topics::weak_property].
277 #[unsafe(method(setDecorationContainerView:))]
278 #[unsafe(method_family = none)]
279 pub fn setDecorationContainerView(&self, decoration_container_view: Option<&UIView>);
280
281 /// The current level of Writing Tools activity in your view.
282 ///
283 /// Use this property to determine when Writing Tools is actively making
284 /// changes to your view. During the course of Writing Tools interactions,
285 /// the system reports state changes to the delegate’s
286 /// ``UIWritingToolsCoordinator/Delegate/writingToolsCoordinator(_:willChangeTo:completion:)``
287 /// method and updates this property accordingly.
288 #[unsafe(method(state))]
289 #[unsafe(method_family = none)]
290 pub fn state(&self) -> UIWritingToolsCoordinatorState;
291
292 /// Stops the current Writing Tools operation and dismisses the system UI.
293 ///
294 /// Call this method to abort the current Writing Tools operation. This
295 /// method dismisses the system’s Writing Tools UI and stops any in-flight
296 /// interactions with your view. This method does not undo any changes that
297 /// Writing Tools already made to your view’s content.
298 #[unsafe(method(stopWritingTools))]
299 #[unsafe(method_family = none)]
300 pub fn stopWritingTools(&self);
301
302 #[cfg(feature = "UITextInputTraits")]
303 /// The level of Writing Tools support you want the system to provide
304 /// for your view.
305 ///
306 /// Use this property to request an inline or panel-based experience,
307 /// or to disable Writing Tools for your view altogether. The default
308 /// value of this property is ``UIWritingToolsBehavior/default``.
309 #[unsafe(method(preferredBehavior))]
310 #[unsafe(method_family = none)]
311 pub fn preferredBehavior(&self) -> UIWritingToolsBehavior;
312
313 #[cfg(feature = "UITextInputTraits")]
314 /// Setter for [`preferredBehavior`][Self::preferredBehavior].
315 #[unsafe(method(setPreferredBehavior:))]
316 #[unsafe(method_family = none)]
317 pub fn setPreferredBehavior(&self, preferred_behavior: UIWritingToolsBehavior);
318
319 #[cfg(feature = "UITextInputTraits")]
320 /// The actual level of Writing Tools support the system provides for your view.
321 ///
322 /// The system chooses this value based on the device capabilities, and takes
323 /// the value in the ``preferredBehavior`` property into consideration when
324 /// making the choice. The value in this property is never the default option,
325 /// and is instead one of the specific options such as ``UIWritingToolsBehavior/none``,
326 /// ``UIWritingToolsBehavior/limited``, or ``UIWritingToolsBehavior/complete``.
327 #[unsafe(method(behavior))]
328 #[unsafe(method_family = none)]
329 pub fn behavior(&self) -> UIWritingToolsBehavior;
330
331 #[cfg(feature = "UITextInputTraits")]
332 /// The type of content you allow Writing Tools to generate for your custom
333 /// text view.
334 ///
335 /// Writing Tools can create plain text or rich text, and it can format text
336 /// using lists or tables as needed. If your view doesn’t support specific
337 /// types of content, specify the types you do support in this property.
338 /// The default value of this property is ``UIWritingToolsResultOptions/default``,
339 /// which lets the system determine the type of content to generate.
340 #[unsafe(method(preferredResultOptions))]
341 #[unsafe(method_family = none)]
342 pub fn preferredResultOptions(&self) -> UIWritingToolsResultOptions;
343
344 #[cfg(feature = "UITextInputTraits")]
345 /// Setter for [`preferredResultOptions`][Self::preferredResultOptions].
346 #[unsafe(method(setPreferredResultOptions:))]
347 #[unsafe(method_family = none)]
348 pub fn setPreferredResultOptions(
349 &self,
350 preferred_result_options: UIWritingToolsResultOptions,
351 );
352
353 #[unsafe(method(includesTextListMarkers))]
354 #[unsafe(method_family = none)]
355 pub fn includesTextListMarkers(&self) -> bool;
356
357 /// Setter for [`includesTextListMarkers`][Self::includesTextListMarkers].
358 #[unsafe(method(setIncludesTextListMarkers:))]
359 #[unsafe(method_family = none)]
360 pub fn setIncludesTextListMarkers(&self, includes_text_list_markers: bool);
361
362 #[cfg(feature = "UITextInputTraits")]
363 /// The type of content the system generates for your custom text view.
364 ///
365 /// This property contains the set of options that Writing Tools outputs
366 /// for your view. Writing Tools takes the value in the
367 /// ``UIWritingToolsCoordinator/preferredResultOptions`` property into
368 /// consideration when determining this value.
369 #[unsafe(method(resultOptions))]
370 #[unsafe(method_family = none)]
371 pub fn resultOptions(&self) -> UIWritingToolsResultOptions;
372
373 /// Informs the coordinator about changes your app made to the text
374 /// in the specified context object.
375 ///
376 /// - Parameters:
377 /// - range: The range of text to replace. This range is relative to
378 /// the starting location of the specified context object’s text in
379 /// your view’s text storage. If you initialized the context object
380 /// with the entire contents of your view’s text storage, specify the
381 /// range of text you’re replacing in your text storage. However, if
382 /// you initialized the context object with only a portion of your
383 /// view’s text, specify a range that is relative to the starting
384 /// location of the context object’s text.
385 /// - replacementText: The text that replaces the previous content in
386 /// `range`. Specify an empty string to delete the text in the specified range.
387 /// - reason: The reason you updated the text.
388 /// - contextID: The unique identifier of the context object that
389 /// contains the text you modified.
390 ///
391 /// If you make any changes to the text Writing Tools is evaluating, call
392 /// this method to report those changes to your view’s coordinator object.
393 /// You might make changes in response to an undo command or when someone
394 /// types into the same part of your view’s text. Calling this method
395 /// keeps the coordinator object informed of any changes, and ensures
396 /// it delivers accurate information to its delegate. In response, the
397 /// coordinator refreshes previews and other information related to your
398 /// view. If the scope of the update is significantly large, the coordinator
399 /// can optionally cancel the Writing Tools session altogether.
400 ///
401 /// Use this method to report changes that precisely intersect your context
402 /// object’s text. The first time you call this method for a context object,
403 /// report changes only to the original attributed string in that object.
404 /// If you call this method more than once, report changes to the newly
405 /// modified version of that string. Don’t use this method to report changes
406 /// to text that comes before or after the context object. If you make
407 /// changes before your context object, report those changes separately using the
408 /// ``UIWritingToolsCoordinator/updateForReflowedTextInContextWithIdentifier(_:)`` method.
409 ///
410 /// > Warning: Failure to call this method for a change can cause Writing Tools
411 /// to deliver inaccurate information to your delegate and lead to data loss.
412 #[unsafe(method(updateRange:withText:reason:forContextWithIdentifier:))]
413 #[unsafe(method_family = none)]
414 pub fn updateRange_withText_reason_forContextWithIdentifier(
415 &self,
416 range: NSRange,
417 replacement_text: &NSAttributedString,
418 reason: UIWritingToolsCoordinatorTextUpdateReason,
419 context_id: &NSUUID,
420 );
421
422 /// Informs the coordinator that a change occurred to the view or its text
423 /// that requires a layout update.
424 ///
425 /// - Parameters:
426 /// - contextID: The unique identifier of the context object affected
427 /// by the change. Pass the identifier for the context object that comes
428 /// after the changes.
429 ///
430 /// Use this method to inform Writing Tools when the geometry of your view
431 /// changes, or when the text that precedes one of your context objects changes.
432 /// Changes to the view’s geometry or text can affect the flow of any remaining
433 /// text, and require a layout update. Writing Tools uses this method to
434 /// refresh any layout-dependent information it’s currently tracking. For
435 /// example, it uses it to refresh the location of proofreading marks it’s
436 /// displaying in your view.
437 ///
438 /// If a text change affects the text inside a context object, call the
439 /// ``updateRange(_:with:reason:forContextWithIdentifier:)`` method to report
440 /// that change instead.
441 #[unsafe(method(updateForReflowedTextInContextWithIdentifier:))]
442 #[unsafe(method_family = none)]
443 pub fn updateForReflowedTextInContextWithIdentifier(&self, context_id: &NSUUID);
444 );
445}
446
447/// Methods declared on superclass `NSObject`.
448impl UIWritingToolsCoordinator {
449 extern_methods!(
450 #[unsafe(method(init))]
451 #[unsafe(method_family = init)]
452 pub fn init(this: Allocated<Self>) -> Retained<Self>;
453
454 #[unsafe(method(new))]
455 #[unsafe(method_family = new)]
456 pub fn new(mtm: MainThreadMarker) -> Retained<Self>;
457 );
458}
459
460/// Options that indicate whether Writing Tools is animating changes to
461/// your view’s text.
462///
463/// During an operation, Writing Tools delivers replacement text to the
464/// delegate of the active ``UIWritingToolsCoordinator`` object. Depending
465/// on the configured experience for your view, it delivers these changes
466/// as either interactive or noninteractive replacements. For interactive
467/// replacements, Writing Tools animates the change automatically and provides
468/// you with the information you need to perform any related animations.
469///
470/// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uiwritingtoolscoordinatortextreplacementreason?language=objc)
471// NS_ENUM
472#[repr(transparent)]
473#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
474pub struct UIWritingToolsCoordinatorTextReplacementReason(pub NSInteger);
475impl UIWritingToolsCoordinatorTextReplacementReason {
476 /// An option to animate the replacement of text in your view.
477 ///
478 /// When Writing Tools requests an interactive change in your delegate’s
479 /// ``UIWritingToolsCoordinator/Delegate/writingToolsCoordinator(_:replaceRange:inContext:proposedText:reason:animationParameters:completion:)``
480 /// method, it passes a valid set of animation parameters to that method.
481 /// Update your view’s text storage and use the provided ``UIWritingToolsCoordinator/AnimationParameters``
482 /// type to create any view-specific animations you need to support the
483 /// animated replacement of the text.
484 #[doc(alias = "UIWritingToolsCoordinatorTextReplacementReasonInteractive")]
485 pub const Interactive: Self = Self(0);
486 /// An option to replace the text in your view without animating the change.
487 ///
488 /// When Writing Tools requests a noninteractive change in your delegate’s
489 /// ``UIWritingToolsCoordinator/Delegate/writingToolsCoordinator(_:replaceRange:inContext:proposedText:reason:animationParameters:completion:)``
490 /// method, update your view’s text storage without animating the change.
491 #[doc(alias = "UIWritingToolsCoordinatorTextReplacementReasonNoninteractive")]
492 pub const Noninteractive: Self = Self(1);
493}
494
495unsafe impl Encode for UIWritingToolsCoordinatorTextReplacementReason {
496 const ENCODING: Encoding = NSInteger::ENCODING;
497}
498
499unsafe impl RefEncode for UIWritingToolsCoordinatorTextReplacementReason {
500 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
501}
502
503/// Options that indicate how much of your content Writing Tools requested.
504///
505/// At the start of any Writing Tools interaction, you provide the text for
506/// the system to evaluate from your ``UIWritingToolsCoordinator/Delegate``
507/// object. The request for your content comes with a scope constant that
508/// indicates how much of your view’s text to provide.
509///
510/// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uiwritingtoolscoordinatorcontextscope?language=objc)
511// NS_ENUM
512#[repr(transparent)]
513#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
514pub struct UIWritingToolsCoordinatorContextScope(pub NSInteger);
515impl UIWritingToolsCoordinatorContextScope {
516 /// An option to provide only the view’s currently selected text.
517 ///
518 /// With this option, include the selected text in your context object,
519 /// along with some additional text before and after the selection. When
520 /// performing changes inline with your view’s content, Writing Tools
521 /// applies animations only to the selected text.
522 #[doc(alias = "UIWritingToolsCoordinatorContextScopeUserSelection")]
523 pub const UserSelection: Self = Self(0);
524 /// An option to provide all of your view’s text.
525 ///
526 /// With this option, include all of the text your view manages.
527 /// If your view has multiple text storage objects, create a separate
528 /// context object for each one.
529 #[doc(alias = "UIWritingToolsCoordinatorContextScopeFullDocument")]
530 pub const FullDocument: Self = Self(1);
531 /// An option to provide only the text in the currently visible portion
532 /// of your view.
533 ///
534 /// With this option, include only the currently visible text, along
535 /// with some additional text before and after the visible text.
536 #[doc(alias = "UIWritingToolsCoordinatorContextScopeVisibleArea")]
537 pub const VisibleArea: Self = Self(2);
538}
539
540unsafe impl Encode for UIWritingToolsCoordinatorContextScope {
541 const ENCODING: Encoding = NSInteger::ENCODING;
542}
543
544unsafe impl RefEncode for UIWritingToolsCoordinatorContextScope {
545 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
546}
547
548/// The types of animations that Writing Tools performs during an interactive
549/// update of your view.
550///
551/// Use the `UIWritingToolsCoordinator/TextAnimation` constants to determine
552/// the type of animation that is occurring. During an interactive change to
553/// your view, Writing Tools creates animations to provide feedback about what’s
554/// happening. During the setup for each animation, Writing Tools reports the
555/// type of animation to the coordinator’s delegate, so that you can perform
556/// additional actions related to that animation. For example, during an insertion
557/// animation, you might animate changes to other views in your interface.
558///
559/// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uiwritingtoolscoordinatortextanimation?language=objc)
560// NS_ENUM
561#[repr(transparent)]
562#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
563pub struct UIWritingToolsCoordinatorTextAnimation(pub NSInteger);
564impl UIWritingToolsCoordinatorTextAnimation {
565 /// The animation that Writing Tools performs when waiting to receive
566 /// results from the large language model.
567 ///
568 /// This type of animation applies a visual effect to the text that
569 /// Writing Tools is evaluating. When preparing for this animation, hide
570 /// the text that Writing Tools is about to evaluate. In the same space
571 /// where that text appears, Writing Tools displays a preview image that
572 /// you provide and animates changes to that image.
573 #[doc(alias = "UIWritingToolsCoordinatorTextAnimationAnticipate")]
574 pub const Anticipate: Self = Self(0);
575 /// The animation that Writing Tools performs when removing text from your view.
576 ///
577 /// This type of animation shows the removal of text from your view. When
578 /// preparing for this animation, hide the text in the provided range if
579 /// you haven’t already. If you support animating the reflow of your view’s
580 /// text, you can also prepare any other animations you need. Writing Tools
581 /// uses a preview object you provide to animate the removal of the text.
582 #[doc(alias = "UIWritingToolsCoordinatorTextAnimationRemove")]
583 pub const Remove: Self = Self(1);
584 /// The animation that Writing Tools performs when inserting text into your view.
585 ///
586 /// This type of animation shows the insertion of text to your view. When preparing
587 /// for this animation, hide the text in the provided range if you haven’t
588 /// already. If you support animating the reflow of your view’s text, you can
589 /// also prepare any other animations you need. Writing Tools uses a preview
590 /// object you provide to animate the insertion of the text.
591 #[doc(alias = "UIWritingToolsCoordinatorTextAnimationInsert")]
592 pub const Insert: Self = Self(2);
593}
594
595unsafe impl Encode for UIWritingToolsCoordinatorTextAnimation {
596 const ENCODING: Encoding = NSInteger::ENCODING;
597}
598
599unsafe impl RefEncode for UIWritingToolsCoordinatorTextAnimation {
600 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
601}
602
603impl UIWritingToolsCoordinatorTextAnimation {
604 #[doc(alias = "UIWritingToolsCoordinatorTextAnimationDebugDescription")]
605 #[inline]
606 pub fn debug_description(self) -> Retained<NSString> {
607 extern "C-unwind" {
608 fn UIWritingToolsCoordinatorTextAnimationDebugDescription(
609 animation_type: UIWritingToolsCoordinatorTextAnimation,
610 ) -> *mut NSString;
611 }
612 let ret = unsafe { UIWritingToolsCoordinatorTextAnimationDebugDescription(self) };
613 unsafe { Retained::retain_autoreleased(ret) }
614 .expect("function was marked as returning non-null, but actually returned NULL")
615 }
616}
617
618extern_protocol!(
619 /// An interface that you use to manage interactions between Writing Tools
620 /// and your custom text view.
621 ///
622 /// Adopt the `UIWritingToolsCoordinator.Delegate` protocol in the type you
623 /// use to manage your custom text view. When you add a ``UIWritingToolsCoordinator``
624 /// object to your view, the coordinator uses this protocol to communicate
625 /// with that view. The protocol lets Writing Tools fetch your view’s text,
626 /// report suggested changes back to your view, and deliver visual feedback
627 /// when Writing Tools features are active. Make sure the type that adopts
628 /// this protocol has access to your view’s text storage and can perform
629 /// relevant tasks on behalf of the view.
630 ///
631 /// Writing Tools expects you to call the provided handler blocks at the end
632 /// of your delegate methods. It’s crucial that you execute these blocks in a
633 /// timely manner to allow Writing Tools to perform subsequent tasks. For example,
634 /// Writing Tools waits for you to execute the handlers for animation-related methods
635 /// before moving on to the next stage of the animations.
636 ///
637 /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uiwritingtoolscoordinatordelegate?language=objc)
638 pub unsafe trait UIWritingToolsCoordinatorDelegate: NSObjectProtocol {
639 #[cfg(all(feature = "UIWritingToolsCoordinatorContext", feature = "block2"))]
640 /// Asks your delegate to provide the text to evaluate during the Writing Tools
641 /// operation.
642 ///
643 /// - Parameters:
644 /// - writingToolsCoordinator: The coordinator object requesting information
645 /// from your custom view.
646 /// - scope: The amount of text the coordinator requested. Use this property
647 /// to determine if Writing Tools is evaluating all of your text or only a subset.
648 /// - completion: A completion block to execute with the required information.
649 /// You must execute this block once at end of your method's implementation.
650 /// The block has no return value and takes an array of
651 /// ``UIWritingToolsCoordinator/Context`` objects that contain the requested information.
652 ///
653 /// At the start of every operation, the ``UIWritingToolsCoordinator`` object calls
654 /// this method to request the text to evaluate. Use this method to create one or
655 /// more ``UIWritingToolsCoordinator/Context`` objects with your view’s text.
656 /// Create only one ``UIWritingToolsCoordinator/Context`` object if your view has
657 /// only one text storage object. If your view contains multiple text storage objects,
658 /// create separate ``UIWritingToolsCoordinator/Context`` objects for each
659 /// text storage object. Writing Tools returns updates for each context object
660 /// separately, making it easier for you to incorporate changes into the correct
661 /// text storage object. Don’t create multiple context objects if your view has
662 /// only one text storage object.
663 ///
664 /// The `scope` parameter tells you what content Writing Tools expects you to provide
665 /// in your context object. For example, Writing Tools expects you to provide the
666 /// selected text when the parameter contains the ``UIWritingToolsCoordinator/ContextScope/userSelection``
667 /// option. When Writing Tools requests a subset of your overall text, include
668 /// some of the surrounding text in your context object too. Writing Tools can
669 /// use the extra text you provide to improve the results of its evaluation. For
670 /// example, it might use an entire paragraph, instead of only the selected sentence,
671 /// to evaluate ways to rewrite that sentence. It’s best to include the text up
672 /// to the nearest paragraph boundary before and after the selection. If you
673 /// include extra text in your context object, set the ``UIWritingToolsCoordinator/Context/range``
674 /// property to the range of the selected text.
675 ///
676 /// > Note: When a context object stores only a subset of your view’s text, record
677 /// additional information to map the location of that text to the correct location
678 /// in your view’s text storage. Keep that information up-to-date throughout the
679 /// Writing Tools session.
680 ///
681 /// Pass the context objects you create to the provided completion handler before
682 /// your method returns. Writing Tools waits for you to call the completion
683 /// handler before proceeding with the operation.
684 #[unsafe(method(writingToolsCoordinator:requestsContextsForScope:completion:))]
685 #[unsafe(method_family = none)]
686 fn writingToolsCoordinator_requestsContextsForScope_completion(
687 &self,
688 writing_tools_coordinator: &UIWritingToolsCoordinator,
689 scope: UIWritingToolsCoordinatorContextScope,
690 completion: &block2::DynBlock<
691 dyn Fn(NonNull<NSArray<UIWritingToolsCoordinatorContext>>),
692 >,
693 );
694
695 #[cfg(all(
696 feature = "UIWritingToolsCoordinatorAnimationParameters",
697 feature = "UIWritingToolsCoordinatorContext",
698 feature = "block2"
699 ))]
700 /// Tells the delegate that there are text changes to incorporate into the view.
701 ///
702 /// - Parameters:
703 /// - writingToolsCoordinator: The coordinator object providing the changes
704 /// to your custom view.
705 /// - range: A range of text to update. This range is relative to the text
706 /// in your context object, and it’s your responsibility to match that location
707 /// to the correct location in your text storage. If you initialized the
708 /// context object with the entire contents of your view’s text storage,
709 /// you can use `range` as-is to access that text storage. However, if you
710 /// initialized the context object with only a portion of your view’s text,
711 /// add the starting location of your context object’s text to this value
712 /// to get the correct range for that text storage.
713 /// - context: The context object that contains the original text to modify.
714 /// Use this object to locate the correct text storage object for your view.
715 /// - replacementText: The text to insert in place of the current text at `range`.
716 /// You can insert this text as-is, insert a modified version of this string,
717 /// or reject the replacement text altogether.
718 /// - reason: The type of replacement Writing Tools performs. This parameter
719 /// indicates whether Writing Tools is replacing the text with or without animations.
720 /// - animationParameters: The animation parameters for any interactive changes,
721 /// or `nil` if the changes aren’t interactive. Use this object to create any
722 /// additional animations for the system to run alongside the changes Writing Tools
723 /// makes. For example, use it to update other views that contain related information.
724 /// - completion: A completion handler to execute with the results of the operation.
725 /// The handler has no return value and takes an optional attributed string as
726 /// a parameter. If you incorporate the replacement text, either as-is or with
727 /// modifications, pass the actual string you incorporated to the completion
728 /// block. If you reject the suggested change and leave the original text
729 /// unchanged, specify `nil` for this parameter.
730 ///
731 /// Use this method to update your view’s text storage with the proposed changes.
732 /// Writing Tools can call this method multiple times during the course of a
733 /// session to notify you of changes to different ranges of text. Incorporate
734 /// the changes into your view’s text storage and notify your layout manager
735 /// so it can refresh the view.
736 ///
737 /// > Important: When integrating changes, remember to update `range.location` as needed
738 /// to get the correct location in your view’s text storage.
739 ///
740 /// Remove the text in the appropriate range of your text storage, and replace
741 /// it with the contents of `replacementText`. When you finish, call the completion
742 /// handler and pass in the replacement text you inserted. If you change the
743 /// string in `replacementText` before incorporating it into your text storage,
744 /// return your modified string instead. Returning the string lets Writing Tools
745 /// track any alterations you made to it. You can also pass `nil` to the
746 /// completion handler if you don’t incorporate the replacement text.
747 ///
748 /// For interactive changes, Writing Tools works with your delegate to animate
749 /// the removal of the old text and the insertion of any replacement text. If
750 /// you need to modify other parts of your interface to reflect the changes,
751 /// use the provided ``UIWritingToolsCoordinator/AnimationParameters`` object
752 /// to create additional animations to run at the same time as the system-provided animations.
753 #[unsafe(method(writingToolsCoordinator:replaceRange:inContext:proposedText:reason:animationParameters:completion:))]
754 #[unsafe(method_family = none)]
755 fn writingToolsCoordinator_replaceRange_inContext_proposedText_reason_animationParameters_completion(
756 &self,
757 writing_tools_coordinator: &UIWritingToolsCoordinator,
758 range: NSRange,
759 context: &UIWritingToolsCoordinatorContext,
760 replacement_text: &NSAttributedString,
761 reason: UIWritingToolsCoordinatorTextReplacementReason,
762 animation_parameters: Option<&UIWritingToolsCoordinatorAnimationParameters>,
763 completion: &block2::DynBlock<dyn Fn(*mut NSAttributedString)>,
764 );
765
766 #[cfg(all(feature = "UIWritingToolsCoordinatorContext", feature = "block2"))]
767 /// Asks the delegate to update your view’s current text selection.
768 ///
769 /// - Parameters:
770 /// - writingToolsCoordinator: The coordinator object making the change
771 /// to your view.
772 /// - ranges: One or more ranges of text to select. Each range is relative
773 /// to the text in your context object, and it’s your responsibility to
774 /// match each location to the correct location in your text storage. If
775 /// you initialized the context object with the entire contents of your
776 /// view’s text storage, you can use the ranges as-is to access that text
777 /// storage. However, if you initialized the context object with only a
778 /// portion of your view’s text, add the starting location of your context
779 /// object’s text to each value to get the correct range for that text storage.
780 /// - context: The context object you use to identify the associated text storage.
781 /// - completion: The completion handler to execute when your delegate finishes updating
782 /// the selection. The handler has no parameters or return value. You must
783 /// call this handler at some point during the implementation of your method.
784 ///
785 /// As Writing Tools suggests changes to your view’s text, it calls this method
786 /// to update the text selection accordingly. Use this method to update the
787 /// current selection in your view’s text storage. When you finish making the
788 /// changes, call the provided completion block to let Writing Tools know you’re finished.
789 #[unsafe(method(writingToolsCoordinator:selectRanges:inContext:completion:))]
790 #[unsafe(method_family = none)]
791 fn writingToolsCoordinator_selectRanges_inContext_completion(
792 &self,
793 writing_tools_coordinator: &UIWritingToolsCoordinator,
794 ranges: &NSArray<NSValue>,
795 context: &UIWritingToolsCoordinatorContext,
796 completion: &block2::DynBlock<dyn Fn()>,
797 );
798
799 #[cfg(all(
800 feature = "UIBezierPath",
801 feature = "UIWritingToolsCoordinatorContext",
802 feature = "block2"
803 ))]
804 /// Asks the delegate to provide the bounding paths for the specified
805 /// text in your view.
806 ///
807 /// - Parameters:
808 /// - writingToolsCoordinator: The coordinator object requesting information
809 /// from your custom view.
810 /// - range: The range of text to evaluate. This range is relative to the
811 /// text in your context object, and it’s your responsibility to match that
812 /// location to the correct location in your text storage. If you initialized
813 /// the context object with the entire contents of your view’s text storage,
814 /// you can use `range` as-is to access that text storage. However, if you
815 /// initialized the context object with only a portion of your view’s text,
816 /// add the starting location of your context object’s text to this value to
817 /// get the correct range for that text storage.
818 /// - context: The context object with the target text. Use this object to
819 /// find the text in your view’s text storage.
820 /// - completion: A handler to execute with the required information. The
821 /// handler has no return value and takes an array of Bezier paths as a
822 /// parameter. You must call this handler at some point during your method’s implementation.
823 ///
824 /// After applying proofreading marks to your view’s text, Writing Tools lets
825 /// the person accept or reject individual suggestions. To facilitate interactions,
826 /// the coordinator asks your delegate to provide one or more Bezier paths that
827 /// surround those proofreading suggestions. For each distinct range of text
828 /// with a suggestion, it calls this method to get the Bezier paths that surround
829 /// the corresponding text.
830 ///
831 /// After you determine the location of the specified range of text in your view’s
832 /// text storage, call the
833 /// <doc
834 /// ://com.apple.documentation/documentation/uikit/nstextlayoutmanager/3809995-enumeratetextsegments>
835 /// method of your view’s
836 /// <doc
837 /// ://com.apple.documentation/documentation/uikit/nstextlayoutmanager>
838 /// to compute the selection rectangles for that text. That method finds the text
839 /// segments that contain the text and returns the frame rectangle for each one.
840 /// Create a Bezier path for each rectangle, and convert the coordinates of each path
841 /// to the coordinate space of the view in your coordinator's ``UIWritingToolsCoordinator/decorationContainerView``
842 /// property. Pass the resulting paths to the completion handler.
843 #[unsafe(method(writingToolsCoordinator:requestsBoundingBezierPathsForRange:inContext:completion:))]
844 #[unsafe(method_family = none)]
845 fn writingToolsCoordinator_requestsBoundingBezierPathsForRange_inContext_completion(
846 &self,
847 writing_tools_coordinator: &UIWritingToolsCoordinator,
848 range: NSRange,
849 context: &UIWritingToolsCoordinatorContext,
850 completion: &block2::DynBlock<dyn Fn(NonNull<NSArray<UIBezierPath>>)>,
851 );
852
853 #[cfg(all(
854 feature = "UIBezierPath",
855 feature = "UIWritingToolsCoordinatorContext",
856 feature = "block2"
857 ))]
858 /// Asks the delegate to provide an underline shape for the specified text
859 /// during a proofreading session.
860 ///
861 /// - Parameters:
862 /// - writingToolsCoordinator: The coordinator object requesting information
863 /// from your custom view.
864 /// - range: The range of text to evaluate. This range is relative to the
865 /// text in your context object, and it’s your responsibility to match that
866 /// location to the correct location in your text storage. If you initialized
867 /// the context object with the entire contents of your view’s text storage,
868 /// you can use `range` as-is to access that text storage. However, if you
869 /// initialized the context object with only a portion of your view’s text,
870 /// add the starting location of your context object’s text to this value
871 /// to get the correct range for that text storage.
872 /// - context: The context object with the target text. Use this object to
873 /// find the text in your view’s text storage.
874 /// - completion: A handler to execute with the required information. The
875 /// handler has no return value and takes an array of Bezier paths as a
876 /// parameter. You must call this handler at some point during your method’s implementation.
877 ///
878 /// When applying proofreading marks to your view’s content, the coordinator
879 /// calls this method to retrieve a shape to draw under the specified text.
880 /// You provide the shape using one or more Bezier paths, and the coordinator
881 /// draws and animates that shape during the proofreading session.
882 ///
883 /// After you determine the location of the specified range of text in your
884 /// view’s text storage, find the rectangle around that text. If you're using
885 /// TextKit, you can call the
886 /// <doc
887 /// ://com.apple.documentation/documentation/uikit/nstextlayoutmanager/3809995-enumeratetextsegments>
888 /// method of your view’s
889 /// <doc
890 /// ://com.apple.documentation/documentation/uikit/nstextlayoutmanager>
891 /// to get the rectangles for a range of text. Convert the coordinates of each rectangle
892 /// to the coordinate space of the view in your coordinator's ``UIWritingToolsCoordinator/decorationContainerView``
893 /// property. Use those rectangles to create the Bezier paths for your text.
894 /// For example, you might create a path with a straight or wavy line at the
895 /// bottom of the rectangle.
896 #[unsafe(method(writingToolsCoordinator:requestsUnderlinePathsForRange:inContext:completion:))]
897 #[unsafe(method_family = none)]
898 fn writingToolsCoordinator_requestsUnderlinePathsForRange_inContext_completion(
899 &self,
900 writing_tools_coordinator: &UIWritingToolsCoordinator,
901 range: NSRange,
902 context: &UIWritingToolsCoordinatorContext,
903 completion: &block2::DynBlock<dyn Fn(NonNull<NSArray<UIBezierPath>>)>,
904 );
905
906 #[cfg(all(feature = "UIWritingToolsCoordinatorContext", feature = "block2"))]
907 /// Prepare for animations for the content that Writing Tools is evaluating.
908 ///
909 /// - Parameters:
910 /// - writingToolsCoordinator: The coordinator object notifying you that
911 /// animations are about to begin.
912 /// - textAnimation: The type of animation Writing Tools is preparing.
913 /// - range: The range of text affected by the animation. This range is
914 /// relative to the text in your context object, and it’s your responsibility
915 /// to match that location to the correct location in your text storage.
916 /// If you initialized the context object with the entire contents of your
917 /// view’s text storage, you can use `range` as-is to access that text
918 /// storage. However, if you initialized the context object with only a portion
919 /// of your view’s text, add the starting location of your context object’s
920 /// text to this value to get the correct range for that text storage.
921 /// - context: The context object that contains the original text. Use this
922 /// object to fetch the current text, and to match that text to your underlying
923 /// text storage.
924 /// - completion: A completion handler to execute when you are done. The handler
925 /// has no return value and takes no parameters. You must call this handler
926 /// at some point during your implementation.
927 ///
928 /// During an interactive evaluation of your view’s text, Writing Tools creates
929 /// different animations to provide feedback on what’s happening. For example, it
930 /// creates an ``UIWritingToolsCoordinator/TextAnimation/anticipate`` animation to
931 /// let people know the system is evaluating the text. The `textAnimation` parameter
932 /// tells you what type of animation to prepare for.
933 ///
934 /// Use this method to prepare for the system-provided animations of your view’s
935 /// content. For interactive animations, hide the text in the specified range temporarily
936 /// while the system animations run. For non-interactive animations, dim the text
937 /// for the duration of the animation to indicate it’s not editable. For animations
938 /// to remove or insert text, you can also use this method to set up animations
939 /// to reflow your view’s content to match the changes. At the end of a given animation,
940 /// use your delegate’s ``writingToolsCoordinator(_:finish:for:in:completion:)``
941 /// method to undo any changes you make to your content.
942 ///
943 /// For a single animation type, the system calls the
944 /// ``writingToolsCoordinator(_:requestsPreviewFor:range:context:completion:)`` method,
945 /// followed sequentially by this method and the ``writingToolsCoordinator(_:finish:for:in:completion:)``
946 /// method. Each method executes asynchronously, but the system calls the next
947 /// method in the sequence only after you call the completion handler of the previous
948 /// method. However, multiple animations can run simultaneously, so check the
949 /// `textAnimation` and `range` parameters to differentiate sequences.
950 #[unsafe(method(writingToolsCoordinator:prepareForTextAnimation:forRange:inContext:completion:))]
951 #[unsafe(method_family = none)]
952 fn writingToolsCoordinator_prepareForTextAnimation_forRange_inContext_completion(
953 &self,
954 writing_tools_coordinator: &UIWritingToolsCoordinator,
955 text_animation: UIWritingToolsCoordinatorTextAnimation,
956 range: NSRange,
957 context: &UIWritingToolsCoordinatorContext,
958 completion: &block2::DynBlock<dyn Fn()>,
959 );
960
961 #[cfg(all(
962 feature = "UITargetedPreview",
963 feature = "UIWritingToolsCoordinatorContext",
964 feature = "block2"
965 ))]
966 /// Asks the delegate for a preview image and layout information for the
967 /// specified text.
968 ///
969 /// - Parameters:
970 /// - writingToolsCoordinator: The coordinator object notifying you that
971 /// animations are about to begin.
972 /// - textAnimation: The type of animation Writing Tools is preparing.
973 /// - range: The range of text that requires a preview image. This range
974 /// is relative to the text in your context object, and it’s your responsibility
975 /// to match that location to the correct location in your text storage.
976 /// If you initialized the context object with the entire contents of
977 /// your view’s text storage, you can use `range` as-is to access that
978 /// text storage. However, if you initialized the context object with only
979 /// a portion of your view’s text, add the starting location of your
980 /// context object’s text to this value to get the correct range for that
981 /// text storage.
982 /// - context: The context object that contains the original text. Use this
983 /// object to fetch the current text, and to match that text to your
984 /// underlying text storage.
985 /// - completion: A completion handler to execute when you are done. The
986 /// handler has no return value and takes a ``UITargetedPreview`` object
987 /// as a parameter. You must call this handler at some point during your implementation.
988 ///
989 /// During an interactive evaluation of your view’s text, Writing Tools creates
990 /// different animations to provide feedback on what’s happening. As part of
991 /// the preparation for those animations, Writing Tools asks you to provide
992 /// a preview of the affected content in your view. Writing Tools uses this
993 /// preview to build and execute the animations in the view stored in the
994 /// ``UIWritingToolsCoordinator/effectContainerView`` property of the coordinator object.
995 ///
996 /// To build a preview of your content in iOS, render the specified range of
997 /// text into an image with a transparent background. Install the image in a
998 /// ``UIImageView`` and use that to build your preview object. Set the frame
999 /// rectangle of your image view to the rectangle in your view’s coordinate
1000 /// space that contains the text you captured. When creating the ``UITargetedPreview``
1001 /// object, include both a ``UIPreviewParameters`` and a ``UIPreviewTarget``
1002 /// object. Create the ``UIPreviewTarget`` object with your text view as the
1003 /// container, and set the center point to the center of your text view.
1004 /// Create the ``UIPreviewParameters`` object using the selection rectangles
1005 /// for the text, which you get from your view’s layout manager. Writing Tools
1006 /// uses this information to place your image directly above the text in your view.
1007 ///
1008 /// For a single animation type, the system calls this method, followed sequentially
1009 /// by the ``writingToolsCoordinator(_:prepareFor:range:context:completion:)`` and
1010 /// ``writingToolsCoordinator(_:finish:for:in:completion:)``
1011 /// methods. Each method executes asynchronously, but the system calls the next
1012 /// method in the sequence only after you call the completion handler of the
1013 /// previous method. However, multiple animations can run simultaneously, so
1014 /// check the `textAnimation` parameter to differentiate sequences.
1015 #[unsafe(method(writingToolsCoordinator:requestsPreviewForTextAnimation:ofRange:inContext:completion:))]
1016 #[unsafe(method_family = none)]
1017 fn writingToolsCoordinator_requestsPreviewForTextAnimation_ofRange_inContext_completion(
1018 &self,
1019 writing_tools_coordinator: &UIWritingToolsCoordinator,
1020 text_animation: UIWritingToolsCoordinatorTextAnimation,
1021 range: NSRange,
1022 context: &UIWritingToolsCoordinatorContext,
1023 completion: &block2::DynBlock<dyn Fn(*mut UITargetedPreview)>,
1024 );
1025
1026 #[cfg(all(feature = "UIWritingToolsCoordinatorContext", feature = "block2"))]
1027 /// Asks the delegate to clean up any state related to the specified
1028 /// Writing Tools animation.
1029 ///
1030 /// - Parameters:
1031 /// - writingToolsCoordinator: The coordinator object notifying you
1032 /// that animations are about to begin.
1033 /// - textAnimation: The type of animation Writing Tools finished.
1034 /// - range: The range of text that finished animating. This range is
1035 /// relative to the text in your context object, and it’s your responsibility
1036 /// to match that location to the correct location in your text storage. If
1037 /// you initialized the context object with the entire contents of your
1038 /// view’s text storage, you can use `range` as-is to access that text storage.
1039 /// However, if you initialized the context object with only a portion of
1040 /// your view’s text, add the starting location of your context object’s
1041 /// text to this value to get the correct range for that text storage.
1042 /// - context: The context object that contains the original text.
1043 /// - completion: A completion handler to execute when you are done.
1044 /// The handler has no return value and takes no parameters. You must
1045 /// call this handler at some point during your implementation.
1046 ///
1047 /// Use this method to clean up any data structures you created to support
1048 /// the specified type of Writing Tools animation. You can also use this
1049 /// method to restore the visibility of any text you hid previously. When
1050 /// you finish your cleanup work, call the completion handler to notify Writing Tools.
1051 ///
1052 /// Writing Tools calls this method only after previous calls to the
1053 /// ``writingToolsCoordinator(_:requestsPreviewFor:range:context:completion:)``
1054 /// and ``writingToolsCoordinator(_:prepareFor:range:context:completion:)``
1055 /// methods for the same animation type. However, Writing Tools can interleave
1056 /// calls to this method with calls to prepare an animation of a different
1057 /// type. In your implementation of this method, make sure the actions you
1058 /// take don’t interfere with other in-flight animations.
1059 #[unsafe(method(writingToolsCoordinator:finishTextAnimation:forRange:inContext:completion:))]
1060 #[unsafe(method_family = none)]
1061 fn writingToolsCoordinator_finishTextAnimation_forRange_inContext_completion(
1062 &self,
1063 writing_tools_coordinator: &UIWritingToolsCoordinator,
1064 text_animation: UIWritingToolsCoordinatorTextAnimation,
1065 range: NSRange,
1066 context: &UIWritingToolsCoordinatorContext,
1067 completion: &block2::DynBlock<dyn Fn()>,
1068 );
1069
1070 #[cfg(all(feature = "UIWritingToolsCoordinatorContext", feature = "block2"))]
1071 /// Asks the delegate to divide the specified range of text into the separate
1072 /// containers that render that text.
1073 ///
1074 /// - Parameters:
1075 /// - writingToolsCoordinator: The coordinator object requesting information
1076 /// from your custom view.
1077 /// - range: The range of text to consider in the specified `context` object.
1078 /// The location value of this range is relative to the beginning of the text
1079 /// in your context object, and it’s your responsibility to match that location
1080 /// to the correct location in your text storage. If you initialized the
1081 /// context object with the entire contents of your view’s text storage,
1082 /// you can use `range` as-is to access that text storage. However, if you
1083 /// initialized the context object with only a portion of your view’s text,
1084 /// add the starting location of your context object’s text to this value
1085 /// to get the correct range for that text storage.
1086 /// - context: The context object that contains the text to consider. Use this
1087 /// object to locate the appropriate text storage object for your view.
1088 /// - completion: A completion handler to execute when you are done. The handler
1089 /// has no return value and takes an array of
1090 /// <doc
1091 /// ://com.apple.documentation/documentation/foundation/nsvalue>
1092 /// types, each of which contains an
1093 /// <doc
1094 /// ://com.apple.documentation/documentation/foundation/nsrange>.
1095 /// The union of the ranges you pass to this handler must equal all of the
1096 /// text in `range`. The order of the ranges in the array must be sequential,
1097 /// with each new range's starting location coming after the previous one.
1098 /// There must also not be any gaps or overlap between ranges.
1099 /// You must call this handler at some point during your implementation.
1100 ///
1101 /// If your view uses multiple ``NSTextContainer`` objects to draw text in different
1102 /// regions, use this method to tell Writing Tools about the containers that display
1103 /// the specified text. In your implementation, subdivide `range` to create one new
1104 /// range for each portion of text that resides in a different container object.
1105 /// For example, if the text in `range` is split between two containers, provide
1106 /// two new
1107 /// <doc
1108 /// ://com.apple.documentation/documentation/foundation/nsrange> types
1109 /// that reflect the portion of the total text in each container. If `range` resides completely
1110 /// within one container, call the completion handler with `range` as the only value
1111 /// in the array.
1112 ///
1113 /// When configuring animations for your view, Writing Tools asks your delegate to
1114 /// provide separate previews for each of your view’s container object. Specifically,
1115 /// it calls your delegate’s ``writingToolsCoordinator(_:requestsPreviewFor:range:context:completion:)``
1116 /// method separately for each range of text you return in the completion handler.
1117 /// Your implementation of that method must create a preview suitable for animating
1118 /// the content from the underlying text container.
1119 #[optional]
1120 #[unsafe(method(writingToolsCoordinator:requestsSingleContainerSubrangesOfRange:inContext:completion:))]
1121 #[unsafe(method_family = none)]
1122 fn writingToolsCoordinator_requestsSingleContainerSubrangesOfRange_inContext_completion(
1123 &self,
1124 writing_tools_coordinator: &UIWritingToolsCoordinator,
1125 range: NSRange,
1126 context: &UIWritingToolsCoordinatorContext,
1127 completion: &block2::DynBlock<dyn Fn(NonNull<NSArray<NSValue>>)>,
1128 );
1129
1130 #[cfg(all(
1131 feature = "UIResponder",
1132 feature = "UIView",
1133 feature = "UIWritingToolsCoordinatorContext",
1134 feature = "block2"
1135 ))]
1136 /// Asks the delegate to provide a decoration view for the specified range of text.
1137 ///
1138 /// - Parameters:
1139 /// - writingToolsCoordinator: The coordinator object requesting information
1140 /// from your custom view.
1141 /// - range: The range of text to consider in the specified `context` object.
1142 /// The location value of this range is relative to the beginning of the text
1143 /// in your context object, and it’s your responsibility to match that location
1144 /// to the correct location in your text storage. If you initialized the
1145 /// context object with the entire contents of your view’s text storage, you
1146 /// can use `range` as-is to access that text storage. However, if you initialized
1147 /// the context object with only a portion of your view’s text, add the starting
1148 /// location of your context object’s text to this value to get the correct
1149 /// range for that text storage.
1150 /// - context: The context object that contains the text to consider. Use this
1151 /// object to locate the appropriate text storage object for your view.
1152 /// - completion: A completion handler to execute when you are done. The handler
1153 /// has no return value and takes a ``UIView`` object as a parameter. You must call
1154 /// this handler at some point during your implementation.
1155 ///
1156 /// If your view uses multiple ``NSTextContainer`` objects to draw text in different
1157 /// regions, use this method to provide Writing Tools with the view to use for the
1158 /// specified range of text. After calling your delegate’s ``writingToolsCoordinator(_:requestsSingleContainerSubrangesOf:in:completion:)``
1159 /// method, Writing Tools calls this method for each subrange of text you provided.
1160 /// Find or provide a view situated visibly below the specified text in your text
1161 /// view. It's also satisfactory to provide a view that’s visually in front of the
1162 /// text. Writing Tools uses the provided view to host any proofreading marks for
1163 /// the specified range of text.
1164 ///
1165 /// If your view has only one text container, use the coordinator’s ``UIWritingToolsCoordinator/decorationContainerView``
1166 /// property to specify the view to use for proofreading marks.
1167 #[optional]
1168 #[unsafe(method(writingToolsCoordinator:requestsDecorationContainerViewForRange:inContext:completion:))]
1169 #[unsafe(method_family = none)]
1170 fn writingToolsCoordinator_requestsDecorationContainerViewForRange_inContext_completion(
1171 &self,
1172 writing_tools_coordinator: &UIWritingToolsCoordinator,
1173 range: NSRange,
1174 context: &UIWritingToolsCoordinatorContext,
1175 completion: &block2::DynBlock<dyn Fn(NonNull<UIView>)>,
1176 );
1177
1178 #[cfg(feature = "block2")]
1179 /// Notifies your delegate of relevant state changes when Writing Tools
1180 /// is running in your view.
1181 ///
1182 /// - Parameters:
1183 /// - writingToolsCoordinator: The coordinator object providing
1184 /// information to your custom view.
1185 /// - state: The new state for the Writing Tools session. For information
1186 /// about the possible states, see ``UIWritingToolsCoordinator/State``.
1187 /// - text: The current text for your context object.
1188 /// - reason: The reason for the state change.
1189 /// - context: The context object that contains the original text for
1190 /// Writing Tools to evaluate.
1191 /// - completion: A handler to execute when your delegate finishes processing
1192 /// the change of state. The handler has no parameters or return value. You
1193 /// must call this handler at some point during the implementation of your method.
1194 ///
1195 /// Use state transitions to perform actions related to your view or text storage.
1196 /// When Writing Tools is active, it updates its state to indicate what task
1197 /// it’s currently performing. Writing Tools starts in the ``UIWritingToolsCoordinator/State/inactive``
1198 /// state and moves to other states as it presents UI and starts interacting with
1199 /// your view’s content. For example, it moves to the ``UIWritingToolsCoordinator/State/interactiveStreaming``
1200 /// state when it’s making changes to your view’s text storage.
1201 #[optional]
1202 #[unsafe(method(writingToolsCoordinator:willChangeToState:completion:))]
1203 #[unsafe(method_family = none)]
1204 fn writingToolsCoordinator_willChangeToState_completion(
1205 &self,
1206 writing_tools_coordinator: &UIWritingToolsCoordinator,
1207 new_state: UIWritingToolsCoordinatorState,
1208 completion: &block2::DynBlock<dyn Fn()>,
1209 );
1210
1211 #[cfg(all(feature = "block2", feature = "objc2-core-foundation"))]
1212 /// Asks the delegate to provide the location of the character at the
1213 /// specified point in your view’s coordinate system.
1214 ///
1215 /// - Parameters:
1216 /// - writingToolsCoordinator: The coordinator object requesting
1217 /// information from your custom view.
1218 /// - point: A point in your view’s coordinate space. Find the
1219 /// location of the text under this point, if any.
1220 /// - completion: A handler to execute with the required information.
1221 /// This handler has no return value and takes an
1222 /// <doc
1223 /// ://com.apple.documentation/documentation/foundation/nsrange>
1224 /// and
1225 /// <doc
1226 /// ://com.apple.documentation/documentation/foundation/uuid>
1227 /// as parameters. Set the range to the character’s location in one of your
1228 /// ``UIWritingToolsCoordinator/Context`` objects, which you specify using
1229 /// the
1230 /// <doc
1231 /// ://com.apple.documentation/documentation/foundation/uuid> parameter.
1232 /// You must call this handler at some point during your method’s implementation.
1233 ///
1234 /// When someone interacts with your view during a proofreading operation, Writing Tools
1235 /// calls this method to get the location of the interaction. If the interaction
1236 /// occurs in the text of one of your ``UIWritingToolsCoordinator/Context`` objects,
1237 /// configure an
1238 /// <doc
1239 /// ://com.apple.documentation/documentation/foundation/nsrange>
1240 /// with the character’s location in that context object and a length of `1`. If
1241 /// the interaction occurs outside of the text of your context objects, configure
1242 /// the range with a location of `NSNotFound`.
1243 ///
1244 /// When specifying the location of a character in your context object, provide a
1245 /// location relative to the start of your context object’s text. The first character
1246 /// in a context object’s text is always at location `0`, and it’s your responsibility
1247 /// to track the location of the context object’s text in your text storage object.
1248 /// When the context object’s text begins in the middle of your text storage,
1249 /// subtract the starting location of the context object’s text from the location
1250 /// you specify in your range value. For example, if the context object’s text
1251 /// starts at character `100` in your text storage, and an interaction occurs
1252 /// with the character at location `102`, specify a range with a location of
1253 /// `2` and a length of `1`.
1254 #[deprecated = "In iOS 18.4 and later and visionOS 2.4 and later, UIWritingToolsCoordinator automatically determines the location of the character at the specified point in your view's coordinate system and no longer calls this method."]
1255 #[optional]
1256 #[unsafe(method(writingToolsCoordinator:requestsRangeInContextWithIdentifierForPoint:completion:))]
1257 #[unsafe(method_family = none)]
1258 fn writingToolsCoordinator_requestsRangeInContextWithIdentifierForPoint_completion(
1259 &self,
1260 writing_tools_coordinator: &UIWritingToolsCoordinator,
1261 point: CGPoint,
1262 completion: &block2::DynBlock<dyn Fn(NSRange, NonNull<NSUUID>)>,
1263 );
1264 }
1265);
1266
1267#[deprecated = "renamed to `UIWritingToolsCoordinatorTextAnimation::debug_description`"]
1268#[inline]
1269pub extern "C-unwind" fn UIWritingToolsCoordinatorTextAnimationDebugDescription(
1270 animation_type: UIWritingToolsCoordinatorTextAnimation,
1271) -> Retained<NSString> {
1272 extern "C-unwind" {
1273 fn UIWritingToolsCoordinatorTextAnimationDebugDescription(
1274 animation_type: UIWritingToolsCoordinatorTextAnimation,
1275 ) -> *mut NSString;
1276 }
1277 let ret = unsafe { UIWritingToolsCoordinatorTextAnimationDebugDescription(animation_type) };
1278 unsafe { Retained::retain_autoreleased(ret) }
1279 .expect("function was marked as returning non-null, but actually returned NULL")
1280}