diff --git a/egui/src/grid.rs b/egui/src/grid.rs index 3f54a4fd..ae22a6b8 100644 --- a/egui/src/grid.rs +++ b/egui/src/grid.rs @@ -174,6 +174,7 @@ pub struct Grid { id_source: Id, striped: bool, min_row_height: Option, + spacing: Option, } impl Grid { @@ -182,6 +183,7 @@ impl Grid { id_source: Id::new(id_source), striped: false, min_row_height: None, + spacing: None, } } @@ -199,6 +201,13 @@ impl Grid { self.min_row_height = Some(min_row_height); self } + + /// Set spacing between columns/rows. + /// Default: [`Spacing::item_spacing`]. + pub fn spacing(mut self, spacing: impl Into) -> Self { + self.spacing = Some(spacing.into()); + self + } } impl Grid { @@ -207,8 +216,10 @@ impl Grid { id_source, striped, min_row_height, + spacing, } = self; let min_row_height = min_row_height.unwrap_or_else(|| ui.style().spacing.interact_size.y); + let spacing = spacing.unwrap_or_else(|| ui.style().spacing.item_spacing); // Each grid cell is aligned LEFT_CENTER. // If somebody wants to wrap more things inside a cell, @@ -219,6 +230,7 @@ impl Grid { let grid = GridLayout { striped, min_row_height, + spacing, ..GridLayout::new(ui, id) }; ui.set_grid(grid); diff --git a/egui_demo_lib/src/apps/demo/widget_gallery.rs b/egui_demo_lib/src/apps/demo/widget_gallery.rs index 32cd6bc2..8312fdc3 100644 --- a/egui_demo_lib/src/apps/demo/widget_gallery.rs +++ b/egui_demo_lib/src/apps/demo/widget_gallery.rs @@ -54,7 +54,9 @@ impl super::View for WidgetGallery { color, } = self; - let grid = egui::Grid::new("my_grid").striped(true); + let grid = egui::Grid::new("my_grid") + .striped(true) + .spacing([40.0, 4.0]); grid.show(ui, |ui| { ui.label("Label:"); ui.label("Welcome to the widget gallery!"); @@ -138,7 +140,7 @@ impl super::View for WidgetGallery { ui.collapsing("Click to see what is hidden!", |ui| { ui.horizontal_wrapped_for_text(egui::TextStyle::Body, |ui| { ui.label( - "Not much, as it turns out, but here is a gold star for you for checking:", + "Not much, as it turns out - but here is a gold star for you for checking:", ); ui.colored_label(egui::Color32::GOLD, "☆"); });