pub struct LiveTextInteractionDelegate { /* private fields */ }Implementations§
Source§impl LiveTextInteractionDelegate
impl LiveTextInteractionDelegate
Sourcepub fn new() -> Result<Self, VisionKitError>
pub fn new() -> Result<Self, VisionKitError>
Examples found in repository?
examples/05_live_text_interaction.rs (line 14)
13fn build_delegate() -> Result<LiveTextInteractionDelegate, Box<dyn std::error::Error>> {
14 let delegate = LiveTextInteractionDelegate::new()?;
15 delegate.set_should_begin(true)?;
16 delegate.set_should_handle_key_down_event(true)?;
17 delegate.set_should_show_menu_for_event(true)?;
18 delegate.set_contents_rect_override(Some(Rect::default()))?;
19
20 let content_view = LiveTextContentView::new()?;
21 content_view.set_frame(Rect {
22 x: 0.0,
23 y: 0.0,
24 width: 32.0,
25 height: 32.0,
26 })?;
27 delegate.set_content_view(Some(&content_view))?;
28
29 let updated_menu = LiveTextMenu {
30 title: "VisionKit".to_owned(),
31 items: vec![LiveTextMenuItem {
32 title: "Copy".to_owned(),
33 tag: LiveTextMenuTag::copy_image().map_or(0, LiveTextMenuTag::raw_value),
34 is_separator: false,
35 is_enabled: true,
36 is_hidden: false,
37 state: 0,
38 submenu: None,
39 }],
40 };
41 delegate.set_updated_menu(Some(&updated_menu))?;
42 Ok(delegate)
43}pub fn should_begin(&self) -> Result<bool, VisionKitError>
Sourcepub fn set_should_begin(&self, value: bool) -> Result<(), VisionKitError>
pub fn set_should_begin(&self, value: bool) -> Result<(), VisionKitError>
Examples found in repository?
examples/05_live_text_interaction.rs (line 15)
13fn build_delegate() -> Result<LiveTextInteractionDelegate, Box<dyn std::error::Error>> {
14 let delegate = LiveTextInteractionDelegate::new()?;
15 delegate.set_should_begin(true)?;
16 delegate.set_should_handle_key_down_event(true)?;
17 delegate.set_should_show_menu_for_event(true)?;
18 delegate.set_contents_rect_override(Some(Rect::default()))?;
19
20 let content_view = LiveTextContentView::new()?;
21 content_view.set_frame(Rect {
22 x: 0.0,
23 y: 0.0,
24 width: 32.0,
25 height: 32.0,
26 })?;
27 delegate.set_content_view(Some(&content_view))?;
28
29 let updated_menu = LiveTextMenu {
30 title: "VisionKit".to_owned(),
31 items: vec![LiveTextMenuItem {
32 title: "Copy".to_owned(),
33 tag: LiveTextMenuTag::copy_image().map_or(0, LiveTextMenuTag::raw_value),
34 is_separator: false,
35 is_enabled: true,
36 is_hidden: false,
37 state: 0,
38 submenu: None,
39 }],
40 };
41 delegate.set_updated_menu(Some(&updated_menu))?;
42 Ok(delegate)
43}pub fn contents_rect_override(&self) -> Result<Option<Rect>, VisionKitError>
Sourcepub fn set_contents_rect_override(
&self,
value: Option<Rect>,
) -> Result<(), VisionKitError>
pub fn set_contents_rect_override( &self, value: Option<Rect>, ) -> Result<(), VisionKitError>
Examples found in repository?
examples/05_live_text_interaction.rs (line 18)
13fn build_delegate() -> Result<LiveTextInteractionDelegate, Box<dyn std::error::Error>> {
14 let delegate = LiveTextInteractionDelegate::new()?;
15 delegate.set_should_begin(true)?;
16 delegate.set_should_handle_key_down_event(true)?;
17 delegate.set_should_show_menu_for_event(true)?;
18 delegate.set_contents_rect_override(Some(Rect::default()))?;
19
20 let content_view = LiveTextContentView::new()?;
21 content_view.set_frame(Rect {
22 x: 0.0,
23 y: 0.0,
24 width: 32.0,
25 height: 32.0,
26 })?;
27 delegate.set_content_view(Some(&content_view))?;
28
29 let updated_menu = LiveTextMenu {
30 title: "VisionKit".to_owned(),
31 items: vec![LiveTextMenuItem {
32 title: "Copy".to_owned(),
33 tag: LiveTextMenuTag::copy_image().map_or(0, LiveTextMenuTag::raw_value),
34 is_separator: false,
35 is_enabled: true,
36 is_hidden: false,
37 state: 0,
38 submenu: None,
39 }],
40 };
41 delegate.set_updated_menu(Some(&updated_menu))?;
42 Ok(delegate)
43}Sourcepub fn content_view(
&self,
) -> Result<Option<LiveTextContentView>, VisionKitError>
pub fn content_view( &self, ) -> Result<Option<LiveTextContentView>, VisionKitError>
Examples found in repository?
examples/05_live_text_interaction.rs (line 130)
100fn main() -> Result<(), Box<dyn std::error::Error>> {
101 if !ImageAnalyzer::is_supported() {
102 println!("ImageAnalyzer is not supported on this Mac");
103 return Ok(());
104 }
105
106 let asset_path = asset_path();
107 let analyzer = ImageAnalyzer::new()?;
108 let analysis = analyzer.analyze_image_at_path(
109 &asset_path,
110 ImageOrientation::Up,
111 &ImageAnalyzerConfiguration::new(ImageAnalysisTypes::TEXT),
112 )?;
113
114 let delegate = build_delegate()?;
115 let interaction = LiveTextInteraction::with_delegate(&delegate)?;
116 let tracking_view = LiveTextTrackingImageView::new()?;
117 tracking_view.set_image_at_path(&asset_path)?;
118 interaction.set_tracking_image_view(Some(&tracking_view))?;
119 interaction.track_image_at_path(&asset_path)?;
120 interaction.set_analysis(&analysis)?;
121 interaction.set_preferred_interaction_types(LiveTextInteractionTypes::AUTOMATIC_TEXT_ONLY)?;
122 interaction.set_selectable_items_highlighted(true)?;
123 interaction.set_contents_rect_needs_update()?;
124
125 println!("contents rect: {:?}", interaction.contents_rect()?);
126 println!("overlay text: {:?}", interaction.text());
127 println!("delegate events: {}", delegate.recorded_events()?.len());
128 println!(
129 "delegate content view set: {}",
130 interaction.delegate()?.and_then(|value| value.content_view().ok()).flatten().is_some()
131 );
132 match interaction.tracking_image_view()? {
133 Some(view) => println!("tracking image size: {:?}", view.image_size()?),
134 None => println!("tracking image size: none"),
135 }
136 match LiveTextMenuTag::copy_image() {
137 Ok(tag) => println!("copy image tag: {}", tag.raw_value()),
138 Err(error) => println!("copy image tag: {error}"),
139 }
140 print_selection_state(&interaction)?;
141 print_subject_state(&interaction)?;
142 println!(
143 "live text button visible: {}",
144 interaction.live_text_button_visible()?
145 );
146 println!(
147 "supplementary hidden: {}",
148 interaction.is_supplementary_interface_hidden()?
149 );
150
151 let image_for_subjects_fn: fn(&LiveTextInteraction, &[LiveTextSubject]) -> Result<
152 LiveTextImageData,
153 VisionKitError,
154 > = LiveTextInteraction::image_for_subjects;
155 black_box(image_for_subjects_fn);
156 Ok(())
157}Sourcepub fn set_content_view(
&self,
value: Option<&LiveTextContentView>,
) -> Result<(), VisionKitError>
pub fn set_content_view( &self, value: Option<&LiveTextContentView>, ) -> Result<(), VisionKitError>
Examples found in repository?
examples/05_live_text_interaction.rs (line 27)
13fn build_delegate() -> Result<LiveTextInteractionDelegate, Box<dyn std::error::Error>> {
14 let delegate = LiveTextInteractionDelegate::new()?;
15 delegate.set_should_begin(true)?;
16 delegate.set_should_handle_key_down_event(true)?;
17 delegate.set_should_show_menu_for_event(true)?;
18 delegate.set_contents_rect_override(Some(Rect::default()))?;
19
20 let content_view = LiveTextContentView::new()?;
21 content_view.set_frame(Rect {
22 x: 0.0,
23 y: 0.0,
24 width: 32.0,
25 height: 32.0,
26 })?;
27 delegate.set_content_view(Some(&content_view))?;
28
29 let updated_menu = LiveTextMenu {
30 title: "VisionKit".to_owned(),
31 items: vec![LiveTextMenuItem {
32 title: "Copy".to_owned(),
33 tag: LiveTextMenuTag::copy_image().map_or(0, LiveTextMenuTag::raw_value),
34 is_separator: false,
35 is_enabled: true,
36 is_hidden: false,
37 state: 0,
38 submenu: None,
39 }],
40 };
41 delegate.set_updated_menu(Some(&updated_menu))?;
42 Ok(delegate)
43}pub fn should_handle_key_down_event(&self) -> Result<bool, VisionKitError>
Sourcepub fn set_should_handle_key_down_event(
&self,
value: bool,
) -> Result<(), VisionKitError>
pub fn set_should_handle_key_down_event( &self, value: bool, ) -> Result<(), VisionKitError>
Examples found in repository?
examples/05_live_text_interaction.rs (line 16)
13fn build_delegate() -> Result<LiveTextInteractionDelegate, Box<dyn std::error::Error>> {
14 let delegate = LiveTextInteractionDelegate::new()?;
15 delegate.set_should_begin(true)?;
16 delegate.set_should_handle_key_down_event(true)?;
17 delegate.set_should_show_menu_for_event(true)?;
18 delegate.set_contents_rect_override(Some(Rect::default()))?;
19
20 let content_view = LiveTextContentView::new()?;
21 content_view.set_frame(Rect {
22 x: 0.0,
23 y: 0.0,
24 width: 32.0,
25 height: 32.0,
26 })?;
27 delegate.set_content_view(Some(&content_view))?;
28
29 let updated_menu = LiveTextMenu {
30 title: "VisionKit".to_owned(),
31 items: vec![LiveTextMenuItem {
32 title: "Copy".to_owned(),
33 tag: LiveTextMenuTag::copy_image().map_or(0, LiveTextMenuTag::raw_value),
34 is_separator: false,
35 is_enabled: true,
36 is_hidden: false,
37 state: 0,
38 submenu: None,
39 }],
40 };
41 delegate.set_updated_menu(Some(&updated_menu))?;
42 Ok(delegate)
43}Examples found in repository?
examples/05_live_text_interaction.rs (line 17)
13fn build_delegate() -> Result<LiveTextInteractionDelegate, Box<dyn std::error::Error>> {
14 let delegate = LiveTextInteractionDelegate::new()?;
15 delegate.set_should_begin(true)?;
16 delegate.set_should_handle_key_down_event(true)?;
17 delegate.set_should_show_menu_for_event(true)?;
18 delegate.set_contents_rect_override(Some(Rect::default()))?;
19
20 let content_view = LiveTextContentView::new()?;
21 content_view.set_frame(Rect {
22 x: 0.0,
23 y: 0.0,
24 width: 32.0,
25 height: 32.0,
26 })?;
27 delegate.set_content_view(Some(&content_view))?;
28
29 let updated_menu = LiveTextMenu {
30 title: "VisionKit".to_owned(),
31 items: vec![LiveTextMenuItem {
32 title: "Copy".to_owned(),
33 tag: LiveTextMenuTag::copy_image().map_or(0, LiveTextMenuTag::raw_value),
34 is_separator: false,
35 is_enabled: true,
36 is_hidden: false,
37 state: 0,
38 submenu: None,
39 }],
40 };
41 delegate.set_updated_menu(Some(&updated_menu))?;
42 Ok(delegate)
43}Examples found in repository?
examples/05_live_text_interaction.rs (line 41)
13fn build_delegate() -> Result<LiveTextInteractionDelegate, Box<dyn std::error::Error>> {
14 let delegate = LiveTextInteractionDelegate::new()?;
15 delegate.set_should_begin(true)?;
16 delegate.set_should_handle_key_down_event(true)?;
17 delegate.set_should_show_menu_for_event(true)?;
18 delegate.set_contents_rect_override(Some(Rect::default()))?;
19
20 let content_view = LiveTextContentView::new()?;
21 content_view.set_frame(Rect {
22 x: 0.0,
23 y: 0.0,
24 width: 32.0,
25 height: 32.0,
26 })?;
27 delegate.set_content_view(Some(&content_view))?;
28
29 let updated_menu = LiveTextMenu {
30 title: "VisionKit".to_owned(),
31 items: vec![LiveTextMenuItem {
32 title: "Copy".to_owned(),
33 tag: LiveTextMenuTag::copy_image().map_or(0, LiveTextMenuTag::raw_value),
34 is_separator: false,
35 is_enabled: true,
36 is_hidden: false,
37 state: 0,
38 submenu: None,
39 }],
40 };
41 delegate.set_updated_menu(Some(&updated_menu))?;
42 Ok(delegate)
43}Sourcepub fn recorded_events(
&self,
) -> Result<Vec<LiveTextDelegateEvent>, VisionKitError>
pub fn recorded_events( &self, ) -> Result<Vec<LiveTextDelegateEvent>, VisionKitError>
Examples found in repository?
examples/05_live_text_interaction.rs (line 127)
100fn main() -> Result<(), Box<dyn std::error::Error>> {
101 if !ImageAnalyzer::is_supported() {
102 println!("ImageAnalyzer is not supported on this Mac");
103 return Ok(());
104 }
105
106 let asset_path = asset_path();
107 let analyzer = ImageAnalyzer::new()?;
108 let analysis = analyzer.analyze_image_at_path(
109 &asset_path,
110 ImageOrientation::Up,
111 &ImageAnalyzerConfiguration::new(ImageAnalysisTypes::TEXT),
112 )?;
113
114 let delegate = build_delegate()?;
115 let interaction = LiveTextInteraction::with_delegate(&delegate)?;
116 let tracking_view = LiveTextTrackingImageView::new()?;
117 tracking_view.set_image_at_path(&asset_path)?;
118 interaction.set_tracking_image_view(Some(&tracking_view))?;
119 interaction.track_image_at_path(&asset_path)?;
120 interaction.set_analysis(&analysis)?;
121 interaction.set_preferred_interaction_types(LiveTextInteractionTypes::AUTOMATIC_TEXT_ONLY)?;
122 interaction.set_selectable_items_highlighted(true)?;
123 interaction.set_contents_rect_needs_update()?;
124
125 println!("contents rect: {:?}", interaction.contents_rect()?);
126 println!("overlay text: {:?}", interaction.text());
127 println!("delegate events: {}", delegate.recorded_events()?.len());
128 println!(
129 "delegate content view set: {}",
130 interaction.delegate()?.and_then(|value| value.content_view().ok()).flatten().is_some()
131 );
132 match interaction.tracking_image_view()? {
133 Some(view) => println!("tracking image size: {:?}", view.image_size()?),
134 None => println!("tracking image size: none"),
135 }
136 match LiveTextMenuTag::copy_image() {
137 Ok(tag) => println!("copy image tag: {}", tag.raw_value()),
138 Err(error) => println!("copy image tag: {error}"),
139 }
140 print_selection_state(&interaction)?;
141 print_subject_state(&interaction)?;
142 println!(
143 "live text button visible: {}",
144 interaction.live_text_button_visible()?
145 );
146 println!(
147 "supplementary hidden: {}",
148 interaction.is_supplementary_interface_hidden()?
149 );
150
151 let image_for_subjects_fn: fn(&LiveTextInteraction, &[LiveTextSubject]) -> Result<
152 LiveTextImageData,
153 VisionKitError,
154 > = LiveTextInteraction::image_for_subjects;
155 black_box(image_for_subjects_fn);
156 Ok(())
157}pub fn clear_recorded_events(&self) -> Result<(), VisionKitError>
Trait Implementations§
Source§impl Drop for LiveTextInteractionDelegate
impl Drop for LiveTextInteractionDelegate
Auto Trait Implementations§
impl Freeze for LiveTextInteractionDelegate
impl RefUnwindSafe for LiveTextInteractionDelegate
impl !Send for LiveTextInteractionDelegate
impl !Sync for LiveTextInteractionDelegate
impl Unpin for LiveTextInteractionDelegate
impl UnsafeUnpin for LiveTextInteractionDelegate
impl UnwindSafe for LiveTextInteractionDelegate
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more