TableState

Struct TableState 

Source
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.

§footer_area: Rect

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,

Source

pub fn new() -> Self

Source

pub fn named(name: &str) -> Self

Source§

impl<Selection> TableState<Selection>

Source

pub fn rows(&self) -> usize

Number of rows.

Source

pub fn columns(&self) -> usize

Number of columns.

Source§

impl<Selection> TableState<Selection>

Source

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.

Source

pub fn cell_at_clicked(&self, pos: (u16, u16)) -> Option<(usize, usize)>

Cell at given position.

Source

pub fn column_at_clicked(&self, pos: (u16, u16)) -> Option<usize>

Column at given position.

Source

pub fn row_at_clicked(&self, pos: (u16, u16)) -> Option<usize>

Row at given position.

Source

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

Source

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’.

Source

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>

Source

pub fn clear_offset(&mut self)

Sets both offsets to 0.

Source

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.

Source

pub fn row_offset(&self) -> usize

Current vertical offset.

Source

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.

Source

pub fn page_len(&self) -> usize

Vertical page-size at the current offset.

Source

pub fn row_scroll_by(&self) -> usize

Suggested scroll per scroll-event.

Source

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.

Source

pub fn x_offset(&self) -> usize

Current horizontal offset.

Source

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.

Source

pub fn page_width(&self) -> usize

Horizontal page-size at the current offset.

Source

pub fn x_scroll_by(&self) -> usize

Suggested scroll per scroll-event.

Source

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.

Source

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.

Source

pub fn scroll_to_col(&mut self, pos: usize) -> bool

Ensures that the given column is completely visible.

Source

pub fn scroll_to_x(&mut self, pos: usize) -> bool

Ensures that the given position is visible.

Source

pub fn scroll_up(&mut self, n: usize) -> bool

Reduce the row-offset by n.

Source

pub fn scroll_down(&mut self, n: usize) -> bool

Increase the row-offset by n.

Source

pub fn scroll_left(&mut self, n: usize) -> bool

Reduce the col-offset by n.

Source

pub fn scroll_right(&mut self, n: usize) -> bool

Increase the col-offset by n.

Source§

impl TableState<RowSelection>

Source

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.

Source

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.

Source

pub fn set_scroll_selection(&mut self, scroll: bool)

When scrolling the table, change the selection instead of the offset.

Source

pub fn clear_selection(&mut self)

Clear the selection.

Source

pub fn has_selection(&mut self) -> bool

Anything selected?

Source

pub fn selected(&self) -> Option<usize>

Selected row. The selected row is not constrained by the row-count.

Source

pub fn selected_checked(&self) -> Option<usize>

Return the selected row and ensure it is in the range 0..rows.

Source

pub fn select(&mut self, row: Option<usize>) -> bool

Select the row. The selection is not constrained by the row-count.

Source

pub fn move_to(&mut self, row: usize) -> bool

Move the selection to the given row. Ensures the row is visible afterward.

Source

pub fn move_up(&mut self, n: usize) -> bool

Move the selection up n rows. Ensures the row is visible afterward.

Source

pub fn move_down(&mut self, n: usize) -> bool

Move the selection down n rows. Ensures the row is visible afterward.

Source§

impl TableState<RowSetSelection>

Source

pub fn clear_selection(&mut self)

Clear the selection.

Source

pub fn has_selection(&mut self) -> bool

Anything selected?

Source

pub fn selected(&self) -> HashSet<usize>

Selected rows.

Source

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.

Source

pub fn lead(&self) -> Option<usize>

Current lead.

Source

pub fn anchor(&self) -> Option<usize>

Current anchor.

Source

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.

Source

pub fn add_selected(&mut self, idx: usize)

Add to selection. Only works for retired selections, not for the active anchor-lead range.

Source

pub fn remove_selected(&mut self, idx: usize)

Remove from selection. Only works for retired selections, not for the active anchor-lead range.

Source

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

pub fn move_up(&mut self, n: usize, extend: bool) -> bool

Move the selection up n rows. Ensures the row is visible afterwards.

Source

pub fn move_down(&mut self, n: usize, extend: bool) -> bool

Move the selection down n rows. Ensures the row is visible afterwards.

Source§

impl TableState<CellSelection>

