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>
impl<Msg: 'static> Table<Msg>
Sourcepub fn new(
columns: impl IntoIterator<Item = Column>,
rows: impl Into<Arc<[TableRow]>>,
) -> Self
pub fn new( columns: impl IntoIterator<Item = Column>, rows: impl Into<Arc<[TableRow]>>, ) -> Self
A table with columns showing rows.
Sourcepub fn checked(self, checked: Vec<bool>) -> Self
pub fn checked(self, checked: Vec<bool>) -> Self
Turns on multiple selection; checked[i] tells whether row i is checked.
Sourcepub fn sort(self, column: usize, direction: SortDirection) -> Self
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.
Sourcepub fn empty_text(self, text: impl Into<String>) -> Self
pub fn empty_text(self, text: impl Into<String>) -> Self
Text shown under the header when there are no rows.
Sourcepub fn on_select(self, message: impl Fn(usize) -> Msg + 'static) -> Self
pub fn on_select(self, message: impl Fn(usize) -> Msg + 'static) -> Self
Message for moving the selection to a row.
Sourcepub fn on_activate(self, message: impl Fn(usize) -> Msg + 'static) -> Self
pub fn on_activate(self, message: impl Fn(usize) -> Msg + 'static) -> Self
Message for opening a row (Enter, click).
Sourcepub fn on_toggle(self, message: impl Fn(usize) -> Msg + 'static) -> Self
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).
Sourcepub fn on_sort(
self,
message: impl Fn(usize, SortDirection) -> Msg + 'static,
) -> Self
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.
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>
impl<Msg: 'static> Widget<Msg> for Table<Msg>
Source§fn measure(&self, _cx: &mut MeasureCx<'_>, available: Size) -> Size
fn measure(&self, _cx: &mut MeasureCx<'_>, available: Size) -> Size
available.Source§fn paint_overlay(&self, cx: &mut PaintCx<'_>, anchor: Rect)
fn paint_overlay(&self, cx: &mut PaintCx<'_>, anchor: Rect)
PaintCx::request_overlay. anchor is the area the widget was painted in.Source§fn event(&self, cx: &mut EventCx<'_, Msg>, event: &Event) -> bool
fn event(&self, cx: &mut EventCx<'_, Msg>, event: &Event) -> bool
true when the event was used; unused key and scroll events
bubble to the parent widget.Source§fn children_mut(&mut self) -> &mut [Node<Msg>]
fn children_mut(&mut self) -> &mut [Node<Msg>]
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>
impl<Msg> Unpin for Table<Msg>
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> 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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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