Skip to main content

TablePresentation

Struct TablePresentation 

Source
pub struct TablePresentation { /* private fields */ }
Expand description

Presentation policy used to compose a Table into a View.

The policy owns the border, the edge toggles, cell padding, the total width constraint, and the per-cell styling strategy. It borrows the data and performs no terminal output.

Implementations§

Source§

impl TablePresentation

Source

pub fn new( header_style: BlockStyle, cell_style: BlockStyle, border_style: TextStyle, ) -> Self

Creates a table presentation with a single-line border and one cell of padding.

Source

pub const fn get_style(&self, role: TableRole) -> &BlockStyle

Returns the block style assigned to one logical table cell role.

Source

pub const fn get_border_style(&self) -> &TextStyle

Returns the style drawn on the table’s rules.

Source

pub fn style(self, role: TableRole, style: BlockStyle) -> Self

Replaces the block style assigned to one logical table cell role.

Source

pub fn header_style(self, style: BlockStyle) -> Self

Replaces the header-cell style.

Source

pub fn cell_style(self, style: BlockStyle) -> Self

Replaces the body-cell style.

Source

pub fn header_styles<I>(self, styles: I) -> Self
where I: IntoIterator<Item = Option<BlockStyle>>,

Replaces positional complete header-cell styles.

A missing or None entry keeps the table header style. Extra entries do not create columns.

Source

pub fn column_styles<I>(self, styles: I) -> Self
where I: IntoIterator<Item = Option<BlockStyle>>,

Replaces positional complete body-column styles.

A missing or None entry keeps the table cell style. Extra entries do not create columns.

Source

pub fn border_style(self, style: TextStyle) -> Self

Replaces the style drawn on the table’s rules.

Source

pub const fn border(self, border: TableBorder) -> Self

Replaces the table’s line model and glyph repertoire.

Source

pub const fn border_top(self, enabled: bool) -> Self

Draws or omits the top edge.

Source

pub const fn border_bottom(self, enabled: bool) -> Self

Draws or omits the bottom edge.

Source

pub const fn border_left(self, enabled: bool) -> Self

Draws or omits the left edge.

Source

pub const fn border_right(self, enabled: bool) -> Self

Draws or omits the right edge.

Source

pub const fn border_header(self, enabled: bool) -> Self

Draws or omits the rule between the header and the first body row.

Source

pub const fn border_column(self, enabled: bool) -> Self

Draws or omits the rules between columns.

A connected table uses its LineGlyphs::vertical glyph for outer and inner vertical rules. A straight-rule preset supplies its own vertical marker.

Source

pub const fn border_row(self, enabled: bool) -> Self

Draws or omits the rules between body rows.

Source

pub const fn padding(self, padding: u16) -> Self

Sets the horizontal padding applied to both sides of every cell.

Source

pub const fn width(self, width: u16) -> Self

States the total width the table takes, in terminal cells.

A total width is a statement about the box the table sits in, so compose puts its Canvas in a borderless block of exactly this width. The bound table frame then gives every column an equal share, which is why a width much wider than the content can leave a short column wider than a long one, and a width narrower than the content narrows every column rather than only the widest.

Nothing is measured while composing. The bound frame decides columns and the lines between them together when the view resolves, so they cannot disagree, and a column floors at the narrowest grapheme it must show: a table given less than its floor is as wide as that floor, wrapping its content rather than dropping it.

Without a stated width the table is as wide as its content, and an area narrower than that shrinks it by the same rule. This states the width for a caller who wants one regardless of the area.

The width is a u16 for the same reason BlockStyle::width is: a terminal dimension, not an arbitrary count.

Source

pub fn compose<T>(&self, table: &Table<T>) -> View
where T: TableRow,

Composes table data into an intrinsically sized, renderer-neutral Canvas.

Composition binds an owned snapshot without receiving an available area. During resolution, the bound item first supplies width and width-dependent height requirements, then records cell and rule commands after the final Canvas size is known.

Source

pub fn compose_with<T>( &self, table: &Table<T>, rows: &TableRowPresentation<'_, T>, ) -> View

Composes typed table data with custom row formatting and cell styles.

Trait Implementations§

Source§

impl Clone for TablePresentation

Source§

fn clone(&self) -> TablePresentation

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TablePresentation

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for TablePresentation

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.