Skip to main content

TrayIcon

Struct TrayIcon 

Source
pub struct TrayIcon {
    pub tooltip: String,
    pub icon_rgba: Vec<u8>,
    pub icon_width: u32,
    pub icon_height: u32,
    pub menu: Option<TrayMenu>,
    pub visible: bool,
    pub click_count: usize,
    pub last_action_id: Option<u64>,
    pub badge: Option<String>,
}
Expand description

System tray icon abstraction.

Fields§

§tooltip: String§icon_rgba: Vec<u8>§icon_width: u32§icon_height: u32§menu: Option<TrayMenu>§visible: bool§click_count: usize§last_action_id: Option<u64>§badge: Option<String>

Implementations§

Source§

impl TrayIcon

Source

pub fn new( tooltip: impl Into<String>, icon_rgba: Vec<u8>, icon_width: u32, icon_height: u32, ) -> Self

Creates a new system tray icon.

Source

pub fn set_badge(&mut self, badge: Option<String>)

Sets the notification badge text (e.g. “99+” or “NEW”).

Source

pub fn set_badge_count(&mut self, count: Option<u32>)

Sets the notification badge as a numeric count (or clears it if None or 0).

Source

pub fn badge(&self) -> Option<&str>

Returns current badge text if present.

Source

pub fn set_tooltip(&mut self, tooltip: impl Into<String>)

Sets the hover tooltip text.

Source

pub fn set_menu(&mut self, menu: Option<TrayMenu>)

Sets or clears the tray context menu.

Source

pub fn set_visible(&mut self, visible: bool)

Sets whether the icon is visible in the status bar/system tray.

Source

pub fn trigger_click(&mut self)

Simulates or executes a primary click on the tray icon.

Source

pub fn trigger_menu_action(&mut self, id: u64) -> bool

Simulates or executes a menu item action by ID. Returns true if the item was found and enabled.

Source

pub fn spawn_native<F>(self, event_sink: F) -> NativeTrayHandle
where F: Fn(PlatformEvent) + Send + Sync + 'static,

Spawns an OS-native system tray handle dispatching events through the provided event callback.

On Linux the native indicator is created immediately when this is called on the GTK main thread after gtk::init(). Callers on any other thread, and callers where the Ayatana AppIndicator library is absent, receive a handle-only controller that still dispatches events from the in-process model.

Source

pub fn spawn_handle_only<F>(self, event_sink: F) -> NativeTrayHandle
where F: Fn(PlatformEvent) + Send + Sync + 'static,

Spawns a deterministic in-process tray controller (backend_name() == "handle-only") without attempting OS tray registration.

Trait Implementations§

Source§

impl Clone for TrayIcon

Source§

fn clone(&self) -> Self

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 TrayIcon

Source§

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

Formats the value using the given formatter. Read more

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> IntoInitialState<T> for T

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 = !

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

fn try_from(value: U) -> Result<T, !>

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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,