diff options
author | 2024-07-16 19:05:46 +0200 | |
---|---|---|
committer | 2024-07-16 19:05:46 +0200 | |
commit | b518e30610fa53691c727852f70b497dd19cfc7a (patch) | |
tree | 3dfa0a1e50bd3316f607fad562ff9d5e23f81c34 | |
parent | 24f74768236dac874a602f7aa7de4ca8a0cc793f (diff) | |
download | iced-b518e30610fa53691c727852f70b497dd19cfc7a.tar.gz iced-b518e30610fa53691c727852f70b497dd19cfc7a.tar.bz2 iced-b518e30610fa53691c727852f70b497dd19cfc7a.zip |
Fix `Scrollable::spacing` not embedding the `Scrollbar`
-rw-r--r-- | examples/scrollable/src/main.rs | 14 | ||||
-rw-r--r-- | widget/src/scrollable.rs | 59 |
2 files changed, 28 insertions, 45 deletions
diff --git a/examples/scrollable/src/main.rs b/examples/scrollable/src/main.rs index 969f385e..de4f2f9a 100644 --- a/examples/scrollable/src/main.rs +++ b/examples/scrollable/src/main.rs @@ -216,14 +216,13 @@ impl ScrollableDemo { .padding([40, 0]) .spacing(40), ) - .direction(scrollable::Direction::Vertical { - scrollbar: scrollable::Scrollbar::new() + .direction(scrollable::Direction::Vertical( + scrollable::Scrollbar::new() .width(self.scrollbar_width) .margin(self.scrollbar_margin) .scroller_width(self.scroller_width) .anchor(self.anchor), - spacing: None, - }) + )) .width(Fill) .height(Fill) .id(SCROLLABLE_ID.clone()) @@ -243,14 +242,13 @@ impl ScrollableDemo { .padding([0, 40]) .spacing(40), ) - .direction(scrollable::Direction::Horizontal { - scrollbar: scrollable::Scrollbar::new() + .direction(scrollable::Direction::Horizontal( + scrollable::Scrollbar::new() .width(self.scrollbar_width) .margin(self.scrollbar_margin) .scroller_width(self.scroller_width) .anchor(self.anchor), - spacing: None, - }) + )) .width(Fill) .height(Fill) .id(SCROLLABLE_ID.clone()) diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index 52e5391e..b1082203 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -133,10 +133,7 @@ where /// Sets the [`Anchor`] of the horizontal direction of the [`Scrollable`], if applicable. pub fn anchor_x(mut self, alignment: Anchor) -> Self { match &mut self.direction { - Direction::Horizontal { - scrollbar: horizontal, - .. - } + Direction::Horizontal(horizontal) | Direction::Both { horizontal, .. } => { horizontal.alignment = alignment; } @@ -149,10 +146,7 @@ where /// Sets the [`Anchor`] of the vertical direction of the [`Scrollable`], if applicable. pub fn anchor_y(mut self, alignment: Anchor) -> Self { match &mut self.direction { - Direction::Vertical { - scrollbar: vertical, - .. - } + Direction::Vertical(vertical) | Direction::Both { vertical, .. } => { vertical.alignment = alignment; } @@ -169,9 +163,9 @@ where /// of the [`Scrollable`]. pub fn spacing(mut self, new_spacing: impl Into<Pixels>) -> Self { match &mut self.direction { - Direction::Horizontal { spacing, .. } - | Direction::Vertical { spacing, .. } => { - *spacing = Some(new_spacing.into().0); + Direction::Horizontal(scrollbar) + | Direction::Vertical(scrollbar) => { + scrollbar.spacing = Some(new_spacing.into().0); } Direction::Both { .. } => {} } @@ -202,19 +196,9 @@ where #[derive(Debug, Clone, Copy, PartialEq)] pub enum Direction { /// Vertical scrolling - Vertical { - /// The vertical [`Scrollbar`]. - scrollbar: Scrollbar, - /// The amount of spacing between the [`Scrollbar`] and the contents, if embedded. - spacing: Option<f32>, - }, + Vertical(Scrollbar), /// Horizontal scrolling - Horizontal { - /// The horizontal [`Scrollbar`]. - scrollbar: Scrollbar, - /// The amount of spacing between the [`Scrollbar`] and the contents, if embedded. - spacing: Option<f32>, - }, + Horizontal(Scrollbar), /// Both vertical and horizontal scrolling Both { /// The properties of the vertical scrollbar. @@ -228,28 +212,25 @@ impl Direction { /// Returns the horizontal [`Scrollbar`], if any. pub fn horizontal(&self) -> Option<&Scrollbar> { match self { - Self::Horizontal { scrollbar, .. } => Some(scrollbar), + Self::Horizontal(scrollbar) => Some(scrollbar), Self::Both { horizontal, .. } => Some(horizontal), - Self::Vertical { .. } => None, + Self::Vertical(_) => None, } } /// Returns the vertical [`Scrollbar`], if any. pub fn vertical(&self) -> Option<&Scrollbar> { match self { - Self::Vertical { scrollbar, .. } => Some(scrollbar), + Self::Vertical(scrollbar) => Some(scrollbar), Self::Both { vertical, .. } => Some(vertical), - Self::Horizontal { .. } => None, + Self::Horizontal(_) => None, } } } impl Default for Direction { fn default() -> Self { - Self::Vertical { - scrollbar: Scrollbar::default(), - spacing: None, - } + Self::Vertical(Scrollbar::default()) } } @@ -363,14 +344,18 @@ where limits: &layout::Limits, ) -> layout::Node { let (right_padding, bottom_padding) = match self.direction { - Direction::Vertical { - scrollbar, + Direction::Vertical(Scrollbar { + width, + margin, spacing: Some(spacing), - } => (scrollbar.width + scrollbar.margin * 2.0 + spacing, 0.0), - Direction::Horizontal { - scrollbar, + .. + }) => (width + margin * 2.0 + spacing, 0.0), + Direction::Horizontal(Scrollbar { + width, + margin, spacing: Some(spacing), - } => (0.0, scrollbar.width + scrollbar.margin * 2.0 + spacing), + .. + }) => (0.0, width + margin * 2.0 + spacing), _ => (0.0, 0.0), }; |