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
impl TrayIcon
Sourcepub fn new(title: impl IntoValue<String>) -> TrayIcon
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).
pub fn title(self, title: impl IntoValue<String>) -> TrayIcon
Sourcepub fn icon(self, icon: impl IntoValue<AppIcon>) -> TrayIcon
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.
Sourcepub fn tooltip(self, tooltip: impl IntoValue<String>) -> TrayIcon
pub fn tooltip(self, tooltip: impl IntoValue<String>) -> TrayIcon
Text shown over it, and read by screen readers.
What a click opens: the same menus the menu bar takes (its title isn’t shown).