From de21a651c0616307bb6bfd36da1a06119e629b10 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 7 Jun 2022 03:26:48 +0200 Subject: Implement theme styling for `Scrollable` --- style/src/scrollable.rs | 51 ++++++------------------------------------------- style/src/theme.rs | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 45 deletions(-) (limited to 'style/src') diff --git a/style/src/scrollable.rs b/style/src/scrollable.rs index 748ba888..8da7409c 100644 --- a/style/src/scrollable.rs +++ b/style/src/scrollable.rs @@ -22,55 +22,16 @@ pub struct Scroller { /// A set of rules that dictate the style of a scrollable. pub trait StyleSheet { + type Style: Default + Copy; + /// Produces the style of an active scrollbar. - fn active(&self) -> Scrollbar; + fn active(&self, style: Self::Style) -> Scrollbar; /// Produces the style of an hovered scrollbar. - fn hovered(&self) -> Scrollbar; + fn hovered(&self, style: Self::Style) -> Scrollbar; /// Produces the style of a scrollbar that is being dragged. - fn dragging(&self) -> Scrollbar { - self.hovered() - } -} - -struct Default; - -impl StyleSheet for Default { - fn active(&self) -> Scrollbar { - Scrollbar { - background: None, - border_radius: 5.0, - border_width: 0.0, - border_color: Color::TRANSPARENT, - scroller: Scroller { - color: [0.0, 0.0, 0.0, 0.7].into(), - border_radius: 5.0, - border_width: 0.0, - border_color: Color::TRANSPARENT, - }, - } - } - - fn hovered(&self) -> Scrollbar { - Scrollbar { - background: Some(Background::Color([0.0, 0.0, 0.0, 0.3].into())), - ..self.active() - } - } -} - -impl<'a> std::default::Default for Box { - fn default() -> Self { - Box::new(Default) - } -} - -impl<'a, T> From for Box -where - T: StyleSheet + 'a, -{ - fn from(style_sheet: T) -> Self { - Box::new(style_sheet) + fn dragging(&self, style: Self::Style) -> Scrollbar { + self.hovered(style) } } diff --git a/style/src/theme.rs b/style/src/theme.rs index e1ac719e..3eb4ea70 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -9,6 +9,7 @@ use crate::pane_grid; use crate::progress_bar; use crate::radio; use crate::rule; +use crate::scrollable; use crate::slider; use crate::text_input; use crate::toggler; @@ -458,6 +459,48 @@ impl rule::StyleSheet for Theme { } } +/* + * Scrollable + */ + +impl scrollable::StyleSheet for Theme { + type Style = (); + + fn active(&self, _style: Self::Style) -> scrollable::Scrollbar { + let palette = self.extended_palette(); + + scrollable::Scrollbar { + background: palette.background.weak.color.into(), + border_radius: 2.0, + border_width: 0.0, + border_color: Color::TRANSPARENT, + scroller: scrollable::Scroller { + color: palette.background.strong.color.into(), + border_radius: 2.0, + border_width: 0.0, + border_color: Color::TRANSPARENT, + }, + } + } + + fn hovered(&self, _style: Self::Style) -> scrollable::Scrollbar { + let palette = self.extended_palette(); + + scrollable::Scrollbar { + background: palette.background.weak.color.into(), + border_radius: 2.0, + border_width: 0.0, + border_color: Color::TRANSPARENT, + scroller: scrollable::Scroller { + color: palette.primary.strong.color.into(), + border_radius: 2.0, + border_width: 0.0, + border_color: Color::TRANSPARENT, + }, + } + } +} + /* * Text Input */ -- cgit