Skip to main content

Module scroll

Module scroll 

Source
Expand description

Retained scroll state: the offset of every scroll container, keyed by node Key, and the geometry the last layout resolved for it.

A view makes a scroll container with NodeSpec::scroll_y / scroll_x and never touches this store directly: the wheel, the scrollbar and the keys move the offset, Core::set_scroll and Core::reveal move it from the app, and layout clamps it to the content every frame. What a view does read is ScrollGeometry through Ui::scroll_geometry / Core::scroll_geometry: where the container is, how big its content came out and where it is scrolled to, which is what a virtual list needs to build only the visible rows.

use kui_core::{Core, NodeSpec, Size, TextStyle};

let mut core = Core::new();
let mut ui = core.frame(Size::new(200.0, 100.0), 1.0);
ui.configure_root(NodeSpec::column().fill());
let list = ui.with_keyed("list", NodeSpec::column().fill().scroll_y(), |ui| {
    for i in 0..50 {
        ui.text(&format!("row {i}"), TextStyle::new(14.0));
    }
});
ui.finish();

// Read during the next frame's build (or between frames): last layout's numbers.
let g = core.scroll_geometry(list).expect("laid out as a scroll container");
assert!(g.content.h > g.rect.h);
assert!(g.max_offset.y > 0.0 && g.offset.y == 0.0);

Structs§

ScrollGeometry
What the last layout resolved for a scroll container: where the container landed, how big its content came out, and the offset it clamped. All logical px, in the same viewport coordinates on_layout reports.
ScrollStore
The retained scroll state of one window, owned by Core. Reach it through Core::scroll_offset, Core::set_scroll and Core::scroll_geometry rather than directly.

Constants§

MAX_UNDECLARED_SCROLLS
How many undeclared scroll entries the store keeps before the longest undeclared one is dropped. An entry a layout resolved in the frame that just ended is never evicted, however many there are. An entry is about 64 bytes, so a full budget is about 64 KB.