pub struct TreeModel<BackendT, ContextT, ErrorT, IdT, DataT> {
pub roots: NodeList<BackendT, ContextT, ErrorT, IdT, DataT>,
pub context: ContextT,
/* private fields */
}Expand description
Tree model.
Fields§
§roots: NodeList<BackendT, ContextT, ErrorT, IdT, DataT>Roots.
context: ContextTContext.
Implementations§
Source§impl<BackendT, ContextT, ErrorT, IdT, DataT> TreeModel<BackendT, ContextT, ErrorT, IdT, DataT>
impl<BackendT, ContextT, ErrorT, IdT, DataT> TreeModel<BackendT, ContextT, ErrorT, IdT, DataT>
Sourcepub fn iter(
&self,
only_expanded: bool,
) -> NodeIterator<'_, BackendT, ContextT, ErrorT, IdT, DataT> ⓘ
pub fn iter( &self, only_expanded: bool, ) -> NodeIterator<'_, BackendT, ContextT, ErrorT, IdT, DataT> ⓘ
Iterate nodes in visual order from top to bottom.
When only_expanded is true will skip the children of collapsed branches.
Sourcepub fn at_path(
&self,
path: NodePath,
) -> Option<&Node<BackendT, ContextT, ErrorT, IdT, DataT>>where
BackendT: TreeBackend<ContextT, ErrorT, IdT, DataT>,
pub fn at_path(
&self,
path: NodePath,
) -> Option<&Node<BackendT, ContextT, ErrorT, IdT, DataT>>where
BackendT: TreeBackend<ContextT, ErrorT, IdT, DataT>,
Get node at path.
Sourcepub fn at_path_mut(
&mut self,
path: NodePath,
) -> Option<&mut Node<BackendT, ContextT, ErrorT, IdT, DataT>>where
BackendT: TreeBackend<ContextT, ErrorT, IdT, DataT>,
pub fn at_path_mut(
&mut self,
path: NodePath,
) -> Option<&mut Node<BackendT, ContextT, ErrorT, IdT, DataT>>where
BackendT: TreeBackend<ContextT, ErrorT, IdT, DataT>,
Get node at path.
Examples found in repository?
examples/simple.rs (line 21)
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 at_row(
&self,
row: usize,
) -> Option<&Node<BackendT, ContextT, ErrorT, IdT, DataT>>where
DataT: 'static,
pub fn at_row(
&self,
row: usize,
) -> Option<&Node<BackendT, ContextT, ErrorT, IdT, DataT>>where
DataT: 'static,
Get node at row.
Sourcepub fn path(
&self,
node: &Node<BackendT, ContextT, ErrorT, IdT, DataT>,
) -> Option<NodePath>where
BackendT: TreeBackend<ContextT, ErrorT, IdT, DataT>,
pub fn path(
&self,
node: &Node<BackendT, ContextT, ErrorT, IdT, DataT>,
) -> Option<NodePath>where
BackendT: TreeBackend<ContextT, ErrorT, IdT, DataT>,
Find path to node.
Sourcepub fn add_root(
&mut self,
kind: NodeKind,
id: IdT,
representation: Representation,
)where
BackendT: TreeBackend<ContextT, ErrorT, IdT, DataT>,
pub fn add_root(
&mut self,
kind: NodeKind,
id: IdT,
representation: Representation,
)where
BackendT: TreeBackend<ContextT, ErrorT, IdT, DataT>,
Add a root node.
Examples found in repository?
examples/simple.rs (line 15)
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_root(
&mut self,
index: usize,
kind: NodeKind,
id: IdT,
representation: Representation,
)where
BackendT: TreeBackend<ContextT, ErrorT, IdT, DataT>,
pub fn insert_root(
&mut self,
index: usize,
kind: NodeKind,
id: IdT,
representation: Representation,
)where
BackendT: TreeBackend<ContextT, ErrorT, IdT, DataT>,
Insert a root node.
Sourcepub fn populate(&mut self, depth: Option<usize>) -> Result<(), ErrorT>where
BackendT: TreeBackend<ContextT, ErrorT, IdT, DataT>,
ContextT: Clone,
pub fn populate(&mut self, depth: Option<usize>) -> Result<(), ErrorT>where
BackendT: TreeBackend<ContextT, ErrorT, IdT, DataT>,
ContextT: Clone,
Fetch nodes from backend.
If depth is None will populate the entire tree.
If depth is 0 will do nothing.
Examples found in repository?
examples/file_browser.rs (line 20)
13fn main() {
14 let mut cursive = Cursive::default();
15
16 let current_dir = current_dir().unwrap();
17 let mut tree = FileBackend::tree_view(current_dir.into());
18
19 // Populate the first level (just the roots)
20 tree.model.populate(Some(1)).unwrap();
21
22 let mut browser = LinearLayout::horizontal();
23 browser.add_child(tree.with_name("tree").scrollable().full_screen());
24 browser.add_child(TextView::new("").with_name("details").scrollable().full_screen());
25
26 cursive.add_fullscreen_layer(browser);
27 cursive.add_global_callback('q', |cursive| cursive.quit());
28
29 cursive.run();
30}Trait Implementations§
Auto Trait Implementations§
impl<BackendT, ContextT, ErrorT, IdT, DataT> Freeze for TreeModel<BackendT, ContextT, ErrorT, IdT, DataT>where
ContextT: Freeze,
impl<BackendT, ContextT, ErrorT, IdT, DataT> RefUnwindSafe for TreeModel<BackendT, ContextT, ErrorT, IdT, DataT>where
ContextT: RefUnwindSafe,
BackendT: RefUnwindSafe,
ErrorT: RefUnwindSafe,
IdT: RefUnwindSafe,
DataT: RefUnwindSafe,
impl<BackendT, ContextT, ErrorT, IdT, DataT> Send for TreeModel<BackendT, ContextT, ErrorT, IdT, DataT>
impl<BackendT, ContextT, ErrorT, IdT, DataT> Sync for TreeModel<BackendT, ContextT, ErrorT, IdT, DataT>
impl<BackendT, ContextT, ErrorT, IdT, DataT> Unpin for TreeModel<BackendT, ContextT, ErrorT, IdT, DataT>
impl<BackendT, ContextT, ErrorT, IdT, DataT> UnsafeUnpin for TreeModel<BackendT, ContextT, ErrorT, IdT, DataT>where
ContextT: UnsafeUnpin,
impl<BackendT, ContextT, ErrorT, IdT, DataT> UnwindSafe for TreeModel<BackendT, ContextT, ErrorT, IdT, DataT>where
ContextT: UnwindSafe,
BackendT: UnwindSafe,
ErrorT: UnwindSafe,
IdT: UnwindSafe,
DataT: 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