Skip to main content

GridModel

Trait GridModel 

Source
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§

Source

fn columns(&self) -> &[Column]

The columns, left to right.

Source

fn rows(&self) -> usize

How many rows there are.

Source

fn cell( &self, row: usize, column: usize, text: &mut CellText, palette: &Palette, ) -> CellStyle

Writes the text of the cell at row, column into text (empty on entry) and returns its style, in the grid’s colors (palette, which follows the theme).

Provided Methods§

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

fn columns_revision(&self) -> u64

Changes whenever columns changes (another schema, new widths): the grid then reads the columns again, keeping the widths the user dragged if the column titles are the same as before. Checked each frame after prepare.

Source

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".

Implementors§