diff options
Diffstat (limited to 'widget/src/scrollable.rs')
-rw-r--r-- | widget/src/scrollable.rs | 34 |
1 files changed, 25 insertions, 9 deletions
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`] |