Skip to main content

Table

Struct Table 

Source
pub struct Table<'a, T, Selection = RowSelection>
where T: Copy,
{ /* private fields */ }
Expand description

Table widget that renders data from an Iterator.

This will do minimal rendering of the visible rows/cells of the table.

ⓘ
Table::default()
        .data(state.table_data.iter())
        .widths([
            Constraint::Length(6),
            Constraint::Length(20),
            Constraint::Length(15),
            Constraint::Length(15),
            Constraint::Length(3),
        ])
        .render_cell(0, |_v, area, buf, ctx| {
            format!("{:>5}", ctx.row).render(area, buf)
        })
        .render_cell(1, |v, area, buf, _ctx| {
            v.text.render(area, buf)
        })
        .render_cell(2, |v, area, buf, _ctx| {
            format!("{:5.2}", v.num1).render(area, buf)
        })
        .render_cell(3, |v, area, buf, _ctx| {
            format!("{:5.2}", v.num2).render(area, buf)
        })
        .render_cell(4, |v, area, buf, _ctx| {
            let cc = if v.check { "\u{2622}" } else { "\u{2623}" };
            cc.render(area, buf);
        })
        .column_spacing(1)
        .header(vec!["Nr", "Text", "Val1", "Val2", "State"])
        .footer(vec!["a", "b", "c", "d", "e"])
        .block(
            Block::bordered()
                .border_type(BorderType::Rounded)
                .title("tabledata-iter (no row-count)"),
        )
        .vscroll(Scroll::new())
        .styles(table(&ctx.theme))
        .render(l0[0], buf, &mut state.table);

Implementations§

Source§

impl<'a, T, Selection> Table<'a, T, Selection>
where T: Copy,

Source

pub fn new() -> Table<'a, T, Selection>
where Selection: Default,

New, empty Table.

Source

