Struct cursive_table_view::TableView [−][src]
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);
Implementations
impl<T, H> TableView<T, H> where
T: TableViewItem<H> + PartialEq,
H: Eq + Hash + Copy + Clone + 'static,
[src]
T: TableViewItem<H> + PartialEq,
H: Eq + Hash + Copy + Clone + 'static,
pub fn set_items_stable(&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.
Compared to set_items
, the current selection will be preserved.
(But this is only available for T: PartialEq
.)
impl<T, H> TableView<T, H> where
T: TableViewItem<H>,
H: Eq + Hash + Copy + Clone + 'static,
[src]
T: TableViewItem<H>,
H: Eq + Hash + Copy + Clone + 'static,
pub 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.
pub 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
.
pub fn add_column<S: Into<String>, C: FnOnce(TableColumn<H>) -> TableColumn<H>>(
&mut self,
column: H,
title: S,
callback: C
)
[src]
&mut self,
column: H,
title: S,
callback: C
)
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
.
pub fn remove_column(&mut self, i: usize)
[src]
Remove a column.
pub fn insert_column<S: Into<String>, C: FnOnce(TableColumn<H>) -> TableColumn<H>>(
&mut self,
i: usize,
column: H,
title: S,
callback: C
)
[src]
&mut self,
i: usize,
column: H,
title: S,
callback: C
)
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
.
pub fn default_column(self, column: H) -> Self
[src]
Sets the initially active column of the table.
pub fn set_default_column(&mut self, column: H)
[src]
Sets the initially active column of the table.
pub fn sort_by(&mut self, column: H, order: Ordering)
[src]
Sorts the table using the specified table column
and the passed
order
.
pub fn sort(&mut self)
[src]
Sorts the table using the currently active column and its ordering.
pub 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.
pub fn disable(&mut self)
[src]
Disables this view.
A disabled view cannot be selected.
pub fn enable(&mut self)
[src]
Re-enables this view.
pub fn set_enabled(&mut self, enabled: bool)
[src]
Enable or disable this view.
pub fn is_enabled(&self) -> bool
[src]
Returns true
if this view is enabled.
pub 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| { });
pub 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| { });
pub 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| { });
pub 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| { });
pub 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| { });
pub 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| { });
pub fn clear(&mut self)
[src]
Removes all items from this view.
pub fn len(&self) -> usize
[src]
Returns the number of items in this table.
pub fn is_empty(&self) -> bool
[src]
Returns true
if this table has no items.
pub fn row(&self) -> Option<usize>
[src]
Returns the index of the currently selected table row.
pub fn set_selected_row(&mut self, row_index: usize)
[src]
Selects the row at the specified index.
pub fn selected_row(self, row_index: usize) -> Self
[src]
Selects the row at the specified index.
Chainable variant.
pub 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.
pub 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.
pub fn borrow_item(&self, index: usize) -> Option<&T>
[src]
Returns a immmutable reference to the item at the specified index within the underlying storage vector.
pub 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.
pub fn borrow_items(&mut self) -> &[T]
[src]
Returns a immmutable reference to the items contained within the table.
pub fn borrow_items_mut(&mut self) -> &mut [T]
[src]
Returns a mutable reference to the items contained within the table.
Can be used to modify the items in place.
pub fn item(&self) -> Option<usize>
[src]
Returns the index of the currently selected item within the underlying storage vector.
pub fn set_selected_item(&mut self, item_index: usize)
[src]
Selects the item at the specified index within the underlying storage vector.
pub fn selected_item(self, item_index: usize) -> Self
[src]
Selects the item at the specified index within the underlying storage vector.
Chainable variant.
pub 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.
pub 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.
pub fn take_items(&mut self) -> Vec<T>
[src]
Removes all items from the underlying storage and returns them.
Trait Implementations
impl<T, H> Default for TableView<T, H> where
T: TableViewItem<H> + PartialEq,
H: Eq + Hash + Copy + Clone + 'static,
[src]
T: TableViewItem<H> + PartialEq,
H: Eq + Hash + Copy + Clone + 'static,
fn default() -> Self
[src]
Creates a new empty TableView
without any columns.
See TableView::new()
.
impl<T, H> Scroller for TableView<T, H>
[src]
fn get_scroller_mut(&mut self) -> &mut Core
[src]
fn get_scroller(&self) -> &Core
[src]
impl<T, H> View for TableView<T, H> where
T: TableViewItem<H> + 'static,
H: Eq + Hash + Copy + Clone + 'static,
[src]
T: TableViewItem<H> + 'static,
H: Eq + Hash + Copy + Clone + 'static,
fn draw(&self, printer: &Printer<'_, '_>)
[src]
fn layout(&mut self, size: Vec2)
[src]
fn take_focus(&mut self, _: Direction) -> bool
[src]
fn on_event(&mut self, event: Event) -> EventResult
[src]
fn important_area(&self, size: Vec2) -> Rect
[src]
pub fn needs_relayout(&self) -> bool
[src]
pub fn required_size(&mut self, constraint: XY<usize>) -> XY<usize>
[src]
pub fn call_on_any(
&mut self,
&Selector<'_>,
&'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
[src]
&mut self,
&Selector<'_>,
&'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
pub fn focus_view(&mut self, &Selector<'_>) -> Result<(), ViewNotFound>
[src]
pub fn type_name(&self) -> &'static str
[src]
Auto Trait Implementations
impl<T, H> !RefUnwindSafe for TableView<T, H>
impl<T, H> !Send for TableView<T, H>
impl<T, H> !Sync for TableView<T, H>
impl<T, H> Unpin for TableView<T, H> where
H: Unpin,
T: Unpin,
H: Unpin,
T: Unpin,
impl<T, H> !UnwindSafe for TableView<T, H>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> AnyView for T where
T: View,
[src]
T: View,
pub fn as_any(&self) -> &(dyn Any + 'static)
[src]
Downcast self to a Any
.
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
[src]
Downcast self to a mutable Any
.
pub fn as_boxed_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Erased for T
impl<T> Finder for T where
T: View,
[src]
T: View,
pub fn call_on_all<V, F>(&mut self, sel: &Selector<'_>, callback: F) where
F: FnMut(&mut V),
V: View,
[src]
F: FnMut(&mut V),
V: View,
pub fn call_on<V, F, R>(&mut self, sel: &Selector<'_>, callback: F) -> Option<R> where
F: FnOnce(&mut V) -> R,
V: View,
[src]
F: FnOnce(&mut V) -> R,
V: View,
pub fn call_on_name<V, F, R>(&mut self, name: &str, callback: F) -> Option<R> where
F: FnOnce(&mut V) -> R,
V: View,
[src]
F: FnOnce(&mut V) -> R,
V: View,
pub fn call_on_id<V, F, R>(&mut self, id: &str, callback: F) -> Option<R> where
F: FnOnce(&mut V) -> R,
V: View,
[src]
F: FnOnce(&mut V) -> R,
V: View,
pub fn find_name<V>(
&mut self,
name: &str
) -> Option<OwningHandle<OwningRef<Rc<RefCell<V>>, RefCell<V>>, RefMut<'static, V>>> where
V: View,
[src]
&mut self,
name: &str
) -> Option<OwningHandle<OwningRef<Rc<RefCell<V>>, RefCell<V>>, RefMut<'static, V>>> where
V: View,
pub fn find_id<V>(
&mut self,
id: &str
) -> Option<OwningHandle<OwningRef<Rc<RefCell<V>>, RefCell<V>>, RefMut<'static, V>>> where
V: View,
[src]
&mut self,
id: &str
) -> Option<OwningHandle<OwningRef<Rc<RefCell<V>>, RefCell<V>>, RefMut<'static, V>>> where
V: View,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> IntoBoxedView for T where
T: View,
[src]
T: View,
pub fn into_boxed_view(self) -> Box<dyn View + 'static, Global>
[src]
impl<T> Nameable for T where
T: View,
[src]
T: View,
pub fn with_name<S>(self, name: S) -> NamedView<Self> where
S: Into<String>,
[src]
S: Into<String>,
pub fn with_id<S>(self, id: S) -> NamedView<Self> where
S: Into<String>,
[src]
S: Into<String>,
impl<T> Resizable for T where
T: View,
[src]
T: View,
pub fn boxed(
self,
width: SizeConstraint,
height: SizeConstraint
) -> ResizedView<Self>
[src]
self,
width: SizeConstraint,
height: SizeConstraint
) -> ResizedView<Self>
pub fn resized(
self,
width: SizeConstraint,
height: SizeConstraint
) -> ResizedView<Self>
[src]
self,
width: SizeConstraint,
height: SizeConstraint
) -> ResizedView<Self>
pub fn fixed_size<S>(self, size: S) -> ResizedView<Self> where
S: Into<XY<usize>>,
[src]
S: Into<XY<usize>>,
pub fn fixed_width(self, width: usize) -> ResizedView<Self>
[src]
pub fn fixed_height(self, height: usize) -> ResizedView<Self>
[src]
pub fn full_screen(self) -> ResizedView<Self>
[src]
pub fn full_width(self) -> ResizedView<Self>
[src]
pub fn full_height(self) -> ResizedView<Self>
[src]
pub fn max_size<S>(self, size: S) -> ResizedView<Self> where
S: Into<XY<usize>>,
[src]
S: Into<XY<usize>>,
pub fn max_width(self, max_width: usize) -> ResizedView<Self>
[src]
pub fn max_height(self, max_height: usize) -> ResizedView<Self>
[src]
pub fn min_size<S>(self, size: S) -> ResizedView<Self> where
S: Into<XY<usize>>,
[src]
S: Into<XY<usize>>,
pub fn min_width(self, min_width: usize) -> ResizedView<Self>
[src]
pub fn min_height(self, min_height: usize) -> ResizedView<Self>
[src]
impl<T> Scrollable for T where
T: View,
[src]
T: View,
pub fn scrollable(self) -> ScrollView<Self>
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> With for T
[src]
pub fn wrap_with<U, F>(self, f: F) -> U where
F: FnOnce(Self) -> U,
[src]
F: FnOnce(Self) -> U,
pub fn with<F>(self, f: F) -> Self where
F: FnOnce(&mut Self),
[src]
F: FnOnce(&mut Self),
pub fn try_with<E, F>(self, f: F) -> Result<Self, E> where
F: FnOnce(&mut Self) -> Result<(), E>,
[src]
F: FnOnce(&mut Self) -> Result<(), E>,
pub fn with_if<F>(self, condition: bool, f: F) -> Self where
F: FnOnce(&mut Self),
[src]
F: FnOnce(&mut Self),