Skip to main content

TableState

Struct TableState 

Source
pub struct TableState {
    pub selected: Option<usize>,
    pub hovered: Option<usize>,
    pub offset: usize,
    /* private fields */
}
Expand description

Mutable state for a Table widget.

Fields§

§selected: Option<usize>

Index of the currently selected row, if any.

§hovered: Option<usize>

Index of the currently hovered row, if any.

§offset: usize

Scroll offset (first visible row index).

Implementations§

Source§

impl TableState

Source

pub fn select(&mut self, index: Option<usize>)

Set the selected row index, resetting offset on deselect.

Source

pub fn with_persistence_id(self, id: impl Into<String>) -> Self

Create a new TableState with a persistence ID for state saving.

Source

pub fn persistence_id(&self) -> Option<&str>

Get the persistence ID, if set.

Source§

impl TableState

Source

pub fn undo_id(&self) -> UndoWidgetId

Get the undo widget ID.

This can be used to associate undo commands with this state instance.

Source

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

Get the current sort column.

Source

pub fn sort_ascending(&self) -> bool

Get whether the sort is ascending.

Source

pub fn set_sort(&mut self, column: Option<usize>, ascending: bool)

Set the sort state.

Source

pub fn filter(&self) -> &str

Get the filter text.

Source

pub fn set_filter(&mut self, filter: impl Into<String>)

Set the filter text.

Source

pub fn handle_mouse( &mut self, event: &MouseEvent, hit: Option<(HitId, HitRegion, u64)>, expected_id: HitId, row_count: usize, ) -> MouseResult

Handle a mouse event for this table.

§Hit data convention

The hit data (u64) encodes the row index. When the table renders with a hit_id, each visible row registers HitRegion::Content with data = row_index as u64.

§Arguments
  • event — the mouse event from the terminal
  • hit — result of frame.hit_test(event.x, event.y), if available
  • expected_id — the HitId this table was rendered with
  • row_count — total number of rows in the table
Source

pub fn scroll_up(&mut self, lines: usize)

Scroll the table up by the given number of lines.

Source

pub fn scroll_down(&mut self, lines: usize, row_count: usize)

Scroll the table down by the given number of lines.

Clamps so that the last row can still appear at the top of the viewport.

Trait Implementations§

Source§

impl Clone for TableState

Source§

fn clone(&self) -> TableState

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 Debug for TableState

Source§

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

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

impl Default for TableState

Source§

fn default() -> TableState

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

impl Stateful for TableState

Source§

type State = TablePersistState

The state type that gets persisted. Read more
Source§

fn state_key(&self) -> StateKey

Unique key identifying this widget instance. Read more
Source§

fn save_state(&self) -> TablePersistState

Extract current state for persistence. Read more
Source§

fn restore_state(&mut self, state: TablePersistState)

Restore state from persistence. Read more
Source§

fn state_version() -> u32

State schema version for forward-compatible migrations. Read more
Source§

impl TableUndoExt for TableState

Source§

fn sort_state(&self) -> (Option<usize>, bool)

Get the current sort state.
Source§

fn set_sort_state(&mut self, column: Option<usize>, ascending: bool)

Set the sort state.
Source§

fn filter_text(&self) -> &str

Get the current filter.
Source§

fn set_filter_text(&mut self, filter: &str)

Set the filter.
Source§

impl UndoSupport for TableState

Source§

fn undo_widget_id(&self) -> UndoWidgetId

Get the widget’s unique ID for undo tracking.
Source§

fn create_snapshot(&self) -> Box<dyn Any + Send>

Create a snapshot of the current state for undo purposes. Read more
Source§

fn restore_snapshot(&mut self, snapshot: &dyn Any) -> bool

Restore state from a snapshot. Read more

Auto Trait Implementations§

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more