Struct cursive_table_view::TableView
[−]
[src]
pub struct TableView<T: TableViewItem<H>, H: Eq + Hash + Copy + Clone + 'static> { /* fields omitted */ }
View to select an item among a list, supporting multiple columns for sorting.
Examples
// Provide a type for the table's columns #[derive(Copy, Clone, PartialEq, Eq, Hash)] enum BasicColumn { Name, Count, Rate } // Define the item type #[derive(Clone, Debug)] struct Foo { name: String, count: usize, rate: usize } impl TableViewItem<BasicColumn> for Foo { fn to_column(&self, column: BasicColumn) -> String { match column { BasicColumn::Name => self.name.to_string(), BasicColumn::Count => format!("{}", self.count), BasicColumn::Rate => format!("{}", self.rate) } } fn cmp(&self, other: &Self, column: BasicColumn) -> Ordering where Self: Sized { match column { BasicColumn::Name => self.name.cmp(&other.name), BasicColumn::Count => self.count.cmp(&other.count), BasicColumn::Rate => self.rate.cmp(&other.rate) } } } // Configure the actual table let table = TableView::<Foo, BasicColumn>::new() .column(BasicColumn::Name, "Name", |c| c.width(20)) .column(BasicColumn::Count, "Count", |c| c.align(HAlign::Center)) .column(BasicColumn::Rate, "Rate", |c| { c.ordering(Ordering::Greater).align(HAlign::Right).width(20) }) .default_column(BasicColumn::Name);
Methods
impl<T: TableViewItem<H>, H: Eq + Hash + Copy + Clone + 'static> TableView<T, H>
[src]
fn new() -> Self
[src]
Creates a new empty TableView
without any columns.
A TableView should be accompanied by a enum of type H
representing
the table columns.
fn column<S: Into<String>, C: FnOnce(TableColumn<H>) -> TableColumn<H>>(
self,
column: H,
title: S,
callback: C
) -> Self
[src]
self,
column: H,
title: S,
callback: C
) -> Self
Adds a column for the specified table colum from type H
along with
a title for its visual display.
The provided callback can be used to further configure the
created TableColumn
.
fn default_column(self, column: H) -> Self
[src]
Sets the initially active column of the table.
fn sort_by(&mut self, column: H, order: Ordering)
[src]
Sorts the table using the specified table column
and the passed
order
.
fn sort(&mut self)
[src]
Sorts the table using the currently active column and its ordering.
fn order(&self) -> Option<(H, Ordering)>
[src]
Returns the currently active column that is used for sorting along with its ordering.
Might return None
if there are currently no items in the table
and it has not been sorted yet.
fn disable(&mut self)
[src]
Disables this view.
A disabled view cannot be selected.
fn enable(&mut self)
[src]
Re-enables this view.
fn set_enabled(&mut self, enabled: bool)
[src]
Enable or disable this view.
fn is_enabled(&self) -> bool
[src]
Returns true
if this view is enabled.
fn set_on_sort<F>(&mut self, cb: F) where
F: Fn(&mut Cursive, H, Ordering) + 'static,
[src]
F: Fn(&mut Cursive, H, Ordering) + 'static,
Sets a callback to be used when a selected column is sorted by
pressing <Enter>
.
Example
table.set_on_sort(|siv: &mut Cursive, column: BasicColumn, order: Ordering| {
});
fn on_sort<F>(self, cb: F) -> Self where
F: Fn(&mut Cursive, H, Ordering) + 'static,
[src]
F: Fn(&mut Cursive, H, Ordering) + 'static,
Sets a callback to be used when a selected column is sorted by
pressing <Enter>
.
Chainable variant.
Example
table.on_sort(|siv: &mut Cursive, column: BasicColumn, order: Ordering| {
});
fn set_on_submit<F>(&mut self, cb: F) where
F: Fn(&mut Cursive, usize, usize) + 'static,
[src]
F: Fn(&mut Cursive, usize, usize) + 'static,
Sets a callback to be used when <Enter>
is pressed while an item
is selected.
Both the currently selected row and the index of the corresponding item within the underlying storage vector will be given to the callback.
Example
table.set_on_submit(|siv: &mut Cursive, row: usize, index: usize| {
});
fn on_submit<F>(self, cb: F) -> Self where
F: Fn(&mut Cursive, usize, usize) + 'static,
[src]
F: Fn(&mut Cursive, usize, usize) + 'static,
Sets a callback to be used when <Enter>
is pressed while an item
is selected.
Both the currently selected row and the index of the corresponding item within the underlying storage vector will be given to the callback.
Chainable variant.
Example
table.on_submit(|siv: &mut Cursive, row: usize, index: usize| {
});
fn set_on_select<F>(&mut self, cb: F) where
F: Fn(&mut Cursive, usize, usize) + 'static,
[src]
F: Fn(&mut Cursive, usize, usize) + 'static,
Sets a callback to be used when an item is selected.
Both the currently selected row and the index of the corresponding item within the underlying storage vector will be given to the callback.
Example
table.set_on_select(|siv: &mut Cursive, row: usize, index: usize| {
});
fn on_select<F>(self, cb: F) -> Self where
F: Fn(&mut Cursive, usize, usize) + 'static,
[src]
F: Fn(&mut Cursive, usize, usize) + 'static,
Sets a callback to be used when an item is selected.
Both the currently selected row and the index of the corresponding item within the underlying storage vector will be given to the callback.
Chainable variant.
Example
table.on_select(|siv: &mut Cursive, row: usize, index: usize| {
});
fn clear(&mut self)
[src]
Removes all items from this view.
fn len(&self) -> usize
[src]
Returns the number of items in this table.
fn is_empty(&self) -> bool
[src]
Returns true
if this table has no items.
fn row(&self) -> Option<usize>
[src]
Returns the index of the currently selected table row.
fn set_selected_row(&mut self, row_index: usize)
[src]
Selects the row at the specified index.
fn selected_row(self, row_index: usize) -> Self
[src]
Selects the row at the specified index.
Chainable variant.
fn set_items(&mut self, items: Vec<T>)
[src]
Sets the contained items of the table.
The currently active sort order is preserved and will be applied to all items.
fn items(self, items: Vec<T>) -> Self
[src]
Sets the contained items of the table.
The order of the items will be preserved even when the table is sorted.
Chainable variant.
fn borrow_item(&mut self, index: usize) -> Option<&T>
[src]
Returns a immmutable reference to the item at the specified index within the underlying storage vector.
fn borrow_item_mut(&mut self, index: usize) -> Option<&mut T>
[src]
Returns a mutable reference to the item at the specified index within the underlying storage vector.
fn borrow_items(&mut self) -> &Vec<T>
[src]
Returns a immmutable reference to the items contained within the table.
fn borrow_items_mut(&mut self) -> &mut Vec<T>
[src]
Returns a mutable reference to the items contained within the table.
Can be used to modify the items in place.
fn item(&self) -> Option<usize>
[src]
Returns the index of the currently selected item within the underlying storage vector.
fn set_selected_item(&mut self, item_index: usize)
[src]
Selects the item at the specified index within the underlying storage vector.
fn selected_item(self, item_index: usize) -> Self
[src]
Selects the item at the specified index within the underlying storage vector.
Chainable variant.
fn insert_item(&mut self, item: T)
[src]
Inserts a new item into the table.
The currently active sort order is preserved and will be applied to the newly inserted item.
fn remove_item(&mut self, item_index: usize) -> Option<T>
[src]
Removes the item at the specified index within the underlying storage vector and returns it.
fn take_items(&mut self) -> Vec<T>
[src]
Removes all items from the underlying storage and returns them.
Trait Implementations
impl<T: TableViewItem<H> + 'static, H: Eq + Hash + Copy + Clone + 'static> View for TableView<T, H>
[src]
fn draw(&self, printer: &Printer)
[src]
Draws the view with the given printer (includes bounds) and focus.
fn layout(&mut self, size: Vec2)
[src]
Called once the size for this view has been decided, Read more
fn take_focus(&mut self, _: Direction) -> bool
[src]
This view is offered focus. Will it take it? Read more
fn on_event(&mut self, event: Event) -> EventResult
[src]
Called when a key was pressed. Read more
fn required_size(&mut self, constraint: XY<usize>) -> XY<usize>
[src]
Returns the minimum size the view requires with the given restrictions. Read more
fn needs_relayout(&self) -> bool
[src]
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>)
[src]
Runs a closure on the view identified by the given selector. Read more
fn focus_view(&mut self, &Selector) -> Result<(), ()>
[src]
Moves the focus to the view identified by the given selector. Read more