pub struct TreeView<T: Display + Debug> { /* private fields */ }Expand description
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);Implementations§
Source§impl<T: Display + Debug + Send + Sync> TreeView<T>
impl<T: Display + Debug + Send + Sync> TreeView<T>
Sourcepub fn set_enabled(&mut self, enabled: bool)
pub fn set_enabled(&mut self, enabled: bool)
Enable or disable this view.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Returns true if this view is enabled.
Sourcepub fn set_on_submit<F>(&mut self, cb: F)
pub fn set_on_submit<F>(&mut self, cb: F)
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| {
});Sourcepub fn on_submit<F>(self, cb: F) -> Self
pub fn on_submit<F>(self, cb: F) -> Self
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| {
});Sourcepub fn set_on_select<F>(&mut self, cb: F)
pub fn set_on_select<F>(&mut self, cb: F)
Sets a callback to be used when an item is selected.
§Example
tree.set_on_select(|siv: &mut Cursive, row: usize| {
});Sourcepub fn on_select<F>(self, cb: F) -> Self
pub fn on_select<F>(self, cb: F) -> Self
Sets a callback to be used when an item is selected.
Chainable variant.
§Example
tree.on_select(|siv: &mut Cursive, row: usize| {
});Sourcepub fn set_on_collapse<F>(&mut self, cb: F)
pub fn set_on_collapse<F>(&mut self, cb: F)
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| {
});Sourcepub fn on_collapse<F>(self, cb: F) -> Self
pub fn on_collapse<F>(self, cb: F) -> Self
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| {
});Sourcepub fn take_items(&mut self) -> Vec<T>
pub fn take_items(&mut self) -> Vec<T>
Removes all items from this view, returning them.
Sourcepub fn row(&self) -> Option<usize>
pub fn row(&self) -> Option<usize>
Returns the index of the currently selected tree row.
None is returned in case of the tree being empty.
Sourcepub fn first_col(&self, row: usize) -> Option<usize>
pub fn first_col(&self, row: usize) -> Option<usize>
Returns position on the x axis of the symbol (first character of an item) at the given row.
None is returned in case the specified row does not visually exist.
Sourcepub fn item_width(&self, row: usize) -> Option<usize>
pub fn item_width(&self, row: usize) -> Option<usize>
Returns total width (including the symbol) of the item at the given row.
None is returned in case the specified row does not visually exist.
Sourcepub fn set_selected_row(&mut self, row: usize)
pub fn set_selected_row(&mut self, row: usize)
Selects the row at the specified index.
Sourcepub fn selected_row(self, row: usize) -> Self
pub fn selected_row(self, row: usize) -> Self
Selects the row at the specified index.
Chainable variant.
Sourcepub fn borrow_item(&self, row: usize) -> Option<&T>
pub fn borrow_item(&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.
Sourcepub fn borrow_item_mut(&mut self, row: usize) -> Option<&mut T>
pub 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.
Sourcepub fn insert_item(
&mut self,
item: T,
placement: Placement,
row: usize,
) -> Option<usize>
pub fn insert_item( &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.
Sourcepub fn insert_container_item(
&mut self,
item: T,
placement: Placement,
row: usize,
) -> Option<usize>
pub fn insert_container_item( &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
Nonewill be returned since there is no visible row for the container to occupy.
Sourcepub fn remove_item(&mut self, row: usize) -> Option<Vec<T>>
pub 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.
Sourcepub fn remove_children(&mut self, row: usize) -> Option<Vec<T>>
pub 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.
Sourcepub fn extract_item(&mut self, row: usize) -> Option<T>
pub 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.
Sourcepub fn collapse_item(&mut self, row: usize)
pub fn collapse_item(&mut self, row: usize)
Collapses the children of the given row.
Sourcepub fn expand_item(&mut self, row: usize)
pub fn expand_item(&mut self, row: usize)
Expands the children of the given row.
Sourcepub fn set_collapsed(&mut self, row: usize, collapsed: bool)
pub fn set_collapsed(&mut self, row: usize, collapsed: bool)
Collapses or expands the children of the given row.
Sourcepub fn collapsed(self, row: usize, collapsed: bool) -> Self
pub fn collapsed(self, row: usize, collapsed: bool) -> Self
Collapses or expands the children of the given row.
Chained variant.
Sourcepub fn focus_down(&mut self, n: usize)
pub fn focus_down(&mut self, n: usize)
Select item n rows down from the one currently selected.
Sourcepub fn item_parent(&self, row: usize) -> Option<usize>
pub fn item_parent(&self, row: usize) -> Option<usize>
Returns position of the parent of the item located in row.
None is returned if row is not currenlty visible or if the item has no ancestors.
Trait Implementations§
Source§impl<T: Display + Send + Sync + Debug + 'static> View for TreeView<T>
impl<T: Display + Send + Sync + Debug + 'static> View for TreeView<T>
Source§fn draw(&self, printer: &Printer<'_, '_>)
fn draw(&self, printer: &Printer<'_, '_>)
Source§fn required_size(&mut self, _req: Vec2) -> Vec2
fn required_size(&mut self, _req: Vec2) -> Vec2
Source§fn layout(&mut self, size: Vec2)
fn layout(&mut self, size: Vec2)
Source§fn take_focus(&mut self, _: Direction) -> Result<EventResult, CannotFocus>
fn take_focus(&mut self, _: Direction) -> Result<EventResult, CannotFocus>
Source§fn on_event(&mut self, event: Event) -> EventResult
fn on_event(&mut self, event: Event) -> EventResult
Source§fn important_area(&self, size: Vec2) -> Rect
fn important_area(&self, size: Vec2) -> Rect
Source§fn needs_relayout(&self) -> bool
fn needs_relayout(&self) -> bool
Source§fn call_on_any(
&mut self,
_: &Selector<'_>,
_: &mut dyn FnMut(&mut (dyn View + 'static)),
)
fn call_on_any( &mut self, _: &Selector<'_>, _: &mut dyn FnMut(&mut (dyn View + 'static)), )
Source§fn focus_view(&mut self, _: &Selector<'_>) -> Result<EventResult, ViewNotFound>
fn focus_view(&mut self, _: &Selector<'_>) -> Result<EventResult, ViewNotFound>
Auto Trait Implementations§
impl<T> Freeze for TreeView<T>
impl<T> !RefUnwindSafe for TreeView<T>
impl<T> Send for TreeView<T>where
T: Send,
impl<T> Sync for TreeView<T>where
T: Sync,
impl<T> Unpin for TreeView<T>where
T: Unpin,
impl<T> !UnwindSafe for TreeView<T>
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> Finder for Twhere
T: View,
impl<T> Finder for Twhere
T: View,
Source§fn call_on_all<V, F>(&mut self, sel: &Selector<'_>, callback: F)
fn call_on_all<V, F>(&mut self, sel: &Selector<'_>, callback: F)
sel. Read moreSource§fn call_on<V, F, R>(&mut self, sel: &Selector<'_>, callback: F) -> Option<R>
fn call_on<V, F, R>(&mut self, sel: &Selector<'_>, callback: F) -> Option<R>
sel. Read moreSource§fn call_on_name<V, F, R>(&mut self, name: &str, callback: F) -> Option<R>
fn call_on_name<V, F, R>(&mut self, name: &str, callback: F) -> Option<R>
call_on with a view::Selector::Name.Source§impl<T> IntoBoxedView for Twhere
T: View,
impl<T> IntoBoxedView for Twhere
T: View,
Source§fn into_boxed_view(self) -> Box<dyn View>
fn into_boxed_view(self) -> Box<dyn View>
Box<View>.Source§impl<T> Resizable for Twhere
T: View,
impl<T> Resizable for Twhere
T: View,
Source§fn resized(
self,
width: SizeConstraint,
height: SizeConstraint,
) -> ResizedView<Self>
fn resized( self, width: SizeConstraint, height: SizeConstraint, ) -> ResizedView<Self>
self in a ResizedView with the given size constraints.Source§fn fixed_size<S>(self, size: S) -> ResizedView<Self>
fn fixed_size<S>(self, size: S) -> ResizedView<Self>
self into a fixed-size ResizedView.Source§fn fixed_width(self, width: usize) -> ResizedView<Self>
fn fixed_width(self, width: usize) -> ResizedView<Self>
self into a fixed-width ResizedView.Source§fn fixed_height(self, height: usize) -> ResizedView<Self>
fn fixed_height(self, height: usize) -> ResizedView<Self>
self into a fixed-width ResizedView.Source§fn full_screen(self) -> ResizedView<Self>
fn full_screen(self) -> ResizedView<Self>
self into a full-screen ResizedView.Source§fn full_width(self) -> ResizedView<Self>
fn full_width(self) -> ResizedView<Self>
self into a full-width ResizedView.Source§fn full_height(self) -> ResizedView<Self>
fn full_height(self) -> ResizedView<Self>
self into a full-height ResizedView.Source§fn max_size<S>(self, size: S) -> ResizedView<Self>
fn max_size<S>(self, size: S) -> ResizedView<Self>
self into a limited-size ResizedView.Source§fn max_width(self, max_width: usize) -> ResizedView<Self>
fn max_width(self, max_width: usize) -> ResizedView<Self>
self into a limited-width ResizedView.Source§fn max_height(self, max_height: usize) -> ResizedView<Self>
fn max_height(self, max_height: usize) -> ResizedView<Self>
self into a limited-height ResizedView.Source§fn min_size<S>(self, size: S) -> ResizedView<Self>
fn min_size<S>(self, size: S) -> ResizedView<Self>
self into a ResizedView at least sized size.Source§fn min_width(self, min_width: usize) -> ResizedView<Self>
fn min_width(self, min_width: usize) -> ResizedView<Self>
self in a ResizedView at least min_width wide.Source§fn min_height(self, min_height: usize) -> ResizedView<Self>
fn min_height(self, min_height: usize) -> ResizedView<Self>
self in a ResizedView at least min_height tall.Source§impl<T> Scrollable for Twhere
T: View,
impl<T> Scrollable for Twhere
T: View,
Source§fn scrollable(self) -> ScrollView<Self>
fn scrollable(self) -> ScrollView<Self>
self in a ScrollView.