Clean up demo code

This commit is contained in:
Emil Ernerfeldt 2022-03-31 12:39:02 +02:00
parent d9eac765dc
commit b2124f4cd1

View file

@ -1,4 +1,3 @@
use egui::{Label, Vec2};
use egui_extras::{Size, StripBuilder, TableBuilder};
/// Shows off a table with dynamic layout
@ -29,15 +28,25 @@ impl super::View for TableDemo {
fn ui(&mut self, ui: &mut egui::Ui) {
ui.checkbox(&mut self.virtual_scroll, "Virtual scroll demo");
// The table is inside a grid as its container would otherwise grow slowly as it takes all available height
ui.spacing_mut().item_spacing = Vec2::splat(4.0);
// Leave room for the source code link after the table demo:
StripBuilder::new(ui)
.size(Size::Remainder)
.size(Size::Absolute(10.0))
.vertical(|mut grid| {
grid.cell_clip(|ui| {
ui.spacing_mut().item_spacing = Vec2::splat(3.0);
.size(Size::Remainder) // for the table
.size(Size::Absolute(10.0)) // for the source code link
.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)
.column(Size::Absolute(120.0))
@ -62,7 +71,7 @@ impl super::View for TableDemo {
});
row.col_clip(|ui| {
ui.add(
Label::new("virtual scroll, easily with thousands of rows!")
egui::Label::new("virtual scroll, easily with thousands of rows!")
.wrap(false),
);
});
@ -83,7 +92,7 @@ impl super::View for TableDemo {
});
row.col_clip(|ui| {
ui.add(
Label::new(
egui::Label::new(
format!("Normal scroll, each row can have a different height. Height: {}", height),
)
.wrap(false),
@ -96,12 +105,5 @@ impl super::View for TableDemo {
}
}
});
});
grid.cell(|ui| {
ui.vertical_centered(|ui| {
ui.add(crate::__egui_github_link_file!());
});
});
});
}
}