pub struct Column<T> { /* private fields */ }Expand description
A typed column. Sorting compares records, independently of their display text.
Implementations§
Source§impl<T> Column<T>
impl<T> Column<T>
Sourcepub fn new(
title: impl Into<String>,
width: u16,
format: impl Fn(&T) -> String + 'static,
) -> Self
pub fn new( title: impl Into<String>, width: u16, format: impl Fn(&T) -> String + 'static, ) -> Self
Create a column with a width in terminal cells (minimum four).
Sourcepub fn bar_chart(self, max: f64, value: impl Fn(&T) -> f64 + 'static) -> Self
pub fn bar_chart(self, max: f64, value: impl Fn(&T) -> f64 + 'static) -> Self
Render a horizontal bar instead of the formatted text in each data cell.
max is the shared scale: that value fills the column, excluding its
separator. Bars resize with the column and use its normal cell style.
Use Self::cell_style to color bars by record.
Values are clamped to 0..=max. Non-finite values and a non-positive or
non-finite maximum render empty. Eighth-cell blocks represent fractions;
values smaller than one eighth of a cell render empty.
The application chooses the maximum, so filtering and paging do not
silently rescale bars. The formatter remains the text used for search,
copying and full-value details; sorting still uses the comparator.
use ratagrid::Column;
let column = Column::new("Usage", 25, |gb: &f64| format!("{gb:.1} GB"))
.bar_chart(60.0, |gb| *gb)
.sortable(|a, b| a.total_cmp(b));Sourcepub fn cell_style(self, style: impl Fn(&T) -> Style + 'static) -> Self
pub fn cell_style(self, style: impl Fn(&T) -> Style + 'static) -> Self
Style data cells using the underlying record, independently of display text. This patches the base cell style; selection, hover, flashes and the cell cursor apply afterward. The callback runs only for visible cells and should remain inexpensive.
Sourcepub fn sortable(self, compare: impl Fn(&T, &T) -> Ordering + 'static) -> Self
pub fn sortable(self, compare: impl Fn(&T, &T) -> Ordering + 'static) -> Self
Enable sorting with a comparator over the underlying records.
Sourcepub fn sortable_external(self) -> Self
pub fn sortable_external(self) -> Self
Enable source-side sorting in an externally paginated grid, without an unused local comparator. Owned grids treat this column as unsortable.
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> Freeze for Column<T>
impl<T> Unpin for Column<T>
impl<T> UnsafeUnpin for Column<T>where
Box<dyn Fn(&T) -> String>: UnsafeUnpin,
Option<Box<dyn Fn(&T, &T) -> Ordering>>: UnsafeUnpin,
Option<Box<dyn Fn(&T) -> Style>>: UnsafeUnpin,
Option<BarChart<T>>: 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