pub struct TrayConfig { /* private fields */ }Expand description
Initial configuration for a Tray.
Implementations§
Source§impl TrayConfig
impl TrayConfig
Sourcepub fn new(icon: Icon) -> TrayConfig
pub fn new(icon: Icon) -> TrayConfig
Start a configuration with the required tray icon.
Examples found in repository?
examples/basic.rs (line 30)
14fn main() {
15 // A 16x16 solid red icon.
16 let side = 16u32;
17 let mut rgba = Vec::with_capacity((side * side * 4) as usize);
18 for _ in 0..side * side {
19 rgba.extend_from_slice(&[220, 40, 40, 255]);
20 }
21 let icon = Icon::from_rgba(side, side, rgba).expect("valid icon");
22 let notify_icon = icon.clone();
23
24 let menu = Menu::new()
25 .item(MenuItem::button(SAY_HI, "Say hi"))
26 .item(MenuItem::checkbox(TOGGLE, "Toggle me", false))
27 .item(MenuItem::separator())
28 .item(MenuItem::button(QUIT, "Quit"));
29
30 let config = TrayConfig::new(icon).tooltip("ldtray example").menu(menu);
31
32 let tray = match Tray::new(config) {
33 Ok(tray) => tray,
34 Err(err) => {
35 eprintln!("tray unavailable: {err}");
36 eprintln!("(this is expected on a headless server — exiting cleanly)");
37 return;
38 }
39 };
40
41 let handle = tray.handle();
42 println!("tray is up — right-click it for the menu, or Ctrl-C to abort");
43
44 let result = tray.run(move |event| {
45 println!("event: {event:?}");
46 match event {
47 Event::Menu(id) if id.0 == SAY_HI => {
48 let _ = handle.notify(
49 Notification::new("ldtray", "Hello from the tray!")
50 .with_icon(notify_icon.clone()),
51 );
52 }
53 Event::Menu(id) if id.0 == QUIT => {
54 let _ = handle.quit();
55 }
56 _ => {}
57 }
58 });
59
60 if let Err(err) = result {
61 eprintln!("event loop ended with error: {err}");
62 }
63}Sourcepub fn tooltip(self, tooltip: impl Into<String>) -> TrayConfig
pub fn tooltip(self, tooltip: impl Into<String>) -> TrayConfig
Builder: set the hover tooltip text.
Examples found in repository?
examples/basic.rs (line 30)
14fn main() {
15 // A 16x16 solid red icon.
16 let side = 16u32;
17 let mut rgba = Vec::with_capacity((side * side * 4) as usize);
18 for _ in 0..side * side {
19 rgba.extend_from_slice(&[220, 40, 40, 255]);
20 }
21 let icon = Icon::from_rgba(side, side, rgba).expect("valid icon");
22 let notify_icon = icon.clone();
23
24 let menu = Menu::new()
25 .item(MenuItem::button(SAY_HI, "Say hi"))
26 .item(MenuItem::checkbox(TOGGLE, "Toggle me", false))
27 .item(MenuItem::separator())
28 .item(MenuItem::button(QUIT, "Quit"));
29
30 let config = TrayConfig::new(icon).tooltip("ldtray example").menu(menu);
31
32 let tray = match Tray::new(config) {
33 Ok(tray) => tray,
34 Err(err) => {
35 eprintln!("tray unavailable: {err}");
36 eprintln!("(this is expected on a headless server — exiting cleanly)");
37 return;
38 }
39 };
40
41 let handle = tray.handle();
42 println!("tray is up — right-click it for the menu, or Ctrl-C to abort");
43
44 let result = tray.run(move |event| {
45 println!("event: {event:?}");
46 match event {
47 Event::Menu(id) if id.0 == SAY_HI => {
48 let _ = handle.notify(
49 Notification::new("ldtray", "Hello from the tray!")
50 .with_icon(notify_icon.clone()),
51 );
52 }
53 Event::Menu(id) if id.0 == QUIT => {
54 let _ = handle.quit();
55 }
56 _ => {}
57 }
58 });
59
60 if let Err(err) = result {
61 eprintln!("event loop ended with error: {err}");
62 }
63}Builder: set the context menu.
Examples found in repository?
examples/basic.rs (line 30)
14fn main() {
15 // A 16x16 solid red icon.
16 let side = 16u32;
17 let mut rgba = Vec::with_capacity((side * side * 4) as usize);
18 for _ in 0..side * side {
19 rgba.extend_from_slice(&[220, 40, 40, 255]);
20 }
21 let icon = Icon::from_rgba(side, side, rgba).expect("valid icon");
22 let notify_icon = icon.clone();
23
24 let menu = Menu::new()
25 .item(MenuItem::button(SAY_HI, "Say hi"))
26 .item(MenuItem::checkbox(TOGGLE, "Toggle me", false))
27 .item(MenuItem::separator())
28 .item(MenuItem::button(QUIT, "Quit"));
29
30 let config = TrayConfig::new(icon).tooltip("ldtray example").menu(menu);
31
32 let tray = match Tray::new(config) {
33 Ok(tray) => tray,
34 Err(err) => {
35 eprintln!("tray unavailable: {err}");
36 eprintln!("(this is expected on a headless server — exiting cleanly)");
37 return;
38 }
39 };
40
41 let handle = tray.handle();
42 println!("tray is up — right-click it for the menu, or Ctrl-C to abort");
43
44 let result = tray.run(move |event| {
45 println!("event: {event:?}");
46 match event {
47 Event::Menu(id) if id.0 == SAY_HI => {
48 let _ = handle.notify(
49 Notification::new("ldtray", "Hello from the tray!")
50 .with_icon(notify_icon.clone()),
51 );
52 }
53 Event::Menu(id) if id.0 == QUIT => {
54 let _ = handle.quit();
55 }
56 _ => {}
57 }
58 });
59
60 if let Err(err) = result {
61 eprintln!("event loop ended with error: {err}");
62 }
63}Trait Implementations§
Source§impl Clone for TrayConfig
impl Clone for TrayConfig
Source§fn clone(&self) -> TrayConfig
fn clone(&self) -> TrayConfig
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for TrayConfig
impl RefUnwindSafe for TrayConfig
impl Send for TrayConfig
impl Sync for TrayConfig
impl Unpin for TrayConfig
impl UnsafeUnpin for TrayConfig
impl UnwindSafe for TrayConfig
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