etui/widgets/tree

Types

Visual symbols for tree lines and expansion indicators.

pub type TreeGlyphs {
  TreeGlyphs(
    collapsed: String,
    expanded: String,
    leaf: String,
    indent: String,
  )
}

Constructors

  • TreeGlyphs(
      collapsed: String,
      expanded: String,
      leaf: String,
      indent: String,
    )

    Arguments

    collapsed

    Prefix for collapsed node with children.

    expanded

    Prefix for expanded node with children.

    leaf

    Prefix for leaf node.

    indent

    Indent per depth level (repeated).

A tree node, either a leaf or an internal node with children. count shows a right-aligned number after the label (e.g. unread count, children count). Error(Nil) hides it.

pub type TreeNode {
  TreeNode(
    id: String,
    label: String,
    children: List(TreeNode),
    count: Result(Int, Nil),
  )
}

Constructors

  • TreeNode(
      id: String,
      label: String,
      children: List(TreeNode),
      count: Result(Int, Nil),
    )

State: which nodes are expanded, which is selected.

pub type TreeState {
  TreeState(expanded: List(String), selected: String)
}

Constructors

  • TreeState(expanded: List(String), selected: String)

    Arguments

    expanded

    IDs of expanded nodes.

    selected

    ID of currently selected node.

Tree widget configuration.

pub type TreeWidget {
  TreeWidget(
    roots: List(TreeNode),
    fg: style.Color,
    bg: style.Color,
    highlight_style: style.Style,
    glyphs: TreeGlyphs,
  )
}

Constructors

Values

pub fn ascii_glyphs() -> TreeGlyphs

ASCII-safe glyphs for terminals without Unicode support.

pub fn collapse(id: String, state: TreeState) -> TreeState

Collapse a node (hide children).

pub fn default_glyphs() -> TreeGlyphs

Default Unicode glyphs (▶ ▼ and box-drawing indent).

pub fn effective_offset(
  state: TreeState,
  t: TreeWidget,
  height: Int,
) -> Int

Effective scroll offset for a viewport of height rows. Use as offset when building a scrollbar.

pub fn expand(id: String, state: TreeState) -> TreeState

Expand a node (show children).

pub fn is_expanded(state: TreeState, id: String) -> Bool

True if the node with the given id is expanded.

pub fn leaf(id: String, label: String) -> TreeNode

Create a leaf node (no children).

pub fn leaf_with_count(
  id: String,
  label: String,
  count: Int,
) -> TreeNode

Leaf with a right-aligned count.

pub fn node(
  id: String,
  label: String,
  children: List(TreeNode),
) -> TreeNode

Create an internal node with children.

pub fn node_with_count(
  id: String,
  label: String,
  count: Int,
  children: List(TreeNode),
) -> TreeNode

Internal node with a right-aligned count.

pub fn render(
  buf: buffer.Buffer,
  area: geometry.Rect,
  t: TreeWidget,
  state: TreeState,
) -> buffer.Buffer

Render the tree, scrolling so the selected node is visible.

pub fn select_next(state: TreeState, t: TreeWidget) -> TreeState

Move selection to the next visible node.

pub fn select_prev(state: TreeState, t: TreeWidget) -> TreeState

Move selection to the previous visible node.

pub fn selected(state: TreeState) -> Result(String, Nil)

ID of the currently selected node. Error(Nil) if nothing selected.

pub fn state_from_tree(t: TreeWidget) -> TreeState

Initial state with first root pre-selected.

pub fn state_new() -> TreeState

Initial state: first root node selected, all nodes collapsed.

pub fn toggle_selected(
  state: TreeState,
  t: TreeWidget,
) -> TreeState

Toggle expand/collapse on the currently selected node.

pub fn tree_new(roots: List(TreeNode)) -> TreeWidget

New tree widget. The first root node is selected initially.

pub fn visible_row_count(state: TreeState, t: TreeWidget) -> Int

Number of visible rows (respects expand/collapse state). Use as total when building a scrollbar.

pub fn with_colors(
  t: TreeWidget,
  fg: style.Color,
  bg: style.Color,
) -> TreeWidget
pub fn with_count(n: TreeNode, count: Int) -> TreeNode

Attach a count to an existing node.

pub fn with_glyphs(t: TreeWidget, g: TreeGlyphs) -> TreeWidget
pub fn with_highlight_style(
  t: TreeWidget,
  s: style.Style,
) -> TreeWidget
Search Document