pub struct Text { /* private fields */ }Expand description
Specifies text used in the toast template.
Implementations§
Source§impl Text
impl Text
Sourcepub fn new(content: impl Into<String>) -> Self
pub fn new(content: impl Into<String>) -> Self
Create a new text element.
Examples found in repository?
examples/sample.rs (line 32)
15fn main() -> Result<()> {
16 let manager = ToastManager::new(ToastManager::POWERSHELL_AUM_ID);
17
18 let mut toast = Toast::new();
19
20 let hero_image =
21 Image::new_local(Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/images/flower.jpg"))?
22 .with_placement(ImagePlacement::Hero);
23
24 let icon_image =
25 Image::new_local(Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/images/cat.jpg"))?
26 .with_placement(ImagePlacement::AppLogoOverride)
27 .with_hint_crop(ImageHintCrop::Circle);
28
29 toast
30 .tag("example")
31 .text1("Title")
32 .text2(Text::new("Body"))
33 .text3(Text::new("Via SMS").with_placement(TextPlacement::Attribution))
34 .image(1, hero_image)
35 .image(2, icon_image)
36 .duration(ToastDuration::Long)
37 .audio(Audio::new(Sound::Looping(LoopingSound::Alarm5)).with_looping())
38 .input(
39 Input::new("box", InputType::Selection)
40 .with_title("Select an option")
41 .with_default_input("breakfast"),
42 )
43 .selection(Selection::new("breakfast", "Breakfast"))
44 .selection(Selection::new("lunch", "Lunch"))
45 .selection(Selection::new("dinner", "Dinner"))
46 .action(Action::new("Send", "send", "").with_input_id("box"))
47 .action(Action::new("Dismiss", "dismiss", ""));
48
49 // Clone the action_take atomic bool for the closures
50 // This is necessary because the closures are Fn/FnMut,
51 // and we need to be able to modify the action_take bool
52 // from within the closures
53 let action_take = Arc::new(AtomicBool::new(false));
54 let action_clone = Arc::clone(&action_take);
55 let dismiss_clone = Arc::clone(&action_take);
56
57 fn handle_activated_action(action: Option<ActivatedAction>) {
58 match action {
59 Some(action) => {
60 let message = format!(
61 "You clicked on {}{}!",
62 action.arg,
63 action
64 .values
65 .get(&action.input_id.unwrap_or_default())
66 .map_or(String::new(), |value| format!(", input = {value}"))
67 );
68 println!("{message}");
69 }
70 None => println!("You clicked me!"),
71 }
72 }
73
74 manager
75 .on_activated(Some("box"), move |action| {
76 handle_activated_action(action);
77 action_clone.store(true, Ordering::SeqCst);
78 })
79 .on_dismissed(move |reason| {
80 match reason {
81 Ok(r) if r.reason == DismissalReason::UserCanceled => println!("UserCanceled"),
82 Ok(r) if r.reason == DismissalReason::ApplicationHidden => {
83 println!("ApplicationHidden")
84 }
85 Ok(r) if r.reason == DismissalReason::TimedOut => println!("TimedOut"),
86 Ok(_r) => println!("Unknown dismissal reason"),
87 Err(e) => eprintln!("Error: {e:?}"),
88 }
89 dismiss_clone.store(true, Ordering::SeqCst);
90 })
91 .on_failed(|e| eprintln!("Error: {e:?}"))
92 .show(&toast)
93 .expect("Failed to show toast");
94
95 // Wait for the user to interact with the toast
96 let time_instant = Instant::now();
97 while time_instant.elapsed() < Duration::from_secs(25) {
98 if action_take.load(Ordering::SeqCst) {
99 break;
100 }
101 sleep(Duration::from_millis(100));
102 }
103
104 Ok(())
105}Sourcepub fn with_placement(self, placement: TextPlacement) -> Self
pub fn with_placement(self, placement: TextPlacement) -> Self
The placement of the text.
Examples found in repository?
examples/sample.rs (line 33)
15fn main() -> Result<()> {
16 let manager = ToastManager::new(ToastManager::POWERSHELL_AUM_ID);
17
18 let mut toast = Toast::new();
19
20 let hero_image =
21 Image::new_local(Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/images/flower.jpg"))?
22 .with_placement(ImagePlacement::Hero);
23
24 let icon_image =
25 Image::new_local(Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/images/cat.jpg"))?
26 .with_placement(ImagePlacement::AppLogoOverride)
27 .with_hint_crop(ImageHintCrop::Circle);
28
29 toast
30 .tag("example")
31 .text1("Title")
32 .text2(Text::new("Body"))
33 .text3(Text::new("Via SMS").with_placement(TextPlacement::Attribution))
34 .image(1, hero_image)
35 .image(2, icon_image)
36 .duration(ToastDuration::Long)
37 .audio(Audio::new(Sound::Looping(LoopingSound::Alarm5)).with_looping())
38 .input(
39 Input::new("box", InputType::Selection)
40 .with_title("Select an option")
41 .with_default_input("breakfast"),
42 )
43 .selection(Selection::new("breakfast", "Breakfast"))
44 .selection(Selection::new("lunch", "Lunch"))
45 .selection(Selection::new("dinner", "Dinner"))
46 .action(Action::new("Send", "send", "").with_input_id("box"))
47 .action(Action::new("Dismiss", "dismiss", ""));
48
49 // Clone the action_take atomic bool for the closures
50 // This is necessary because the closures are Fn/FnMut,
51 // and we need to be able to modify the action_take bool
52 // from within the closures
53 let action_take = Arc::new(AtomicBool::new(false));
54 let action_clone = Arc::clone(&action_take);
55 let dismiss_clone = Arc::clone(&action_take);
56
57 fn handle_activated_action(action: Option<ActivatedAction>) {
58 match action {
59 Some(action) => {
60 let message = format!(
61 "You clicked on {}{}!",
62 action.arg,
63 action
64 .values
65 .get(&action.input_id.unwrap_or_default())
66 .map_or(String::new(), |value| format!(", input = {value}"))
67 );
68 println!("{message}");
69 }
70 None => println!("You clicked me!"),
71 }
72 }
73
74 manager
75 .on_activated(Some("box"), move |action| {
76 handle_activated_action(action);
77 action_clone.store(true, Ordering::SeqCst);
78 })
79 .on_dismissed(move |reason| {
80 match reason {
81 Ok(r) if r.reason == DismissalReason::UserCanceled => println!("UserCanceled"),
82 Ok(r) if r.reason == DismissalReason::ApplicationHidden => {
83 println!("ApplicationHidden")
84 }
85 Ok(r) if r.reason == DismissalReason::TimedOut => println!("TimedOut"),
86 Ok(_r) => println!("Unknown dismissal reason"),
87 Err(e) => eprintln!("Error: {e:?}"),
88 }
89 dismiss_clone.store(true, Ordering::SeqCst);
90 })
91 .on_failed(|e| eprintln!("Error: {e:?}"))
92 .show(&toast)
93 .expect("Failed to show toast");
94
95 // Wait for the user to interact with the toast
96 let time_instant = Instant::now();
97 while time_instant.elapsed() < Duration::from_secs(25) {
98 if action_take.load(Ordering::SeqCst) {
99 break;
100 }
101 sleep(Duration::from_millis(100));
102 }
103
104 Ok(())
105}Sourcepub fn info_attribution(self) -> Self
pub fn info_attribution(self) -> Self
Set the placement of the text to TextPlacement::Attribution.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Text
impl RefUnwindSafe for Text
impl Send for Text
impl Sync for Text
impl Unpin for Text
impl UnwindSafe for Text
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