pub struct TableState<Selection> {Show 17 fields
pub focus: FocusFlag,
pub area: Rect,
pub inner: Rect,
pub header_area: Rect,
pub table_area: Rect,
pub row_areas: Vec<Rect>,
pub column_areas: Vec<Rect>,
pub column_layout: Vec<Rect>,
pub footer_area: Rect,
pub rows: usize,
pub _counted_rows: usize,
pub columns: usize,
pub vscroll: ScrollState,
pub hscroll: ScrollState,
pub selection: Selection,
pub mouse: MouseFlags,
pub non_exhaustive: NonExhaustive,
}
Expand description
Table state.
Fields§
§focus: FocusFlag
Current focus state. read+write
area: Rect
Total area. read only Renewed with each render.
inner: Rect
Area inside the border and scrollbars read only Renewed with each render.
header_area: Rect
Total header area. read only Renewed with each render.
table_area: Rect
Total table area. read only Renewed with each render.
row_areas: Vec<Rect>
Area per visible row. The first element is at row_offset. read only Renewed with each render.
column_areas: Vec<Rect>
Area for each column plus the following spacer if any. Invisible columns have width 0, height is the height of the table_area. read only Renewed with each render.
column_layout: Vec<Rect>
Layout areas for each column plus the following spacer if any. Positions are 0-based, y and height are 0. read only Renewed with each render.
Total footer area. read only Renewed with each render.
rows: usize
Row count. read+write Renewed with each render anyway.
_counted_rows: usize
§columns: usize
Column count. read only Renewed with each render.
vscroll: ScrollState
Row scrolling data. read+write max_offset set with each render.
hscroll: ScrollState
Column scrolling data. read+write max_offset set with each render.
selection: Selection
Selection data. read+write selection model. selection is not bound by rows.
mouse: MouseFlags
Helper for mouse interactions.
non_exhaustive: NonExhaustive
Implementations§
Source§impl<Selection> TableState<Selection>where
Selection: Default,
impl<Selection> TableState<Selection>where
Selection: Default,
Source§impl<Selection> TableState<Selection>
impl<Selection> TableState<Selection>
Source§impl<Selection> TableState<Selection>
impl<Selection> TableState<Selection>
Sourcepub fn row_cells(&self, row: usize) -> Option<(Rect, Vec<Rect>)>
pub fn row_cells(&self, row: usize) -> Option<(Rect, Vec<Rect>)>
Returns the whole row-area and the cell-areas for the given row, if it is visible.
Attention: These areas might be 0-length if the column is scrolled beyond the table-area.
Sourcepub fn cell_at_clicked(&self, pos: (u16, u16)) -> Option<(usize, usize)>
pub fn cell_at_clicked(&self, pos: (u16, u16)) -> Option<(usize, usize)>
Cell at given position.
Sourcepub fn cell_at_drag(&self, pos: (u16, u16)) -> (usize, usize)
pub fn cell_at_drag(&self, pos: (u16, u16)) -> (usize, usize)
Cell when dragging. Position can be outside the table area. See row_at_drag, col_at_drag
Sourcepub fn row_at_drag(&self, pos: (u16, u16)) -> usize
pub fn row_at_drag(&self, pos: (u16, u16)) -> usize
Row when dragging. Position can be outside the table area. If the position is above the table-area this returns offset - #rows. If the position is below the table-area this returns offset + page_len + #rows.
This doesn’t account for the row-height of the actual rows outside the table area, just assumes ‘1’.
Sourcepub fn column_at_drag(&self, pos: (u16, u16)) -> usize
pub fn column_at_drag(&self, pos: (u16, u16)) -> usize
Column when dragging. Position can be outside the table area. If the position is left of the table area this returns offset - 1. If the position is right of the table area this returns offset + page_width + 1.
Source§impl<Selection: TableSelection> TableState<Selection>
impl<Selection: TableSelection> TableState<Selection>
Sourcepub fn clear_offset(&mut self)
pub fn clear_offset(&mut self)
Sets both offsets to 0.
Sourcepub fn row_max_offset(&self) -> usize
pub fn row_max_offset(&self) -> usize
Maximum offset that is accessible with scrolling.
This is shorter than the length by whatever fills the last page. This is the base for the scrollbar content_length.
Sourcepub fn row_offset(&self) -> usize
pub fn row_offset(&self) -> usize
Current vertical offset.
Sourcepub fn set_row_offset(&mut self, offset: usize) -> bool
pub fn set_row_offset(&mut self, offset: usize) -> bool
Change the vertical offset.
Due to overscroll it’s possible that this is an invalid offset for the widget. The widget must deal with this situation.
The widget returns true if the offset changed at all.
Sourcepub fn row_scroll_by(&self) -> usize
pub fn row_scroll_by(&self) -> usize
Suggested scroll per scroll-event.
Sourcepub fn x_max_offset(&self) -> usize
pub fn x_max_offset(&self) -> usize
Maximum offset that is accessible with scrolling.
This is shorter than the length of the content by whatever fills the last page. This is the base for the scrollbar content_length.
Sourcepub fn set_x_offset(&mut self, offset: usize) -> bool
pub fn set_x_offset(&mut self, offset: usize) -> bool
Change the horizontal offset.
Due to overscroll it’s possible that this is an invalid offset for the widget. The widget must deal with this situation.
The widget returns true if the offset changed at all.
Sourcepub fn page_width(&self) -> usize
pub fn page_width(&self) -> usize
Horizontal page-size at the current offset.
Sourcepub fn x_scroll_by(&self) -> usize
pub fn x_scroll_by(&self) -> usize
Suggested scroll per scroll-event.
Sourcepub fn scroll_to_selected(&mut self) -> bool
pub fn scroll_to_selected(&mut self) -> bool
Ensures that the selected item is visible. Caveat: This doesn’t work nicely if you have varying row-heights.
Sourcepub fn scroll_to_row(&mut self, pos: usize) -> bool
pub fn scroll_to_row(&mut self, pos: usize) -> bool
Ensures that the given row is visible. Caveat: This doesn’t work nicely if you have varying row-heights.
Sourcepub fn scroll_to_col(&mut self, pos: usize) -> bool
pub fn scroll_to_col(&mut self, pos: usize) -> bool
Ensures that the given column is completely visible.
Sourcepub fn scroll_to_x(&mut self, pos: usize) -> bool
pub fn scroll_to_x(&mut self, pos: usize) -> bool
Ensures that the given position is visible.
Sourcepub fn scroll_down(&mut self, n: usize) -> bool
pub fn scroll_down(&mut self, n: usize) -> bool
Increase the row-offset by n.
Sourcepub fn scroll_left(&mut self, n: usize) -> bool
pub fn scroll_left(&mut self, n: usize) -> bool
Reduce the col-offset by n.
Sourcepub fn scroll_right(&mut self, n: usize) -> bool
pub fn scroll_right(&mut self, n: usize) -> bool
Increase the col-offset by n.
Source§impl TableState<RowSelection>
impl TableState<RowSelection>
Sourcepub fn items_added(&mut self, pos: usize, n: usize)
pub fn items_added(&mut self, pos: usize, n: usize)
Update the state to match adding items. This corrects the number of rows, offset and selection.
Sourcepub fn items_removed(&mut self, pos: usize, n: usize)
pub fn items_removed(&mut self, pos: usize, n: usize)
Update the state to match removing items. This corrects the number of rows, offset and selection.
Sourcepub fn set_scroll_selection(&mut self, scroll: bool)
pub fn set_scroll_selection(&mut self, scroll: bool)
When scrolling the table, change the selection instead of the offset.
Sourcepub fn clear_selection(&mut self)
pub fn clear_selection(&mut self)
Clear the selection.
Sourcepub fn has_selection(&mut self) -> bool
pub fn has_selection(&mut self) -> bool
Anything selected?
Sourcepub fn selected(&self) -> Option<usize>
pub fn selected(&self) -> Option<usize>
Selected row. The selected row is not constrained by the row-count.
Sourcepub fn selected_checked(&self) -> Option<usize>
pub fn selected_checked(&self) -> Option<usize>
Return the selected row and ensure it is in the range 0..rows.
Sourcepub fn select(&mut self, row: Option<usize>) -> bool
pub fn select(&mut self, row: Option<usize>) -> bool
Select the row. The selection is not constrained by the row-count.
Sourcepub fn move_to(&mut self, row: usize) -> bool
pub fn move_to(&mut self, row: usize) -> bool
Move the selection to the given row. Ensures the row is visible afterward.
Source§impl TableState<RowSetSelection>
impl TableState<RowSetSelection>
Sourcepub fn clear_selection(&mut self)
pub fn clear_selection(&mut self)
Clear the selection.
Sourcepub fn has_selection(&mut self) -> bool
pub fn has_selection(&mut self) -> bool
Anything selected?
Sourcepub fn set_lead(&mut self, row: Option<usize>, extend: bool) -> bool
pub fn set_lead(&mut self, row: Option<usize>, extend: bool) -> bool
Change the lead-selection. Limits the value to the number of rows.
If extend is false the current selection is cleared and both lead and
anchor are set to the given value.
If extend is true, the anchor is kept where it is and lead is changed.
Everything in the range anchor..lead
is selected. It doesn’t matter
if anchor < lead.
Sourcepub fn retire_selection(&mut self)
pub fn retire_selection(&mut self)
Retire the current anchor/lead selection to the set of selected rows. Resets lead and anchor and starts a new selection round.
Sourcepub fn add_selected(&mut self, idx: usize)
pub fn add_selected(&mut self, idx: usize)
Add to selection. Only works for retired selections, not for the active anchor-lead range.
Sourcepub fn remove_selected(&mut self, idx: usize)
pub fn remove_selected(&mut self, idx: usize)
Remove from selection. Only works for retired selections, not for the active anchor-lead range.
Sourcepub fn move_to(&mut self, row: usize, extend: bool) -> bool
pub fn move_to(&mut self, row: usize, extend: bool) -> bool
Move the selection to the given row. Ensures the row is visible afterwards.
Source§impl TableState<CellSelection>
impl TableState<CellSelection>
pub fn clear_selection(&mut self)
pub fn has_selection(&mut self) -> bool
Sourcepub fn select_row(&mut self, row: Option<usize>) -> bool
pub fn select_row(&mut self, row: Option<usize>) -> bool
Select a row. Column stays the same.
Sourcepub fn select_column(&mut self, column: Option<usize>) -> bool
pub fn select_column(&mut self, column: Option<usize>) -> bool
Select a column, row stays the same.
Sourcepub fn move_to_row(&mut self, row: usize) -> bool
pub fn move_to_row(&mut self, row: usize) -> bool
Select a row, limit to maximum.
Sourcepub fn move_to_col(&mut self, col: usize) -> bool
pub fn move_to_col(&mut self, col: usize) -> bool
Select a cell, clamp between 0 and maximum.
Sourcepub fn move_up(&mut self, n: usize) -> bool
pub fn move_up(&mut self, n: usize) -> bool
Move the selection up n rows. Ensures the row is visible afterwards.
Sourcepub fn move_down(&mut self, n: usize) -> bool
pub fn move_down(&mut self, n: usize) -> bool
Move the selection down n rows. Ensures the row is visible afterwards.
Sourcepub fn move_left(&mut self, n: usize) -> bool
pub fn move_left(&mut self, n: usize) -> bool
Move the selection left n columns. Ensures the row is visible afterwards.
Sourcepub fn move_right(&mut self, n: usize) -> bool
pub fn move_right(&mut self, n: usize) -> bool
Move the selection right n columns. Ensures the row is visible afterwards.
Trait Implementations§
Source§impl<Selection: Clone> Clone for TableState<Selection>
impl<Selection: Clone> Clone for TableState<Selection>
Source§impl<Selection: Debug> Debug for TableState<Selection>
impl<Selection: Debug> Debug for TableState<Selection>
Source§impl<Selection: Default> Default for TableState<Selection>
impl<Selection: Default> Default for TableState<Selection>
Source§impl<Selection> HandleEvent<Event, DoubleClick, DoubleClickOutcome> for TableState<Selection>
impl<Selection> HandleEvent<Event, DoubleClick, DoubleClickOutcome> for TableState<Selection>
Source§fn handle(&mut self, event: &Event, _keymap: DoubleClick) -> DoubleClickOutcome
fn handle(&mut self, event: &Event, _keymap: DoubleClick) -> DoubleClickOutcome
Handles double-click events on the table.
Source§impl HandleEvent<Event, MouseOnly, TableOutcome> for TableState<CellSelection>
impl HandleEvent<Event, MouseOnly, TableOutcome> for TableState<CellSelection>
Source§impl HandleEvent<Event, MouseOnly, TableOutcome> for TableState<NoSelection>
impl HandleEvent<Event, MouseOnly, TableOutcome> for TableState<NoSelection>
Source§impl HandleEvent<Event, MouseOnly, TableOutcome> for TableState<RowSelection>
impl HandleEvent<Event, MouseOnly, TableOutcome> for TableState<RowSelection>
Source§impl HandleEvent<Event, MouseOnly, TableOutcome> for TableState<RowSetSelection>
impl HandleEvent<Event, MouseOnly, TableOutcome> for TableState<RowSetSelection>
Source§impl HandleEvent<Event, Regular, TableOutcome> for TableState<CellSelection>
impl HandleEvent<Event, Regular, TableOutcome> for TableState<CellSelection>
Source§impl HandleEvent<Event, Regular, TableOutcome> for TableState<NoSelection>
impl HandleEvent<Event, Regular, TableOutcome> for TableState<NoSelection>
Source§impl HandleEvent<Event, Regular, TableOutcome> for TableState<RowSelection>
impl HandleEvent<Event, Regular, TableOutcome> for TableState<RowSelection>
Source§impl HandleEvent<Event, Regular, TableOutcome> for TableState<RowSetSelection>
impl HandleEvent<Event, Regular, TableOutcome> for TableState<RowSetSelection>
Source§impl<Selection> HasFocus for TableState<Selection>
impl<Selection> HasFocus for TableState<Selection>
Source§fn build(&self, builder: &mut FocusBuilder)
fn build(&self, builder: &mut FocusBuilder)
Source§fn is_focused(&self) -> bool
fn is_focused(&self) -> bool
Source§fn lost_focus(&self) -> bool
fn lost_focus(&self) -> bool
Source§fn gained_focus(&self) -> bool
fn gained_focus(&self) -> bool
Source§impl<Selection> RelocatableState for TableState<Selection>
impl<Selection> RelocatableState for TableState<Selection>
Auto Trait Implementations§
impl<Selection> !Freeze for TableState<Selection>
impl<Selection> !RefUnwindSafe for TableState<Selection>
impl<Selection> !Send for TableState<Selection>
impl<Selection> !Sync for TableState<Selection>
impl<Selection> Unpin for TableState<Selection>where
Selection: Unpin,
impl<Selection> !UnwindSafe for TableState<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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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