1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use ratatui::style::Style;
use ratatui::text::Line;
use ratatui::widgets::Borders;
/// Scroll policy used to keep the selection visible.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum TreeScrollPolicy {
/// Keep the selection visible; only scroll when it would leave the viewport.
KeepInView,
/// Keep the selection centered within the viewport.
CenterOnSelect,
}
/// Visual settings for the tree list view widget.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TreeListViewStyle<'a> {
/// Optional title displayed in the surrounding block.
pub title: Option<Line<'a>>,
/// Style applied to the outer block.
pub block_style: Style,
/// Style applied to the block borders.
pub border_style: Style,
/// Style applied to the highlighted (selected) row.
pub highlight_style: Style,
/// Style applied to marked rows.
pub mark_style: Style,
/// Style applied to tree guide lines.
pub line_style: Style,
/// Symbol rendered before the selected row.
pub highlight_symbol: &'a str,
/// Borders to render around the widget.
pub borders: Borders,
/// Render only the visible slice of rows for large trees.
pub virtualize_rows: bool,
/// Scroll behavior for keeping the selection visible.
pub scroll_policy: TreeScrollPolicy,
}
impl TreeListViewStyle<'_> {
/// Creates default style without borders.
#[must_use]
pub fn borderless() -> Self {
Self {
borders: Borders::NONE,
..Self::default()
}
}
/// Creates default style with row virtualization enabled.
#[must_use]
pub fn virtualized() -> Self {
Self {
virtualize_rows: true,
..Self::default()
}
}
}
impl Default for TreeListViewStyle<'_> {
fn default() -> Self {
Self {
title: None,
block_style: Style::default(),
border_style: Style::default(),
highlight_style: Style::default(),
mark_style: Style::default(),
line_style: Style::default(),
highlight_symbol: ">> ",
borders: Borders::ALL,
virtualize_rows: false,
scroll_policy: TreeScrollPolicy::KeepInView,
}
}
}