Clean up demo code
This commit is contained in:
parent
d9eac765dc
commit
b2124f4cd1
1 changed files with 63 additions and 61 deletions
|
@ -1,4 +1,3 @@
|
||||||
use egui::{Label, Vec2};
|
|
||||||
use egui_extras::{Size, StripBuilder, TableBuilder};
|
use egui_extras::{Size, StripBuilder, TableBuilder};
|
||||||
|
|
||||||
/// Shows off a table with dynamic layout
|
/// Shows off a table with dynamic layout
|
||||||
|
@ -29,79 +28,82 @@ 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_scroll, "Virtual scroll demo");
|
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
|
// Leave room for the source code link after the table demo:
|
||||||
ui.spacing_mut().item_spacing = Vec2::splat(4.0);
|
|
||||||
StripBuilder::new(ui)
|
StripBuilder::new(ui)
|
||||||
.size(Size::Remainder)
|
.size(Size::Remainder) // for the table
|
||||||
.size(Size::Absolute(10.0))
|
.size(Size::Absolute(10.0)) // for the source code link
|
||||||
.vertical(|mut grid| {
|
.vertical(|mut strip| {
|
||||||
grid.cell_clip(|ui| {
|
strip.cell_clip(|ui| {
|
||||||
ui.spacing_mut().item_spacing = Vec2::splat(3.0);
|
self.table_ui(ui);
|
||||||
|
});
|
||||||
|
strip.cell(|ui| {
|
||||||
|
ui.vertical_centered(|ui| {
|
||||||
|
ui.add(crate::__egui_github_link_file!());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TableBuilder::new(ui)
|
impl TableDemo {
|
||||||
.striped(true)
|
fn table_ui(&mut self, ui: &mut egui::Ui) {
|
||||||
.column(Size::Absolute(120.0))
|
TableBuilder::new(ui)
|
||||||
.column(Size::RemainderMinimum(180.0))
|
.striped(true)
|
||||||
.column(Size::Absolute(100.0))
|
.column(Size::Absolute(120.0))
|
||||||
.header(20.0, |mut header| {
|
.column(Size::RemainderMinimum(180.0))
|
||||||
header.col(|ui| {
|
.column(Size::Absolute(100.0))
|
||||||
ui.heading("Left");
|
.header(20.0, |mut header| {
|
||||||
|
header.col(|ui| {
|
||||||
|
ui.heading("Left");
|
||||||
|
});
|
||||||
|
header.col(|ui| {
|
||||||
|
ui.heading("Middle");
|
||||||
|
});
|
||||||
|
header.col(|ui| {
|
||||||
|
ui.heading("Right");
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.body(|mut body| {
|
||||||
|
if self.virtual_scroll {
|
||||||
|
body.rows(20.0, 100_000, |index, mut row| {
|
||||||
|
row.col(|ui| {
|
||||||
|
ui.label(index.to_string());
|
||||||
|
});
|
||||||
|
row.col_clip(|ui| {
|
||||||
|
ui.add(
|
||||||
|
egui::Label::new("virtual scroll, easily with thousands of rows!")
|
||||||
|
.wrap(false),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
row.col(|ui| {
|
||||||
|
ui.label(index.to_string());
|
||||||
|
});
|
||||||
});
|
});
|
||||||
header.col(|ui| {
|
} else {
|
||||||
ui.heading("Middle");
|
for i in 0..100 {
|
||||||
});
|
let height = match i % 8 {
|
||||||
header.col(|ui| {
|
0 => 25.0,
|
||||||
ui.heading("Right");
|
4 => 30.0,
|
||||||
});
|
_ => 20.0,
|
||||||
})
|
};
|
||||||
.body(|mut body| {
|
body.row(height, |mut row| {
|
||||||
if self.virtual_scroll {
|
|
||||||
body.rows(20.0, 100_000, |index, mut row| {
|
|
||||||
row.col(|ui| {
|
row.col(|ui| {
|
||||||
ui.label(index.to_string());
|
ui.label(i.to_string());
|
||||||
});
|
});
|
||||||
row.col_clip(|ui| {
|
row.col_clip(|ui| {
|
||||||
ui.add(
|
ui.add(
|
||||||
Label::new("virtual scroll, easily with thousands of rows!")
|
egui::Label::new(
|
||||||
.wrap(false),
|
format!("Normal scroll, each row can have a different height. Height: {}", height),
|
||||||
|
)
|
||||||
|
.wrap(false),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
row.col(|ui| {
|
row.col(|ui| {
|
||||||
ui.label(index.to_string());
|
ui.label(i.to_string());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
for i in 0..100 {
|
|
||||||
let height = match i % 8 {
|
|
||||||
0 => 25.0,
|
|
||||||
4 => 30.0,
|
|
||||||
_ => 20.0,
|
|
||||||
};
|
|
||||||
body.row(height, |mut row| {
|
|
||||||
row.col(|ui| {
|
|
||||||
ui.label(i.to_string());
|
|
||||||
});
|
|
||||||
row.col_clip(|ui| {
|
|
||||||
ui.add(
|
|
||||||
Label::new(
|
|
||||||
format!("Normal scroll, each row can have a different height. Height: {}", height),
|
|
||||||
)
|
|
||||||
.wrap(false),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
row.col(|ui| {
|
|
||||||
ui.label(i.to_string());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
grid.cell(|ui| {
|
|
||||||
ui.vertical_centered(|ui| {
|
|
||||||
ui.add(crate::__egui_github_link_file!());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue