Skip to main content

Module menus

Module menus 

Source
Expand description

Menus drawn from their declarations, with egui’s own menus ([egui::containers::menu::MenuButton], SubMenuButton’s [egui::containers::menu::SubMenu], [egui::Popup]): egui’s keyboard navigation and accessibility come with them.

A command item shows the command’s title, its first key binding (from the keymap, so a menu never shows a key that does not work) and a tick when its checked clause holds; it is greyed, with the reason, where the command does not apply. Clicking runs the command as the user, in the context the menu opened in.

Every row starts with the gutter (docs/icons.md, section 5): a column of fixed width (Kit::menu_gutter, scaled by the density) holding the command’s icon (CommandSpec::icon, or icon_on while checked), the tick of a checked item without an icon, the dot of a chosen radio item, or the spinner of a running command; a checked command with an icon shows it framed (menu-item-gutter‘s selected state), as Word does. Labels start after it whether a row has an icon or not, so they align; shortcuts keep a right-aligned column, before the submenu arrows’ column. Labels, keys and notes are in egui’s Body text style (as egui’s own menus, not Button); a theme’s menu-item.key-font-size draws the keys and notes smaller, and the ↗ of an entry opening a link with them. The SETTING_ICONS setting turns the icons off (the gutter is then kept only in a menu with a check or radio item) or follows the platform. The gutter is decorative: AccessKit reads the title, and a check or radio item as checked or not.

A list item (MenuItem::list) is filled by the list provider of its name (Ctx::list_provider), asked when the menu opens and never on every frame: the recent files, the profiles. Each entry it gives runs a command with its arguments; the lists debug collector shows what each provider gave last.

  • bar draws a menu as a menu bar (the shell draws app.main), moving the menus that do not fit into a “…” menu;
  • show draws a menu’s items inside an open menu or popup;
  • context_menu opens a declared menu on a widget’s secondary click (or Shift+F10 and the Menu key while it has the focus), and context_menu_with with arguments of the moment (the clicked row’s path), merged into every item’s command and seen by the when clauses as args.<key>; not where a widget claimed the secondary click for itself (egui_pop_core::pointer::claim);
  • popup_at opens a declared menu as a popup under a rectangle or at a point (a logo, Alt+Space); egui-pop draws it until an item is chosen, a click lands outside or Escape is pressed;
  • submenu adds a submenu item to a menu drawn by hand (a context menu built in a closure), in the declared menus’ look, opened by the pointer resting on it or by the keyboard, closed one level by Escape.

Opening a menu by popup_at or a context menu runs the STEP_OPEN step (ADR 0011): a plugin may veto it or change its arguments.

use egui_pop_api::{AppHandle, menus};
use egui_pop_model::ids::MenuId;

const ROW: MenuId = MenuId::from_static("demo.row");

fn row(ui: &mut egui::Ui, app: &AppHandle, path: &str) {
    let r = ui.label("Right-click me");
    menus::context_menu_with(&r, app, &ROW, serde_json::json!({ "path": path }));
}

Structs§

At
Where a popup menu opens: under a rectangle (a button, a logo), or at a point.
BarLayout
Where a menu bar drew its menus last.
ListItem
An entry a list provider gives when its menu opens.
ListTrace
What a list provider gave last, as the lists collector shows it.
RowTrace
A menu row as it was drawn, for agents and tests.

Enums§

Mark
What a row’s gutter holds, as agents read it (rows_drawn).
MenuIcons
What the SETTING_ICONS setting asks for.

Constants§

POPUP_LISTENER
The popup menu’s listener on pop.popup.close: closed by anyone (Escape, an item chosen, its window closing under it), it is no longer open, in that call.
POPUP_OWNER
The popup menu’s owner on the bus (POPUP_LISTENER).
POPUP_PREFIX
The start of the popup menu’s popup id: menu@<window>.
SETTING_ICONS
The setting: whether menus show the commands’ icons in their gutter, on (the default, Word’s look), off, or platform (MenuIcons).
STEP_OPEN
A menu opens as a popup or a context menu: {"menu": id, "args": arguments, "how": "popup" | "context"}. A veto keeps it closed, a redirect changes its arguments.

Functions§

bar
Draws a menu as a bar of menu buttons: each item a submenu opening a popup. The menus that do not fit go into a “…” menu (see bar_within).
bar_end
Draws a menu’s command items as icon buttons at the end of a bar (the shell’s menu bar draws MENU_BAR_END there), in the menu’s order: each the command’s icon (its icon_on while its checked clause holds, the button then drawn selected), its title and first key binding in the tooltip. An item whose command does not apply (its when) is left out, not greyed: a bar’s end shows what can be done. A command without an icon shows its title. Laid out from the end: call it in a right-to-left Ui. Returns the width it took.
bar_layout
Where a menu drawn as a bar (bar, the shell’s app.main) put its menus last, if it was drawn.
bar_within
Draws a menu as a bar of menu buttons, keeping reserve points free at its end (what the bar shows after its menus).
close_popup
Closes the popup menu, if one is open (its pop.popup.close).
command_row
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.
context_menu
Opens a declared menu on the widget’s secondary click (or a long touch). Its items are evaluated in the context of the moment it opened, and their commands run in it. It does not open where a widget inside claimed the secondary click (egui_pop_core::pointer::claim).
context_menu_opened
As context_menu_with, by_key saying that the keyboard opens it now (Shift+F10 or the Menu key, read with claim::menu_key): for a row of a widget that keeps the focus itself, a tree’s cursor row.
context_menu_with
As context_menu, with arguments of this call (the clicked row’s path): merged into every item’s command arguments, and seen by when clauses as args.<key>.
has_end_items
Whether bar_end would draw something for this menu now.
menu_icons
What the SETTING_ICONS setting says now.
platform_shows_icons
Whether the platform shows icons in menus, from the desktop (XDG_CURRENT_DESKTOP) and KDE’s kdeglobals: not on GNOME; on KDE Plasma as its ShowIconsInMenuItems (group KDE) says, yes when it does not say; yes elsewhere (Windows, macOS, other desktops).
popup_at
Opens a declared menu as a popup under a rectangle or at a point, evaluated in the context of now; egui-pop draws it from the next frame until an item is chosen, a click lands outside or Escape is pressed. One popup at a time: another replaces it. It opens in the window the user works in (AppHandle::active_window: a detached panel’s window when it was opened from there), the rectangle in that window’s points, and goes to the main window if that window closes. Opened while a ScopedTheme draws (a theme editor’s preview), it is drawn in that theme. Returns whether it opened (a hook on STEP_OPEN may veto it).
popup_at_with
As popup_at, with arguments merged into the items’ commands.
popup_open
The menu open as a popup, if one is.
popup_window
The window the popup menu shows in, if one is open: the one it was opened in, or the main window once that one is closed.
rows_drawn
The menu rows drawn in the last complete pass (every open menu’s, and menus drawn in place): their labels, icons, gutter marks and where their labels start, so an agent or a test reads what a menu shows without pixels.
show
Draws a menu’s items in the current Ui (an open menu or popup), in the current context.
show_in
Draws a menu’s items, evaluated in a given context.
submenu
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.

Type Aliases§

ListFn
A list provider: the entries of a list, in the context the menu opens in.