Skip to main content

tui_treelistview/
context.rs

1use ratatui::style::Style;
2
3/// A node's effective expansion state in the current projection.
4#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5pub enum TreeExpansionState {
6    Leaf,
7    Collapsed,
8    Expanded,
9    ForcedByFilter,
10    Unloaded,
11    Loading,
12}
13
14impl TreeExpansionState {
15    /// Returns `true` when the node's descendants are currently visible.
16    #[must_use]
17    pub const fn is_expanded(self) -> bool {
18        matches!(self, Self::Expanded | Self::ForcedByFilter)
19    }
20
21    /// Returns `true` when the node accepts an expand action.
22    #[must_use]
23    pub const fn is_expandable(self) -> bool {
24        !matches!(self, Self::Leaf | Self::Loading)
25    }
26}
27
28/// A node's role in a filtered projection.
29#[derive(Clone, Copy, Debug, PartialEq, Eq)]
30pub enum TreeMatchState {
31    Unfiltered,
32    Direct,
33    Ancestor,
34}
35
36/// A node's aggregated mark state.
37#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
38pub enum TreeMarkState {
39    #[default]
40    Unmarked,
41    Partial,
42    Marked,
43}
44
45/// Node state available to row renderers.
46#[derive(Clone, Copy, Debug, PartialEq, Eq)]
47pub struct TreeRowNodeState {
48    pub expansion: TreeExpansionState,
49    pub mark: TreeMarkState,
50    pub match_state: TreeMatchState,
51}
52
53/// View state available to row renderers.
54#[derive(Clone, Copy, Debug, PartialEq, Eq)]
55pub struct TreeRowRenderState {
56    pub draw_lines: bool,
57    pub is_selected: bool,
58    pub selected_column: Option<usize>,
59}
60
61/// Context for rendering one tree row.
62#[derive(Clone, Copy, Debug, PartialEq, Eq)]
63pub struct TreeRowContext<'a> {
64    /// Node depth, with roots at level `0`.
65    pub level: usize,
66    /// For each path level, indicates whether that node is the last sibling.
67    pub is_tail_stack: &'a [bool],
68    pub node: TreeRowNodeState,
69    pub render: TreeRowRenderState,
70    pub line_style: Style,
71}