Struct rat_widget::table::RTable
source · pub struct RTable<'a, Selection> { /* private fields */ }Implementations§
source§impl<'a, Selection> RTable<'a, Selection>
impl<'a, Selection> RTable<'a, Selection>
sourcepub fn new_ratatui<R, C>(rows: R, widths: C) -> Selfwhere
R: IntoIterator,
R::Item: Into<Row<'a>>,
C: IntoIterator,
C::Item: Into<Constraint>,
Selection: Default,
pub fn new_ratatui<R, C>(rows: R, widths: C) -> Selfwhere
R: IntoIterator,
R::Item: Into<Row<'a>>,
C: IntoIterator,
C::Item: Into<Constraint>,
Selection: Default,
Create a new FTable with preformatted data. For compatibility with ratatui.
Use of RTable::data is preferred.
sourcepub fn rows<T>(self, rows: T) -> Selfwhere
T: IntoIterator<Item = Row<'a>>,
pub fn rows<T>(self, rows: T) -> Selfwhere
T: IntoIterator<Item = Row<'a>>,
Set preformatted row-data. For compatibility with ratatui.
Use of RTable::data is preferred.
sourcepub fn data(self, data: impl TableData<'a> + 'a) -> Self
pub fn data(self, data: impl TableData<'a> + 'a) -> Self
Set a reference to the TableData facade to your data.
The way to go is to define a small struct that contains just a reference to your data. Then implement TableData for this struct.
use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
use ratatui::prelude::Style;
use ratatui::text::Span;
use ratatui::widgets::Widget;
use rat_ftable::{FTable, FTableState, TableData};
struct Data1<'a>(&'a [SampleRow]);
impl<'a> TableData<'a> for Data1<'a> {
// returns (cols, rows)
fn size(&self) -> (usize, usize) {
(5, self.0.len())
}
fn row_height(&self, row: usize) -> u16 {
// to some calculations ...
1
}
fn row_style(&self, row: usize) -> Style {
// to some calculations ...
Style::default()
}
fn render_cell(&self, column: usize, row: usize, area: Rect, buf: &mut Buffer) {
if let Some(data) = self.0.get(row) {
let rend = match column {
0 => Span::from("column1"),
1 => Span::from("column2"),
2 => Span::from("column3"),
_ => return
};
rend.render(area, buf);
}
}
}
// When you are creating the table widget you hand over a reference
// to the facade struct.
let my_data_somewhere_else = vec![SampleRow;999999];
let mut table_state_somewhere_else = FTableState::default();
let tabledata1 = Data1(&my_data_somewhere_else);
let table1 = FTable::default().data(&tabledata1);
table1.render(area, buf, &mut table_state_somewhere_else);sourcepub fn iter(self, data: impl TableDataIter<'a> + 'a) -> Self
pub fn iter(self, data: impl TableDataIter<'a> + 'a) -> Self
Alternative representation for the data is as an Iterator that yields a TableRowData.
Caution: If you can’t give the number of rows, the table will iterate over all the data.
Set the table-footer.
sourcepub fn column_spacing(self, spacing: u16) -> Self
pub fn column_spacing(self, spacing: u16) -> Self
Spacing between columns.
sourcepub fn layout_width(self, width: u16) -> Self
pub fn layout_width(self, width: u16) -> Self
Overrides the width of the rendering area for layout purposes. Layout uses this width, even if it means that some columns are not visible.
sourcepub fn styles(self, styles: FTableStyle) -> Self
pub fn styles(self, styles: FTableStyle) -> Self
Set all styles as a bundle.
sourcepub fn header_style(self, style: Option<Style>) -> Self
pub fn header_style(self, style: Option<Style>) -> Self
Base style for the table.
Base style for the table.
sourcepub fn select_row_style(self, select_style: Option<Style>) -> Self
pub fn select_row_style(self, select_style: Option<Style>) -> Self
Style for a selected row. The chosen selection must support row-selection for this to take effect.
pub fn show_row_focus(self, show: bool) -> Self
sourcepub fn select_column_style(self, select_style: Option<Style>) -> Self
pub fn select_column_style(self, select_style: Option<Style>) -> Self
Style for a selected column. The chosen selection must support column-selection for this to take effect.
pub fn show_column_focus(self, show: bool) -> Self
sourcepub fn select_cell_style(self, select_style: Option<Style>) -> Self
pub fn select_cell_style(self, select_style: Option<Style>) -> Self
Style for a selected cell. The chosen selection must support cell-selection for this to take effect.
pub fn show_cell_focus(self, show: bool) -> Self
sourcepub fn select_header_style(self, select_style: Option<Style>) -> Self
pub fn select_header_style(self, select_style: Option<Style>) -> Self
Style for a selected header cell. The chosen selection must support column-selection for this to take effect.
pub fn show_header_focus(self, show: bool) -> Self
Style for a selected footer cell. The chosen selection must support column-selection for this to take effect.
sourcepub fn focus_style(self, focus_style: Option<Style>) -> Self
pub fn focus_style(self, focus_style: Option<Style>) -> Self
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.
pub fn debug(self, debug: bool) -> Self
Trait Implementations§
source§impl<'a, Selection> ScrollingWidget<RTableState<Selection>> for RTable<'a, Selection>
impl<'a, Selection> ScrollingWidget<RTableState<Selection>> for RTable<'a, Selection>
source§fn need_scroll(
&self,
area: Rect,
_state: &mut RTableState<Selection>,
) -> (bool, bool)
fn need_scroll( &self, area: Rect, _state: &mut RTableState<Selection>, ) -> (bool, bool)
source§impl<'a, Selection> StatefulWidget for RTable<'a, Selection>where
Selection: TableSelection,
impl<'a, Selection> StatefulWidget for RTable<'a, Selection>where
Selection: TableSelection,
source§impl<'a, Selection> StatefulWidgetRef for RTable<'a, Selection>where
Selection: TableSelection,
impl<'a, Selection> StatefulWidgetRef for RTable<'a, Selection>where
Selection: TableSelection,
§type State = RTableState<Selection>
type State = RTableState<Selection>
Auto Trait Implementations§
impl<'a, Selection> !Freeze for RTable<'a, Selection>
impl<'a, Selection> !RefUnwindSafe for RTable<'a, Selection>
impl<'a, Selection> !Send for RTable<'a, Selection>
impl<'a, Selection> !Sync for RTable<'a, Selection>
impl<'a, Selection> Unpin for RTable<'a, Selection>where
Selection: Unpin,
impl<'a, Selection> !UnwindSafe for RTable<'a, Selection>
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