Skip to main content

TrayIcon

Struct TrayIcon 

Source
pub struct TrayIcon { /* private fields */ }
Expand description

The app’s icon in the platform’s tray, with a menu: what brings back an app that runs without windows, shows it’s still running and holds its Quit. One per app: set_tray replaces it, and it goes when the scope that installed it ends. A click opens the menu on every platform, so give it an item that opens the window.

ⓘ
set_tray(
    TrayIcon::new("Player")
        .icon(AppIcon::named("player-symbolic").image(AppIcon::bytes(include_bytes!("tray.png"))))
        .tooltip(move || format!("{} songs queued", queue.get().len()))
        .menu(Menu::new("").children((
            MenuItem::new("Open Player").on_select(move || open.set(true)),
            MenuSeparator,
            MenuItem::new("Quit").role(MenuRole::Quit).on_select(quit),
        ))),
);

In view!, in a component that holds it as long as it should show, its children are its menu’s: <TrayIcon title="Player" icon=icon><MenuItem @select=quit>"Quit"</MenuItem></TrayIcon>.

Implementations§

Source§

impl TrayIcon

Source

pub fn new(title: impl IntoValue<String>) -> TrayIcon

title is its accessible name, and its name where the platform lists tray items (Plasma’s system tray settings, Windows’ taskbar settings).

Source

pub fn title(self, title: impl IntoValue<String>) -> TrayIcon

Source

pub fn icon(self, icon: impl IntoValue<AppIcon>) -> TrayIcon

What it shows, which the app swaps to show state. Each platform wants its own: a monochrome template image on macOS (AppKit tints it), an icon name from the theme on Linux (AppIcon::named, a -symbolic one where the theme has it), an .ico with the small sizes on Windows. Without, the app’s icon. An image is read when the icon changes: to show other pixels, give other bytes or another path.

Source

pub fn tooltip(self, tooltip: impl IntoValue<String>) -> TrayIcon

Text shown over it, and read by screen readers.

Source

pub fn menu(self, menu: Menu) -> TrayIcon

What a click opens: the same menus the menu bar takes (its title isn’t shown).

Trait Implementations§

Source§

impl View for TrayIcon

Source§

fn build(self, ui: &Ui) -> NodeId

A placeholder in the tree, which takes no room: the icon is the app’s, in the platform’s tray.

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<V> Children for V
where V: View,

Source§

fn into_views(self, out: &mut Vec<AnyView>)

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, 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.