Skip to main content

Column

Struct Column 

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

Source

pub fn text( id: &str, title: &str, value: impl Fn(&T) -> String + 'static, ) -> Self

A text column.

Source

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.

Source

pub fn check( id: &str, title: &str, value: impl Fn(&T) -> bool + 'static, ) -> Self

A checkbox column. Clicking a checkbox emits TableEvent::Toggle; the model doesn’t change the row itself.

Source

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.

Source

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.

Source

pub fn with_time(self) -> Self

Shows a date column’s time too (“Today at 09:41”).

Source

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.

Source

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.

Source

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

Source

pub fn fit(self) -> Self

Sizes the column to its widest content (and its title) whenever the rows change. With many rows, the longest values are measured.

Source

pub fn width(self, width: f64) -> Self

Initial width in points (default 120).

Source

pub fn min_width(self, min_width: f64) -> Self

Smallest width the user can drag the column to.

Source

pub fn decimals(self, decimals: usize) -> Self

Decimal places shown for a number column (default 0).

Source

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) emits TableEvent::Edit; the model doesn’t change the row: apply it with TableModel::update_row. No effect on checkbox columns.

Source

pub fn sortable(self, sortable: bool) -> Self

Whether a header click sorts by this column (default true).

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for Column<T>

§

impl<T> !Send for Column<T>

§

impl<T> !Sync for Column<T>

§

impl<T> !UnwindSafe for Column<T>

§

impl<T> Forget for Column<T>

§

impl<T> Freeze for Column<T>
where Option<Box<dyn Fn(&T) -> Option<CellImage>>>: Freeze, Option<Box<dyn Fn(&T) -> CellStyle>>: Freeze, Box<dyn Fn(&T) -> Value>: Freeze,

§

impl<T> Move for Column<T>

§

impl<T> Unpin for Column<T>
where Option<Box<dyn Fn(&T) -> Option<CellImage>>>: Unpin, Option<Box<dyn Fn(&T) -> CellStyle>>: Unpin, Box<dyn Fn(&T) -> Value>: Unpin,

§

impl<T> UnsafeUnpin for Column<T>

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> AutoreleaseSafe for T
where T: ?Sized,

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