Skip to content

ui::TrayIcon

Header: winui/ui/TrayIcon.hpp.

An icon in the taskbar's notification area, with a hover text, a right-click menu and notifications. It is only the icon. The app runs its own loop (ui::run()) and ends it with ui::quit(). A flyout is an ordinary Window the app owns and attaches through TrayIconOptions::flyout.

The icon is added when the TrayIcon is created and removed when it is destroyed. UI thread only.

Example:

int main()
{
    ui::Property<float> volume{40.0f};

    ui::Window flyout{ui::tray_flyout_options({.title = "Volume", .width = 320.0f})};
    flyout.set_content(ui::VerticalStack{
        .spacing  = 16.0f,
        .margin   = ui::Thickness{20.0f},
        .content  = {ui::Slider{.value = volume}},
    });

    ui::TrayIcon tray{{
        .tool_tip = "Volume",
        .icon     = ui::WindowIcon{.glyph = ui::IconGlyph{0xE767}},
        .menu     = {{.text = "Open", .on_click = [&] { tray.show_flyout(); }},
                    {.text = "Quit", .on_click = [] { ui::quit(); }}},
        .flyout  = &flyout,
    }};
    return ui::run(); // until ui::quit(); closing the flyout only hides it
}

TrayIcon

TrayIcon(TrayIconOptions options = {})

Adds the icon. When there is no taskbar yet, the icon is added as soon as the taskbar starts.

~TrayIcon

~TrayIcon()

Removes the icon.

TrayIcon

TrayIcon(const TrayIcon&) = delete

Not copyable: owns the icon.

operator=

TrayIcon& operator=(const TrayIcon&) = delete

Not copyable: owns the icon.

set_tool_tip

void set_tool_tip(std::string tool_tip)

Replace the icon's hover text.

set_icon

void set_icon(WindowIcon icon)

Replace the icon, for example to show a state. See TrayIconOptions::icon_follows_taskbar_theme.

set_menu

void set_menu(std::vector<MenuItem> items)

Replace the right-click menu.

notify

void notify(Notification notification)

Shows a notification from the icon. It is what ui::notify() shows, sent with the tray icon as its source, so NotificationIcon::App is the tray icon. The user's notification settings decide whether it is shown. Replaces one still showing. A click runs notification.on_click, or TrayIconOptions::on_notification_click when that is empty.

Example:

ui::TrayIcon tray{{.tool_tip = "Timer"}};
tray.notify({.title = "Timer", .text = "Time is up.", .on_click = [&] { tray.show_flyout(); }});

show_flyout

void show_flyout()

Open the flyout next to the icon, sized to its content, and give it the focus. Does nothing without a flyout.

hide_flyout

void hide_flyout()

Hide the flyout. It is not destroyed, so its content and state stay.

toggle_flyout

void toggle_flyout()

show_flyout() if hidden, hide_flyout() if open: what a click on the icon does.