pub struct Column<T> { /* private fields */ }Expand description
A column: an id (stable, used for sorting and saved state), a title, and how to get the cell value from a row.
Implementations§
Source§impl<T> Column<T>
impl<T> Column<T>
Sourcepub fn text(
id: &str,
title: &str,
value: impl Fn(&T) -> String + 'static,
) -> Self
pub fn text( id: &str, title: &str, value: impl Fn(&T) -> String + 'static, ) -> Self
A text column.
Sourcepub fn number(
id: &str,
title: &str,
value: impl Fn(&T) -> f64 + 'static,
) -> Self
pub fn number( id: &str, title: &str, value: impl Fn(&T) -> f64 + 'static, ) -> Self
A right-aligned number column, sorted numerically. f64::NAN is no
value (a database’s NULL, say): shown as nothing.
Sourcepub fn check(
id: &str,
title: &str,
value: impl Fn(&T) -> bool + 'static,
) -> Self
pub fn check( id: &str, title: &str, value: impl Fn(&T) -> bool + 'static, ) -> Self
A checkbox column. Clicking a checkbox is reported to Table::on_toggle;
the model doesn’t change the row itself.
Sourcepub fn progress(
id: &str,
title: &str,
value: impl Fn(&T) -> f64 + 'static,
) -> Self
pub fn progress( id: &str, title: &str, value: impl Fn(&T) -> f64 + 'static, ) -> Self
A progress bar from 0 to 1 (values outside are clamped). Sorted and copied as the number; VoiceOver reads it as a percentage.
Sourcepub fn date(
id: &str,
title: &str,
value: impl Fn(&T) -> Option<SystemTime> + 'static,
) -> Self
pub fn date( id: &str, title: &str, value: impl Fn(&T) -> Option<SystemTime> + 'static, ) -> Self
A date column: shown in the user’s format and language (“12 Mar
2024”, “Today”, “Yesterday”), sorted by date, oldest first;
None shows nothing and sorts before every date. Copied as shown.
with_time adds the time.
Sourcepub fn short_dates(self) -> Self
pub fn short_dates(self) -> Self
A date column in the short style, numbers only (“9/23/22, 4:26 PM”; “23.09.22, 16:26” in German), not relative: a data grid’s dates, where many must fit (the default is “Sep 23, 2022”, “Today”).
Sourcepub fn none_text(self, text: &str) -> Self
pub fn none_text(self, text: &str) -> Self
What a date column shows for None (default nothing): “Running”
for a timer with no end yet, “Never” for a file never opened. It
still sorts before every date, and is copied as shown.
Sourcepub fn icon(self, image: impl Fn(&T) -> Option<CellImage> + 'static) -> Self
pub fn icon(self, image: impl Fn(&T) -> Option<CellImage> + 'static) -> Self
Shows an image before each cell’s text (a text or number column),
e.g. a file’s icon before its name. None leaves the space empty.
Sourcepub fn icon_action(self, label: &str) -> Self
pub fn icon_action(self, label: &str) -> Self
Makes the icon a button: clicking it reports
Table::on_icon_click (and doesn’t select the row), as the
arrow beside a linked value that opens what it links to. label is
what VoiceOver says for it (“Open the linked row”).
Sourcepub fn style(self, style: impl Fn(&T) -> CellStyle + 'static) -> Self
pub fn style(self, style: impl Fn(&T) -> CellStyle + 'static) -> Self
Styles each cell of a text or number column from its row: a colour,
a background tint, italic or struck-through text. The style is read
when a cell is shown; after changing what it depends on, refresh the
rows (TableModel::update_row).
Sourcepub fn fit(self) -> Self
pub fn fit(self) -> Self
Sizes the column to its widest content (and its title) whenever the rows change. Beyond 2,000 rows, it measures a sample spread through them, so a million rows cost what 2,000 do.
Sourcepub fn width(self, width: f64) -> Self
pub fn width(self, width: f64) -> Self
Initial width in points (default 120). The last column then grows to fill the table’s width, and narrows when the window is narrower than the columns.
Sourcepub fn min_width(self, min_width: f64) -> Self
pub fn min_width(self, min_width: f64) -> Self
Smallest width the user can drag the column to (default 40), and, for the last column, the narrowest it gets in a narrow window.
Sourcepub fn decimals(self, decimals: usize) -> Self
pub fn decimals(self, decimals: usize) -> Self
Decimal places shown for a number column (default 0).
Sourcepub fn editable(self, editable: bool) -> Self
pub fn editable(self, editable: bool) -> Self
Lets the user edit this column’s text or number cells (double-click,
or Return on the selected row’s cell). Finishing an edit (Return, Tab
or a click elsewhere; not Escape) is reported to Table::on_edit; the model doesn’t change the row: apply it with
TableModel::update_row. No effect on checkbox columns.