diff options
author | 2024-02-24 19:46:44 +0100 | |
---|---|---|
committer | 2024-02-24 19:46:44 +0100 | |
commit | 7d3735f0fa88372157e7f1041be3e2513067c80b (patch) | |
tree | 6fd3f8a53ffa4fdd623cf860b2fb744a425b1194 /widget/src/scrollable.rs | |
parent | ca9694f2f40a5b2121a4adc4ae6c56aa12882ab4 (diff) | |
download | iced-7d3735f0fa88372157e7f1041be3e2513067c80b.tar.gz iced-7d3735f0fa88372157e7f1041be3e2513067c80b.tar.bz2 iced-7d3735f0fa88372157e7f1041be3e2513067c80b.zip |
Assert `scrollable` content size never fills scrolling axis
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`] |