pub struct TableView<T, H> { /* fields omitted */ }
Expand description

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

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.)

Creates a new empty TableView without any columns.

A TableView should be accompanied by a enum of type H representing the table columns.

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.

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.

Remove a column.

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.

Sets the initially active column of the table.

Sets the initially active column of the table.

Sorts the table using the specified table column and the passed order.

Sorts the table using the currently active column and its ordering.

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.

Disables this view.

A disabled view cannot be selected.

Re-enables this view.

Enable or disable this view.

Returns true if this view is enabled.

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| {

});

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| {

});

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| {

});

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| {

});

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| {

});

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| {

});

Removes all items from this view.

Returns the number of items in this table.

Returns true if this table has no items.

Returns the index of the currently selected table row.

Selects the row at the specified index.

Selects the row at the specified index.

Chainable variant.

Sets the contained items of the table.

The currently active sort order is preserved and will be applied to all items.

Sets the contained items of the table.

The order of the items will be preserved even when the table is sorted.

Chainable variant.

Returns a immmutable reference to the item at the specified index within the underlying storage vector.

Returns a mutable reference to the item at the specified index within the underlying storage vector.

Returns a immmutable reference to the items contained within the table.

Returns a mutable reference to the items contained within the table.

Can be used to modify the items in place.

Returns the index of the currently selected item within the underlying storage vector.

Selects the item at the specified index within the underlying storage vector.

Selects the item at the specified index within the underlying storage vector.

Chainable variant.

Inserts a new item into the table.

The currently active sort order is preserved and will be applied to the newly inserted item.

If no sort option is set, the item will be added to the end of the table.

Inserts a new item into the table.

The currently active sort order is preserved and will be applied to the newly inserted item.

If no sort option is set, the item will be inserted at the given index.

Panics

If index > self.len().

Removes the item at the specified index within the underlying storage vector and returns it.

Removes all items from the underlying storage and returns them.

Trait Implementations

Creates a new empty TableView without any columns.

See TableView::new().

Returns a mutable access to the scroll core.

Returns an immutable access to the scroll core.

Draws the view with the given printer (includes bounds) and focus. Read more

Called once the size for this view has been decided. Read more

Attempt to give this view the focus. Read more

Called when an event is received (key press, mouse event, …). Read more

What part of the view is important and should be visible? Read more

Should return true if the view content changed since the last call to layout(). Read more

Returns the minimum size the view requires with the given restrictions. Read more

Runs a closure on the view identified by the given selector. Read more

Moves the focus to the view identified by the given selector. Read more

Returns the type of this view. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Downcast self to a Any.

Downcast self to a mutable Any.

Returns a boxed any from a boxed self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Runs a callback on all views identified by sel. Read more

Runs a callback on the view identified by sel. Read more

Convenient method to use call_on with a view::Selector::Name.

Convenient method to find a view wrapped in an NamedView.

Performs the conversion.

Performs the conversion.

Returns a Box<View>.

Wraps this view into an NamedView with the given id. Read more

Wraps self in a ResizedView with the given size constraints.

Wraps self into a fixed-size ResizedView.

Wraps self into a fixed-width ResizedView.

Wraps self into a fixed-width ResizedView.

Wraps self into a full-screen ResizedView.

Wraps self into a full-width ResizedView.

Wraps self into a full-height ResizedView.

Wraps self into a limited-size ResizedView.

Wraps self into a limited-width ResizedView.

Wraps self into a limited-height ResizedView.

Wraps self into a ResizedView at least sized size.

Wraps self in a ResizedView at least min_width wide.

Wraps self in a ResizedView at least min_height tall.

Wraps self in a ScrollView.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Calls the given closure and return the result. Read more

Calls the given closure on self.

Calls the given closure on self.

Calls the given closure if condition == true.