Tray icon with menu

Hello. I'm asking for help, I can't make a menu for the tray icon.

use dialoguer::Input;
use tray_icon::Icon;
use tray_icon::TrayIconBuilder;
use tray_icon:: menu::Menu;
use tray_icon::menu::MenuItem;

fn main() {
   
    let image_pic = image::open("znachki/11d@2x.png").expect("msg"); 
    let img: Vec<u8> = image_pic.into_bytes();
    let icon = Icon::from_rgba(img, 100, 100).unwrap();   
    
    let uuu = MenuItem::new("slava", true, None);
    let tray_menu = Menu::new();
    tray_menu.insert(&uuu, 0).unwrap();
    tray_menu.insert(&uuu, 1).unwrap(); 

    let tray_icon = TrayIconBuilder::new()
    .with_menu(Box::new(tray_menu))
    .with_tooltip("system-tray - tray icon library!")
    .with_icon(icon)
    .build()
    .unwrap();

    let name: String = Input::new()
    .with_prompt("Your name?")
    .interact_text()
    .unwrap();
 
println!("Your name is: {}", name);

}
1 Like

what are you trying to do, and what's the error you see?

I don't know about the tray_icon library, but if it's about the tray area in the taskbar, I think you need a GUI event loop, at least on Windows.

2 Likes

Hello. I am able to create the tray icon itself. I can't make a menu that should appear when clicking on this icon. It's a little difficult for me right now, since I just started learning rust.

The menu itself is being created:
let tray_menu = Menu::new();

Here it is passed to the icon
let tray_icon = TrayIconBuilder::new() .with_menu(Box::new(tray_menu))

I don't understand how to create the menu bars with the names themselves.

Are you, perhaps, on Mac? The documentation for the insert method indicates that only submenus can be added to the menu: Menu in tray_icon::menu - Rust

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.