mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 13:20:05 -04:00
add basic table demo
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -916,6 +916,7 @@ dependencies = [
|
|||||||
"criterion",
|
"criterion",
|
||||||
"egui",
|
"egui",
|
||||||
"egui_datepicker",
|
"egui_datepicker",
|
||||||
|
"egui_dynamic_grid",
|
||||||
"ehttp",
|
"ehttp",
|
||||||
"enum-map",
|
"enum-map",
|
||||||
"epi",
|
"epi",
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ all-features = true
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
egui = { version = "0.15.0", path = "../egui", default-features = false }
|
egui = { version = "0.15.0", path = "../egui", default-features = false }
|
||||||
epi = { version = "0.15.0", path = "../epi" }
|
epi = { version = "0.15.0", path = "../epi" }
|
||||||
|
egui_dynamic_grid = { version = "0.15.0", path = "../egui_dynamic_grid" }
|
||||||
egui_datepicker = { version = "0.15.0", path = "../egui_datepicker", optional = true }
|
egui_datepicker = { version = "0.15.0", path = "../egui_datepicker", optional = true }
|
||||||
|
|
||||||
chrono = { version = "0.4", features = ["js-sys", "wasmbind"], optional = true }
|
chrono = { version = "0.4", features = ["js-sys", "wasmbind"], optional = true }
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ impl Default for Demos {
|
|||||||
Box::new(super::plot_demo::PlotDemo::default()),
|
Box::new(super::plot_demo::PlotDemo::default()),
|
||||||
Box::new(super::scrolling::Scrolling::default()),
|
Box::new(super::scrolling::Scrolling::default()),
|
||||||
Box::new(super::sliders::Sliders::default()),
|
Box::new(super::sliders::Sliders::default()),
|
||||||
|
Box::new(super::table_demo::TableDemo::default()),
|
||||||
Box::new(super::widget_gallery::WidgetGallery::default()),
|
Box::new(super::widget_gallery::WidgetGallery::default()),
|
||||||
Box::new(super::window_options::WindowOptions::default()),
|
Box::new(super::window_options::WindowOptions::default()),
|
||||||
Box::new(super::tests::WindowResizeTest::default()),
|
Box::new(super::tests::WindowResizeTest::default()),
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ pub mod password;
|
|||||||
pub mod plot_demo;
|
pub mod plot_demo;
|
||||||
pub mod scrolling;
|
pub mod scrolling;
|
||||||
pub mod sliders;
|
pub mod sliders;
|
||||||
|
pub mod table_demo;
|
||||||
pub mod tests;
|
pub mod tests;
|
||||||
pub mod toggle_switch;
|
pub mod toggle_switch;
|
||||||
pub mod widget_gallery;
|
pub mod widget_gallery;
|
||||||
|
|||||||
59
egui_demo_lib/src/apps/demo/table_demo.rs
Normal file
59
egui_demo_lib/src/apps/demo/table_demo.rs
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
use egui_dynamic_grid::{Padding, Size, TableBuilder};
|
||||||
|
|
||||||
|
/// Shows off a table with dynamic layout
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct TableDemo {}
|
||||||
|
|
||||||
|
impl super::Demo for TableDemo {
|
||||||
|
fn name(&self) -> &'static str {
|
||||||
|
"☰ Table"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn show(&mut self, ctx: &egui::CtxRef, open: &mut bool) {
|
||||||
|
egui::Window::new(self.name())
|
||||||
|
.open(open)
|
||||||
|
.resizable(true)
|
||||||
|
.default_width(300.0)
|
||||||
|
.show(ctx, |ui| {
|
||||||
|
use super::View as _;
|
||||||
|
self.ui(ui);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl super::View for TableDemo {
|
||||||
|
fn ui(&mut self, ui: &mut egui::Ui) {
|
||||||
|
TableBuilder::new(ui, Padding::new(2.0, 5.0))
|
||||||
|
.striped(true)
|
||||||
|
.column(Size::Absolute(100.0))
|
||||||
|
.column(Size::RemainderMinimum(150.0))
|
||||||
|
.column(Size::Absolute(50.0))
|
||||||
|
.header(50.0, |mut header| {
|
||||||
|
header.col(|ui| {
|
||||||
|
ui.label("Left");
|
||||||
|
});
|
||||||
|
header.col(|ui| {
|
||||||
|
ui.label("Middle");
|
||||||
|
});
|
||||||
|
header.col(|ui| {
|
||||||
|
ui.label("Right");
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.body(|mut body| {
|
||||||
|
for i in 1..100 {
|
||||||
|
body.row(40.0, |mut row| {
|
||||||
|
row.col(|ui| {
|
||||||
|
ui.label(format!("{}", i));
|
||||||
|
});
|
||||||
|
row.col(|ui| {
|
||||||
|
ui.label(format!("{}", i));
|
||||||
|
});
|
||||||
|
row.col(|ui| {
|
||||||
|
ui.label(format!("{}", i));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user