2022-03-31 19:13:25 +00:00
|
|
|
use egui_extras::{Size, StripBuilder, TableBuilder};
|
|
|
|
|
|
|
|
/// Shows off a table with dynamic layout
|
|
|
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct TableDemo {
|
|
|
|
virtual_scroll: bool,
|
2022-04-01 10:01:00 +00:00
|
|
|
resizable: bool,
|
2022-03-31 19:13:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl super::Demo for TableDemo {
|
|
|
|
fn name(&self) -> &'static str {
|
|
|
|
"☰ Table Demo"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn show(&mut self, ctx: &egui::Context, open: &mut bool) {
|
|
|
|
egui::Window::new(self.name())
|
|
|
|
.open(open)
|
|
|
|
.resizable(true)
|
|
|
|
.default_width(400.0)
|
|
|
|
.show(ctx, |ui| {
|
|
|
|
use super::View as _;
|
|
|
|
self.ui(ui);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl super::View for TableDemo {
|
|
|
|
fn ui(&mut self, ui: &mut egui::Ui) {
|
2022-04-01 10:01:00 +00:00
|
|
|
ui.checkbox(&mut self.virtual_scroll, "Virtual scroll");
|
|
|
|
ui.checkbox(&mut self.resizable, "Resizable columns");
|
2022-03-31 19:13:25 +00:00
|
|
|
|
|
|
|
// Leave room for the source code link after the table demo:
|
|
|
|
StripBuilder::new(ui)
|
2022-04-01 10:01:00 +00:00
|
|
|
.size(Size::remainder()) // for the table
|
|
|
|
.size(Size::exact(10.0)) // for the source code link
|
2022-03-31 19:13:25 +00:00
|
|
|
.vertical(|mut strip| {
|
|
|
|
strip.cell_clip(|ui| {
|
|
|
|
self.table_ui(ui);
|
|
|
|
});
|
|
|
|
strip.cell(|ui| {
|
|
|
|
ui.vertical_centered(|ui| {
|
|
|
|
ui.add(crate::__egui_github_link_file!());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TableDemo {
|
|
|
|
fn table_ui(&mut self, ui: &mut egui::Ui) {
|
|
|
|
TableBuilder::new(ui)
|
|
|
|
.striped(true)
|
2022-04-01 10:01:00 +00:00
|
|
|
.column(Size::initial(60.0).at_least(40.0))
|
|
|
|
.column(Size::remainder().at_least(60.0))
|
|
|
|
.column(Size::initial(60.0).at_least(40.0))
|
|
|
|
.resizable(self.resizable)
|
2022-03-31 19:13:25 +00:00
|
|
|
.header(20.0, |mut header| {
|
2022-04-01 10:01:00 +00:00
|
|
|
header.col_clip(|ui| {
|
2022-03-31 19:13:25 +00:00
|
|
|
ui.heading("Left");
|
|
|
|
});
|
2022-04-01 10:01:00 +00:00
|
|
|
header.col_clip(|ui| {
|
2022-03-31 19:13:25 +00:00
|
|
|
ui.heading("Middle");
|
|
|
|
});
|
2022-04-01 10:01:00 +00:00
|
|
|
header.col_clip(|ui| {
|
2022-03-31 19:13:25 +00:00
|
|
|
ui.heading("Right");
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.body(|mut body| {
|
|
|
|
if self.virtual_scroll {
|
|
|
|
body.rows(20.0, 100_000, |index, mut row| {
|
2022-04-01 10:01:00 +00:00
|
|
|
row.col_clip(|ui| {
|
2022-03-31 19:13:25 +00:00
|
|
|
ui.label(index.to_string());
|
|
|
|
});
|
|
|
|
row.col_clip(|ui| {
|
|
|
|
ui.add(
|
|
|
|
egui::Label::new("virtual scroll, easily with thousands of rows!")
|
|
|
|
.wrap(false),
|
|
|
|
);
|
|
|
|
});
|
2022-04-01 10:01:00 +00:00
|
|
|
row.col_clip(|ui| {
|
2022-03-31 19:13:25 +00:00
|
|
|
ui.label(index.to_string());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
2022-04-01 10:01:00 +00:00
|
|
|
for i in 0..20 {
|
|
|
|
let thick = i % 4 == 0;
|
|
|
|
let height = if thick { 25.0 } else { 15.0 };
|
2022-03-31 19:13:25 +00:00
|
|
|
body.row(height, |mut row| {
|
2022-04-01 10:01:00 +00:00
|
|
|
row.col_clip(|ui| {
|
2022-03-31 19:13:25 +00:00
|
|
|
ui.label(i.to_string());
|
|
|
|
});
|
|
|
|
row.col_clip(|ui| {
|
2022-04-01 10:01:00 +00:00
|
|
|
ui.style_mut().wrap = Some(false);
|
|
|
|
if thick {
|
|
|
|
ui.heading("Extra thick row");
|
|
|
|
} else {
|
|
|
|
ui.label("Normal row");
|
|
|
|
}
|
2022-03-31 19:13:25 +00:00
|
|
|
});
|
2022-04-01 10:01:00 +00:00
|
|
|
row.col_clip(|ui| {
|
2022-03-31 19:13:25 +00:00
|
|
|
ui.label(i.to_string());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|