Skip to main content

TableEditState

Struct TableEditState 

Source
pub struct TableEditState<T, E> {
    pub mode: Mode,
    pub table: TableState,
    pub editor: E,
    pub data: Vec<T>,
    pub mouse: MouseFlags,
    pub non_exhaustive: NonExhaustive,
}
Expand description

State for TableEdit.

It has a mode-field for insert/edit/view.

Focus

When editing the widget blocks the Focus it is part of. You can’t leave the table as long as it’s editing.

It is intended that the editor-widget sets up a separate Focus for all the widgets and navigates independently of the main application Focus.

Fields§

§mode: Mode

Editing mode.

§table: TableState

Backing table.

§editor: E

Editor

§data: Vec<T>

Data store

§mouse: MouseFlags§non_exhaustive: NonExhaustive

Implementations§

Source§

impl<T, E> TableEditState<T, E>

Source

pub fn new(editor: E) -> TableEditState<T, E>

Source

pub fn named(name: &str, editor: E) -> TableEditState<T, E>

Source

pub fn with(self, data: impl IntoIterator<Item = T>) -> TableEditState<T, E>

Populate the table-data.

Source§

impl<T, E> TableEditState<T, E>

Source

pub fn rows(&self) -> usize

Number of rows.

Source

pub fn columns(&self) -> usize

Number of columns.

Source§

impl<T, E> TableEditState<T, E>

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<T, E> TableEditState<T, E>

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. The offset may be beyond the number of rows.

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. The offset may be beyond the table-width.

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. Caveat: Number of rows needs to be correct.

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. Caveat: Number of rows needs to be correct.

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<T, E> TableEditState<T, E>

Source

pub fn clear_selection(&mut self)

Clear the selection.

Source§

impl<T, E> TableEditState<T, E>

Source

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

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

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_deselect(&mut self) -> bool

Set the selection to None and set the offset to 0

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<T, E> TableEditState<T, E>
where E: TableEditorState<T>, T: Clone,

Source

pub fn set_value(&mut self, data: Vec<T>)

Set the data.

Source

pub fn value(&self) -> &Vec<T>

Get the data.

This will not contain the data of the currently editing row. Instead, it will contain the value before the edit started.

Source

pub fn clear(&mut self)

Clear the widget.

Source

pub fn is_editing(&self) -> bool

Editing is active?

Source

pub fn is_insert(&self) -> bool

Is the current edit an insert?

Source

pub fn remove(&mut self, row: usize)

Remove the item at the given row.

Source

pub fn edit_new<'a>( &mut self, row: usize, ctx: &'a <E as TableEditorState<T>>::Context<'a>, ) -> Result<(), <E as TableEditorState<T>>::Err>

Edit a new item inserted at the selected row.

Source

pub fn edit<'a>( &mut self, col: Option<usize>, row: usize, ctx: &'a <E as TableEditorState<T>>::Context<'a>, ) -> Result<(), <E as TableEditorState<T>>::Err>

Edit the item at the given row. A starting column can be provided too.

Source

pub fn cancel<'a>( &mut self, ctx: &'a <E as TableEditorState<T>>::Context<'a>, ) -> Result<(), <E as TableEditorState<T>>::Err>

Cancel editing. When inserting a new row, the row will be removed.

Source

pub fn commit<'a>( &mut self, ctx: &'a <E as TableEditorState<T>>::Context<'a>, ) -> Result<(), <E as TableEditorState<T>>::Err>

Commit the changes in the editor.

Source

pub fn commit_and_append<'a>( &mut self, ctx: &'a <E as TableEditorState<T>>::Context<'a>, ) -> Result<(), <E as TableEditorState<T>>::Err>

Commit the current changes and start editing the next row. If the end of the table is reached a row will be appended.

Source

pub fn commit_and_edit<'a>( &mut self, ctx: &'a <E as TableEditorState<T>>::Context<'a>, ) -> Result<(), <E as TableEditorState<T>>::Err>

Commit the current changes and start editing the next row. Does not append at the end of the table.

Trait Implementations§

Source§

impl<T, E> Default for TableEditState<T, E>
where E: Default,

Source§

fn default() -> TableEditState<T, E>

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

impl<'a, T, S> HandleEvent<Event, &'a <S as TableEditorState<T>>::Context<'a>, Result<Outcome, <S as TableEditorState<T>>::Err>> for TableEditState<T, S>
where S: HandleEvent<Event, &'a <S as TableEditorState<T>>::Context<'a>, Result<Outcome, <S as TableEditorState<T>>::Err>> + TableEditorState<T>, T: Clone,

Source§

fn handle( &mut self, event: &Event, ctx: &'a <S as TableEditorState<T>>::Context<'a>, ) -> Result<Outcome, <S as TableEditorState<T>>::Err>

Handle an event. Read more
Source§

impl<T, E> HasFocus for TableEditState<T, E>

Source§

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

Build the focus-structure for the container/widget.
Source§

fn focus(&self) -> FocusFlag

Access to the focus flag.
Source§

fn area(&self) -> Rect

Area for mouse focus. Read more
Source§

fn navigable(&self) -> Navigation

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

fn build_nav(&self, navigable: Navigation, builder: &mut FocusBuilder)

Build the focus-structure for the container/widget. 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 is_focused(&self) -> bool

Does this widget have the focus. Or, if the flag is used for a container, does any of widget inside the container have the focus. Read more
Source§

fn lost_focus(&self) -> bool

This widget just lost the focus. This flag is set by [Focus::handle] if there is a focus transfer, and will be reset by the next call to [Focus::handle]. Read more
Source§

fn gained_focus(&self) -> bool

This widget just gained the focus. This flag is set by [Focus::handle] if there is a focus transfer, and will be reset by the next call to [Focus::handle]. Read more
Source§

fn is_obscured(&self) -> bool

Is the widget area hit by the current mouse-position and is there no other widget/container with a higher z-index. Then this widget is not obscured. Read more
Source§

impl<T, E> HasScreenCursor for TableEditState<T, E>
where E: HasScreenCursor,

Source§

fn screen_cursor(&self) -> Option<(u16, u16)>

This returns the cursor position if Read more
Source§

impl<T, E> RelocatableState for TableEditState<T, E>

Source§

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

Relocate the areas in this widgets state. Read more
Source§

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

Relocate only popup areas. As rendering the popups is a separate render, this has to be separate too.
Source§

fn relocate_popup_hidden(&mut self)

Relocate all popup areas to a clip-rect (0,0+0x0).
Source§

fn relocate_hidden(&mut self)

Relocate all areas to a clip-rect (0,0+0x0).

Auto Trait Implementations§

§

impl<T, E> !Freeze for TableEditState<T, E>

§

impl<T, E> !RefUnwindSafe for TableEditState<T, E>

§

impl<T, E> !Send for TableEditState<T, E>

§

impl<T, E> !Sync for TableEditState<T, E>

§

impl<T, E> !UnwindSafe for TableEditState<T, E>

§

impl<T, E> Forget for TableEditState<T, E>

§

impl<T, E> Unpin for TableEditState<T, E>
where E: Unpin, Vec<T>: Unpin,

§

impl<T, E> UnsafeUnpin for TableEditState<T, E>
where E: UnsafeUnpin, Vec<T>: 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.