Assert scrollable content size never fills scrolling axis

This commit is contained in:
Héctor Ramón Jiménez 2024-02-24 19:46:44 +01:00
parent ca9694f2f4
commit 7d3735f0fa
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
2 changed files with 55 additions and 39 deletions

View file

@ -47,16 +47,38 @@ where
Theme: StyleSheet,
Renderer: crate::core::Renderer,
{
/// Creates a new [`Scrollable`].
/// Creates a new vertical [`Scrollable`].
pub fn new(
content: impl Into<Element<'a, Message, Theme, Renderer>>,
) -> Self {
Self::with_direction(content, Direction::default())
}
/// Creates a new [`Scrollable`] with the given [`Direction`].
pub fn with_direction(
content: impl Into<Element<'a, Message, Theme, Renderer>>,
direction: Direction,
) -> Self {
let content = content.into();
debug_assert!(
direction.vertical().is_none()
|| !content.as_widget().size_hint().height.is_fill(),
"scrollable content must not fill its vertical scrolling axis"
);
debug_assert!(
direction.horizontal().is_none()
|| !content.as_widget().size_hint().width.is_fill(),
"scrollable content must not fill its horizontal scrolling axis"
);
Scrollable {
id: None,
width: Length::Shrink,
height: Length::Shrink,
direction: Direction::default(),
content: content.into(),
direction,
content,
on_scroll: None,
style: Default::default(),
}
@ -80,12 +102,6 @@ where
self
}
/// Sets the [`Direction`] of the [`Scrollable`] .
pub fn direction(mut self, direction: Direction) -> Self {
self.direction = direction;
self
}
/// Sets a function to call when the [`Scrollable`] is scrolled.
///
/// The function takes the [`Viewport`] of the [`Scrollable`]