From b476ab277a03b1fa87221defcd9489fba43ed89d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Thu, 21 Aug 2025 23:06:07 +0200 Subject: [PATCH] Remove `debug_assert!` from `scrollable` by enforcing compression --- widget/src/scrollable.rs | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index 0b0b6f9b..9c4748ea 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -111,22 +111,12 @@ where class: Theme::default(), last_status: None, } - .validate() + .enclose() } - fn validate(mut self) -> Self { + fn enclose(mut self) -> Self { let size_hint = self.content.as_widget().size_hint(); - debug_assert!( - self.direction.vertical().is_none() || !size_hint.height.is_fill(), - "scrollable content must not fill its vertical scrolling axis" - ); - - debug_assert!( - self.direction.horizontal().is_none() || !size_hint.width.is_fill(), - "scrollable content must not fill its horizontal scrolling axis" - ); - if self.direction.horizontal().is_none() { self.width = self.width.enclose(size_hint.width); } @@ -146,7 +136,7 @@ where /// Sets the [`Direction`] of the [`Scrollable`]. pub fn direction(mut self, direction: impl Into) -> Self { self.direction = direction.into(); - self.validate() + self.enclose() } /// Sets the [`Id`] of the [`Scrollable`]. @@ -437,20 +427,24 @@ where ..Padding::ZERO }, |limits| { - let child_limits = layout::Limits::new( + let is_horizontal = self.direction.horizontal().is_some(); + let is_vertical = self.direction.vertical().is_some(); + + let child_limits = layout::Limits::with_compression( limits.min(), Size::new( - if self.direction.horizontal().is_some() { + if is_horizontal { f32::INFINITY } else { limits.max().width }, - if self.direction.vertical().is_some() { + if is_vertical { f32::INFINITY } else { limits.max().height }, ), + Size::new(is_horizontal, is_vertical), ); self.content.as_widget_mut().layout(