From 7d3735f0fa88372157e7f1041be3e2513067c80b Mon Sep 17 00:00:00 2001
From: Héctor Ramón Jiménez <hector@hecrj.dev>
Date: Sat, 24 Feb 2024 19:46:44 +0100
Subject: Assert `scrollable` content size never fills scrolling axis

---
 widget/src/scrollable.rs | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)

(limited to 'widget/src/scrollable.rs')

diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs
index 3814c590..c4873648 100644
--- a/widget/src/scrollable.rs
+++ b/widget/src/scrollable.rs
@@ -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`]
-- 
cgit