pub struct DataGrid<M> { /* private fields */ }Expand description
A grid of rows from a GridModel: the user scrolls it (wheel, touchpad, scroll bar,
keys), selects a row (click, arrow keys, Page Up and Down, Home, End), sorts it by
clicking a column’s title (again to reverse), and resizes columns by dragging the edges
between titles. Leading columns can stay in place while the rest scroll sideways
(with_frozen_columns).
Only the rows on screen are asked of the model, each frame, and painting allocates nothing
once their characters are cached, however many rows there are. Change the data through
model_mut from an Ui::update on the grid,
which repaints it. The grid follows the model’s GridModel::columns_revision and
GridModel::generation each frame.
A selection is a row, kept on its record while rows move if the model gives rows keys
(GridModel::row_key) and cleared when its record is removed or filtered out (as in
Qt’s proxy models); without keys, sorting clears it. It reports
ActionKind::Selected with the row when the user
selects one, ActionKind::Submitted when they activate
it (Enter, a double click), and ActionKind::Changed when
a click sorted the rows. Give it DataGrid::style.
Implementations§
Source§impl<M: GridModel> DataGrid<M>
impl<M: GridModel> DataGrid<M>
Sourcepub fn with_frozen_columns(self, columns: usize) -> Self
pub fn with_frozen_columns(self, columns: usize) -> Self
The grid with its first columns columns kept in place while the others scroll
sideways (all of them, if there are fewer).
Sourcepub fn style() -> Style
pub fn style() -> Style
A grid filling its parent’s free space, allowed to be smaller than its rows, and clipping them.
Sourcepub fn model_mut(&mut self, cx: &mut EventCx<'_>) -> &mut M
pub fn model_mut(&mut self, cx: &mut EventCx<'_>) -> &mut M
The data, to change (from an Ui::update on the grid): the
grid repaints, and keeps its selection and scroll within the rows there are.
Sourcepub fn reset_columns(&mut self, cx: &mut EventCx<'_>)
pub fn reset_columns(&mut self, cx: &mut EventCx<'_>)
Reads the model’s columns again (after it changed them), dropping the user’s widths, and a sort or a drag on a column that is gone.
Sourcepub fn select(&mut self, cx: &mut EventCx<'_>, row: Option<usize>)
pub fn select(&mut self, cx: &mut EventCx<'_>, row: Option<usize>)
Selects row (none for None) and scrolls it into view.
Sourcepub fn scroll_to_row(&mut self, cx: &mut EventCx<'_>, row: usize)
pub fn scroll_to_row(&mut self, cx: &mut EventCx<'_>, row: usize)
Scrolls so that row is the first on screen, or as near as the rows allow.
Sourcepub fn sort_order(&self) -> Option<(usize, SortOrder)>
pub fn sort_order(&self) -> Option<(usize, SortOrder)>
The column and order the rows are sorted by: the model’s own, if it reports it, else the last one a click asked for.
Sourcepub fn visible_rows(&self) -> usize
pub fn visible_rows(&self) -> usize
How many rows are painted, the last one possibly cut off (0 before the first layout).
Sourcepub fn whole_rows(&self) -> usize
pub fn whole_rows(&self) -> usize
How many rows fit whole: what a page is, and how many the last screen shows.
Trait Implementations§
Source§impl<M: GridModel + 'static> Widget for DataGrid<M>
impl<M: GridModel + 'static> Widget for DataGrid<M>
Source§fn layout(&mut self, cx: &mut LayoutCx<'_>, size: Size)
fn layout(&mut self, cx: &mut LayoutCx<'_>, size: Size)
Source§fn paint(&mut self, cx: &PaintCx<'_>, canvas: &mut Canvas<'_>)
fn paint(&mut self, cx: &PaintCx<'_>, canvas: &mut Canvas<'_>)
Source§fn event(&mut self, cx: &mut EventCx<'_>, event: &Event<'_>) -> Handled
fn event(&mut self, cx: &mut EventCx<'_>, event: &Event<'_>) -> Handled
event. An event the widget does not handle goes on to its parent.Source§fn accepts_focus(&self) -> bool
fn accepts_focus(&self) -> bool
Source§fn accessibility(&self, cx: &PaintCx<'_>, node: &mut AccessNode)
fn accessibility(&self, cx: &PaintCx<'_>, node: &mut AccessNode)
node, which starts as a
Role::Group with the widget’s rectangle. Called only while
assistive technology is listening; it may allocate.Source§fn access_action(
&mut self,
cx: &mut EventCx<'_>,
request: &AccessRequest<'_>,
) -> Handled
fn access_action( &mut self, cx: &mut EventCx<'_>, request: &AccessRequest<'_>, ) -> Handled
Source§fn measure(&mut self, cx: &mut LayoutCx<'_>, constraints: Constraints) -> Size
fn measure(&mut self, cx: &mut LayoutCx<'_>, constraints: Constraints) -> Size
constraints, for a widget without children (one
with children is sized by its style and its children). Physical pixels.