Skip to main content

TableModel

Struct TableModel 

Source
pub struct TableModel<T: 'static> { /* private fields */ }
Expand description

A native table backed by rows of T. See the module docs.

Implementations§

Source§

impl<T: 'static> TableModel<T>

Source

pub fn new(id: ViewId, columns: Vec<Column<T>>) -> Self

Creates the native table (not yet in a window: it’s added the first time the host draws it, see TableModel::ensure_mounted).

Source

pub fn id(&self) -> ViewId

The view id the table was created with.

Source

pub fn ensure_mounted(&self)

Adds the table to the attached window if it isn’t yet. Called by the host widget before placing it.

Source

pub fn set_columns(&self, columns: Vec<Column<T>>)

Replaces the columns, keeping the same native table (a query browser’s results change shape with every query). The sort is cleared. Call set_rows after it when the rows change too: nothing is drawn in between.

Source

pub fn set_rows(&self, rows: Vec<T>)

Replaces all rows (the current sort is applied). Clears the selection.

Source

pub fn rows(&self) -> Ref<'_, Vec<T>>

The rows, in model order (unsorted).

Source

pub fn len(&self) -> usize

Number of rows.

Source

pub fn is_empty(&self) -> bool

Whether there are no rows.

Source

pub fn update_row(&self, index: usize, row: T)

Replaces one row. Redraws only that row unless the table is sorted (then the order is recomputed; the selection is kept).

Source

pub fn insert(&self, index: usize, row: T)

Inserts a row at a model index (the selection is kept).

Source

pub fn append(&self, rows: Vec<T>)

Appends rows in one step, for live data (a log tail, a feed): when unsorted, the new rows are added to the end and AppKit only learns the new count (cost independent of the rows already there; the selection is kept). When sorted, the order is recomputed.

Source

pub fn scroll_to_end(&self)

Scrolls so the last row is visible.

Source

pub fn is_at_end(&self) -> bool

Whether the table is scrolled to its last row (within one row), e.g. to keep following new rows only while the user hasn’t scrolled up.

Source

pub fn push(&self, row: T)

Appends a row.

Source

pub fn remove(&self, index: usize) -> Option<T>

Removes a row (the selection is kept for the other rows).

Source

pub fn move_rows(&self, rows: &[usize], before: Option<usize>) -> Vec<usize>

Moves rows (model indices) to just above the row before (or to the end), keeping their order, as a drop reported by TableEvent::RowsMoved asks. Returns their new model indices; they end up selected.

Source

pub fn set_row_drag(&self, on: bool)

Lets rows be dragged out: each carries its cells as tab-separated text (for other apps), and its model index for set_reorderable. Off by default (a drag then extends the selection).

Source

pub fn set_reorderable(&self, on: bool)

Lets the user drag rows to a new place (also turns on set_row_drag); each drop is reported as TableEvent::RowsMoved. Refused while the table is sorted.

Source

pub fn set_file_drop(&self, extensions: Option<&[&str]>)

Accepts files dropped from the Finder: Some(&["csv", "txt"]) for those extensions, Some(&[]) for any file, None to stop. Each drop is reported as TableEvent::FilesDropped.

Source

pub fn set_pastes(&self, on: bool)

Reports ⌘V on the table as TableEvent::Paste (and enables Paste in the Edit menu while there is text to paste). Off by default.

Source

pub fn set_keys(&self, keys: &[TableKey])

Reports these keys, pressed without ⌘, ⌥ or ⌃ while rows are selected, as TableEvent::Key instead of AppKit’s handling (Space would type-select, Delete beep). None by default.

Source

pub fn selected_text(&self) -> String

The selected rows as tab-separated text (columns in their current order, one line per row, as ⌘C copies them).

Source

pub fn copy_to(&self, pasteboard: &NSPasteboard) -> bool

Copies the selected rows to pasteboard (what ⌘C does with the general pasteboard). False if nothing is selected.

Source

pub fn paste_from(&self, pasteboard: &NSPasteboard) -> bool

Pastes pasteboard’s text (what ⌘V does with the general pasteboard): queues TableEvent::Paste if the table takes pastes.

Source

pub fn row_at(&self, position: usize) -> Option<usize>

The model index of the row shown at position (0 = top row as currently sorted); None past the end or for a group header.

Source

pub fn set_group_by(&self, key: Option<GroupKey<T>>)

Groups the rows under headers by key (e.g. a date or a category): groups appear in the order their first row has in the model, rows keep the sort’s order within each group, and each group starts with a header row showing the key (full width, not selectable, floating while its rows scroll). None ungroups. Row indices in events stay model indices.

Source

pub fn groups(&self) -> Vec<String>

The groups’ titles, in the order shown (empty when not grouped).

Source

pub fn shown_rows(&self) -> usize

The number of rows shown, group headers included.

Source

pub fn selection(&self) -> Vec<usize>

Selected rows (model indices, ascending in view order).

Source

pub fn select(&self, rows: &[usize])

Selects rows by model index (emits no event).

Source

pub fn sort(&self) -> Option<Sort>

The current sort, if any.

Source

pub fn set_sort(&self, sort: Option<Sort>)

Sets the sort (shown in the header) and, with built-in sorting, applies it.

Source

pub fn set_sorts_in_place(&self, on: bool)

Built-in sorting (default on): header clicks reorder the rows here. Turn it off to sort yourself on TableEvent::Sort (e.g. in a database) and call TableModel::set_rows.

Source

pub fn column_state(&self) -> Vec<ColumnState>

Columns in their current order, with widths.

Source

pub fn set_column_state(&self, state: &[ColumnState])

Restores a saved arrangement (unknown ids are ignored).

Source

pub fn drain_events(&self) -> Vec<TableEvent>

Takes the queued user events (for the host widget).

Source

pub fn cells_created(&self) -> usize

Diagnostics: cell views created so far (reuse keeps this near the number of visible cells).

Source

pub fn scroll_view(&self) -> Retained<NSScrollView> ⓘ

The NSScrollView holding the table, for hosts that place it themselves (no crate::attached window).

Source

pub fn table_view(&self) -> Retained<NSTableView> ⓘ

The underlying NSTableView (escape hatch).

Trait Implementations§

Source§

impl<T: 'static> Clone for TableModel<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: 'static> Debug for TableModel<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for TableModel<T>

§

impl<T> !Send for TableModel<T>

§

impl<T> !Sync for TableModel<T>

§

impl<T> !UnwindSafe for TableModel<T>

§

impl<T> Forget for TableModel<T>

§

impl<T> Freeze for TableModel<T>
where Rc<Inner<T>>: Freeze,

§

impl<T> Unpin for TableModel<T>
where Rc<Inner<T>>: Unpin,

§

impl<T> UnsafeUnpin for TableModel<T>
where Rc<Inner<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> AutoreleaseSafe for T
where T: ?Sized,

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> 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 = !

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.