Skip to main content

Table

Struct Table 

Source
pub struct Table<Msg> { /* private fields */ }
Expand description

Rows of cells under a header row. Only the rows on screen are drawn, so a table stays fast with any number of rows; pass the rows as an Arc<[TableRow]> kept in your state to avoid copying them every frame.

The header sits on a raised surface with faint titles. Columns are separated by space; their widths follow ColumnWidth and Column::min, and when the minimums do not fit, the columns scroll sideways: arrows at the ends of the header show which side hides columns. The application owns the selection, the checked rows and the sort order and is told about changes through messages. A hovered or selected row raises its surface and shows the pillar; only its first cell slides one cell right. The check mark of a multi-select table never moves.

Keys while focused: ↑/↓ or k/j, PgUp/PgDn, Home/End move; Enter activates; Space toggles in multi-select tables and activates otherwise; ←/→ scroll columns that overflow; with Table::on_sort, s sorts by the next sortable column and shift+s reverses the order.

The mouse does the same: a click on a row selects and activates it, a click on its check mark (or the cell after it) only toggles, a click on a sortable title sorts by it and a second click reverses it, and a click on a header arrow scrolls the columns one step.

Style keys: rows use list-item (hover, selected, focus, pressed) and list-item.faint like List; table-header (bg, fg) with hover over a sortable title and selected on the sorted one; table-sort for the sort arrow; table-scroll (fg, bg) with hover for the header arrows; list-header for the empty text; scrollbar.

Implementations§

Source§

impl<Msg: 'static> Table<Msg>

Source

pub fn new( columns: impl IntoIterator<Item = Column>, rows: impl Into<Arc<[TableRow]>>, ) -> Self

A table with columns showing rows.

Source

pub fn selected(self, index: Option<usize>) -> Self

The selected row index.

Source

pub fn checked(self, checked: Vec<bool>) -> Self

Turns on multiple selection; checked[i] tells whether row i is checked.

Source

pub fn sort(self, column: usize, direction: SortDirection) -> Self

Shows the sort arrow on column pointing in direction. The rows must already be in that order; the table does not reorder them.

Source

pub fn empty_text(self, text: impl Into<String>) -> Self

Text shown under the header when there are no rows.

Source

pub fn on_select(self, message: impl Fn(usize) -> Msg + 'static) -> Self

Message for moving the selection to a row.

Source

pub fn on_activate(self, message: impl Fn(usize) -> Msg + 'static) -> Self

Message for opening a row (Enter, click).

Source

pub fn on_toggle(self, message: impl Fn(usize) -> Msg + 'static) -> Self

Message for checking or unchecking a row of a multi-select table (Space, click on the mark).

Source

pub fn on_sort( self, message: impl Fn(usize, SortDirection) -> Msg + 'static, ) -> Self

Message asking to sort by a column in a direction; turns on sorting by clicking titles of Column::sortable columns and with s / shift+s.

Source

pub fn context_menu( self, items: impl Fn(usize) -> Vec<ContextItem<Msg>> + 'static, ) -> Self

Gives every row a context menu: items(index) builds the entries for the row of that index, and the menu acts on the row it was opened on rather than on the selected one.

A right press on a row opens the menu at the pointer; the menu key or Shift+F10 opens the menu of the selected row below it, scrolling it into view first. The row the menu belongs to stays raised while it is open, so it is clear what the entries act on. A right press on a row that is not checked makes it the selection first, so a menu never acts on rows the person did not mean.

Trait Implementations§

Source§

impl<Msg: 'static> Widget<Msg> for Table<Msg>

Source§

fn measure(&self, _cx: &mut MeasureCx<'_>, available: Size) -> Size

The size the widget wants when it may use up to available.
Source§

fn paint(&self, cx: &mut PaintCx<'_>, area: Rect)

Draws the widget into area.
Source§

fn paint_overlay(&self, cx: &mut PaintCx<'_>, anchor: Rect)

Draws the widget’s overlay after the whole view was painted, when it asked for one with PaintCx::request_overlay. anchor is the area the widget was painted in.
Source§

fn event(&self, cx: &mut EventCx<'_, Msg>, event: &Event) -> bool

Handles input. Returns true when the event was used; unused key and scroll events bubble to the parent widget.
Source§

fn focusable(&self) -> bool

Whether the widget can take keyboard focus.
Source§

fn children(&self) -> &[Node<Msg>]

Child nodes, for widgets that contain other widgets.
Source§

fn children_mut(&mut self) -> &mut [Node<Msg>]

Mutable child nodes, used to assign ids.

Auto Trait Implementations§

§

impl<Msg> !RefUnwindSafe for Table<Msg>

§

impl<Msg> !Send for Table<Msg>

§

impl<Msg> !Sync for Table<Msg>

§

impl<Msg> !UnwindSafe for Table<Msg>

§

impl<Msg> Freeze for Table<Msg>
where Option<Box<dyn Fn(usize) -> Msg>>: Freeze, Option<Box<dyn Fn(usize, SortDirection) -> Msg>>: Freeze, Option<Box<dyn Fn(usize) -> Vec<ContextItem<Msg>>>>: Freeze,

§

impl<Msg> Unpin for Table<Msg>
where Option<Box<dyn Fn(usize) -> Msg>>: Unpin, Option<Box<dyn Fn(usize, SortDirection) -> Msg>>: Unpin, Option<Box<dyn Fn(usize) -> Vec<ContextItem<Msg>>>>: Unpin,

§

impl<Msg> UnsafeUnpin for Table<Msg>
where Option<Box<dyn Fn(usize) -> Msg>>: UnsafeUnpin, Option<Box<dyn Fn(usize, SortDirection) -> Msg>>: UnsafeUnpin, Option<Box<dyn Fn(usize) -> Vec<ContextItem<Msg>>>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.