pub fn data( self, data: impl IntoIterator<Item = T> + 'a, ) -> Table<'a, T, Selection>

Set the table-data as an iterator over the row-values.

Source

pub fn row_height( self, row_height_fn: impl FnMut(T, &TableContext<'_>) -> u8 + 'a, ) -> Table<'a, T, Selection>

A closure that calculates the row-height for a given row-value.

Source

pub fn render_row( self, render_row_fn: impl FnMut(T, Rect, &mut Buffer, &TableContext<'_>) -> bool + 'a, ) -> Table<'a, T, Selection>

A closure for row-level rendering. The area covers the full row.

Return

Returns true if the individual cells should be rendered too.

Source

pub fn render_cell( self, column: usize, render_cell_fn: impl FnMut(T, Rect, &mut Buffer, &TableContext<'_>) + 'a, ) -> Table<'a, T, Selection>

A closure for rendering a single column.

The area covers the exact column. Extra information is available in the TableContext.

The given Buffer covers the full row so you could render something outside the cells bounds. Cells for a given row are always rendered in ascending order.

Source

pub fn header<I>(self, header: I) -> Table<'a, T, Selection>
where I: IntoIterator, <I as IntoIterator>::Item: Into<Text<'a>>,

Set the table-header.

Source

pub fn footer<I>(self, footer: I) -> Table<'a, T, Selection>
where I: IntoIterator, <I as IntoIterator>::Item: Into<Text<'a>>,

Set the table-footer.

Source

pub fn widths<I>(self, widths: I) -> Table<'a, T, Selection>

Column widths as Constraints.

The constraints work in tandem with Table::layout_width.

Source

pub fn varying_heights(self, varying: bool) -> Table<'a, T, Selection>

If your table uses varying row-heights for each row calculating visible positions and offsets will fail.

If you set this flag the row-height for each row is stored in the state and will be used for positioning and offset.

Source

pub fn flex(self, flex: Flex) -> Table<'a, T, Selection>

Flex for the column layout.

Source

pub fn column_spacing(self, spacing: u16) -> Table<'a, T, Selection>

Spacing between columns.

Source

pub fn layout_width(self, width: LayoutWidth) -> Table<'a, T, Selection>

Set the display width of the table.

Default The width of the rendered area is used.

Source

pub fn block(self, block: Block<'a>) -> Table<'a, T, Selection>

Draws a block around the table widget.

Source

pub fn border_style(self, style: Style) -> Table<'a, T, Selection>

Sets the border-style for the Block, if any.

Source

pub fn title_style(self, style: Style) -> Table<'a, T, Selection>

Sets the title-style for the Block, if any.

Source

pub fn scroll(self, scroll: Scroll<'a>) -> Table<'a, T, Selection>

Scrollbars

Source

pub fn hscroll(self, scroll: Scroll<'a>) -> Table<'a, T, Selection>

Scrollbars

Source

pub fn vscroll(self, scroll: Scroll<'a>) -> Table<'a, T, Selection>

Scrollbars

Source

pub fn styles(self, styles: TableStyle) -> Table<'a, T, Selection>

Set all styles as a bundle.

Source

pub fn style(self, style: Style) -> Table<'a, T, Selection>

Base style for the table.

Source

pub fn header_style(self, style: Option<Style>) -> Table<'a, T, Selection>

Base style for the table.

Source

pub fn footer_style(self, style: Option<Style>) -> Table<'a, T, Selection>

Base style for the table.

Source

pub fn select_row_style( self, select_style: Option<Style>, ) -> Table<'a, T, Selection>

Style for a selected row. The chosen selection must support row-selection for this to take effect.

Source

pub fn show_row_focus(self, show: bool) -> Table<'a, T, Selection>

Add the focus-style to the row-style if the table is focused.

Source

pub fn select_column_style( self, select_style: Option<Style>, ) -> Table<'a, T, Selection>

Style for a selected column. The chosen selection must support column-selection for this to take effect.

Source

pub fn show_column_focus(self, show: bool) -> Table<'a, T, Selection>

Add the focus-style to the column-style if the table is focused.

Source

pub fn select_cell_style( self, select_style: Option<Style>, ) -> Table<'a, T, Selection>

Style for a selected cell. The chosen selection must support cell-selection for this to take effect.

Source

pub fn show_cell_focus(self, show: bool) -> Table<'a, T, Selection>

Add the focus-style to the cell-style if the table is focused.

Source

pub fn select_header_style( self, select_style: Option<Style>, ) -> Table<'a, T, Selection>

Style for a selected header cell. The chosen selection must support column-selection for this to take effect.

Source

pub fn show_header_focus(self, show: bool) -> Table<'a, T, Selection>

Add the focus-style to the header-style if the table is focused.

Style for a selected footer cell. The chosen selection must support column-selection for this to take effect.

Add the footer-style to the table-style if the table is focused.

Source

pub fn focus_style(self, focus_style: Option<Style>) -> Table<'a, T, Selection>

This style will be patched onto the selection to indicate that the widget has the input focus.

The selection must support some kind of selection for this to be effective.

Source

pub fn width(&self) -> u16

Inherent width.

Source

pub fn height(&self) -> u16

Inherent height.

Trait Implementations§

Source§

impl<'a, T, Selection> Default for Table<'a, T, Selection>
where T: Copy,

Source§

fn default() -> Table<'a, T, Selection>

Returns the “default value” for a type. Read more
Source§

impl<'a, T, Selection> StatefulWidget for Table<'a, T, Selection>
where T: Copy + 'a, Selection: TableSelection + Default,

Source§

type State = TableState<Selection>

State associated with the stateful widget. Read more
Source§

fn render( self, area: Rect, buf: &mut Buffer, state: &mut <Table<'a, T, Selection> as StatefulWidget>::State, )

Draws the current state of the widget in the given buffer. That is the only method required to implement a custom stateful widget.

Auto Trait Implementations§

§

impl<'a, T, Selection = RowSelection> !RefUnwindSafe for Table<'a, T, Selection>

§

impl<'a, T, Selection = RowSelection> !Send for Table<'a, T, Selection>

§

impl<'a, T, Selection = RowSelection> !Sync for Table<'a, T, Selection>

§

impl<'a, T, Selection = RowSelection> !UnwindSafe for Table<'a, T, Selection>

§

impl<'a, T, Selection> Forget for Table<'a, T, Selection>

§

impl<'a, T, Selection> Freeze for Table<'a, T, Selection>
where Option<Box<dyn Iterator<Item = T> + 'a>>: Freeze, Option<Box<dyn FnMut(T, &TableContext<'_>) -> u8 + 'a>>: Freeze, Option<Box<dyn FnMut(T, Rect, &mut Buffer, &TableContext<'_>) -> bool + 'a>>: Freeze, Vec<Option<Box<dyn FnMut(T, Rect, &mut Buffer, &TableContext<'_>) + 'a>>>: Freeze, PhantomData<Selection>: Freeze,

§

impl<'a, T, Selection> Move for Table<'a, T, Selection>

§

impl<'a, T, Selection> Unpin for Table<'a, T, Selection>
where Option<Box<dyn Iterator<Item = T> + 'a>>: Unpin, Option<Box<dyn FnMut(T, &TableContext<'_>) -> u8 + 'a>>: Unpin, Option<Box<dyn FnMut(T, Rect, &mut Buffer, &TableContext<'_>) -> bool + 'a>>: Unpin, Vec<Option<Box<dyn FnMut(T, Rect, &mut Buffer, &TableContext<'_>) + 'a>>>: Unpin, PhantomData<Selection>: Unpin,

§

impl<'a, T, Selection> UnsafeUnpin for Table<'a, T, Selection>
where Option<Box<dyn Iterator<Item = T> + 'a>>: UnsafeUnpin, Option<Box<dyn FnMut(T, &TableContext<'_>) -> u8 + 'a>>: UnsafeUnpin, Option<Box<dyn FnMut(T, Rect, &mut Buffer, &TableContext<'_>) -> bool + 'a>>: UnsafeUnpin, Vec<Option<Box<dyn FnMut(T, Rect, &mut Buffer, &TableContext<'_>) + 'a>>>: UnsafeUnpin, PhantomData<Selection>: 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.