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.
This commit is contained in:
Michael Grupp 2025-08-05 14:43:02 +02:00 committed by GitHub
parent 8333615072
commit a1e5501db8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 0 deletions

View File

@ -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(),

View File

@ -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());
}