diff options
author | 2023-04-13 00:03:22 +0200 | |
---|---|---|
committer | 2023-04-13 00:03:22 +0200 | |
commit | 1de7da1091c697e4f3f746b5df0e02aff7e2bc3e (patch) | |
tree | e11b8f166b2eda787882069ffc8fb42e0e9dd819 | |
parent | 3dc76ca94853fdee8611c00ceebfe82a758c5a7b (diff) | |
parent | 66939b22b0ee7e1dc0e5ef31594fae5810ffa7b2 (diff) | |
download | iced-1de7da1091c697e4f3f746b5df0e02aff7e2bc3e.tar.gz iced-1de7da1091c697e4f3f746b5df0e02aff7e2bc3e.tar.bz2 iced-1de7da1091c697e4f3f746b5df0e02aff7e2bc3e.zip |
Merge pull request #1749 from FinnPerry/fix/add-width-to-scrollable
Configurable `width` for `Scrollable`
-rw-r--r-- | native/src/widget/scrollable.rs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs index c0590b1e..78dcdca2 100644 --- a/native/src/widget/scrollable.rs +++ b/native/src/widget/scrollable.rs @@ -33,6 +33,7 @@ where Renderer::Theme: StyleSheet, { id: Option<Id>, + width: Length, height: Length, vertical: Properties, horizontal: Option<Properties>, @@ -50,6 +51,7 @@ where pub fn new(content: impl Into<Element<'a, Message, Renderer>>) -> Self { Scrollable { id: None, + width: Length::Shrink, height: Length::Shrink, vertical: Properties::default(), horizontal: None, @@ -65,6 +67,12 @@ where self } + /// Sets the width of the [`Scrollable`]. + pub fn width(mut self, width: impl Into<Length>) -> Self { + self.width = width.into(); + self + } + /// Sets the height of the [`Scrollable`]. pub fn height(mut self, height: impl Into<Length>) -> Self { self.height = height.into(); @@ -173,7 +181,7 @@ where } fn width(&self) -> Length { - self.content.as_widget().width() + self.width } fn height(&self) -> Length { @@ -188,7 +196,7 @@ where layout( renderer, limits, - Widget::<Message, Renderer>::width(self), + self.width, self.height, self.horizontal.is_some(), |renderer, limits| { @@ -397,15 +405,7 @@ pub fn layout<Renderer>( horizontal_enabled: bool, layout_content: impl FnOnce(&Renderer, &layout::Limits) -> layout::Node, ) -> layout::Node { - let limits = limits - .max_height(f32::INFINITY) - .max_width(if horizontal_enabled { - f32::INFINITY - } else { - limits.max().width - }) - .width(width) - .height(height); + let limits = limits.width(width).height(height); let child_limits = layout::Limits::new( Size::new(limits.min().width, 0.0), |