cursive_tree/view/tree.rs
1use super::super::{backend::*, model::*};
2
3//
4// TreeView
5//
6
7/// Tree view.
8///
9/// Nodes can be leaves (no children) or branches (potentially have children) and can have custom
10/// data (`DataT`) attached to them. Their representation can be stylized with multiple colors and
11/// effects.
12///
13/// Supported events:
14///
15/// * Up/Down keys: move selection
16/// * PgUp/PgDown keys: move selection by 10 (configurable)
17/// * Left/Right keys: collapse/expand selected branch node
18/// * Enter key: toggle selected branch node collapse/expand
19/// * "-"/"+" keys: collapse/expand selected branch and all children recursively
20/// * Mouse click on node: select
21/// * Mouse click to the left of the node: toggle branch collapse/expand
22///
23/// The view's data and behavior are backed by a [TreeBackend]. The nodes are stored and managed by
24/// a [TreeModel]. The model can be populated in advance and can also fetch data from the backend
25/// on demand, e.g. when a branch node is expanded.
26pub struct TreeView<BackendT>
27where
28 BackendT: TreeBackend,
29{
30 /// Tree model.
31 pub model: TreeModel<BackendT>,
32
33 /// Selected row.
34 pub selected_row: Option<usize>,
35
36 /// Page size for PgUp/PgDown.
37 pub page: usize,
38
39 /// Whether we want to display debug information.
40 pub debug: bool,
41}
42
43impl<BackendT> From<TreeModel<BackendT>> for TreeView<BackendT>
44where
45 BackendT: TreeBackend,
46{
47 fn from(model: TreeModel<BackendT>) -> Self {
48 Self { model, selected_row: None, page: 10, debug: false }
49 }
50}