From 0eaaeaa517a00765045de155bb1de01c2d8f553f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 12 Feb 2024 19:24:09 +0100 Subject: Simplify `scrollable` styling API --- style/src/theme.rs | 77 +++++++++++++++--------------------------------------- 1 file changed, 21 insertions(+), 56 deletions(-) (limited to 'style/src/theme.rs') diff --git a/style/src/theme.rs b/style/src/theme.rs index 4579181b..0b56e101 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -1188,32 +1188,22 @@ impl Scrollable { impl scrollable::StyleSheet for Theme { type Style = Scrollable; - fn appearance(&self, style: &Self::Style) -> scrollable::Appearance { + fn active(&self, style: &Self::Style) -> scrollable::Appearance { match style { Scrollable::Default => { let palette = self.extended_palette(); scrollable::Appearance { - background: None, - gap: Some(palette.background.weak.color.into()), - } - } - Scrollable::Custom(custom) => custom.appearance(self), - } - } - - fn active(&self, style: &Self::Style) -> scrollable::Scrollbar { - match style { - Scrollable::Default => { - let palette = self.extended_palette(); - - scrollable::Scrollbar { - background: Some(palette.background.weak.color.into()), - border: Border::with_radius(2), - scroller: scrollable::Scroller { - color: palette.background.strong.color, + container: container::Appearance::default(), + scrollbar: scrollable::Scrollbar { + background: Some(palette.background.weak.color.into()), border: Border::with_radius(2), + scroller: scrollable::Scroller { + color: palette.background.strong.color, + border: Border::with_radius(2), + }, }, + gap: None, } } Scrollable::Custom(custom) => custom.active(self), @@ -1224,19 +1214,24 @@ impl scrollable::StyleSheet for Theme { &self, style: &Self::Style, is_mouse_over_scrollbar: bool, - ) -> scrollable::Scrollbar { + ) -> scrollable::Appearance { match style { Scrollable::Default => { if is_mouse_over_scrollbar { let palette = self.extended_palette(); - scrollable::Scrollbar { - background: Some(palette.background.weak.color.into()), - border: Border::with_radius(2), - scroller: scrollable::Scroller { - color: palette.primary.strong.color, + scrollable::Appearance { + scrollbar: scrollable::Scrollbar { + background: Some( + palette.background.weak.color.into(), + ), border: Border::with_radius(2), + scroller: scrollable::Scroller { + color: palette.primary.strong.color, + border: Border::with_radius(2), + }, }, + ..self.active(style) } } else { self.active(style) @@ -1248,42 +1243,12 @@ impl scrollable::StyleSheet for Theme { } } - fn dragging(&self, style: &Self::Style) -> scrollable::Scrollbar { + fn dragging(&self, style: &Self::Style) -> scrollable::Appearance { match style { Scrollable::Default => self.hovered(style, true), 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, - is_mouse_over_scrollbar: bool, - ) -> scrollable::Scrollbar { - match style { - Scrollable::Default => self.hovered(style, is_mouse_over_scrollbar), - Scrollable::Custom(custom) => { - custom.hovered_horizontal(self, is_mouse_over_scrollbar) - } - } - } - - fn dragging_horizontal( - &self, - style: &Self::Style, - ) -> scrollable::Scrollbar { - match style { - Scrollable::Default => self.hovered_horizontal(style, true), - Scrollable::Custom(custom) => custom.dragging_horizontal(self), - } - } } /// The style of text. -- cgit