diff --git a/egui/src/grid.rs b/egui/src/grid.rs index 2d8f47e496ed..c550df8f2519 100644 --- a/egui/src/grid.rs +++ b/egui/src/grid.rs @@ -297,10 +297,10 @@ impl GridLayout { } /// Paint the background for the next row & columns. - pub(crate) fn do_paint(&mut self, min: Pos2, painter: &Painter) { + pub(crate) fn paint(&mut self, cursor_min: Pos2, painter: &Painter) { for p in &self.color_spec.row_pickers { if let Some(color) = p(self.row) { - self.paint_row(min, color, painter) + self.paint_row(cursor_min, color, painter) } } // Only paint columns when we're on the first row. @@ -310,7 +310,7 @@ impl GridLayout { // Iterate over columns for col in 0..self.prev_state.dimensions().y { if let Some(color) = p(col) { - self.paint_column(col, min, color, painter); + self.paint_column(col, cursor_min, color, painter); } } } @@ -325,7 +325,7 @@ impl GridLayout { self.col = 0; self.row += 1; - self.do_paint(cursor.min, painter); + self.paint(cursor.min, painter); } pub(crate) fn save(&self) { @@ -369,7 +369,7 @@ impl GridLayout { #[must_use = "You should call .show()"] pub struct Grid { id_source: Id, - striped: bool, + row_stripes: bool, header_row: bool, min_col_width: Option, min_row_height: Option, @@ -384,7 +384,7 @@ impl Grid { pub fn new(id_source: impl std::hash::Hash) -> Self { Self { id_source: Id::new(id_source), - striped: false, + row_stripes: false, header_row: false, min_col_width: None, min_row_height: None, @@ -395,24 +395,12 @@ impl Grid { } } - /// Replace the color picker for columns - pub fn with_column_color(mut self, predicate: ColorPickerFn) -> Self { - self.color_spec.col_pickers = vec![predicate]; - self - } - /// Add a `ColorPickerFn` to the color spec without overwriting existing column colors. pub fn add_column_color(mut self, predicate: ColorPickerFn) -> Self { self.color_spec.col_pickers.push(predicate); self } - /// Replace the color picker for rows - pub fn with_row_color(mut self, predicate: ColorPickerFn) -> Self { - self.color_spec.row_pickers = vec![predicate]; - self - } - /// Add a `ColorPickerFn` to the color spec without overwriting existing row colors. pub fn add_row_color(mut self, predicate: ColorPickerFn) -> Self { self.color_spec.row_pickers.push(predicate); @@ -423,11 +411,13 @@ impl Grid { /// /// This can make a table easier to read. /// Default: `false`. - pub fn striped(mut self, striped: bool) -> Self { - self.striped = striped; + pub fn striped(mut self, row_stripes: bool) -> Self { + self.row_stripes = row_stripes; self } + /// If `true`, adds a contrasting color to the first row. + /// Default: `false`. pub fn header_row(mut self, header_row: bool) -> Self { self.header_row = header_row; self @@ -472,7 +462,7 @@ impl Grid { pub fn show(self, ui: &mut Ui, add_contents: impl FnOnce(&mut Ui) -> R) -> InnerResponse { let Self { id_source, - striped, + row_stripes: striped, header_row, min_col_width, min_row_height, diff --git a/egui/src/placer.rs b/egui/src/placer.rs index dfcf00c14bb1..668f6cfa189c 100644 --- a/egui/src/placer.rs +++ b/egui/src/placer.rs @@ -180,7 +180,7 @@ impl Placer { pub(crate) fn start_row(&mut self, painter: &Painter) { if let Some(grid) = &mut self.grid { - grid.do_paint(self.region.cursor.min, painter) + grid.paint(self.region.cursor.min, painter) } } diff --git a/egui_demo_lib/src/apps/demo/demo_app_windows.rs b/egui_demo_lib/src/apps/demo/demo_app_windows.rs index 4e10cd156f37..47ec158df614 100644 --- a/egui_demo_lib/src/apps/demo/demo_app_windows.rs +++ b/egui_demo_lib/src/apps/demo/demo_app_windows.rs @@ -78,11 +78,11 @@ impl Default for Tests { fn default() -> Self { Self::from_demos(vec![ Box::new(super::tests::CursorTest::default()), + Box::new(super::tests::GridTest::default()), Box::new(super::tests::IdTest::default()), Box::new(super::tests::InputTest::default()), Box::new(super::layout_test::LayoutTest::default()), Box::new(super::tests::ManualLayoutTest::default()), - Box::new(super::tests::GridTest::default()), ]) } } diff --git a/egui_demo_lib/src/apps/demo/tests.rs b/egui_demo_lib/src/apps/demo/tests.rs index 5aa575739a23..05f24ee06a8e 100644 --- a/egui_demo_lib/src/apps/demo/tests.rs +++ b/egui_demo_lib/src/apps/demo/tests.rs @@ -1,5 +1,3 @@ -use egui::Rgba; - #[derive(Default)] pub struct CursorTest {} @@ -215,14 +213,16 @@ impl super::Demo for GridTest { impl super::View for GridTest { fn ui(&mut self, ui: &mut egui::Ui) { + use egui::Rgba; + ui.add( egui::Slider::new(&mut self.min_col_width, 0.0..=400.0).text("Minimum column width"), ); ui.add( egui::Slider::new(&mut self.max_col_width, 0.0..=400.0).text("Maximum column width"), ); - ui.add(egui::Slider::new(&mut self.num_cols, 0..=8).text("Columns")); - ui.add(egui::Slider::new(&mut self.num_rows, 0..=20).text("Rows")); + ui.add(egui::Slider::new(&mut self.num_cols, 0..=8).text("Column stripes")); + ui.add(egui::Slider::new(&mut self.num_rows, 0..=20).text("Row stripes")); ui.horizontal(|ui| { ui.add(egui::Checkbox::new(&mut self.striped, "Striped"));