pub trait GridModel {
// Required methods
fn columns(&self) -> &[Column];
fn rows(&self) -> usize;
fn cell(
&self,
row: usize,
column: usize,
text: &mut CellText,
palette: &Palette,
) -> CellStyle;
// Provided methods
fn prepare(&mut self) { ... }
fn sort(&mut self, column: usize, order: SortOrder) -> bool { ... }
fn sort_state(&self) -> Option<(usize, SortOrder)> { ... }
fn row_key(&self, row: usize) -> Option<u64> { ... }
fn row_of_key(&self, key: u64) -> Option<usize> { ... }
fn columns_revision(&self) -> u64 { ... }
fn generation(&self) -> u64 { ... }
}Expand description
The data of a grid widget: its columns, its rows, and each cell’s text and style, plus what the widget asks of it as the user works with it.
Rows are numbered from 0 in the order they are shown; the widget asks only for the rows
on screen. cell runs for every visible cell every frame and formats into
a stack buffer, so it must not allocate.
Required Methods§
Provided Methods§
Sourcefn prepare(&mut self)
fn prepare(&mut self)
Brings the model up to date before the grid paints (taking in data that arrived, for
example). It may allocate when the data changed; it should not otherwise. It runs only
when the grid paints, not while it is hidden (an inactive tab): feed a model that
must keep up while hidden from the application, through
DataGrid::model_mut.
Sourcefn sort(&mut self, column: usize, order: SortOrder) -> bool
fn sort(&mut self, column: usize, order: SortOrder) -> bool
Sorts the rows by column (an index into columns) in order, when
the user asks for it (a click on its title); false if the model does not sort by
that column, which leaves the order alone.
Sourcefn sort_state(&self) -> Option<(usize, SortOrder)>
fn sort_state(&self) -> Option<(usize, SortOrder)>
The column and order the rows are sorted by now, if the model knows (a model sorted before the user clicked, or one that sorts itself); the grid shows it and reverses it on the next click.
Sourcefn row_key(&self, row: usize) -> Option<u64>
fn row_key(&self, row: usize) -> Option<u64>
A value identifying the record at row while rows are added, removed or sorted (a
database key, an instrument id). With it, a selection follows its record; without
it (None, the default), a selection is a position and is cleared by sorting.
Sourcefn row_of_key(&self, key: u64) -> Option<usize>
fn row_of_key(&self, key: u64) -> Option<usize>
Where the record row_key gave key for is now, if it is still
shown. Asked once a frame while a row is selected: make it fast for large models.
None (the record was removed, or is filtered out) clears the selection.
Sourcefn columns_revision(&self) -> u64
fn columns_revision(&self) -> u64
Sourcefn generation(&self) -> u64
fn generation(&self) -> u64
Changes when the rows were replaced wholesale (another table), so that keys from
before mean nothing: the grid then clears its selection and scrolls to the top.
Checked each frame after prepare.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".