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>
impl<T: 'static> TableModel<T>
Sourcepub fn new(id: ViewId, columns: Vec<Column<T>>) -> Self
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).
Sourcepub fn ensure_mounted(&self)
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.
Sourcepub fn set_columns(&self, columns: Vec<Column<T>>)
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.
Sourcepub fn set_rows(&self, rows: Vec<T>)
pub fn set_rows(&self, rows: Vec<T>)
Replaces all rows (the current sort is applied). Clears the selection.
Sourcepub fn update_row(&self, index: usize, row: T)
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).
Sourcepub fn insert(&self, index: usize, row: T)
pub fn insert(&self, index: usize, row: T)
Inserts a row at a model index (the selection is kept).
Sourcepub fn append(&self, rows: Vec<T>)
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.
Sourcepub fn scroll_to_end(&self)
pub fn scroll_to_end(&self)
Scrolls so the last row is visible.
Sourcepub fn is_at_end(&self) -> bool
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.
Sourcepub fn remove(&self, index: usize) -> Option<T>
pub fn remove(&self, index: usize) -> Option<T>
Removes a row (the selection is kept for the other rows).
Sourcepub fn move_rows(&self, rows: &[usize], before: Option<usize>) -> Vec<usize>
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.
Sourcepub fn set_row_drag(&self, on: bool)
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).
Sourcepub fn set_reorderable(&self, on: bool)
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.
Sourcepub fn set_file_drop(&self, extensions: Option<&[&str]>)
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.
Sourcepub fn set_animates(&self, on: bool)
pub fn set_animates(&self, on: bool)
Sourcepub fn set_url_drop(&self, on: bool)
pub fn set_url_drop(&self, on: bool)
Accepts web addresses dragged from a browser (a link, or the address
bar’s icon). Each drop is reported as TableEvent::UrlsDropped.
Off by default.
Sourcepub fn set_pastes(&self, on: bool)
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.
Sourcepub fn set_keys(&self, keys: &[TableKey])
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.
Sourcepub fn set_cell_focus(&self, on: bool)
pub fn set_cell_focus(&self, on: bool)
Cell focus, as in a spreadsheet: the table keeps a focused column,
which a click on a cell moves to its column and ← and → move one
column at a time (TableEvent::FocusedColumn). The focused cell of
each selected row is outlined. With the selection it names the cells
an action applies to (Set to NULL, Copy Cell). Off by default.
Sourcepub fn focused_column(&self) -> Option<String>
pub fn focused_column(&self) -> Option<String>
The focused column’s id (see set_cell_focus).
Sourcepub fn set_focused_column(&self, column: Option<&str>)
pub fn set_focused_column(&self, column: Option<&str>)
Focuses a column by id (None: no column), scrolling it into view.
Doesn’t report an event.
Sourcepub fn focus_ring(&self, view_row: usize) -> Option<(f64, f64, f64, f64)>
pub fn focus_ring(&self, view_row: usize) -> Option<(f64, f64, f64, f64)>
The focused cell’s outline in row view_row (a view position), in
the row’s coordinates, if the row is shown, selected and a column is
focused. For checks.
Sourcepub fn selected_text(&self) -> String
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).
Sourcepub fn copy_to(&self, pasteboard: &NSPasteboard) -> bool
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.
Sourcepub fn paste_from(&self, pasteboard: &NSPasteboard) -> bool
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.
Sourcepub fn row_at(&self, position: usize) -> Option<usize>
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.
Sourcepub fn set_group_by(&self, key: Option<GroupKey<T>>)
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.
Sourcepub fn groups(&self) -> Vec<String>
pub fn groups(&self) -> Vec<String>
The groups’ titles, in the order shown (empty when not grouped).
Sourcepub fn shown_rows(&self) -> usize
pub fn shown_rows(&self) -> usize
The number of rows shown, group headers included.
Sourcepub fn set_sort(&self, sort: Option<Sort>)
pub fn set_sort(&self, sort: Option<Sort>)
Sets the sort (shown in the header) and, with built-in sorting, applies it.
Sourcepub fn set_sorts_in_place(&self, on: bool)
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.
Sourcepub fn column_state(&self) -> Vec<ColumnState>
pub fn column_state(&self) -> Vec<ColumnState>
Columns in their current order, with widths.
Sourcepub fn set_column_state(&self, state: &[ColumnState])
pub fn set_column_state(&self, state: &[ColumnState])
Restores a saved arrangement (unknown ids are ignored).
Sourcepub fn drain_events(&self) -> Vec<TableEvent>
pub fn drain_events(&self) -> Vec<TableEvent>
Takes the queued user events (for the host widget).
Sourcepub fn cells_created(&self) -> usize
pub fn cells_created(&self) -> usize
Diagnostics: cell views created so far (reuse keeps this near the number of visible cells).
Sourcepub fn scroll_view(&self) -> Retained<NSScrollView> ⓘ
pub fn scroll_view(&self) -> Retained<NSScrollView> ⓘ
The NSScrollView holding the table, for hosts that place it
themselves (no crate::attached window).
Sourcepub fn table_view(&self) -> Retained<NSTableView> ⓘ
pub fn table_view(&self) -> Retained<NSTableView> ⓘ
The underlying NSTableView (escape hatch).