JFLib

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 Command CMD record: one row of the app's command table (AppDesc::cmds)
    • id: u32 -- command id (!= 0); also the widget id of cmd_button
    • icon: u32 -- IC_* code point or 0
    • label: &'static str -- UTF-8 label, '&' marks the mnemonic ("&&" = '&')
    • key: u16 -- accelerator key VK_* (0 = none)
    • mods: u8 -- MOD_SHIFT | MOD_CTRL | MOD_ALT
    • flags: u8 -- initial CF_* state

impl Command

  • const fn new(id: u32, label: &'static str, icon: u32, mods: u32, key: u32, flags: u32) -> Command CMD id, "&Label", icon, mods, key, flags (the order of the asm macro)

  • enum Mi menu record (MENUBAR / MENU / MI_* of ui.inc); menus are static slices of them

    • Cmd(u32) -- MI_CMD cmd: a row from the command table
    • Sep -- MI_SEP
    • Sub(&'static str, &'static [Mi]) -- MI_SUB "Label", submenu
    • Menu(&'static str, &'static [Mi]) -- MENU "Label", menu: a top-level menu of a menu bar
    • Item(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) -> bool accel_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) -> bool ui_popup_is_open(id): popup id is open
  • fn popup_count(&self) -> u32 ui_popup_count -> open popups of the live window (U3)
  • fn popup_open(&mut self, id: u32) ui_popup_open(id): open popup id (inside a flyout: as a child of that flyout, otherwise it replaces every open popup); an open popup only loses its children
  • fn popup_open_at(&mut self, id: u32, x: i32, y: i32) popup_open_at(id, x, y): open popup id as 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 popup id and 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 when id opened; nothing happens when id is not open.
  • fn flyout_begin(&mut self, id: u32, flags: u32) -> bool ui_flyout_begin(id, FL_*) -> popup id is 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 table
  • fn 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) -> u32 ui_cmd_flags(id) -> CF_* state (cmd_state, else the table flags)
  • fn cmd_label(&self, id: u32) -> String ui_cmd_label(id) -> label of a command without '&' ("" if unknown)
  • fn accel_text(&self, id: u32) -> String ui_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 cmd_button(&mut self, id: u32, flags: u32) -> u32 ui_cmd_button(id, ST_*) -> EV_*: button for a command: icon and label from the table (ST_ICON_ONLY: icon only), tooltip "Label (Strg+S)", ST_DISABLED / ST_CHECKED from the command state; a click queues the command. Hidden commands draw nothing.
  • fn menu_item(&mut self, id: u32, label: &str) -> u32 ui_menu_item(id, label) -> EV_*: menu row inside a flyout (next_icon; next_flags ST_DISABLED / ST_CHECKED); activation closes every popup
  • fn menu_item_keys(&mut self, id: u32, label: &str, keys: &str) -> u32 menu_item with keys (key_text) at the end of the row: a row whose keys the app handles itself (no command of the table)
  • fn key_text(&self, vk: u32, mods: u32) -> String a key with modifiers (MOD_*) as the accelerator texts write it: "Strg+Umschalt+S", "F5" (the UI language's names; accel_order_set holds)
  • fn menu_cmd(&mut self, cmd: u32) -> u32 ui_menu_cmd(cmd) -> EV_*: menu row for a command (widget id = command id)
  • fn menu_sep(&mut self) -> u32 ui_menu_sep -> 0: separator line across the flyout
  • fn menu_list_empty(&mut self, base: u32, text: &str) the disabled row an empty Mi::List with this base id shows instead of its placeholder ("": the placeholder again), for a list that can be empty for different reasons
  • fn menu_list<T: AsRef<str>>(&mut self, base: u32, rows: &[T]) the rows of the Mi::List menus with this base id (row k: id base + k; the asm app's STRLIST buffer); the list ends at the first empty string
  • fn menu_list_flags(&mut self, base: u32, flags: &[u8]) (JD27) the ML_* flags of the rows of the Mi::List menus with this base id, set after menu_list (which clears them; flags[k] for row k, rows past the end of flags: 0). ML_CHILD: row k goes into the submenu of the nearest row before it without ML_CHILD -- that row shows a chevron, opens its submenu as an MI_SUB row does (hover, click, Enter, Right; not while it is disabled) and runs no command itself; the submenu's rows run App::command(base + k, 0) with their cmd_state as other rows; ML_CHILD rows before every row without it stay plain rows. ML_SEP: a separator line above the row (not above the first row of the list or of a submenu). Visio's FlyoutChild and BeginGroup of a shape's Actions rows.
  • fn menubar(&mut self, menubar: Option<&'static [Mi]>) -> u32 ui_menubar(menubar) -> EV_OPEN while one of its menus is open (None = the one of AppDesc::menubar). WinUI MenuBar: subtle 32 DIP items, a flyout per menu. Keyboard: Alt (tap) or F10 enter / leave menu bar mode, Alt+mnemonic opens a menu, Left / Right move between the menus, Down / Enter open one, Esc steps back.
  • fn menu_popup(&mut self, menu: &'static [Mi]) ui_menu_popup(menu): open a menu at the pointer (the runtime draws it); for the menu key / Shift+F10 (an EV_RCLICK kbnav.rs gave the focused widget in this pass) at the widget's lower left corner with its first row focused
  • fn menu_popup_at(&mut self, menu: &'static [Mi], x: i32, y: i32) menu_popup_at(menu, x, y): open a menu at the point (x, y) (px of the window, as last_rect; a canvas: UiInput::rect plus its x, y), the runtime draws it as menu_popup's. For a context menu whose place the app learns after the right click (a web engine answers later): open it in the frame the answer comes; rows that change with the answer: a flyout of the app's own through popup_open_at.
  • fn context_menu(&mut self, menu: &'static [Mi]) -> u32 ui_context_menu(menu) -> EV_OPEN while menu is open for the last widget. Opens on a right click (released over the widget), or with the menu key / Shift+F10 while the widget has the focus -- a list row: while the list has it and the row is selected -- (then at its lower left corner, first row focused).
  • fn context_target(&self) -> u32 ui_context_target -> id of the widget whose context menu is (or was last) open
  • fn dropdown_button(&mut self, id: u32, label: &str) -> u32 ui_dropdown_button(id, label) -> EV_* | EV_OPEN while popup id is open (a click, Enter / Space, Alt+Down or F4 opens it; the app draws the flyout with flyout_begin(id, ..) right after). next_flags ST_SUBTLE: flat tool bar look, ST_ICON_ONLY: icon + chevron, the label as tooltip (U1)
  • fn split_button(&mut self, id: u32, label: &str) -> u32 ui_split_button(id, label) -> EV_* of the main part | EV_OPEN while popup id is open. The chevron part (widget id | 0x80000000; Alt+Down / F4 on the main part) opens it.
  • fn combobox(&mut self, id: u32, sel: &mut i32, list: &[&str]) -> u32 ui_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. list is 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 when part changes (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 pass
  • fn tooltips_on(&self) -> bool whether tooltips show (tooltips_set)

Source: docs/API.md in the JFLib repository.