Remove debug_assert! from scrollable by enforcing compression

This commit is contained in:
Héctor Ramón Jiménez 2025-08-21 23:06:07 +02:00
parent 3ad578e248
commit b476ab277a
No known key found for this signature in database
GPG key ID: 7CC46565708259A7

View file

@ -111,22 +111,12 @@ where
class: Theme::default(), class: Theme::default(),
last_status: None, last_status: None,
} }
.validate() .enclose()
} }
fn validate(mut self) -> Self { fn enclose(mut self) -> Self {
let size_hint = self.content.as_widget().size_hint(); 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() { if self.direction.horizontal().is_none() {
self.width = self.width.enclose(size_hint.width); self.width = self.width.enclose(size_hint.width);
} }
@ -146,7 +136,7 @@ where
/// Sets the [`Direction`] of the [`Scrollable`]. /// Sets the [`Direction`] of the [`Scrollable`].
pub fn direction(mut self, direction: impl Into<Direction>) -> Self { pub fn direction(mut self, direction: impl Into<Direction>) -> Self {
self.direction = direction.into(); self.direction = direction.into();
self.validate() self.enclose()
} }
/// Sets the [`Id`] of the [`Scrollable`]. /// Sets the [`Id`] of the [`Scrollable`].
@ -437,20 +427,24 @@ where
..Padding::ZERO ..Padding::ZERO
}, },
|limits| { |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(), limits.min(),
Size::new( Size::new(
if self.direction.horizontal().is_some() { if is_horizontal {
f32::INFINITY f32::INFINITY
} else { } else {
limits.max().width limits.max().width
}, },
if self.direction.vertical().is_some() { if is_vertical {
f32::INFINITY f32::INFINITY
} else { } else {
limits.max().height limits.max().height
}, },
), ),
Size::new(is_horizontal, is_vertical),
); );
self.content.as_widget_mut().layout( self.content.as_widget_mut().layout(