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 clicked, and the child nodes rendered beneath it. 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    /// clicked, 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 clicked 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}