pub struct Tree { /* private fields */ }Implementations§
Source§impl Tree
impl Tree
Sourcepub fn add(&mut self, label: Box<dyn Renderable + Send + Sync>) -> &mut Tree
pub fn add(&mut self, label: Box<dyn Renderable + Send + Sync>) -> &mut Tree
Add a child node with the given label.
Returns a mutable reference to the newly created child, allowing for chaining to build nested structures.
§Arguments
label- The content to display for the child node.
§Returns
A mutable reference to the newly added child Tree.
§Example
use rich_rs::{Tree, Text};
let mut root = Tree::new(Box::new(Text::plain("Root")));
let child = root.add(Box::new(Text::plain("Child")));
child.add(Box::new(Text::plain("Grandchild")));Sourcepub fn add_with_options(
&mut self,
label: Box<dyn Renderable + Send + Sync>,
options: TreeNodeOptions,
) -> &mut Tree
pub fn add_with_options( &mut self, label: Box<dyn Renderable + Send + Sync>, options: TreeNodeOptions, ) -> &mut Tree
Add a child node with the given label and options.
Options allow overriding style, guide_style, expanded, and highlight
on a per-node basis. Fields set to None inherit from the parent.
§Arguments
label- The content to display for the child node.options- Per-node overrides.
§Returns
A mutable reference to the newly added child Tree.
Sourcepub fn add_tree(&mut self, tree: Tree)
pub fn add_tree(&mut self, tree: Tree)
Add an existing tree as a child.
This is useful for combining pre-built subtrees.
§Arguments
tree- An existing Tree to add as a child.
§Example
use rich_rs::{Tree, Text};
let mut subtree = Tree::new(Box::new(Text::plain("Subtree")));
subtree.add(Box::new(Text::plain("Leaf")));
let mut root = Tree::new(Box::new(Text::plain("Root")));
root.add_tree(subtree);Sourcepub fn with_style(self, style: Style) -> Self
pub fn with_style(self, style: Style) -> Self
Sourcepub fn with_guide_style(self, style: Style) -> Self
pub fn with_guide_style(self, style: Style) -> Self
Sourcepub fn with_expanded(self, expanded: bool) -> Self
pub fn with_expanded(self, expanded: bool) -> Self
Set whether children are expanded (visible).
§Arguments
expanded- If true, children are rendered; if false, only this node is shown.
Sourcepub fn with_highlight(self, highlight: bool) -> Self
pub fn with_highlight(self, highlight: bool) -> Self
Set whether to highlight labels.
§Arguments
highlight- If true, labels may be highlighted (for future use).
Sourcepub fn with_hide_root(self, hide: bool) -> Self
pub fn with_hide_root(self, hide: bool) -> Self
Set whether to hide the root node.
When true, only children are rendered (no root label or root guide lines).
§Arguments
hide- If true, the root node’s label is hidden.
Sourcepub fn children_count(&self) -> usize
pub fn children_count(&self) -> usize
Get the number of direct children.
Sourcepub fn has_children(&self) -> bool
pub fn has_children(&self) -> bool
Check if this node has any children.
Sourcepub fn is_expanded(&self) -> bool
pub fn is_expanded(&self) -> bool
Check if children are expanded.
Sourcepub fn guide_style(&self) -> Style
pub fn guide_style(&self) -> Style
Get the style for guide lines.
Sourcepub fn children_mut(&mut self) -> &mut Vec<Tree>
pub fn children_mut(&mut self) -> &mut Vec<Tree>
Get a mutable reference to the children.