Data table UI implementation for egui
MSRV is 1.75, with RPITIT
Demo Web Page
Features
Usage
In Cargo.toml
, add egui-data-table
to your dependencies section
[dependencies]
egui-data-table = "0.1"
Minimal example:
use egui_data_table::egui;
struct MyRowData(i32, String, bool);
struct MyRowViewer;
impl egui_data_table::RowViewer<MyRowData> for MyRowViewer {
fn num_columns(&mut self) -> usize {
3
}
fn show_cell_view(&mut self, ui: &mut egui::Ui, row: &MyRowData, column: usize) {
let _ = match column {
0 => ui.label(format!("{}", row.0)),
1 => ui.label(&row.1),
2 => ui.checkbox(&mut { row.2 }, ""),
_ => unreachable!()
};
}
fn show_cell_editor(
&mut self,
ui: &mut egui::Ui,
row: &mut MyRowData,
column: usize,
) -> Option<egui::Response> {
match column {
0 => ui.add(egui::DragValue::new(&mut row.0).speed(1.0)),
1 => {
egui::TextEdit::multiline(&mut row.1)
.desired_rows(1)
.code_editor()
.show(ui)
.response
}
2 => ui.checkbox(&mut row.2, ""),
_ => unreachable!()
}
.into() }
fn set_cell_value(&mut self, src: &MyRowData, dst: &mut MyRowData, column: usize) {
match column {
0 => dst.0 = src.0,
1 => dst.1 = src.1.clone(),
2 => dst.2 = src.2,
_ => unreachable!()
}
}
fn new_empty_row(&mut self) -> MyRowData {
MyRowData(0, Default::default(), false)
}
}
fn show(ui: &mut egui::Ui, table: &mut egui_data_table::DataTable<MyRowData>) {
ui.add(egui_data_table::Renderer::new(
table,
&mut { MyRowViewer },
));
}
For more details / advanced usage, see demo