Data views: grid, tree, badges, meters#
Source: lib/ui/data.rs
data -- data views: grid (table with columns), tree, badges, status dots, meters
grid_begin(id, &mut st, cols, keys) -> (first, end)
a virtualized table (fills its parent unless next_size says otherwise): a fixed
header (click: sort by the column, again: descending;
drag a column's right edge: its width, double click there: the default width) and
the rows below it in a vertical scroll view (row height and header height from
StyleData::grid_metrics). keys: one stable key per row in display order (the app
sorts and filters; the selection is kept by key, so it survives refreshes).
Emit rows first .. end-1: grid_row(&mut st, i), then per column grid_cell(&st, c)
and any widget (it is placed into the cell), or grid_text(&st, c, s).
Mouse: click selects, Ctrl+click toggles, Shift+click selects a range, double click
activates, right click selects the row and reports it. Keys (grid focused): Up /
Down / PgUp / PgDn / Home / End move the current row (Shift: extend), Ctrl+A all,
Space toggles the current row, Enter activates.
grid_row(&mut st, i) -> EV row i (widget id id + 1 + i)
grid_cell(&st, c) the next widget goes into column c of the current row
grid_text(&st, c, s) text in column c (ellipsis, the column's alignment)
grid_end(&mut st) -> GridEv ev: EV_ACT selection changed, EV_DOUBLE a row was
activated, EV_RCLICK context menu requested; row: that
row's index; sort_changed: re-sort the keys
tree(id, &mut st, rows, row_h) -> TreeEv
a virtualized tree from the app's visible rows (TreeRow: key, depth, children,
check state, icon, label, detail); the chevron / Right / Left expand and collapse
(st.expanded; TreeEv::expanded names a newly opened node for lazy loading), the
check box / Space report TreeEv::check (the app applies it, e.g. with cascade),
double click / Enter TreeEv::activated
badge(kind, label) status pill (BADGE_NEUTRAL .. BADGE_ACCENT; next_icon); in
a narrower cell the label is cut with "…"
status_dot(kind) a small status dot (10 DIP)
meter(id, v, max, kind) a capacity bar (next_size sets its size)
Ids: the header box (id << 3) | 0x80000000, the header cells ((id ^ 0xA5A5) << 3 | k) |
0x80000000 with k = 1 + column (sort), the grips ((id ^ 0x5A5A) << 3 | k) | 0x80000000; the
rows' scroll view id (its bars (id << 3 | 1 / 2) | 0x80000000); rows id + 1 + i; tree chevrons / check boxes
(id + 1 + i) | 0x40000000 / | 0x20000000.
struct GridCol<'a>a grid column: title, width and minimum width in DIP, GC_* flagstitle: &'a strwidth: i32min: i32flags: u32
impl<'a> GridCol<'a>
const fn new(title: &'a str, width: i32) -> GridCol<'a>a columnwidthDIP wide (at least 48)const fn flags(mut self, flags: u32) -> GridCol<'a>the same column with GC_* flagsconst fn min(mut self, min: i32) -> GridCol<'a>the same column with a minimum width (DIP)struct GridStatethe app-owned state of a grid: selection (by key), current row, sort, column widthssel: BTreeSet<u64>-- the selected rows' keyscur: Option<u64>-- the current row (keyboard focus / last clicked)sort: Option<(usize, bool)>-- the sort column and direction (true = descending); None = the app's orderwidths: Vec<i32>-- column widths set by the user (DIP, 0 = the column's own)striped: bool-- alternate row shading
impl GridState
fn selected_in_order(&self) -> Vec<u64>the keys selected, in display order of the last passfn select_only(&mut self, key: Option<u64>)select exactly this key (None: nothing) and make it currentfn retain(&mut self, keys: &[u64])drop selected keys that are no longer shown (after a refresh)struct GridEvwhat happened in a grid during the passev: u32-- EV_ACT selection changed, EV_DOUBLE a row was activated, EV_RCLICK context requestedrow: i32-- the activated / context row (-1 = none)sort_changed: bool-- the sort column or direction changed
struct TreeRow<'a>one visible row of a tree (the app flattens its model through TreeState::expanded)key: u64depth: u16has_children: boolcheck: Option<u8>-- check box state 0 / 1 / 2 (indeterminate); None = no check boxicon: u32label: &'a strdetail: Option<&'a str>-- secondary text after the label (size, date)
struct TreeStatethe app-owned state of a tree: expanded nodes, current nodeexpanded: BTreeSet<u64>cur: Option<u64>marks: BTreeMap<u64, u32>-- app data per node (free use, e.g. a loading flag)
struct TreeEvwhat happened in a tree during the passexpanded: Option<u64>-- a node opened in this pass (load its children)collapsed: Option<u64>-- a node closed in this passcheck: Option<(u64, u8)>-- a check box was toggled: (key, new state 0 / 1)activated: Option<u64>-- double click / Enter on a nodesel_changed: bool-- the current node changed
impl Ui
fn grid_begin(&mut self, id: u32, st: &mut GridState, cols: &[GridCol], keys: &[u64]) -> (i32, i32)ui_grid_begin(id, &mut st, cols, keys) -> (first, end): the rows to emitfn grid_row(&mut self, st: &mut GridState, i: i32) -> u32ui_grid_row(&mut st, i) -> EV_* of row i (EV_ACT clicked)fn grid_cell(&mut self, st: &GridState, c: usize)ui_grid_cell(&st, c): the next widget is placed into column c of the current row (inset by the cell padding, full row height)fn grid_text(&mut self, st: &GridState, c: usize, s: &str)ui_grid_text(&st, c, s): body text in column c (cut with "…", the column's alignment)fn grid_text_ts(&mut self, st: &GridState, c: usize, ts: u32, s: &str)ui_grid_text_ts(&st, c, ts, s): text in column c with a text style (TS_* | TX_*)fn grid_end(&mut self, st: &mut GridState) -> GridEvui_grid_end(&mut st) -> GridEvfn tree(&mut self, id: u32, st: &mut TreeState, rows: &[TreeRow], row_h: i32) -> TreeEvui_tree(id, &mut st, rows, row_h) -> TreeEv: the visible rows of a tree (row_h DIP, 0 = the grid row height)fn badge(&mut self, kind: u32, label: &str)ui_badge(kind, label): a status pill (BADGE_*; next_icon puts an icon before the text); placed narrower than the pill (a grid cell), the label is cut with "…"fn status_dot(&mut self, kind: u32)ui_status_dot(kind): a 10 DIP status dot (BADGE_*)fn meter(&mut self, id: u32, v: i64, max: i64, kind: u32)ui_meter(id, v, max, kind): a capacity bar (natural 120 x 8 DIP; next_size)