diff --git a/egui_demo_lib/src/apps/demo/grid_demo.rs b/egui_demo_lib/src/apps/demo/grid_demo.rs index c39aaa71..85154209 100644 --- a/egui_demo_lib/src/apps/demo/grid_demo.rs +++ b/egui_demo_lib/src/apps/demo/grid_demo.rs @@ -32,6 +32,7 @@ impl super::View for GridDemo { relative: 0.5, minimum: 60.0, }) + .size(Size::Absolute(14.0)) .vertical(|mut grid| { grid.cell(|ui| { ui.painter() @@ -99,6 +100,11 @@ impl super::View for GridDemo { }); }); }); + grid.cell(|ui| { + ui.vertical_centered(|ui| { + ui.add(crate::__egui_github_link_file!()); + }); + }); }); } } diff --git a/egui_demo_lib/src/apps/demo/table_demo.rs b/egui_demo_lib/src/apps/demo/table_demo.rs index 58c3792e..2be5921a 100644 --- a/egui_demo_lib/src/apps/demo/table_demo.rs +++ b/egui_demo_lib/src/apps/demo/table_demo.rs @@ -1,5 +1,5 @@ use egui::{Label, RichText}; -use egui_extras::{Padding, Size, TableBuilder}; +use egui_extras::{GridBuilder, Padding, Size, TableBuilder}; /// Shows off a table with dynamic layout #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] @@ -29,64 +29,77 @@ impl super::View for TableDemo { 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 - TableBuilder::new(ui, Padding::new(3.0, 16.0)) - .striped(true) - .column(Size::Absolute(120.0)) - .column(Size::RemainderMinimum(180.0)) - .column(Size::Absolute(100.0)) - .header(20.0, |mut header| { - header.col(|ui| { - ui.label(RichText::new("Left").heading()); - }); - header.col(|ui| { - ui.label(RichText::new("Middle").heading()); - }); - header.col(|ui| { - ui.label(RichText::new("Right").heading()); - }); - }) - .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)); - }); + // The table is inside a grid as its container would otherwise grow slowly as it takes all available height + GridBuilder::new(ui, Padding::new(0.0, 0.0)) + .size(Size::Remainder) + .size(Size::Absolute(14.0)) + .vertical(|mut grid| { + grid.cell(|ui| { + // TODO: Fix table as a padding smaller than 16 grows the window + TableBuilder::new(ui, Padding::new(3.0, 16.0)) + .striped(true) + .column(Size::Absolute(120.0)) + .column(Size::RemainderMinimum(180.0)) + .column(Size::Absolute(100.0)) + .header(20.0, |mut header| { + header.col(|ui| { + ui.label(RichText::new("Left").heading()); }); - } else { - for i in 0..100 { - let height = match i % 8 { - 0 => 25.0, - 4 => 30.0, - _ => 20.0, - }; - body.row(height, |mut row| { + header.col(|ui| { + ui.label(RichText::new("Middle").heading()); + }); + header.col(|ui| { + ui.label(RichText::new("Right").heading()); + }); + }) + .body(|mut body| { + if self.virtual_scrool { + body.rows(20.0, 100_000, |index, mut row| { row.col(|ui| { - ui.label(format!("{}", i)); + ui.label(format!("{}", index)); }); row.col(|ui| { ui.add( - Label::new( - format!("Normal scroll, each row can have a different height. Height: {}", height), - ) - .wrap(false), + Label::new("virtual scroll, easily with thousands of rows!") + .wrap(false), ); }); row.col(|ui| { - ui.label(format!("{}", i)); + ui.label(format!("{}", index)); }); }); + } 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(format!("{}", i)); + }); + row.col(|ui| { + ui.add( + Label::new( + format!("Normal scroll, each row can have a different height. Height: {}", height), + ) + .wrap(false), + ); + }); + row.col(|ui| { + ui.label(format!("{}", i)); + }); + }); + } } - } + }); }); + grid.cell(|ui| { + ui.vertical_centered(|ui| { + ui.add(crate::__egui_github_link_file!()); + }); + }); + }); } } diff --git a/egui_extras/src/grid.rs b/egui_extras/src/grid.rs index 1635c543..c4c91c64 100644 --- a/egui_extras/src/grid.rs +++ b/egui_extras/src/grid.rs @@ -44,6 +44,7 @@ impl<'a> GridBuilder<'a> { } /// Build horizontal grid + /// Takes the available horizontal width, so there can't be anything right of the grid or the container will grow slowly! pub fn horizontal(self, grid: F) where F: for<'b> FnOnce(Grid<'a, 'b>), @@ -62,6 +63,7 @@ impl<'a> GridBuilder<'a> { } /// Build vertical grid + /// Takes the full available vertical height, so there can't be anything below of the grid or the container will grow slowly! pub fn vertical(self, grid: F) where F: for<'b> FnOnce(Grid<'a, 'b>), diff --git a/egui_extras/src/table.rs b/egui_extras/src/table.rs index 8a35c1b7..a6078d15 100644 --- a/egui_extras/src/table.rs +++ b/egui_extras/src/table.rs @@ -1,6 +1,7 @@ /// Table view with (optional) fixed header and scrolling body. /// Cell widths are precalculated with given size hints so we can have tables like this: /// | fixed size | all available space/minimum | 30% of available width | fixed size | +/// Takes all available height, so if you want something below the table, put it in a grid. use crate::{ layout::{CellSize, LineDirection}, sizing::Sizing,