Skip to main content

euv_ui/component/tree/view/
struct.rs

1use super::*;
2
3/// One node of the [`euv_tree`] component.
4///
5/// A node is a label, the opaque value written into the selection signal
6/// when its row is activated, and the child nodes rendered beneath this one. The
7/// struct is recursive, so it cannot be `Copy`; it derives `Clone` so a
8/// caller can build several trees from one shared template.
9#[derive(Clone, CustomDebug, Default)]
10pub struct EuvTreeNode {
11    /// The visible node text rendered in `c_euv_tree_node_label`.
12    pub label: &'static str,
13    /// The opaque value written into the `selected` signal when the row is
14    /// activated, and the identity the expansion state is keyed by.
15    pub value: &'static str,
16    /// The child nodes rendered beneath this one.
17    pub children: Vec<EuvTreeNode>,
18}
19
20/// Props for the [`euv_tree`] component.
21///
22/// Defines the strongly-typed interface for a hierarchical tree. The
23/// selection is owned by the caller through the `selected` signal, so the
24/// tree takes part in two-way binding with the rest of the page; the
25/// expansion state is owned by the component itself.
26#[derive(Clone, CustomDebug, Default)]
27pub struct EuvTreeProps {
28    /// The root nodes of the tree.
29    pub nodes: Vec<EuvTreeNode>,
30    /// The signal holding the selected node's value.
31    pub selected: Signal<String>,
32    /// Optional callback invoked with the activated node's value.
33    #[debug(skip)]
34    pub on_select: Option<Rc<dyn Fn(&'static str)>>,
35    /// Whether every node starts out expanded on the first render.
36    pub default_expanded: bool,
37}
38
39/// Shared render state passed through the recursive tree renderer.
40pub(super) struct TreeViewContext<'a> {
41    /// The caller-owned selected-value signal.
42    pub(super) selected: Signal<String>,
43    /// The value currently selected by the caller.
44    pub(super) selected_value: &'a str,
45    /// The visible value that owns the single tab stop.
46    pub(super) roving_value: &'a str,
47    /// The component-owned expanded-values signal.
48    pub(super) expanded: Signal<Vec<String>>,
49    /// The expanded values read once for this render.
50    pub(super) expanded_values: &'a [String],
51    /// The callback invoked when a node is activated.
52    pub(super) on_select: Option<Rc<dyn Fn(&'static str)>>,
53}