Skip to main content

command_row

Function command_row 

Source
pub fn command_row(
    ui: &mut Ui,
    label: &str,
    shortcut: Option<&str>,
    disabled: Option<&str>,
) -> Response
Expand description

A command row in a menu drawn by hand (a popup or context menu built in a closure), drawn as the declared menus’ command rows: the kit’s menu-item, its label at the start, shortcut (the keys’ text, such as Ctrl+C) muted at the end in the menu’s key font. Greyed and not clickable while disabled gives why, the reason in its tooltip. Assistive technology reads a menu item named by label, its shortcut as its keyboard shortcut.

The caller acts on a click and closes the menu (ui.close()), as in any egui menu.

Need (dialog): a command row with its shortcut in a menu drawn by hand.

use egui_pop_api::menus;

fn row_menu(ui: &mut egui::Ui, can_paste: bool) {
    if menus::command_row(ui, "Copy", Some("Ctrl+C"), None).clicked() {
        ui.close();
    }
    let why = (!can_paste).then_some("Nothing to paste");
    if menus::command_row(ui, "Paste", Some("Ctrl+V"), why).clicked() {
        ui.close();
    }
}