From d91f4f6aa74d0693179a02167d626efa3ac4c20b Mon Sep 17 00:00:00 2001 From: Bingus Date: Sat, 19 Nov 2022 10:29:37 -0800 Subject: Add multidirectional scrolling capabilities to the existing Scrollable. --- style/src/scrollable.rs | 17 ++++++++++++++++- style/src/theme.rs | 24 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) (limited to 'style/src') diff --git a/style/src/scrollable.rs b/style/src/scrollable.rs index c6d7d537..64ed8462 100644 --- a/style/src/scrollable.rs +++ b/style/src/scrollable.rs @@ -37,11 +37,26 @@ pub trait StyleSheet { /// Produces the style of an active scrollbar. fn active(&self, style: &Self::Style) -> Scrollbar; - /// Produces the style of an hovered scrollbar. + /// Produces the style of a hovered scrollbar. fn hovered(&self, style: &Self::Style) -> Scrollbar; /// Produces the style of a scrollbar that is being dragged. fn dragging(&self, style: &Self::Style) -> Scrollbar { self.hovered(style) } + + /// Produces the style of an active horizontal scrollbar. + fn active_horizontal(&self, style: &Self::Style) -> Scrollbar { + self.active(style) + } + + /// Produces the style of a hovered horizontal scrollbar. + fn hovered_horizontal(&self, style: &Self::Style) -> Scrollbar { + self.hovered(style) + } + + /// Produces the style of a horizontal scrollbar that is being dragged. + fn dragging_horizontal(&self, style: &Self::Style) -> Scrollbar { + self.hovered_horizontal(style) + } } diff --git a/style/src/theme.rs b/style/src/theme.rs index 271d9a29..cef8f2be 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -925,6 +925,30 @@ impl scrollable::StyleSheet for Theme { Scrollable::Custom(custom) => custom.dragging(self), } } + + fn active_horizontal(&self, style: &Self::Style) -> scrollable::Scrollbar { + match style { + Scrollable::Default => self.active(style), + Scrollable::Custom(custom) => custom.active_horizontal(self), + } + } + + fn hovered_horizontal(&self, style: &Self::Style) -> scrollable::Scrollbar { + match style { + Scrollable::Default => self.hovered(style), + Scrollable::Custom(custom) => custom.hovered_horizontal(self), + } + } + + fn dragging_horizontal( + &self, + style: &Self::Style, + ) -> scrollable::Scrollbar { + match style { + Scrollable::Default => self.hovered_horizontal(style), + Scrollable::Custom(custom) => custom.dragging_horizontal(self), + } + } } /// The style of text. -- cgit From 9f85e0c721927f1e3bd195a998ec7a80ec0e7455 Mon Sep 17 00:00:00 2001 From: bungoboingo Date: Sat, 24 Dec 2022 21:27:44 -0800 Subject: Reworked Scrollable to account for lack of widget order guarantees. Fixed thumb "snapping" bug on scrollable when cursor is out of bounds. --- style/src/theme.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'style/src') diff --git a/style/src/theme.rs b/style/src/theme.rs index cef8f2be..f780f952 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -872,6 +872,15 @@ pub enum Scrollable { Custom(Box>), } +impl Scrollable { + /// Creates a custom [`Scrollable`] theme. + pub fn custom + 'static>( + style: T, + ) -> Self { + Self::Custom(Box::new(style)) + } +} + impl scrollable::StyleSheet for Theme { type Style = Scrollable; -- cgit