Skip to main content

Table

Struct Table 

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

A widget that displays a table with configurable column idths, optional header and scrollable row content. A widget that displays a table with configurable column widths, optional header and scrollable row content.

Each cell is represented by an Element, so cell can be any widget. Layout of the cells is controlled by per-column widths and optional spacing between columns.

§Example

let rows = get_people();
let widths = [Unit::Fill(3), Unit::Fill(1), Unit::Fill(3)];
let state = Rc::new(RefCell::new(TableState::new(0).selected(1)));

let table = Table::new(rows, widths, state)
    .header(vec!["Name", "Age", "Email"])
    .header_separator(BorderType::Double)
    .column_spacing(2);

let mut term = Term::default();
term.render(table)?;

Implementations§

Source§

impl Table

Source

pub fn new<R, W>(rows: R, widths: W, state: Rc<RefCell<TableState>>) -> Self
where R: IntoIterator, R::Item: Into<Row>, W: IntoIterator, W::Item: Into<Unit>,

Creates new Table with given rows and columns widths

Source

pub fn header<H>(self, header: H) -> Self
where H: Into<Row>,

Adds given header to the Table

Source

pub fn header_separator(self, separator: BorderType) -> Self

Sets the header separator of the Table

Source

pub fn rows<R, C>(self, rows: R) -> Self
where R: IntoIterator, R::Item: IntoIterator<Item = C>, C: Into<Element>,

Sets Table rows to the given value

Source

pub fn selected_row_style<S>(self, style: S) -> Self
where S: Into<Style>,

Sets the selected row style

Source

pub fn selected_column_style<S>(self, style: S) -> Self
where S: Into<Style>,

Sets the selected column style

Source

pub fn selected_cell_style<S>(self, style: S) -> Self
where S: Into<Style>,

Sets the selected cell style

Source

pub fn widths<W>(self, widths: W) -> Self
where W: IntoIterator, W::Item: Into<Unit>,

Sets columns widths of the Table

Source

pub fn column_spacing(self, space: usize) -> Self

Sets the column spacing of the Table

Source

pub fn auto_scroll(self) -> Self

Enables automatic scrolling to ensure the selected item is visible.

Source

pub fn force_scrollbar(self) -> Self

Forces scrollbar to be always visible. By default the scrollbar hides when the content doesn’t overflow.

Trait Implementations§

Source§

impl Debug for Table

Source§

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

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

impl From<Table> for Box<dyn Widget>

Source§

fn from(value: Table) -> Self

Converts to this type from the input type.
Source§

impl From<Table> for Element

Source§

fn from(value: Table) -> Self

Converts to this type from the input type.
Source§

impl Widget for Table

Source§

fn render(&self, buffer: &mut Buffer, rect: Rect, cache: &mut Cache)

Renders the widget into the given Buffer within the provided Rect bounds.
Source§

fn height(&self, size: &Vec2) -> usize

Returns the height of the Widget based on the width of the given size.
Source§

fn width(&self, size: &Vec2) -> usize

Returns the width of the Widget based on the height of the given size.
Source§

fn children(&self) -> Vec<&Element>

Gets widget’s children

Auto Trait Implementations§

§

impl Freeze for Table

§

impl !RefUnwindSafe for Table

§

impl !Send for Table

§

impl !Sync for Table

§

impl Unpin for Table

§

impl !UnwindSafe for Table

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> Scale<T> for T

Source§

fn scale(self) -> T

Scale this type to the given other type.
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.