Skip to main content

tui_treelistview/
style.rs

1use ratatui::style::Style;
2use ratatui::text::Line;
3use ratatui::widgets::Borders;
4
5/// Policy for keeping the selection in the vertical viewport.
6#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
7pub enum TreeScrollPolicy {
8    #[default]
9    KeepInView,
10    CenterOnSelect,
11}
12
13/// Strategy for building table rows.
14#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
15pub enum TreeRowRendering {
16    Full,
17    #[default]
18    Virtualized,
19}
20
21/// Horizontal layout policy.
22#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
23pub enum TreeHorizontalScroll {
24    Disabled,
25    #[default]
26    Enabled,
27}
28
29/// Visual tree configuration.
30#[derive(Clone, Debug, PartialEq, Eq)]
31pub struct TreeListViewStyle<'a> {
32    pub title: Option<Line<'a>>,
33    pub block_style: Style,
34    pub border_style: Style,
35    pub highlight_style: Style,
36    pub column_highlight_style: Style,
37    pub cell_highlight_style: Style,
38    pub marked_style: Style,
39    pub partial_mark_style: Style,
40    pub direct_match_style: Style,
41    pub ancestor_match_style: Style,
42    pub line_style: Style,
43    pub highlight_symbol: &'a str,
44    pub borders: Borders,
45    pub column_spacing: u16,
46    pub row_rendering: TreeRowRendering,
47    pub horizontal_scroll: TreeHorizontalScroll,
48    pub scroll_policy: TreeScrollPolicy,
49}
50
51impl TreeListViewStyle<'_> {
52    /// Creates a style without an outer border.
53    #[must_use]
54    pub fn borderless() -> Self {
55        Self {
56            borders: Borders::NONE,
57            ..Self::default()
58        }
59    }
60}
61
62impl Default for TreeListViewStyle<'_> {
63    fn default() -> Self {
64        Self {
65            title: None,
66            block_style: Style::default(),
67            border_style: Style::default(),
68            highlight_style: Style::default(),
69            column_highlight_style: Style::default(),
70            cell_highlight_style: Style::default(),
71            marked_style: Style::default(),
72            partial_mark_style: Style::default(),
73            direct_match_style: Style::default(),
74            ancestor_match_style: Style::default(),
75            line_style: Style::default(),
76            highlight_symbol: ">> ",
77            borders: Borders::ALL,
78            column_spacing: 1,
79            row_rendering: TreeRowRendering::Virtualized,
80            horizontal_scroll: TreeHorizontalScroll::Enabled,
81            scroll_policy: TreeScrollPolicy::KeepInView,
82        }
83    }
84}