diff --git a/widget/src/image.rs b/widget/src/image.rs index b5bf241e..4315709a 100644 --- a/widget/src/image.rs +++ b/widget/src/image.rs @@ -79,6 +79,7 @@ pub struct Image<'a, Handle = image::Handle> { opacity: f32, scale: f32, expand: bool, + _phantom_data: std::marker::PhantomData<&'a ()>, } impl<'a, Handle> Image<'a, Handle> { @@ -103,6 +104,7 @@ impl<'a, Handle> Image<'a, Handle> { scale: 1.0, expand: false, border_radius: [0.0; 4].into(), + _phantom_data: std::marker::PhantomData, } } diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index 1213692d..6af5303d 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -257,6 +257,69 @@ where self } + /// Sets the scrollbar width of the [`Scrollbar`]. + pub fn scrollbar_width(mut self, width: impl Into) -> Self { + let width = width.into().0.max(0.0); + + match &mut self.direction { + Direction::Horizontal(scrollbar) + | Direction::Vertical(scrollbar) => { + scrollbar.width = width; + } + Direction::Both { + horizontal, + vertical, + } => { + horizontal.width = width; + vertical.width = width; + } + } + + self + } + + /// Sets the scroller width of the [`Scrollbar`]. + pub fn scroller_width(mut self, width: impl Into) -> Self { + let width = width.into().0.max(0.0); + + match &mut self.direction { + Direction::Horizontal(scrollbar) + | Direction::Vertical(scrollbar) => { + scrollbar.scroller_width = width; + } + Direction::Both { + horizontal, + vertical, + } => { + horizontal.scroller_width = width; + vertical.scroller_width = width; + } + } + + self + } + + /// Sets the padding at the start and end of the [`Scrollbar`]. + pub fn scrollbar_padding(mut self, padding: impl Into) -> Self { + let padding = padding.into().0.max(0.0); + + match &mut self.direction { + Direction::Horizontal(scrollbar) + | Direction::Vertical(scrollbar) => { + scrollbar.padding = padding; + } + Direction::Both { + horizontal, + vertical, + } => { + horizontal.padding = padding; + vertical.padding = padding; + } + } + + self + } + /// Sets the style of this [`Scrollable`]. #[must_use] pub fn style(mut self, style: impl Fn(&Theme, Status) -> Style + 'a) -> Self @@ -379,16 +442,18 @@ pub struct Scrollbar { scroller_width: f32, alignment: Anchor, spacing: Option, + padding: f32, } impl Default for Scrollbar { fn default() -> Self { Self { - width: 8.0, + width: 10.0, margin: 0.0, - scroller_width: 8.0, + scroller_width: 10.0, alignment: Anchor::Start, spacing: None, + padding: 0.0, } } } @@ -438,6 +503,12 @@ impl Scrollbar { self.spacing = Some(spacing.into().0); self } + + /// Sets the padding at the start and end of the [`Scrollbar`]. + pub fn padding(mut self, padding: impl Into) -> Self { + self.padding = padding.into().0.max(0.0); + self + } } /// The anchor of the scroller of the [`Scrollable`] relative to its [`Viewport`] @@ -2268,6 +2339,7 @@ impl Scrollbars { width, margin, scroller_width, + padding, .. } = *vertical; @@ -2282,9 +2354,10 @@ impl Scrollbars { // Total bounds of the scrollbar + margin + scroller width let total_scrollbar_bounds = Rectangle { x: bounds.x + bounds.width - total_scrollbar_width, - y: bounds.y, + y: bounds.y + padding, width: total_scrollbar_width, - height: (bounds.height - x_scrollbar_height).max(0.0), + height: (bounds.height - x_scrollbar_height - 2.0 * padding) + .max(0.0), }; // Bounds of just the scrollbar @@ -2292,9 +2365,10 @@ impl Scrollbars { x: bounds.x + bounds.width - total_scrollbar_width / 2.0 - width / 2.0, - y: bounds.y, + y: bounds.y + padding, width, - height: (bounds.height - x_scrollbar_height).max(0.0), + height: (bounds.height - x_scrollbar_height - 2.0 * padding) + .max(0.0), }; let ratio = bounds.height / content_bounds.height; @@ -2339,6 +2413,7 @@ impl Scrollbars { width, margin, scroller_width, + padding, .. } = *horizontal; @@ -2352,19 +2427,21 @@ impl Scrollbars { // Total bounds of the scrollbar + margin + scroller width let total_scrollbar_bounds = Rectangle { - x: bounds.x, + x: bounds.x + padding, y: bounds.y + bounds.height - total_scrollbar_height, - width: (bounds.width - scrollbar_y_width).max(0.0), + width: (bounds.width - scrollbar_y_width - 2.0 * padding) + .max(0.0), height: total_scrollbar_height, }; // Bounds of just the scrollbar let scrollbar_bounds = Rectangle { - x: bounds.x, + x: bounds.x + padding, y: bounds.y + bounds.height - total_scrollbar_height / 2.0 - width / 2.0, - width: (bounds.width - scrollbar_y_width).max(0.0), + width: (bounds.width - scrollbar_y_width - 2.0 * padding) + .max(0.0), height: width, };