Expand description
Rust context menu for Windows and Linux(Gtk3).
Supports dark/light theme and color/size/font configurations.
- Colors(
config::ColorScheme)- Text color
- Background color
- Border color
- Size(
config::MenuSize)- Menu padding
- Menu item padding
- Font(
config::MenuFont)- Font family
- Size and weight
§Example
Use ManuBuilder to create a Menu with MenuItems.
fn example(window_handle: isize) {
let mut builder = MenuBuilder::new(window_handle);
// Using HWND
// let mut builder = MenuBuilder::new_for_hwnd(hwnd);
// Using gtk::ApplicationWindow or gtk::Window
// let mut builder = MenuBuilder::new_for_window(window);
builder.check("menu_item1", "Menu Label 1", true, None);
builder.separator();
builder.text_with_accelerator("menu_item2", "Menu Label 2", None, "Ctrl+P");
builder.text_with_accelerator("menu_item3", "Menu Label 3", None, "F11");
builder.text("menu_item4", "Menu Label 4", None);
builder.separator();
builder.text_with_accelerator("menu_item5", "Menu Label 5", None, "Ctrl+S");
builder.separator();
let mut submenu = builder.submenu("Submenu1", "Submenu", None);
submenu.radio("submenu_item1", "Menu Label 1", "Submenu1", true, None);
submenu.radio("submenu_item2", "Menu Label 2", "Submenu1", false, None);
submenu.build().unwrap();
let menu = builder.build().unwrap();
}Call Menu.popup_at() to show Menu and receive the selected MenuItem using MenuEvent.
fn show_context_menu(x:i32, y:i32) {
menu.popup_at(x, y);
}
if let Ok(event) = MenuEvent::receiver().try_recv() {
let selected_menu_item = event.item;
}Or call Menu.popup_at_async() to show Menu and wait asynchronously for a selected MenuItem.
async fn show_context_menu(x:i32, y:i32) {
let selected_menu_item = menu.popup_at(x, y).await;
}§Platform-specific notes
§Windows
WebView2 may receive all keyboard input instead of its parent window(#1703). You can disable it by either
- Enabling “webview” feature
features = ["webview"]- Enabling Webview2 “msWebView2BrowserHitTransparent” feature
--enable-features=msWebView2BrowserHitTransparent§Linux
Gtk3 is required. MenuItem’s text color is applied to SVG icon if the SVG file contains the “symbolic” term as the last component of the file name.
Modules§
Structs§
- Menu
- Context Menu.
- Menu
Builder - Builder to create Menu.
- Menu
Event - Menu
Icon - Menu
Item - Menu item.