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//! View widgets and shared data
7//!
8//! View widgets allow data-oriented design. This is vaguely similar to the
9//! Model-View-Controller pattern or Elm's Model-View-Update design, but with
10//! no direct link between Model and Controller:
11//!
12//! 1. Model traits describe data **models**: [`ListData`], [`MatrixData`]
13//! 2. [**Drivers**](`driver`) describe how to build a widget view over data
14//! and (optionally) how to handle **messages** from view widgets
15//! 3. **Controllers** are special widgets which manage views over data
16//!
17//! Three controllers are provided by this crate:
18//!
19//! - [`ListView`] constructs a row or column of views over indexable data
20//! - [`MatrixView`] constructs a table/sheet of views over two-dimensional
21//! indexable data
22//!
23//! Both [`ListView`] and [`MatrixView`] support virtual scrolling: the number
24//! of view widget instances is limited (approximately) to the number required
25//! to cover the visible area, and these are re-used to enable fast scrolling
26//! through large data sets.
27
28#![cfg_attr(docsrs, feature(doc_auto_cfg))]
29
30mod data_impls;
31mod data_traits;
32pub use data_traits::*;
33
34pub mod filter;
35
36pub mod driver;
37pub use driver::Driver;
38
39mod list_view;
40pub use list_view::ListView;
41
42mod matrix_view;
43pub use matrix_view::MatrixView;
44
45/// Used to notify selection and deselection of [`ListView`] and [`MatrixView`] children
46#[derive(Clone, Debug)]
47pub enum SelectionMsg<K> {
48 /// Selection of item
49 Select(K),
50 /// Deselection of item
51 ///
52 /// Note: not emitted due to selection of another item in single-item selection mode.
53 Deselect(K),
54}
55
56/// Selection mode used by [`ListView`]
57#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
58pub enum SelectionMode {
59 /// Disable selection
60 #[default]
61 None,
62 /// Support single-item selection. Selecting another item automatically
63 /// clears the prior selection (without sending [`SelectionMsg::Deselect`]).
64 Single,
65 /// Support multi-item selection.
66 Multiple,
67}