add virtual scroll demo
This commit is contained in:
parent
e00c726bff
commit
31d8cbb2c0
1 changed files with 41 additions and 10 deletions
|
@ -1,10 +1,12 @@
|
||||||
use egui::RichText;
|
use egui::{Label, RichText};
|
||||||
use egui_dynamic_grid::{Padding, Size, TableBuilder};
|
use egui_dynamic_grid::{Padding, Size, TableBuilder};
|
||||||
|
|
||||||
/// Shows off a table with dynamic layout
|
/// Shows off a table with dynamic layout
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct TableDemo {}
|
pub struct TableDemo {
|
||||||
|
virtual_scrool: bool,
|
||||||
|
}
|
||||||
|
|
||||||
impl super::Demo for TableDemo {
|
impl super::Demo for TableDemo {
|
||||||
fn name(&self) -> &'static str {
|
fn name(&self) -> &'static str {
|
||||||
|
@ -15,7 +17,7 @@ impl super::Demo for TableDemo {
|
||||||
egui::Window::new(self.name())
|
egui::Window::new(self.name())
|
||||||
.open(open)
|
.open(open)
|
||||||
.resizable(true)
|
.resizable(true)
|
||||||
.default_width(300.0)
|
.default_width(400.0)
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
use super::View as _;
|
use super::View as _;
|
||||||
self.ui(ui);
|
self.ui(ui);
|
||||||
|
@ -25,12 +27,14 @@ impl super::Demo for TableDemo {
|
||||||
|
|
||||||
impl super::View for TableDemo {
|
impl super::View for TableDemo {
|
||||||
fn ui(&mut self, ui: &mut egui::Ui) {
|
fn ui(&mut self, ui: &mut egui::Ui) {
|
||||||
|
ui.checkbox(&mut self.virtual_scrool, "Virtual scroll demo");
|
||||||
|
|
||||||
// TODO: Fix table as a padding smaller than 16 grows the window
|
// TODO: Fix table as a padding smaller than 16 grows the window
|
||||||
TableBuilder::new(ui, Padding::new(3.0, 16.0))
|
TableBuilder::new(ui, Padding::new(3.0, 16.0))
|
||||||
.striped(true)
|
.striped(true)
|
||||||
|
.column(Size::Absolute(120.0))
|
||||||
|
.column(Size::RemainderMinimum(180.0))
|
||||||
.column(Size::Absolute(100.0))
|
.column(Size::Absolute(100.0))
|
||||||
.column(Size::RemainderMinimum(150.0))
|
|
||||||
.column(Size::Absolute(50.0))
|
|
||||||
.header(20.0, |mut header| {
|
.header(20.0, |mut header| {
|
||||||
header.col(|ui| {
|
header.col(|ui| {
|
||||||
ui.label(RichText::new("Left").heading());
|
ui.label(RichText::new("Left").heading());
|
||||||
|
@ -43,19 +47,46 @@ impl super::View for TableDemo {
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.body(|mut body| {
|
.body(|mut body| {
|
||||||
|
if self.virtual_scrool {
|
||||||
|
body.rows(20.0, 100_000, |index, mut row| {
|
||||||
|
row.col(|ui| {
|
||||||
|
ui.label(format!("{}", index));
|
||||||
|
});
|
||||||
|
row.col(|ui| {
|
||||||
|
ui.add(
|
||||||
|
Label::new("virtual scroll, easily with thousands of rows!")
|
||||||
|
.wrap(false),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
row.col(|ui| {
|
||||||
|
ui.label(format!("{}", index));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
for i in 0..100 {
|
for i in 0..100 {
|
||||||
body.row(20.0, |mut row| {
|
let height = match i % 8 {
|
||||||
|
0 => 25.0,
|
||||||
|
4 => 30.0,
|
||||||
|
_ => 20.0,
|
||||||
|
};
|
||||||
|
body.row(height, |mut row| {
|
||||||
row.col(|ui| {
|
row.col(|ui| {
|
||||||
ui.label(format!("{}", i));
|
ui.label(format!("{}", i));
|
||||||
});
|
});
|
||||||
row.col(|ui| {
|
row.col(|ui| {
|
||||||
ui.label(format!("{}", i));
|
ui.add(
|
||||||
|
Label::new(
|
||||||
|
format!("Normal scroll, each row can have a different height. Height: {}", height),
|
||||||
|
)
|
||||||
|
.wrap(false),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
row.col(|ui| {
|
row.col(|ui| {
|
||||||
ui.label(format!("{}", i));
|
ui.label(format!("{}", i));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue