28 releases

0.3.5 Oct 16, 2024
0.3.4 Oct 9, 2024
0.3.1 Sep 27, 2024
0.2.3 Aug 22, 2024
0.1.6 Jun 24, 2024

#100 in GUI

Download history 219/week @ 2024-07-16 689/week @ 2024-07-23 167/week @ 2024-07-30 7/week @ 2024-08-06 246/week @ 2024-08-13 305/week @ 2024-08-20 3/week @ 2024-08-27 101/week @ 2024-09-10 232/week @ 2024-09-17 237/week @ 2024-09-24 272/week @ 2024-10-01 360/week @ 2024-10-08 177/week @ 2024-10-15 4/week @ 2024-10-22

570 downloads per month

MIT license

175KB
4K SLoC

wcpopup   Latest Version Documentation

Rust context menu for Windows and Linux(Gtk3).
Supports dark/light theme and color/size configuration.

  • Colors
    • Text color
    • Background color
    • Border color
  • Size
    • Menu padding
    • Menu item padding
  • Font
    • Font family
    • Size and weight

samplesample

Usage

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
    // let mut builder = MenuBuilder::new_for_window(window);

    builder.check("menu_item1", "Fit To Window", true, None);
    builder.separator();
    builder.text_with_accelerator("menu_item2", "Playlist", None, "Ctrl+P");
    builder.text_with_accelerator("menu_item3", "Toggle Fullscreen", None, "F11");
    builder.text("menu_item4", "Picture In Picture", None);
    builder.separator();
    builder.text_with_accelerator("menu_item5", "Capture", None, "Ctrl+S");
    builder.separator();

    let mut submenu = builder.submenu("submenu1", "Theme", None);
    submenu.radio("submenu_item1", "Light", "Theme", true, None);
    submenu.radio("submenu_item2", "Dark", "Theme", 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).
Using WebView2, you may need to enable the feature flag.

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

Accelerator

Accelerators are used only to display available shortcut keys by default.
Use "accelerator" feature to treat accelerators as commands.
With this feature, when a shortcut key is pressed, the corresponding MenuItem is returned as the result of Menu.popup_at().

features = ["accelerator"]

Dependencies

~4–47MB
~776K SLoC