Simplify table demo
This commit is contained in:
parent
a17519fb34
commit
ea5941c3a1
1 changed files with 29 additions and 30 deletions
|
@ -3,7 +3,6 @@ use egui_extras::{Size, StripBuilder, TableBuilder, TableRow};
|
||||||
|
|
||||||
/// 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)]
|
|
||||||
pub struct TableDemo {
|
pub struct TableDemo {
|
||||||
heterogeneous_rows: bool,
|
heterogeneous_rows: bool,
|
||||||
virtual_scroll: bool,
|
virtual_scroll: bool,
|
||||||
|
@ -11,6 +10,17 @@ pub struct TableDemo {
|
||||||
num_rows: usize,
|
num_rows: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for TableDemo {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
heterogeneous_rows: true,
|
||||||
|
virtual_scroll: false,
|
||||||
|
resizable: true,
|
||||||
|
num_rows: 100,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl super::Demo for TableDemo {
|
impl super::Demo for TableDemo {
|
||||||
fn name(&self) -> &'static str {
|
fn name(&self) -> &'static str {
|
||||||
"☰ Table Demo"
|
"☰ Table Demo"
|
||||||
|
@ -30,40 +40,29 @@ 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) {
|
||||||
let mut settings_height = 44.0;
|
ui.horizontal(|ui| {
|
||||||
if self.virtual_scroll {
|
ui.vertical(|ui| {
|
||||||
settings_height = 66.0;
|
ui.checkbox(&mut self.resizable, "Resizable columns");
|
||||||
} else {
|
ui.checkbox(&mut self.virtual_scroll, "Virtual Scroll");
|
||||||
self.heterogeneous_rows = false
|
if self.virtual_scroll {
|
||||||
}
|
ui.checkbox(&mut self.heterogeneous_rows, "Heterogeneous row heights");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if self.virtual_scroll {
|
||||||
|
ui.add(
|
||||||
|
egui::Slider::new(&mut self.num_rows, 0..=100_000)
|
||||||
|
.logarithmic(true)
|
||||||
|
.text("Num rows"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Leave room for the source code link after the table demo:
|
// Leave room for the source code link after the table demo:
|
||||||
StripBuilder::new(ui)
|
StripBuilder::new(ui)
|
||||||
.size(Size::exact(settings_height)) // for the settings
|
|
||||||
.size(Size::remainder()) // for the table
|
.size(Size::remainder()) // for the table
|
||||||
.size(Size::exact(10.0)) // for the source code link
|
.size(Size::exact(10.0)) // for the source code link
|
||||||
.vertical(|mut strip| {
|
.vertical(|mut strip| {
|
||||||
strip.cell(|ui| {
|
|
||||||
StripBuilder::new(ui)
|
|
||||||
.size(Size::exact(150.0))
|
|
||||||
.size(Size::remainder())
|
|
||||||
.horizontal(|mut strip| {
|
|
||||||
strip.cell(|ui| {
|
|
||||||
ui.checkbox(&mut self.virtual_scroll, "Virtual Scroll");
|
|
||||||
if self.virtual_scroll {
|
|
||||||
ui.checkbox(&mut self.heterogeneous_rows, "Heterogeneous rows");
|
|
||||||
}
|
|
||||||
ui.checkbox(&mut self.resizable, "Resizable columns");
|
|
||||||
});
|
|
||||||
if self.virtual_scroll {
|
|
||||||
strip.cell(|ui| {
|
|
||||||
ui.add(
|
|
||||||
egui::Slider::new(&mut self.num_rows, 0..=300_000)
|
|
||||||
.text("Num rows"),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
strip.cell(|ui| {
|
strip.cell(|ui| {
|
||||||
self.table_ui(ui);
|
self.table_ui(ui);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue