pub struct LiveModel { /* private fields */ }Expand description
A densa_data::LiveTable as the model of a grid widget (densa_widgets::DataGrid): one
view of the table, sorted when the user clicks a column title and filtered by the app,
with rows keyed by their record so a selection follows its row as the data changes.
Change the table through table_mut; the view follows each change
incrementally. Cells are formatted as in ArrowTable, from
formatters brought up to date by GridModel::prepare, which the grid calls before it
paints; until then, rows from batches added since show empty cells rather than stale
values. Columns are sized from the first rows to arrive and widened when later numbers
no longer fit, and the grid takes in new sizes by itself
(GridModel::columns_revision), keeping widths the user dragged.
Costs: a frame without changes allocates nothing; one after upserts allocates a
formatter per new batch, and after a compaction rebuilds them all. Sorting or filtering
builds a new view, O(n log n) in the table’s rows.
Implementations§
Source§impl LiveModel
impl LiveModel
Sourcepub fn new(table: LiveTable) -> Result<Self, DataError>
pub fn new(table: LiveTable) -> Result<Self, DataError>
A model showing every row of table, unsorted (in row-id order: the order keys
arrived, until deleted keys’ places are reused).
§Errors
Those of LiveTable::add_view; none for a view of every row, unsorted.
Sourcepub fn table_mut(&mut self) -> &mut LiveTable
pub fn table_mut(&mut self) -> &mut LiveTable
The table, to upsert, delete or compact; the view follows. Another table put in its place is shown from the next paint, filtered and sorted the same way where its columns allow, and the grid starts over (no selection, its columns read again).
Sourcepub fn view(&self) -> Option<View<'_>>
pub fn view(&self) -> Option<View<'_>>
The rows shown, in order (None only between replacing the table and the next
paint).
Sourcepub fn record(&self, index: usize) -> Option<RecordId>
pub fn record(&self, index: usize) -> Option<RecordId>
The record of the row at index, as shown.
Sourcepub fn set_filter(&mut self, filter: Option<Filter>) -> Result<(), DataError>
pub fn set_filter(&mut self, filter: Option<Filter>) -> Result<(), DataError>
Shows only the rows filter keeps (all of them for None), in the same sort. A
selected row the filter hides is no longer selected.
§Errors
Those of LiveTable::add_view for the filter (an unknown column, a comparison
with a value of another type); the model is unchanged then.
Sourcepub fn set_decimals(
&mut self,
column: usize,
decimals: Option<usize>,
) -> Result<(), TableError>
pub fn set_decimals( &mut self, column: usize, decimals: Option<usize>, ) -> Result<(), TableError>
As ArrowTable::set_decimals; the grid takes in
the new width.
§Errors
TableError::NoSuchColumn if there is no such column.
Sourcepub fn set_column_chars(
&mut self,
column: usize,
chars: usize,
) -> Result<(), TableError>
pub fn set_column_chars( &mut self, column: usize, chars: usize, ) -> Result<(), TableError>
As ArrowTable::set_column_chars; the grid
takes in the new width.
§Errors
TableError::NoSuchColumn if there is no such column.
Trait Implementations§
Source§impl GridModel for LiveModel
impl GridModel for LiveModel
Source§fn cell(
&self,
row: usize,
column: usize,
text: &mut CellText,
palette: &Palette,
) -> CellStyle
fn cell( &self, row: usize, column: usize, text: &mut CellText, palette: &Palette, ) -> CellStyle
row, column into text (empty on entry) and
returns its style, in the grid’s colors (palette, which follows the theme).Source§fn prepare(&mut self)
fn prepare(&mut self)
DataGrid::model_mut.Source§fn sort(&mut self, column: usize, order: SortOrder) -> bool
fn sort(&mut self, column: usize, order: SortOrder) -> bool
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.Source§fn sort_state(&self) -> Option<(usize, SortOrder)>
fn sort_state(&self) -> Option<(usize, SortOrder)>
Source§fn row_key(&self, row: usize) -> Option<u64>
fn row_key(&self, row: usize) -> Option<u64>
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.Source§fn row_of_key(&self, key: u64) -> Option<usize>
fn row_of_key(&self, key: u64) -> Option<usize>
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.Source§fn columns_revision(&self) -> u64
fn columns_revision(&self) -> u64
Source§fn generation(&self) -> u64
fn generation(&self) -> u64
prepare.