Popups, menus, command table, tooltips#
Source: lib/ui/popup.rs
popup -- popups, flyouts, menus, menu bar, command table and accelerators, drop-down / split buttons, combo boxes, tooltips
[src/ui/ui_popup.s]
Popups (a stack of up to 6 levels per window, drawn on L_POPUP):
popup_open(id) open popup `id` (inside a flyout: as its child)
popup_close() close every popup; the focus returns to the opener
popup_close_id(id) close popup `id` and the popups inside it; the
flyouts it sits in stay open
popup_is_open(id) -> bool popup_count() -> n
flyout_begin(id, FL_*) -> bool draw popup `id` when it is open: a flyout surface
anchored to the last widget, content box BOX_V|PAD_4
flyout_end() always paired with flyout_begin
A press outside every popup closes them all and is consumed; Esc closes the top one;
Up / Down move the focus inside the top one.
popup_ext(i) / popup_rect(i) -> rect (U3, §6: popups that leave their window; the area
they may use is the monitor's work area -- they flip above / to the left where it ends)
Commands (the table AppDesc::cmds, Command records):
cmd_find(id) -> &Command cmd_state(id, CF_*) cmd_flags(id) -> CF_*
cmd_label(id) -> label without '&' accel_text(id) -> "Strg+Umschalt+S"
accel_order_set(1): "Strg+Alt+Umschalt+S" (ui_accel_order)
cmd_button(id, ST_*) -> EV button from the table (icon, label, tooltip with
the accelerator, disabled / checked); queues it
Menus (Mi records; Mi::List rows come from menu_list(base, rows), row k = id base + k with
the CF_CHECKED / CF_DISABLED state of cmd_state(base + k, ..); a
checked row with an icon gives the flyout a check column and an icon column):
menubar(None | Some(bar)) -> EV_OPEN WinUI MenuBar (None = AppDesc::menubar): items,
flyouts, submenus, keys (Alt / F10, Alt+mnemonic,
arrows, Enter, Esc)
menu_popup(menu) open a menu at the pointer (drawn by the runtime)
context_menu(menu) -> EV_OPEN post-modifier: right click / menu key / Shift+F10 on
the last widget opens `menu`
context_target() -> id the widget whose context menu is open
menu_item(id, label) -> EV row inside a flyout (next_icon, next_flags
ST_DISABLED / ST_CHECKED); activation closes popups
menu_item_keys(id, label, keys) -> EV the same with the text of its keys at the row's
end, for keys the app's own widgets handle (IDE1)
key_text(vk, mods) -> "Strg+Umschalt+S" a key as the accelerator texts write it
menu_cmd(cmd) -> EV menu_sep() a row for a command (queues it), a separator
menu_list(base, rows) the rows of the Mi::List with that base (the asm's
app-owned STRLIST buffer)
menu_list_flags(base, flags) (JD27) ML_* per row, after menu_list: ML_CHILD rows go
into the submenu of the row before them (Visio's
FlyoutChild), ML_SEP draws a separator above a row
Drop-down controls:
dropdown_button(id, label) -> EV button with a chevron; opens popup `id` (EV_OPEN)
split_button(id, label) -> EV EV_ACT from the main part; the chevron part
(id | 0x80000000) opens popup `id`
combobox(id, &mut sel, list) -> EV EV_ACT when sel changed, EV_OPEN while open
(drop-downs open with Alt+Down, and with F4 unless the command table has an F4 accelerator)
Tooltips:
tooltip(s) post-modifier: tooltip for the last widget after
500 ms of hover (timer UIT_TOOLTIP wakes the loop)
tooltip_part(s, part) the same for one part of the last widget (an item of
a canvas, part != 0): the delay starts again when the
part changes, a press hides it until another part
tooltips_set(on) / tooltips_on() every tooltip of the app on or off (an app's option
"no ScreenTips"; on at start)
Runtime: accel_dispatch() at the start of uiw_pass_end: runtime-drawn menus, stale
popups, command accelerators.
Ids: a menu's popup id is a hash of the menu's address (menu_pid), the menu bar's item
ids a hash of the bar's address -- like the asm, whose dumps therefore show other
numbers for them. (JD27) The submenu of a Mi::List row has a popup id of its own range
0xF... (list_sub_pid: the list's base and the row), never one of menu_pid's 0xB....
struct CommandCMD record: one row of the app's command table (AppDesc::cmds)id: u32-- command id (!= 0); also the widget id of cmd_buttonicon: u32-- IC_* code point or 0label: &'static str-- UTF-8 label, '&' marks the mnemonic ("&&" = '&')key: u16-- accelerator key VK_* (0 = none)mods: u8-- MOD_SHIFT | MOD_CTRL | MOD_ALTflags: u8-- initial CF_* state
impl Command
const fn new(id: u32, label: &'static str, icon: u32, mods: u32, key: u32, flags: u32) -> CommandCMD id, "&Label", icon, mods, key, flags (the order of the asm macro)enum Mimenu record (MENUBAR / MENU / MI_* of ui.inc); menus arestaticslices of themCmd(u32)-- MI_CMD cmd: a row from the command tableSep-- MI_SEPSub(&'static str, &'static [Mi])-- MI_SUB "Label", submenuMenu(&'static str, &'static [Mi])-- MENU "Label", menu: a top-level menu of a menu barItem(u32, &'static str, u32)-- MI_ITEM id, "Label", icon: a plain row, runs App::command(id, 0)List(u32, u16, &'static str)-- MI_LIST base, max, "placeholder": one row per string of the rows set with Ui::menu_list(base, ..) (at most max); row k runs App::command(base + k, 0) and has the widget id base + k, checked or disabled by cmd_state(base + k, CF_*) like a command; no rows: the placeholder as a disabled row ("" = none) (U1). Ui::menu_list_flags puts rows into submenus of other rows and separators between them (JD27)
impl Ui
fn accel_run(&mut self, key: u32) -> boolaccel_run(key) -> true when key (VK | mods << 16, as ui.key_take gives it) is the accelerator of an enabled, visible command of the table: it runs (cmd_run(id, 0), after the frame) as if the key had reached the table, open popups close. For a widget with HB_KEYS that hands a key back (one a web page did not use, say).fn popup_is_open(&self, id: u32) -> boolui_popup_is_open(id): popupidis openfn popup_count(&self) -> u32ui_popup_count -> open popups of the live window (U3)fn popup_open(&mut self, id: u32)ui_popup_open(id): open popupid(inside a flyout: as a child of that flyout, otherwise it replaces every open popup); an open popup only loses its childrenfn popup_open_at(&mut self, id: u32, x: i32, y: i32)popup_open_at(id, x, y): open popupidas popup_open does, its flyout hanging at the point (x, y) (px of the window, as last_rect: a canvas's UiInput::rect plus its x, y) instead of at the last widget; an open one moves there. For a place the app learns later than the click (a web engine's context menu); the app draws flyout_begin(id, ..) as usual.fn popup_close(&mut self)ui_popup_close: close every popup (the focus returns to where it was)fn popup_close_id(&mut self, id: u32)popup_close_id(id): close popupidand the popups opened inside it; the popups it was opened in stay open (a date_picker inside a flyout of the app's own closes its calendar, not the flyout). The focus returns to where it was whenidopened; nothing happens whenidis not open.fn flyout_begin(&mut self, id: u32, flags: u32) -> boolui_flyout_begin(id, FL_*) -> popupidis open: then its content follows (a vertical box with 4 DIP padding) until flyout_end, which is called in any case. The flyout is anchored to the last placed widget (FL_POINT: to the pointer position where it opened) and kept inside the window.fn popup_ext(&self, i: u32) -> Option<[i32; 4]>ui_popup_ext(i) -> rect x, y, w, h (px, window coordinates) of item i of the live window when it was drawn in the last pass partly outside its framebuffer. Items 0 .. 5 are the open popups, 6 the tooltip. (U3, OS popup windows)fn popup_rect(&self, i: u32) -> Option<[i32; 4]>ui_popup_rect(i) -> rect (px) of item i of the live window when it was drawn in the last pass (anywhere). The main window gives its popups own OS windows with it while tool windows are shown, so menus stay above them.fn flyout_end(&mut self)ui_flyout_end: close the content of flyout_begin (also when it returned false)fn cmd_find(&self, id: u32) -> Option<&'static Command>ui_cmd_find(id) -> the command record of the app's command tablefn cmd_state(&mut self, id: u32, flags: u32)ui_cmd_state(id, flags): set the CF_* state of a command; it stays until changed (calling it every frame with the same flags is fine) and overrides the table flags. Up to 1536 commands have a state; more print one UIWARN and are ignored.fn cmd_flags(&self, id: u32) -> u32ui_cmd_flags(id) -> CF_* state (cmd_state, else the table flags)fn cmd_label(&self, id: u32) -> Stringui_cmd_label(id) -> label of a command without '&' ("" if unknown)fn accel_text(&self, id: u32) -> Stringui_accel_text(id) -> accelerator of a command as text, e.g. "Strg+Umschalt+S"fn accel_order_set(&mut self, order: u32)ui_accel_order: 0 = "Strg+Umschalt+Alt+X" (default), 1 = "Strg+Alt+Umschalt+X" (U1)fn key_text(&self, vk: u32, mods: u32) -> Stringa key with modifiers (MOD_*) as the accelerator texts write it: "Strg+Umschalt+S", "F5" (the UI language's names; accel_order_set holds)fn context_target(&self) -> u32ui_context_target -> id of the widget whose context menu is (or was last) openfn combobox(&mut self, id: u32, sel: &mut i32, list: &[&str]) -> u32ui_combobox(id, &mut sel, list) -> EV_*: EV_ACT when sel changed, EV_OPEN while the list is open. WinUI ComboBox: 32 DIP, control fill, chevron; the list opens over the box with the selected row (accent pill) on it. Keyboard: Up / Down change the selection, Enter / Space / Alt+Down / F4 open the list.listis a STRLIST (it ends at the first empty string).fn tooltip(&mut self, s: &str)ui_tooltip(s): post-modifier: show s as the tooltip of the last widget after 500 ms of hover (at once when another tooltip hid less than 300 ms ago); hidden on press, key or leave. Icon-only buttons call it with their label.fn tooltip_part(&mut self, s: &str, part: u64)ui_tooltip_part(s, part): post-modifier like tooltip(s) for one part of the last widget (an item on a canvas: a cable, a port). The delay starts again whenpartchanges (at once when a tooltip hid less than 300 ms ago, as between toolbar buttons); a press hides it until the pointer is over another part; part 0 shows nothing.fn tooltips_set(&mut self, on: bool)tooltips_set(on): every tooltip of the app on (the default) or off -- an app's option "no ScreenTips"; a tooltip up hides with the next passfn tooltips_on(&self) -> boolwhether tooltips show (tooltips_set)