Skip to main content

LiveTextMenuTag

Struct LiveTextMenuTag 

Source
pub struct LiveTextMenuTag(/* private fields */);

Implementations§

Source§

impl LiveTextMenuTag

Source

pub const fn new(raw_value: i64) -> Self

Source

pub const fn raw_value(self) -> i64

Examples found in repository?
examples/05_live_text_interaction.rs (line 137)
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}
Source

pub fn copy_image() -> Result<Self, VisionKitError>

Examples found in repository?
examples/05_live_text_interaction.rs (line 33)
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}
44
45fn print_selection_state(
46    interaction: &LiveTextInteraction,
47) -> Result<(), Box<dyn std::error::Error>> {
48    match interaction.selected_ranges() {
49        Ok(ranges) => {
50            interaction.set_selected_ranges(&ranges)?;
51            println!("selected ranges: {}", ranges.len());
52        }
53        Err(error) => println!("selected ranges: {error}"),
54    }
55    match interaction.selected_attributed_text() {
56        Ok(text) => println!("selected attributed text runs: {}", text.runs.len()),
57        Err(error) => println!("selected attributed text runs: {error}"),
58    }
59    match interaction.supplementary_interface_font() {
60        Ok(font) => {
61            interaction.set_supplementary_interface_font(font.as_ref())?;
62            println!("supplementary font set: {}", font.is_some());
63        }
64        Err(error) => println!("supplementary font set: {error}"),
65    }
66    Ok(())
67}
68
69fn print_subject_state(
70    interaction: &LiveTextInteraction,
71) -> Result<(), Box<dyn std::error::Error>> {
72    println!(
73        "subject unavailable case: {:?}",
74        LiveTextSubjectUnavailable::ImageUnavailable
75    );
76    match interaction.begin_subject_analysis_if_necessary() {
77        Ok(()) => println!("subject analysis started"),
78        Err(error) => println!("subject analysis started: {error}"),
79    }
80    match interaction.subjects() {
81        Ok(subjects) => {
82            println!("subjects: {}", subjects.len());
83            println!(
84                "highlighted subjects: {}",
85                interaction.highlighted_subjects()?.len()
86            );
87            if let Some(subject) = subjects.first() {
88                println!("subject bounds: {:?}", subject.bounds()?);
89            }
90            match interaction.image_for_subjects(&subjects) {
91                Ok(image) => println!("subject image bytes: {}", image.png_data.len()),
92                Err(error) => println!("subject image bytes: {error}"),
93            }
94        }
95        Err(error) => println!("subjects: {error}"),
96    }
97    Ok(())
98}
99
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}
Source

pub fn share_image() -> Result<Self, VisionKitError>

Source

pub fn copy_subject() -> Result<Self, VisionKitError>

Source

pub fn share_subject() -> Result<Self, VisionKitError>

Source

pub fn lookup_item() -> Result<Self, VisionKitError>

Source

pub fn recommended_app_items() -> Result<Self, VisionKitError>

Trait Implementations§

Source§

impl Clone for LiveTextMenuTag

Source§

fn clone(&self) -> LiveTextMenuTag

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LiveTextMenuTag

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for LiveTextMenuTag

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Hash for LiveTextMenuTag

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for LiveTextMenuTag

Source§

fn eq(&self, other: &LiveTextMenuTag) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for LiveTextMenuTag

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for LiveTextMenuTag

Source§

impl Eq for LiveTextMenuTag

Source§

impl StructuralPartialEq for LiveTextMenuTag

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,