Skip to main content

Column

Struct Column 

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

Source

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

Source

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

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.

Source

pub fn sortable(self, compare: impl Fn(&T, &T) -> Ordering + 'static) -> Self

Enable sorting with a comparator over the underlying records.

Source

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>
where Box<dyn Fn(&T) -> String>: Freeze, Option<Box<dyn Fn(&T, &T) -> Ordering>>: Freeze, Option<Box<dyn Fn(&T) -> Style>>: Freeze, Option<BarChart<T>>: Freeze,

§

impl<T> Unpin for Column<T>
where Box<dyn Fn(&T) -> String>: Unpin, Option<Box<dyn Fn(&T, &T) -> Ordering>>: Unpin, Option<Box<dyn Fn(&T) -> Style>>: Unpin, Option<BarChart<T>>: Unpin,

§

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