ui/vlist.rs#
Source: lib/ui/vlist.rs
vlist -- lists whose rows have different heights, virtualized: only the rows in view are
built, laid out and drawn, for any number of rows
ui.vlist_begin(id, &mut VListState, count) -> (first, end) the rows to emit, first ..
end - 1 (the view takes its place like a box: natural 320 x 240 DIP, next_size(-1, -1)
fills)
ui.vlist_item_begin(i) -> EV row i: the style's list row (hover, selection, focus)
and a BOX_V of the list's width at the row's place; the box's natural height is the
row's height (measured every pass it is built, unless st.set_height gave one).
EV_ACT clicked, EV_DOUBLE, EV_RCLICK
ui.vlist_item_end()
ui.vlist_end(&mut VListState) -> EV EV_ACT the selection changed (a click, the keys),
EV_DOUBLE Enter or a double click, EV_FOCUS, EV_HOVER
ui.vlist_sel() -> i32 the selection while the rows are emitted
VListState::new() / sel (-1: none) / estimate (DIP of a row not measured yet; 0: 40, then
the mean of the measured rows) / set_height(i, dip) (0: measure again) /
invalidate(i) / invalidate_all() / insert(at, n) / remove(at, n) (rows above the view:
it keeps showing the same rows) / reveal(i) / scroll_to(i) / first_visible() ->
(row, px of it above the view) / row_height(i) (px, measured or estimated) /
row_known(i) / set_count(n) (vlist_begin does it) / scroll_pos() / set_scroll_pos(px)
/ total_height() (px; rows not measured count with the estimate)
Scrolling is anchored at the first visible row (its index and how far it is scrolled out):
rows above it may change their height, come or go without moving what is shown. The
heights sit in Fenwick trees (the heights known and how many are known; the others count
with the estimate), so a position and the row at a position cost O(log n); the scroll bar
shows the anchor's position in the total. Keys (focused): Up / Down, PgUp / PgDn (a view of
rows), Home / End move the selection and scroll it into view (exactly, once the rows on the
way are measured), Enter: EV_DOUBLE. The wheel scrolls (smoothly unless animations are
off), the scroll bar drags. A change of dpi, width or text scale measures every row again.
Ids: id the view (focus; K_LIST: value sel, max count), id + 1 + i the rows (K_LISTITEM,
value i), (id + 1 + i) | 0xC000_0000 their content boxes, part_id(id, 1) the scroll bar.
Rows (crate): the height cache and anchor on their own -- the Markdown viewer (md_view.rs)
scrolls its blocks with it.
struct VListStatethe state of a list with rows of different heights (see the module header)sel: i32-- the selected row, -1 noneestimate: i32-- the height of a row that was not measured yet (DIP; 0: 40 at first, then the mean of the measured rows)
impl VListState
fn new() -> VListStateno rows yet, nothing selectedfn set_height(&mut self, i: usize, dip: i32)row i isdiphigh (the app knows it: its box is not measured); 0 measures it againfn invalidate(&mut self, i: usize)row i is measured again the next time it is builtfn invalidate_all(&mut self)every row is measured againfn insert(&mut self, at: usize, n: usize)n rows were inserted before rowat: the view keeps showing the rows it showed (also the selection stays on its row)fn remove(&mut self, at: usize, n: usize)rows at .. at + n were removed (the selection on one of them: none)fn reveal(&mut self, i: usize)scroll row i fully into view (the next pass)fn scroll_to(&mut self, i: usize)show row i at the top of the viewfn first_visible(&self) -> (usize, i32)the first visible row and how many px of it are scrolled out above the viewfn row_height(&self, i: usize) -> i32row i's height in px (measured or given; else the estimate)fn row_known(&self, i: usize) -> boolrow i's height is measured or givenfn set_count(&mut self, n: usize)the number of rows (vlist_begin sets it from its count; rows come and go at the end)fn scroll_pos(&self) -> i64the scroll position: px from the first row's top to the view's top (rows not measured count with the estimate)fn set_scroll_pos(&mut self, px: i64)scroll to a position (px; the next pass keeps the view inside the rows)fn total_height(&self) -> i64the height of all rows (px; rows not measured count with the estimate)
impl Ui
fn vlist_begin(&mut self, id: u32, st: &mut VListState, count: usize) -> (usize, usize)ui_vlist_begin(id, &mut st, count) -> (first, end): the rows to emit (see the module header)fn vlist_item_begin(&mut self, i: usize) -> u32ui_vlist_item_begin(i) -> EV_*: row i (see the module header)fn vlist_item_end(&mut self)ui_vlist_item_end: the row's height is measuredfn vlist_sel(&self) -> i32the selection of the innermost vlist while its rows are emitted (-1 outside one)fn vlist_end(&mut self, st: &mut VListState) -> u32ui_vlist_end(&mut st) -> EV_* (see the module header)