pub struct Node<BackendT>where
BackendT: TreeBackend,{
pub depth: usize,
pub kind: NodeKind,
pub id: BackendT::ID,
pub representation: Representation,
pub representation_size: Vec2,
pub branch_state: BranchState,
pub children: Option<NodeList<BackendT>>,
pub data: Option<BackendT::Data>,
/* private fields */
}Expand description
Tree node.
Fields§
§depth: usizeDepth.
kind: NodeKindKind.
id: BackendT::IDID.
representation: RepresentationRepresentation.
representation_size: Vec2Representation size.
Cached so we only have to calculate it once.
Note that nodes can ostensibly have heights >1, i.e. they can be multiline, however this is not currently supported by TreeView.
branch_state: BranchStateState for Branch node.
children: Option<NodeList<BackendT>>Children for Branch node.
data: Option<BackendT::Data>Data.
Implementations§
Source§impl<BackendT> Node<BackendT>where
BackendT: TreeBackend,
impl<BackendT> Node<BackendT>where
BackendT: TreeBackend,
Sourcepub fn new(
depth: usize,
kind: NodeKind,
id: BackendT::ID,
representation: Representation,
) -> Self
pub fn new( depth: usize, kind: NodeKind, id: BackendT::ID, representation: Representation, ) -> Self
Constructor.
Sourcepub fn symbol(&self, context: BackendT::Context) -> Symbol<'_>
pub fn symbol(&self, context: BackendT::Context) -> Symbol<'_>
Symbol.
Its char count is always 1.
Sourcepub fn at_path_mut(&mut self, path: NodePath) -> Option<&mut Self>
pub fn at_path_mut(&mut self, path: NodePath) -> Option<&mut Self>
Get node at path.
Sourcepub fn fill_path(&self, path: &mut NodePath, node: &Self) -> bool
pub fn fill_path(&self, path: &mut NodePath, node: &Self) -> bool
Fill path to node.
Returns true if found.
Sourcepub fn populate(
&mut self,
depth: Option<usize>,
context: BackendT::Context,
) -> Result<(), BackendT::Error>
pub fn populate( &mut self, depth: Option<usize>, context: BackendT::Context, ) -> Result<(), BackendT::Error>
Sourcepub fn add_child(
&mut self,
kind: NodeKind,
id: BackendT::ID,
representation: Representation,
)
pub fn add_child( &mut self, kind: NodeKind, id: BackendT::ID, representation: Representation, )
Add a child node.
Will do nothing if not a Branch.
Examples found in repository?
examples/simple.rs (line 22)
8fn main() {
9 let mut cursive = Cursive::default();
10
11 let mut tree = SimpleTreeBackend::tree_view(());
12
13 // A few roots
14
15 tree.model.add_root(NodeKind::Leaf, (), "Hello".into());
16 tree.model.add_root(NodeKind::Branch, (), "World".into());
17
18 // Add 10 children to "World"
19
20 let world = tree.model.at_path_mut([1].into()).unwrap();
21 for i in 0..10 {
22 world.add_child(NodeKind::Leaf, (), format!("Child #{}", i + 1).into());
23 }
24
25 // Add 10 grandchildren each to "Child #5" -> "Child #10"
26 // Note that we change them to branch in order to support having children
27
28 let mut gc = 0;
29 for c in 4..10 {
30 let child = tree.model.at_path_mut([1, c].into()).unwrap();
31 child.kind = NodeKind::Branch;
32 for _ in 0..10 {
33 child.add_child(NodeKind::Leaf, (), format!("Grandchild #{}", gc + 1).into());
34 gc += 1;
35 }
36 }
37
38 // Expand all nodes
39
40 tree.model.expand(None).unwrap();
41
42 cursive.add_fullscreen_layer(Panel::new(tree.scrollable()));
43 cursive.add_global_callback('q', |cursive| cursive.quit());
44
45 cursive.run();
46}Sourcepub fn insert_child(
&mut self,
index: usize,
kind: NodeKind,
id: BackendT::ID,
representation: Representation,
)
pub fn insert_child( &mut self, index: usize, kind: NodeKind, id: BackendT::ID, representation: Representation, )
Inserts a child node.
Will do nothing if not a Branch.
Sourcepub fn expand(
&mut self,
depth: Option<usize>,
context: BackendT::Context,
) -> Result<(), BackendT::Error>
pub fn expand( &mut self, depth: Option<usize>, context: BackendT::Context, ) -> Result<(), BackendT::Error>
Sourcepub fn toggle_branch_state(
&mut self,
context: BackendT::Context,
) -> Result<(), BackendT::Error>
pub fn toggle_branch_state( &mut self, context: BackendT::Context, ) -> Result<(), BackendT::Error>
Toggle the branch state.
Expand if collapsed, collapse if expanded.
Will do nothing if not a Branch.
Sourcepub fn data(
&mut self,
context: BackendT::Context,
) -> Result<Option<Cow<'_, BackendT::Data>>, BackendT::Error>
pub fn data( &mut self, context: BackendT::Context, ) -> Result<Option<Cow<'_, BackendT::Data>>, BackendT::Error>
Data.
If not already cached will fetch it from the backend.
Examples found in repository?
examples/file_browser.rs (line 68)
63 fn handle_selection_changed(cursive: &mut Cursive) {
64 let content = match cursive.call_on_name("tree", |tree: &mut TreeView<Self>| {
65 // Although we're not using the context in data() but we still need to provide it
66 let base_directory = tree.model.context.clone();
67 Ok(match tree.selected_node_mut() {
68 Some(node) => match node.data(base_directory)? {
69 Some(metadata) => Some(format_metadata(&metadata)?),
70 None => None,
71 },
72 None => None,
73 })
74 }) {
75 Some(Ok(Some(text))) => text,
76 Some(Err(error)) => return Self::handle_error(cursive, error),
77 _ => "".into(),
78 };
79
80 cursive.call_on_name("details", |details: &mut TextView| {
81 details.set_content(content);
82 });
83 }Trait Implementations§
Source§impl<BackendT> FromIterator<Node<BackendT>> for NodeList<BackendT>where
BackendT: TreeBackend,
impl<BackendT> FromIterator<Node<BackendT>> for NodeList<BackendT>where
BackendT: TreeBackend,
Auto Trait Implementations§
impl<BackendT> Freeze for Node<BackendT>
impl<BackendT> RefUnwindSafe for Node<BackendT>where
<BackendT as TreeBackend>::ID: RefUnwindSafe,
<BackendT as TreeBackend>::Data: RefUnwindSafe,
BackendT: RefUnwindSafe,
impl<BackendT> Send for Node<BackendT>
impl<BackendT> Sync for Node<BackendT>
impl<BackendT> Unpin for Node<BackendT>where
<BackendT as TreeBackend>::ID: Unpin,
<BackendT as TreeBackend>::Data: Unpin,
BackendT: Unpin,
impl<BackendT> UnsafeUnpin for Node<BackendT>
impl<BackendT> UnwindSafe for Node<BackendT>where
<BackendT as TreeBackend>::ID: UnwindSafe,
<BackendT as TreeBackend>::Data: UnwindSafe,
BackendT: UnwindSafe,
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
Mutably borrows from an owned value. Read more