From a1e5501db8902aa08d8462abf5ed3e0ac95889c5 Mon Sep 17 00:00:00 2001 From: Michael Grupp Date: Tue, 5 Aug 2025 14:43:02 +0200 Subject: [PATCH] Improve `debug_assert` when calling `add_space()` in `Grid` layout (#7399) Makes it clearer to understand than the lower-level `advance_cursor` assert for an user who accidentally does this. --- crates/egui/src/placer.rs | 2 ++ crates/egui/src/ui.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/crates/egui/src/placer.rs b/crates/egui/src/placer.rs index a56bcdb2..b5f68f72 100644 --- a/crates/egui/src/placer.rs +++ b/crates/egui/src/placer.rs @@ -145,6 +145,8 @@ impl Placer { /// Advance the cursor by this many points. /// [`Self::min_rect`] will expand to contain the cursor. + /// + /// Note that `advance_cursor` isn't supported when in a grid layout. pub(crate) fn advance_cursor(&mut self, amount: f32) { debug_assert!( self.grid.is_none(), diff --git a/crates/egui/src/ui.rs b/crates/egui/src/ui.rs index 56392156..5586734b 100644 --- a/crates/egui/src/ui.rs +++ b/crates/egui/src/ui.rs @@ -1877,6 +1877,7 @@ impl Ui { /// Add extra space before the next widget. /// /// The direction is dependent on the layout. + /// Note that `add_space` isn't supported when in a grid layout. /// /// This will be in addition to the [`crate::style::Spacing::item_spacing`] /// that is always added, but `item_spacing` won't be added _again_ by `add_space`. @@ -1884,6 +1885,7 @@ impl Ui { /// [`Self::min_rect`] will expand to contain the space. #[inline] pub fn add_space(&mut self, amount: f32) { + debug_assert!(!self.is_grid(), "add_space makes no sense in a grid layout"); self.placer.advance_cursor(amount.round_ui()); }