kas_view/lib.rs
1// Licensed under the Apache License, Version 2.0 (the "License");
2// you may not use this file except in compliance with the License.
3// You may obtain a copy of the License in the LICENSE-APACHE file or at:
4// https://www.apache.org/licenses/LICENSE-2.0
5
6//! # Views
7//!
8//! Views allow virtual scrolling over (subsets of) a data set.
9//! Each visible data `Item` is assigned a **view widget**, with dynamic
10//! re-assignment as the view changes.
11//!
12//! ## Data clerks
13//!
14//! The full data set might be available in local memory, on disk, or on a
15//! remote server, and may be viewed as a raw list of items or through a filter
16//! or query. A [`clerk`] is required to manage this access.
17//!
18//! ## View controller
19//!
20//! This crate provides the following **view controllers**:
21//!
22//! - [`ListView`] constructs a row or column view over items indexed by type `usize`
23//! - [`GridView`] constructs a table over items indexed by type `(u32, u32)`
24//!
25//! ## Driver
26//!
27//! A view controller uses a **driver** to construct and re-assign view widgets.
28//! Simple types (strings and numbers) may use a pre-defined [`driver`],
29//! otherwise a custom implementation of [`Driver`] is required.
30
31pub mod clerk;
32pub mod filter;
33
34pub mod driver;
35pub use driver::Driver;
36
37mod list_view;
38pub use list_view::ListView;
39
40mod grid_view;
41pub use grid_view::{GridIndex, GridView};
42
43/// Used to notify selection and deselection of [`ListView`] and [`GridView`] children
44#[derive(Clone, Debug)]
45pub enum SelectionMsg<K> {
46 /// Selection of item
47 Select(K),
48 /// Deselection of item
49 ///
50 /// Note: not emitted due to selection of another item in single-item selection mode.
51 Deselect(K),
52}
53
54/// Selection mode used by [`ListView`]
55#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
56pub enum SelectionMode {
57 /// Disable selection
58 #[default]
59 None,
60 /// Support single-item selection. Selecting another item automatically
61 /// clears the prior selection (without sending [`SelectionMsg::Deselect`]).
62 Single,
63 /// Support multi-item selection.
64 Multiple,
65}
66
67#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
68enum Update {
69 None,
70 Token,
71 Configure,
72}