Expand description
A data table: virtualised rows, a sticky header, columns sorted and resized, cells drawn by the application.
It wraps Rerun’s egui_table (MIT OR Apache-2.0), which draws the
rows in view, the header and the resize handles, and adds what an
egui-pop view has: a selection by key with the keyboard and the
pointer, sorting from the header, and the sort and the widths kept in
the host’s value store (declare them once with declare), every
change a step (table.select, table.sort, table.resize).
Columns can be selected too (DataTable::select_columns): a header
click selects its column (Ctrl toggles it, Shift extends), the column
is tinted from its header to its last row, and the sort moves to the
header’s context menu, as in a spreadsheet. The column under the
pointer is tinted as well and said in the output
(TableOutput::hovered_column). A right click on a header opens its
menu: the sort entries, then the application’s
(DataTable::header_menu).
The application owns the rows: it sorts them as TableState::sort
(or the store) says and gives them through TableRows. An order
decided elsewhere (a sort command) is shown with
TableState::set_sort, without a store.
Enter or a double click on a row activates it (Signal::Activate);
built with DataTable::drag_out, a drag from a row carries rows out
(Signal::DragOut).
use egui_pop_views::table::{Column, DataTable, TableRows, TableState};
struct Files(Vec<(u64, String, u64)>);
impl TableRows<u64> for Files {
fn len(&self) -> usize { self.0.len() }
fn key(&self, row: usize) -> u64 { self.0[row].0 }
fn label(&self, row: usize) -> String { self.0[row].1.clone() }
fn cell(&mut self, ui: &mut egui::Ui, row: usize, column: usize, _selected: bool) {
match column {
0 => { ui.label(&self.0[row].1); }
_ => { ui.label(format!("{} KB", self.0[row].2)); }
}
}
}
fn ui(ui: &mut egui::Ui, state: &mut TableState<u64>, files: &mut Files) {
let columns = [Column::new("name", "Name").width(200.0), Column::new("size", "Size")];
let out = DataTable::new("files", &columns).show(ui, state, files);
if out.sorted {
// Sort the rows as `state.sort()` says.
}
}Re-exports§
pub use crate::list::Signal;
Structs§
- Column
- A column as declared.
- Data
Table - The data table widget.
- Sort
- A table’s order: by a column, up or down.
- Table
Output - What
DataTable::showreturns. - Table
State - A table’s state between passes.
Traits§
- Table
Rows - The rows a table shows; the application owns them, sorted as the table’s sort says.
Functions§
- column_
item - A column’s item in the application-wide selection:
column:<id>. - column_
selection - The columns selected after a header click on
column: alone, or toggled with Ctrl, or the run fromanchorwith Shift (added to the selection with Ctrl too), in the columns’ order. - declare
- Declares a table’s values in the store:
<prefix>/sort(text:name,-nameor empty) and<prefix>/widths(one per column). Call it once, from the plugin owning the table.