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 branch node
18/// * Enter key: toggle branch collapse/expand
19/// * Mouse click on node: select
20/// * Mouse click to the left of the node: toggle branch collapse/expand
21///
22/// The view's data and behavior are backed by a [TreeBackend]. The nodes are stored and managed by
23/// a [TreeModel]. The model can be populated in advance and can also fetch data from the backend
24/// on demand, e.g. when a branch node is expanded.
25pub struct TreeView<BackendT>
26where
27 BackendT: TreeBackend,
28{
29 /// Tree model.
30 pub model: TreeModel<BackendT>,
31
32 /// Selected row.
33 pub selected_row: Option<usize>,
34
35 /// Page size for PgUp/PgDown.
36 pub page: usize,
37
38 /// Whether we want to display debug information.
39 pub debug: bool,
40}
41
42impl<BackendT> From<TreeModel<BackendT>> for TreeView<BackendT>
43where
44 BackendT: TreeBackend,
45{
46 fn from(model: TreeModel<BackendT>) -> Self {
47 Self { model, selected_row: None, page: 10, debug: false }
48 }
49}