pub struct Node<BackendT, ContextT, ErrorT, IdT, DataT> {
pub depth: usize,
pub kind: NodeKind,
pub id: IdT,
pub representation: Representation,
pub representation_size: XY<usize>,
pub branch_state: BranchState,
pub children: Option<NodeList<BackendT, ContextT, ErrorT, IdT, DataT>>,
pub data: Option<DataT>,
/* private fields */
}Expand description
Tree node.
Fields§
§depth: usizeDepth.
kind: NodeKindKind.
id: IdTID.
representation: RepresentationRepresentation.
representation_size: XY<usize>Representation size.
Cached so we only have to calculate it once.
branch_state: BranchStateState for Branch node.
children: Option<NodeList<BackendT, ContextT, ErrorT, IdT, DataT>>Children for Branch node.
data: Option<DataT>Data.
Implementations§
Source§impl<BackendT, ContextT, ErrorT, IdT, DataT> Node<BackendT, ContextT, ErrorT, IdT, DataT>where
BackendT: TreeBackend<ContextT, ErrorT, IdT, DataT>,
impl<BackendT, ContextT, ErrorT, IdT, DataT> Node<BackendT, ContextT, ErrorT, IdT, DataT>where
BackendT: TreeBackend<ContextT, ErrorT, IdT, DataT>,
Sourcepub fn new(
depth: usize,
kind: NodeKind,
id: IdT,
representation: Representation,
) -> Self
pub fn new( depth: usize, kind: NodeKind, id: IdT, representation: Representation, ) -> Self
Constructor.
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: ContextT,
) -> Result<(), ErrorT>where
ContextT: Clone,
pub fn populate(
&mut self,
depth: Option<usize>,
context: ContextT,
) -> Result<(), ErrorT>where
ContextT: Clone,
Sourcepub fn add_child(
&mut self,
kind: NodeKind,
id: IdT,
representation: Representation,
)
pub fn add_child( &mut self, kind: NodeKind, id: IdT, representation: Representation, )
Add a child node.
Examples found in repository?
examples/simple.rs (line 23)
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 // and expand it
20
21 let world = tree.model.at_path_mut([1].into()).unwrap();
22 for i in 0..10 {
23 world.add_child(NodeKind::Leaf, (), format!("Child #{}", i + 1).into());
24 }
25 world.expand_branch(()).unwrap();
26
27 // Add 10 grandchildren each to "Child #5" to "Child #10"
28 // Note that we change then to a branch in order to support having children
29
30 for c in 4..10 {
31 let child = tree.model.at_path_mut([1, c].into()).unwrap();
32 child.kind = NodeKind::Branch;
33 for gc in 0..10 {
34 child.add_child(NodeKind::Leaf, (), format!("Grandchild #{}", gc + 1).into());
35 }
36 }
37
38 cursive.add_fullscreen_layer(tree.scrollable());
39 cursive.add_global_callback('q', |cursive| cursive.quit());
40
41 cursive.run();
42}Sourcepub fn insert_child(
&mut self,
index: usize,
kind: NodeKind,
id: IdT,
representation: Representation,
)
pub fn insert_child( &mut self, index: usize, kind: NodeKind, id: IdT, representation: Representation, )
Inserts a child node.
Sourcepub fn expand_branch(&mut self, context: ContextT) -> Result<bool, ErrorT>where
ContextT: Clone,
pub fn expand_branch(&mut self, context: ContextT) -> Result<bool, ErrorT>where
ContextT: Clone,
Expand the branch.
Will return false if not a Branch or already expanded.
Examples found in repository?
examples/simple.rs (line 25)
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 // and expand it
20
21 let world = tree.model.at_path_mut([1].into()).unwrap();
22 for i in 0..10 {
23 world.add_child(NodeKind::Leaf, (), format!("Child #{}", i + 1).into());
24 }
25 world.expand_branch(()).unwrap();
26
27 // Add 10 grandchildren each to "Child #5" to "Child #10"
28 // Note that we change then to a branch in order to support having children
29
30 for c in 4..10 {
31 let child = tree.model.at_path_mut([1, c].into()).unwrap();
32 child.kind = NodeKind::Branch;
33 for gc in 0..10 {
34 child.add_child(NodeKind::Leaf, (), format!("Grandchild #{}", gc + 1).into());
35 }
36 }
37
38 cursive.add_fullscreen_layer(tree.scrollable());
39 cursive.add_global_callback('q', |cursive| cursive.quit());
40
41 cursive.run();
42}Sourcepub fn collapse_branch(&mut self) -> bool
pub fn collapse_branch(&mut self) -> bool
Collapse the branch.
Will return false if not a Branch or already collapsed.
Sourcepub fn toggle_branch_state(&mut self, context: ContextT) -> Result<(), ErrorT>where
ContextT: Clone,
pub fn toggle_branch_state(&mut self, context: ContextT) -> Result<(), ErrorT>where
ContextT: Clone,
Toggle the branch state.
Expand if collapsed, collapse if expanded.
Will do nothing if not a Branch.
Sourcepub fn data(
&mut self,
context: ContextT,
) -> Result<Option<Cow<'_, DataT>>, ErrorT>where
DataT: Clone,
pub fn data(
&mut self,
context: ContextT,
) -> Result<Option<Cow<'_, DataT>>, ErrorT>where
DataT: Clone,
Data.
If not already cached will fetch it from the backend.
Examples found in repository?
examples/file_browser.rs (line 73)
66 fn handle_selection_changed(cursive: &mut Cursive) {
67 let content = match cursive.call_on_name(
68 "tree",
69 |tree: &mut TreeView<Self, Arc<PathBuf>, io::Error, PathBuf, Metadata>| {
70 // Although we're not using the context in data() but we still need to provide it
71 let base_directory = tree.model.context.clone();
72 Ok(match tree.selected_node_mut() {
73 Some(node) => match node.data(base_directory)? {
74 Some(metadata) => Some(format_metadata(&metadata)?),
75 None => None,
76 },
77 None => None,
78 })
79 },
80 ) {
81 Some(Ok(Some(text))) => text,
82 Some(Err(error)) => return Self::handle_error(cursive, error),
83 _ => "".into(),
84 };
85
86 cursive.call_on_name("details", |details: &mut TextView| {
87 details.set_content(content);
88 });
89 }Trait Implementations§
Source§impl<BackendT, ContextT, ErrorT, IdT, DataT> FromIterator<Node<BackendT, ContextT, ErrorT, IdT, DataT>> for NodeList<BackendT, ContextT, ErrorT, IdT, DataT>
impl<BackendT, ContextT, ErrorT, IdT, DataT> FromIterator<Node<BackendT, ContextT, ErrorT, IdT, DataT>> for NodeList<BackendT, ContextT, ErrorT, IdT, DataT>
Auto Trait Implementations§
impl<BackendT, ContextT, ErrorT, IdT, DataT> Freeze for Node<BackendT, ContextT, ErrorT, IdT, DataT>
impl<BackendT, ContextT, ErrorT, IdT, DataT> RefUnwindSafe for Node<BackendT, ContextT, ErrorT, IdT, DataT>where
IdT: RefUnwindSafe,
DataT: RefUnwindSafe,
BackendT: RefUnwindSafe,
ContextT: RefUnwindSafe,
ErrorT: RefUnwindSafe,
impl<BackendT, ContextT, ErrorT, IdT, DataT> Send for Node<BackendT, ContextT, ErrorT, IdT, DataT>
impl<BackendT, ContextT, ErrorT, IdT, DataT> Sync for Node<BackendT, ContextT, ErrorT, IdT, DataT>
impl<BackendT, ContextT, ErrorT, IdT, DataT> Unpin for Node<BackendT, ContextT, ErrorT, IdT, DataT>
impl<BackendT, ContextT, ErrorT, IdT, DataT> UnsafeUnpin for Node<BackendT, ContextT, ErrorT, IdT, DataT>where
IdT: UnsafeUnpin,
DataT: UnsafeUnpin,
impl<BackendT, ContextT, ErrorT, IdT, DataT> UnwindSafe for Node<BackendT, ContextT, ErrorT, IdT, DataT>where
IdT: UnwindSafe,
DataT: UnwindSafe,
BackendT: UnwindSafe,
ContextT: UnwindSafe,
ErrorT: 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