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.
bardraws a menu as a menu bar (the shell drawsapp.main), moving the menus that do not fit into a “…” menu;showdraws a menu’s items inside an open menu or popup;context_menuopens a declared menu on a widget’s secondary click (or Shift+F10 and theMenukey while it has the focus), andcontext_menu_withwith arguments of the moment (the clicked row’s path), merged into every item’s command and seen by thewhenclauses asargs.<key>; not where a widget claimed the secondary click for itself (egui_pop_core::pointer::claim);popup_atopens 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;submenuadds 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.
- List
Item - An entry a list provider gives when its menu opens.
- List
Trace - What a list provider gave last, as the
listscollector 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). - Menu
Icons - What the
SETTING_ICONSsetting 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, orplatform(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_ENDthere), in the menu’s order: each the command’s icon (itsicon_onwhile itscheckedclause holds, the button then drawn selected), its title and first key binding in the tooltip. An item whose command does not apply (itswhen) 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-leftUi. Returns the width it took. - bar_
layout - Where a menu drawn as a bar (
bar, the shell’sapp.main) put its menus last, if it was drawn. - bar_
within - Draws a menu as a bar of menu buttons, keeping
reservepoints 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 asCtrl+C) muted at the end in the menu’s key font. Greyed and not clickable whiledisabledgives why, the reason in its tooltip. Assistive technology reads a menu item named bylabel, 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_keysaying that the keyboard opens it now (Shift+F10 or theMenukey, read withclaim::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 bywhenclauses asargs.<key>. - has_
end_ items - Whether
bar_endwould draw something for this menu now. - menu_
icons - What the
SETTING_ICONSsetting says now. - platform_
shows_ icons - Whether the platform shows icons in menus, from the desktop
(
XDG_CURRENT_DESKTOP) and KDE’skdeglobals: not on GNOME; on KDE Plasma as itsShowIconsInMenuItems(groupKDE) 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 aScopedThemedraws (a theme editor’s preview), it is drawn in that theme. Returns whether it opened (a hook onSTEP_OPENmay 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’smenu-itemwith the submenu arrow,selectedwhile its submenu is open.adddraws the submenu’s rows; it runs only while the submenu is open, and its value comes back in the response’sinner.
Type Aliases§
- ListFn
- A list provider: the entries of a list, in the context the menu opens in.