Struct cursive_tree_view::TreeView
[−]
[src]
pub struct TreeView<T: Display + Debug> { /* fields omitted */ }
A low level tree view.
Each view provides a number of low level methods for manipulating its contained items and their structure.
All interactions are performed via relative (i.e. visual) row
indices which
makes reasoning about behaviour much easier in the context of interactive
user manipulation of the tree.
Examples
let mut tree = TreeView::new(); tree.insert_item("root".to_string(), Placement::LastChild, 0); tree.insert_item("1".to_string(), Placement::LastChild, 0); tree.insert_item("2".to_string(), Placement::LastChild, 1); tree.insert_item("3".to_string(), Placement::LastChild, 2);
Methods
impl<T: Display + Debug> TreeView<T>
[src]
fn new() -> Self
Creates a new, empty TreeView
.
fn disable(&mut self)
Disables this view.
A disabled view cannot be selected.
fn enable(&mut self)
Re-enables this view.
fn set_enabled(&mut self, enabled: bool)
Enable or disable this view.
fn is_enabled(&self) -> bool
Returns true
if this view is enabled.
fn set_on_submit<F>(&mut self, cb: F) where
F: Fn(&mut Cursive, usize) + 'static,
F: Fn(&mut Cursive, usize) + 'static,
Sets a callback to be used when <Enter>
is pressed while an item
is selected.
Example
tree.set_on_submit(|siv: &mut Cursive, row: usize| { });
fn on_submit<F>(self, cb: F) -> Self where
F: Fn(&mut Cursive, usize) + 'static,
F: Fn(&mut Cursive, usize) + 'static,
Sets a callback to be used when <Enter>
is pressed while an item
is selected.
Chainable variant.
Example
tree.on_submit(|siv: &mut Cursive, row: usize| { });
fn set_on_select<F>(&mut self, cb: F) where
F: Fn(&mut Cursive, usize) + 'static,
F: Fn(&mut Cursive, usize) + 'static,
Sets a callback to be used when an item is selected.
Example
tree.set_on_select(|siv: &mut Cursive, row: usize| { });
fn on_select<F>(self, cb: F) -> Self where
F: Fn(&mut Cursive, usize) + 'static,
F: Fn(&mut Cursive, usize) + 'static,
Sets a callback to be used when an item is selected.
Chainable variant.
Example
tree.on_select(|siv: &mut Cursive, row: usize| { });
fn set_on_collapse<F>(&mut self, cb: F) where
F: Fn(&mut Cursive, usize, bool, usize) + 'static,
F: Fn(&mut Cursive, usize, bool, usize) + 'static,
Sets a callback to be used when an item has its children collapsed or expanded.
Example
tree.set_on_collapse(|siv: &mut Cursive, row: usize, is_collapsed: bool, children: usize| { });
fn on_collapse<F>(self, cb: F) -> Self where
F: Fn(&mut Cursive, usize, bool, usize) + 'static,
F: Fn(&mut Cursive, usize, bool, usize) + 'static,
Sets a callback to be used when an item has its children collapsed or expanded.
Chainable variant.
Example
tree.on_collapse(|siv: &mut Cursive, row: usize, is_collapsed: bool, children: usize| { });
fn clear(&mut self)
Removes all items from this view.
fn take_items(&mut self) -> Vec<T>
Removes all items from this view, returning them.
fn len(&self) -> usize
Returns the number of items in this tree.
fn is_empty(&self) -> bool
Returns true
if this tree has no items.
fn row(&self) -> Option<usize>
Returns the index of the currently selected tree row.
None
is returned in case of the tree being empty.
fn set_selected_row(&mut self, row: usize)
Selects the row at the specified index.
fn selected_row(self, row: usize) -> Self
Selects the row at the specified index.
Chainable variant.
fn borrow_item(&mut self, row: usize) -> Option<&T>
Returns a immutable reference to the item at the given row.
None
is returned in case the specified row
does not visually exist.
fn borrow_item_mut(&mut self, row: usize) -> Option<&mut T>
Returns a mutable reference to the item at the given row.
None
is returned in case the specified row
does not visually exist.
fn insert_item(
&mut self,
item: T,
placement: Placement,
row: usize
) -> Option<usize>
&mut self,
item: T,
placement: Placement,
row: usize
) -> Option<usize>
Inserts a new item
at the given row
with the specified
Placement
, returning the visual row of the item
occupies after its insertion.
None
will be returned in case the item is not visible after insertion
due to one of its parents being in a collapsed state.
fn insert_container_item(
&mut self,
item: T,
placement: Placement,
row: usize
) -> Option<usize>
&mut self,
item: T,
placement: Placement,
row: usize
) -> Option<usize>
Inserts a new container
at the given row
with the specified
Placement
, returning the visual row of the
container occupies after its insertion.
A container is identical to a normal item except for the fact that it can always be collapsed even if it does not contain any children.
Note: If the container is not visible because one of its parents is collapsed
None
will be returned since there is no visible row for the container to occupy.
fn remove_item(&mut self, row: usize) -> Option<Vec<T>>
Removes the item at the given row
along with all of its children.
The returned vector contains the removed items in top to bottom order.
None
is returned in case the specified row
does not visually exist.
fn remove_children(&mut self, row: usize) -> Option<Vec<T>>
Removes all children of the item at the given row
.
The returned vector contains the removed children in top to bottom order.
None
is returned in case the specified row
does not visually exist.
fn extract_item(&mut self, row: usize) -> Option<T>
Extracts the item at the given row
from the tree.
All of the items children will be moved up one level within the tree.
None
is returned in case the specified row
does not visually exist.
fn collapse_item(&mut self, row: usize)
Collapses the children of the given row
.
fn expand_item(&mut self, row: usize)
Expands the children of the given row
.
fn set_collapsed(&mut self, row: usize, collapsed: bool)
Collapses or expands the children of the given row
.
fn collapsed(self, row: usize, collapsed: bool) -> Self
Collapses or expands the children of the given row
.
Chained variant.
Trait Implementations
impl<T: Display + Debug> View for TreeView<T>
[src]
fn draw(&self, printer: &Printer)
Draws the view with the given printer (includes bounds) and focus.
fn required_size(&mut self, req: Vec2) -> Vec2
Returns the minimum size the view requires with the given restrictions. Read more
fn layout(&mut self, size: Vec2)
Called once the size for this view has been decided, Read more
fn take_focus(&mut self, _: Direction) -> bool
This view is offered focus. Will it take it? Read more
fn on_event(&mut self, event: Event) -> EventResult
Called when a key was pressed. Read more
fn needs_relayout(&self) -> bool
Returns true
if the view content changed since last layout phase. Read more
fn call_on_any(&mut self, &Selector, Box<FnMut(&mut Any + 'static) + 'a>)
Finds the view identified by the given selector. Read more
fn focus_view(&mut self, &Selector) -> Result<(), ()>
Moves the focus to the view identified by the given selector. Read more