Source

pub fn clear_selection(&mut self)

Source

pub fn has_selection(&mut self) -> bool

Source

pub fn selected(&self) -> Option<(usize, usize)>

Selected cell.

Source

pub fn select_cell(&mut self, select: Option<(usize, usize)>) -> bool

Select a cell.

Source

pub fn select_row(&mut self, row: Option<usize>) -> bool

Select a row. Column stays the same.

Source

pub fn select_column(&mut self, column: Option<usize>) -> bool

Select a column, row stays the same.

Source

pub fn move_to(&mut self, select: (usize, usize)) -> bool

Select a cell, limit to maximum.

Source

pub fn move_to_row(&mut self, row: usize) -> bool

Select a row, limit to maximum.

Source

pub fn move_to_col(&mut self, col: usize) -> bool

Select a cell, clamp between 0 and maximum.

Source

pub fn move_up(&mut self, n: usize) -> bool

Move the selection up n rows. Ensures the row is visible afterwards.

Source

pub fn move_down(&mut self, n: usize) -> bool

Move the selection down n rows. Ensures the row is visible afterwards.

Source

pub fn move_left(&mut self, n: usize) -> bool

Move the selection left n columns. Ensures the row is visible afterwards.

Source

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>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<Selection: Debug> Debug for TableState<Selection>

Source§

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

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

impl<Selection: Default> Default for TableState<Selection>

Source§

fn default() -> Self

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

impl<Selection> HandleEvent<Event, DoubleClick, DoubleClickOutcome> for TableState<Selection>

Source§

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>

Source§

fn handle(&mut self, event: &Event, _keymap: MouseOnly) -> TableOutcome

Handle an event. Read more
Source§

impl HandleEvent<Event, MouseOnly, TableOutcome> for TableState<NoSelection>

Source§

fn handle(&mut self, event: &Event, _keymap: MouseOnly) -> TableOutcome

Handle an event. Read more
Source§

impl HandleEvent<Event, MouseOnly, TableOutcome> for TableState<RowSelection>

Source§

fn handle(&mut self, event: &Event, _keymap: MouseOnly) -> TableOutcome

Handle an event. Read more
Source§

impl HandleEvent<Event, MouseOnly, TableOutcome> for TableState<RowSetSelection>

Source§

fn handle(&mut self, event: &Event, _: MouseOnly) -> TableOutcome

Handle an event. Read more
Source§

impl HandleEvent<Event, Regular, TableOutcome> for TableState<CellSelection>

Source§

fn handle(&mut self, event: &Event, _keymap: Regular) -> TableOutcome

Handle an event. Read more
Source§

impl HandleEvent<Event, Regular, TableOutcome> for TableState<NoSelection>

Source§

fn handle(&mut self, event: &Event, _keymap: Regular) -> TableOutcome

Handle an event. Read more
Source§

impl HandleEvent<Event, Regular, TableOutcome> for TableState<RowSelection>

Source§

fn handle(&mut self, event: &Event, _keymap: Regular) -> TableOutcome

Handle an event. Read more
Source§

impl HandleEvent<Event, Regular, TableOutcome> for TableState<RowSetSelection>

Source§

fn handle(&mut self, event: &Event, _: Regular) -> TableOutcome

Handle an event. Read more
Source§

impl<Selection> HasFocus for TableState<Selection>

Source§

fn build(&self, builder: &mut FocusBuilder)

Build the focus-structure for the container.
Source§

fn focus(&self) -> FocusFlag

Access to the flag for the rest.
Source§

fn area(&self) -> Rect

Area for mouse focus. Read more
Source§

fn id(&self) -> usize

Provide a unique id for the widget.
Source§

fn area_z(&self) -> u16

Z value for the area. Read more
Source§

fn navigable(&self) -> Navigation

Declares how the widget interacts with focus. Read more
Source§

fn is_focused(&self) -> bool

Focused?
Source§

fn lost_focus(&self) -> bool

Just lost focus.
Source§

fn gained_focus(&self) -> bool

Just gained focus.
Source§

impl<Selection> RelocatableState for TableState<Selection>

Source§

fn relocate(&mut self, shift: (i16, i16), clip: Rect)

Relocate the areas in this widgets state.

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> 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> 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> 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.