Skip to main content

glory_ui/list/
mod.rs

1//! Windowed list primitives. Scrolling only accesses the visible window and
2//! overscan, never an iterator over the whole data set. This is distinct from
3//! keyed `each`, which deliberately mounts its complete sequence.
4//!
5//! The public List supports fixed or measured rows, bounded height metadata,
6//! keyed anchoring and segmented physical scrolling through any Render host.
7//! At most one focused row stays mounted outside the window until blur. Data
8//! edits relocate it through the optional indexed `locate` callback; without
9//! that callback only its old index and the current window can be searched.
10
11mod cache;
12mod layout;
13mod measure;
14mod navigation;
15mod scroll;
16mod widget;
17pub use widget::{List, ListStats, list};
18
19pub use cache::{Cache, ReconcileStats, RowHost};
20pub use layout::{Anchor, Heights, Layout, Window};
21pub use scroll::{ScrollSpace, ScrollUpdate};
22
23/// Keep logical pixel coordinates below the point where f64 spacing exceeds
24/// useful subpixel precision. Physical surfaces have a much smaller host limit.
25pub const MAX_EXTENT: f64 = 281_474_976_710_656.0;
26
27/// Default maximum rows in one render window, including overscan. One focused
28/// row outside the window may additionally remain mounted.
29pub const DEFAULT_ROW_LIMIT: usize = 4096;
30
31#[derive(Clone, Debug, PartialEq, Eq)]
32pub enum Error {
33    InvalidSize,
34    OutOfBounds,
35    Allocation,
36    DuplicateKey,
37    InvalidRange,
38    InvalidLookup,
39    InvalidAnchor,
40    RowLimit { requested: usize, limit: usize },
41}
42
43fn check_rows(requested: usize, limit: usize) -> Result<(), Error> {
44    if requested > limit {
45        Err(Error::RowLimit { requested, limit })
46    } else {
47        Ok(())
48    }
49}
50
51impl std::fmt::Display for Error {
52    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
53        write!(f, "{self:?}")
54    }
55}
56impl std::error::Error for Error {}
57
58fn positive(value: f64) -> bool {
59    value.is_finite() && value > 0.0
60}
61fn nonnegative(value: f64) -> bool {
62    value.is_finite() && value >= 0.0
63}
64fn valid_extent(value: f64) -> bool {
65    nonnegative(value) && value <= MAX_EXTENT
66}