pub struct SpanTreeState { /* private fields */ }Expand description
State for a SpanTree component.
Contains the root spans, selection state, expanded set, and layout configuration.
§Example
use envision::component::{SpanTreeState, SpanNode};
let root = SpanNode::new("r", "root", 0.0, 1000.0)
.with_child(SpanNode::new("c", "child", 100.0, 500.0));
let state = SpanTreeState::new(vec![root]);
assert_eq!(state.roots().len(), 1);
assert_eq!(state.global_start(), 0.0);
assert_eq!(state.global_end(), 1000.0);
assert_eq!(state.selected_index(), Some(0));Implementations§
Source§impl SpanTreeState
impl SpanTreeState
Sourcepub fn new(roots: Vec<SpanNode>) -> Self
pub fn new(roots: Vec<SpanNode>) -> Self
Creates a new span tree state with the given root spans.
All nodes with children start expanded. The first node is selected if the tree is non-empty.
§Example
use envision::component::{SpanTreeState, SpanNode};
let root = SpanNode::new("r", "root", 0.0, 100.0)
.with_child(SpanNode::new("c", "child", 10.0, 50.0));
let state = SpanTreeState::new(vec![root]);
assert_eq!(state.roots().len(), 1);
assert_eq!(state.selected_index(), Some(0));
assert_eq!(state.global_start(), 0.0);
assert_eq!(state.global_end(), 100.0);Sourcepub fn with_title(self, title: impl Into<String>) -> Self
pub fn with_title(self, title: impl Into<String>) -> Self
Sets the title (builder pattern).
§Example
use envision::component::{SpanTreeState, SpanNode};
let state = SpanTreeState::new(vec![SpanNode::new("r", "root", 0.0, 10.0)])
.with_title("Trace");
assert_eq!(state.title(), Some("Trace"));Sourcepub fn with_label_width(self, width: u16) -> Self
pub fn with_label_width(self, width: u16) -> Self
Sets the label column width (builder pattern).
§Example
use envision::component::{SpanTreeState, SpanNode};
let state = SpanTreeState::new(vec![SpanNode::new("r", "root", 0.0, 10.0)])
.with_label_width(40);
assert_eq!(state.label_width(), 40);Sourcepub fn roots(&self) -> &[SpanNode]
pub fn roots(&self) -> &[SpanNode]
Returns the root spans.
§Example
use envision::component::{SpanTreeState, SpanNode};
let state = SpanTreeState::new(vec![
SpanNode::new("a", "svc-a", 0.0, 10.0),
SpanNode::new("b", "svc-b", 5.0, 15.0),
]);
assert_eq!(state.roots().len(), 2);Sourcepub fn roots_mut(&mut self) -> &mut Vec<SpanNode>
pub fn roots_mut(&mut self) -> &mut Vec<SpanNode>
Returns a mutable reference to the root spans.
This is safe because span nodes are simple data containers. The expanded set tracks nodes by string id, so mutating node data does not corrupt expand/collapse state.
§Example
use envision::component::{SpanTreeState, SpanNode};
use ratatui::style::Color;
let root = SpanNode::new("r", "root", 0.0, 100.0);
let mut state = SpanTreeState::new(vec![root]);
state.roots_mut()[0].set_color(Color::Red);
assert_eq!(state.roots()[0].color(), Color::Red);Note: After modifying the collection, the scrollbar may be inaccurate
until the next render. Prefer dedicated methods (e.g., push_event()) when available.
Sourcepub fn set_roots(&mut self, roots: Vec<SpanNode>)
pub fn set_roots(&mut self, roots: Vec<SpanNode>)
Replaces all root spans and recomputes global times.
§Example
use envision::component::{SpanTreeState, SpanNode};
let mut state = SpanTreeState::new(vec![SpanNode::new("old", "old", 0.0, 10.0)]);
state.set_roots(vec![SpanNode::new("new", "new", 5.0, 50.0)]);
assert_eq!(state.roots().len(), 1);
assert_eq!(state.global_start(), 5.0);
assert_eq!(state.global_end(), 50.0);Sourcepub fn selected_index(&self) -> Option<usize>
pub fn selected_index(&self) -> Option<usize>
Returns the currently selected flat index.
§Example
use envision::component::{SpanTreeState, SpanNode};
let state = SpanTreeState::new(vec![SpanNode::new("r", "root", 0.0, 10.0)]);
assert_eq!(state.selected_index(), Some(0));
let empty = SpanTreeState::default();
assert_eq!(empty.selected_index(), None);Sourcepub fn selected_span(&self) -> Option<FlatSpan>
pub fn selected_span(&self) -> Option<FlatSpan>
Returns the currently selected span in flattened view.
§Example
use envision::component::{SpanTreeState, SpanNode};
let root = SpanNode::new("r", "root", 0.0, 100.0);
let state = SpanTreeState::new(vec![root]);
let selected = state.selected_span().unwrap();
assert_eq!(selected.id(), "r");
assert_eq!(selected.label(), "root");Sourcepub fn global_start(&self) -> f64
pub fn global_start(&self) -> f64
Returns the earliest start time across all spans.
Sourcepub fn global_end(&self) -> f64
pub fn global_end(&self) -> f64
Returns the latest end time across all spans.
Sourcepub fn label_width(&self) -> u16
pub fn label_width(&self) -> u16
Returns the label column width.
Sourcepub fn set_title(&mut self, title: impl Into<String>)
pub fn set_title(&mut self, title: impl Into<String>)
Sets the title.
§Example
use envision::component::SpanTreeState;
let mut state = SpanTreeState::default();
state.set_title("Trace View");
assert_eq!(state.title(), Some("Trace View"));Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the tree is empty.
§Example
use envision::component::SpanTreeState;
assert!(SpanTreeState::default().is_empty());Sourcepub fn expanded_ids(&self) -> &HashSet<String>
pub fn expanded_ids(&self) -> &HashSet<String>
Returns the set of expanded node IDs.
Sourcepub fn expand(&mut self, id: &str)
pub fn expand(&mut self, id: &str)
Expands a node by its ID.
§Example
use envision::component::{SpanTreeState, SpanNode};
let root = SpanNode::new("r", "root", 0.0, 100.0)
.with_child(SpanNode::new("c", "child", 10.0, 50.0));
let mut state = SpanTreeState::new(vec![root]);
state.collapse("r");
assert!(!state.expanded_ids().contains("r"));
state.expand("r");
assert!(state.expanded_ids().contains("r"));Sourcepub fn collapse(&mut self, id: &str)
pub fn collapse(&mut self, id: &str)
Collapses a node by its ID.
§Example
use envision::component::{SpanTreeState, SpanNode};
let root = SpanNode::new("r", "root", 0.0, 100.0)
.with_child(SpanNode::new("c", "child", 10.0, 50.0));
let mut state = SpanTreeState::new(vec![root]);
state.collapse("r");
assert!(!state.expanded_ids().contains("r"));Sourcepub fn expand_all(&mut self)
pub fn expand_all(&mut self)
Expands all nodes.
§Example
use envision::component::{SpanTreeState, SpanNode};
let root = SpanNode::new("r", "root", 0.0, 100.0)
.with_child(SpanNode::new("c", "child", 10.0, 50.0));
let mut state = SpanTreeState::new(vec![root]);
state.collapse_all();
state.expand_all();
assert!(state.expanded_ids().contains("r"));Sourcepub fn collapse_all(&mut self)
pub fn collapse_all(&mut self)
Collapses all nodes.
§Example
use envision::component::{SpanTreeState, SpanNode};
let root = SpanNode::new("r", "root", 0.0, 100.0)
.with_child(SpanNode::new("c", "child", 10.0, 50.0));
let mut state = SpanTreeState::new(vec![root]);
state.collapse_all();
assert!(state.expanded_ids().is_empty());Sourcepub fn flatten(&self) -> Vec<FlatSpan>
pub fn flatten(&self) -> Vec<FlatSpan>
Flattens the visible hierarchy into a list of FlatSpan items.
Only expanded nodes have their children included. The order is depth-first, matching the visual tree order.
§Example
use envision::component::{SpanTreeState, SpanNode};
let root = SpanNode::new("r", "root", 0.0, 100.0)
.with_child(SpanNode::new("c1", "child-1", 10.0, 50.0))
.with_child(SpanNode::new("c2", "child-2", 50.0, 90.0));
let state = SpanTreeState::new(vec![root]);
let flat = state.flatten();
assert_eq!(flat.len(), 3);
assert_eq!(flat[0].id(), "r");
assert_eq!(flat[0].depth(), 0);
assert_eq!(flat[1].id(), "c1");
assert_eq!(flat[1].depth(), 1);Sourcepub fn update(&mut self, msg: SpanTreeMessage) -> Option<SpanTreeOutput>
pub fn update(&mut self, msg: SpanTreeMessage) -> Option<SpanTreeOutput>
Updates the state with a message, returning any output.
Trait Implementations§
Source§impl Clone for SpanTreeState
impl Clone for SpanTreeState
Source§fn clone(&self) -> SpanTreeState
fn clone(&self) -> SpanTreeState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SpanTreeState
impl Debug for SpanTreeState
Source§impl Default for SpanTreeState
impl Default for SpanTreeState
Source§impl<'de> Deserialize<'de> for SpanTreeState
impl<'de> Deserialize<'de> for SpanTreeState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for SpanTreeState
impl PartialEq for SpanTreeState
Source§impl Serialize for SpanTreeState
impl Serialize for SpanTreeState
impl StructuralPartialEq for SpanTreeState
Auto Trait Implementations§
impl Freeze for SpanTreeState
impl RefUnwindSafe for SpanTreeState
impl Send for SpanTreeState
impl Sync for SpanTreeState
impl Unpin for SpanTreeState
impl UnsafeUnpin for SpanTreeState
impl UnwindSafe for SpanTreeState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more