Skip to main content

submenu

Function submenu 

Source
pub fn submenu<R>(
    ui: &mut Ui,
    label: &str,
    add: impl FnOnce(&mut Ui) -> R,
) -> InnerResponse<Option<R>>
Expand description

A submenu item in a menu drawn by hand (a context menu built in a closure, egui_pop_core::pointer::claim::context_menu), drawn as the declared menus’ submenu items: the kit’s menu-item with the submenu arrow, selected while its submenu is open. add draws the submenu’s rows; it runs only while the submenu is open, and its value comes back in the response’s inner.

  • The pointer resting on the item motion.submenu.delay (200 ms) opens it; a click opens it at once.
  • On the keyboard, Right, Enter or Space on the item opens it with the focus on its first row; Left in the submenu closes it, back on the item; Escape closes one level (this submenu, not the menu holding it).
  • Assistive technology reads a menu item named by label, with a menu popup, expanded while open.

Choosing a row in the submenu closes every level: the row calls ui.close(), as in any egui menu.

Need (dialog): a submenu in a context menu drawn by hand.

use egui_pop_api::menus;

fn row_menu(ui: &mut egui::Ui, auto: &mut bool) {
    if ui.button("Rename").clicked() {
        ui.close();
    }
    menus::submenu(ui, "Import automatically", |ui| {
        if ui.radio_value(auto, false, "Off").clicked()
            | ui.radio_value(auto, true, "On plug-in").clicked()
        {
            ui.close();
        }
    });
}