Lists, scrolling, tabs, expanders#
Source: lib/ui/list.rs
list -- scroll views, scroll bars, lists, tabs and expanders (WinUI 3 style)
[src/ui/ui_list.s]
scroll_begin(id, flags) clipped viewport that takes its size like a box
(next_size / parent) and lays its children out in a content area that may be
larger; flags = SC_V (default) | SC_H | SC_NOBAR | SC_NOWHEEL | BOX_BG | BOX_CARD |
PAD_n ... Mouse wheel (the system's lines of 16 DIP per notch -- 48 DIP with three --
smooth; a touchpad's pixels at once), overlay scroll bars (2 DIP, 6 DIP
while pointed at, draggable thumb, click on the track pages), Tab focus is scrolled
into view. A style whose bars stay visible (netlab) keeps their room free right of
the content of a view that scrolls only vertically, always, so nothing moves when
the bar comes (StyleList::scrollbar_room; views that also scroll sideways keep
floating bars).
scroll_end()
scroll_to(id, x, y) jump to a position in DIP (-1 keeps that axis)
scroll_pos(id) -> (x, y) current position in DIP
scroll_extent(id) -> (w, h) content size in DIP (last measure; 0 before) (U3)
scrollbar(id, &mut pos, content, view, vertical) -> EV
standalone scroll bar (natural thickness 12 DIP) for custom canvases; pos runs from
0 to content - view in the caller's unit; EV_ACT when pos changed
list_begin(id, &mut sel, count, item_h | LF_*) -> (first, end)
virtualized list (own scroll view, fixed row height in DIP, 0 = 40); emit the rows
first .. end-1; row i has the widget id `id + 1 + i`. Up/Down/Home/End/PgUp/PgDn
move the selection (sel, -1 = none) and scroll it into view; Enter: the selected
row reports EV_DOUBLE (list_end too), Space: the first check box / switch of the
selected row acts; the menu key: the selected row's right click. The list is one Tab
stop; the widgets inside custom rows are Tab stops in the selected row only. Focus
alone selects nothing: a focused list without a selection has the focus visual
around it.
LF_REORDER (U1): a row dragged more than 4 DIP is moved: an accent insertion line
follows the pointer, the view scrolls near its edges, Esc cancels; on release
list_end_full reports EV_DRAG with drop = Some((from, to)) (the app moves item `from`
so that it ends at index `to`) and sel = to. Widgets inside custom rows keep their
clicks. The keyboard moves the selected row the same way: Ctrl+Up / Ctrl+Down one
place, Ctrl+Home / Ctrl+End to the top / bottom.
list_item(i, label) -> EV text row (EV_ACT clicked, EV_DOUBLE, EV_RCLICK)
list_item_begin(i) -> EV custom row: opens a BOX_H inside the row
list_item_end()
list_end_full(&mut sel) -> ListEnd { ev, sel, drop }: EV_ACT if sel changed this pass,
EV_DOUBLE; EV_DRAG with drop = Some((from, to)): a row
was dropped (any number of rows)
list_end(&mut sel) -> (EV, sel) the same with the drop packed as from | to << 16 in
place of sel -- 16 bits each: a drop that does not fit
(a row from 65 536 on) is not reported, the selection
stays on the row (lists that long: list_end_full)
(Rust: list_begin reads the selection into the list, list_end writes it back --
the asm keeps a pointer to the app's variable in between; list_sel() reads it in
the rows)
tabs(id, &mut sel, names) -> EV text tab header row, tab i has the id
`id + 1 + i`; EV_ACT when sel changed (a click
or a right click on a tab), EV_DOUBLE when a
tab was double-clicked; placed
narrower than the tabs, the widest ones give
way (labels cut with "…")
expander_begin(id, header, &mut open) -> open (emit the content when 1)
expander_end()
Widget ids used internally: (id << 3 | k) | 0x80000000 for sub parts (k = 1..7),
(id + 1 + i) | 0xC0000000 for the content box of custom list rows.
struct ListEndWhatUi::list_end_fullreports at the end of a list.ev: u32-- EV_ACT the selection changed this pass, EV_DOUBLE (a double click or Enter on a row), EV_DRAG a row was dropped (LF_REORDER)sel: i32-- the selection (-1 = none), also written to theselhanded to list_end_fulldrop: Option<(usize, usize)>-- with EV_DRAG: (from, to) -- the app moves itemfromso that it ends at indexto
impl Ui
fn scroll_begin(&mut self, id: u32, flags: u32)ui_scroll_begin(id, flags)fn scroll_end(&mut self)ui_scroll_endfn scroll_to(&mut self, id: u32, x: i32, y: i32)ui_scroll_to(id, x, y): DIP, -1 keeps that axis; jumps without animationfn scroll_pos(&mut self, id: u32) -> (i32, i32)ui_scroll_pos(id) -> (x, y) DIPfn scroll_extent(&mut self, id: u32) -> (i32, i32)ui_scroll_extent(id) -> (w, h): measured content size of scroll viewid(DIP; 0 before its first pass). With the view size (last_rect after scroll_end) the app can tell whether the content overflows. (U3)fn scrollbar(&mut self, id: u32, pos: &mut i32, content: i32, view: i32, vertical: bool) -> u32ui_scrollbar(id, &mut pos, content, view, vertical) -> EV_*fn list_begin(&mut self, id: u32, sel: &mut i32, count: i32, item_h: u32) -> (i32, i32)ui_list_begin(id, &mut sel, count, item_h | LF_*) -> (first, end): the rows to emitfn list_item(&mut self, i: i32, label: &str) -> u32ui_list_item(i, label) -> EV_*fn list_item_begin(&mut self, i: i32) -> u32ui_list_item_begin(i) -> EV_*: row i with a BOX_H (gap 8 DIP) for custom contentfn list_sel(&self) -> i32the innermost list's selection while its rows are emitted (the asm's rows see the app's variable change at once; here the list holds it until list_end), -1 outside a listfn list_item_end(&mut self)ui_list_item_endfn list_end(&mut self, sel: &mut i32) -> (u32, i32)ui_list_end(&mut sel) -> (EV_* (EV_ACT if sel changed, EV_DOUBLE), sel); EV_DRAG: a row was dropped, the second value is from | to << 16. Only while both fit in 16 bits: a drop from or to a row past 65 535 is not reported (no EV_DRAG, the selection stays on the row) --list_end_fullreports every drop as two numbersfn list_end_full(&mut self, sel: &mut i32) -> ListEndThe end of a list: its events (EV_ACT the selection changed this pass, EV_DOUBLE, EV_DRAG a row was dropped), the selection written back tosel(-1 = none) and, with EV_DRAG,drop = Some((from, to)): the app moves itemfromso that it ends at indexto(sel istothen). Any number of rows (list_endpacks the drop into 16 bits each).fn tabs_scrolling(&mut self, id: u32, sel: &mut i32, names: &[&str]) -> u32Tab strip with horizontal overflow arrows. Mouse scrolling and Left/Right, Home/End on the strip retain ordinary tab semantics; changed selections and resized viewports reveal the selected tab. Internal IDs follow the usual(id * 8 + part) | 0x80000000convention (parts 1, 2, 3 and 7).fn tabs(&mut self, id: u32, sel: &mut i32, names: &[&str]) -> u32ui_tabs(id, &mut sel, names) -> EV_* (EV_ACT when sel changed: a click or a right click on a tab selects it; EV_DOUBLE when a tab was double-clicked: it is the selected one then)fn expander_begin(&mut self, id: u32, header: &str, open: &mut i32) -> i32ui_expander_begin(id, header, &mut open) -> open: a card-like header (48 DIP) with a chevron; when open the content follows in a padded card below it (BOX_V, PAD_16, gap 8 DIP). Always call expander_end.fn expander_end(&mut self)ui_expander_end