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` --- examples/scrollable/src/style.rs | 79 +--------------------------------------- 1 file changed, 2 insertions(+), 77 deletions(-) (limited to 'examples/scrollable/src/style.rs') diff --git a/examples/scrollable/src/style.rs b/examples/scrollable/src/style.rs index 64922ae4..c2c48470 100644 --- a/examples/scrollable/src/style.rs +++ b/examples/scrollable/src/style.rs @@ -1,4 +1,4 @@ -use iced::{container, scrollable}; +use iced::container; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Theme { @@ -25,17 +25,8 @@ impl<'a> From for Box { } } -impl<'a> From for Box { - fn from(theme: Theme) -> Self { - match theme { - Theme::Light => Default::default(), - Theme::Dark => dark::Scrollable.into(), - } - } -} - mod dark { - use iced::{container, scrollable, Color}; + use iced::{container, Color}; const BACKGROUND: Color = Color::from_rgb( 0x36 as f32 / 255.0, @@ -43,24 +34,6 @@ mod dark { 0x3F as f32 / 255.0, ); - const ACCENT: Color = Color::from_rgb( - 0x6F as f32 / 255.0, - 0xFF as f32 / 255.0, - 0xE9 as f32 / 255.0, - ); - - const SCROLLBAR: Color = Color::from_rgb( - 0x2E as f32 / 255.0, - 0x33 as f32 / 255.0, - 0x38 as f32 / 255.0, - ); - - const SCROLLER: Color = Color::from_rgb( - 0x20 as f32 / 255.0, - 0x22 as f32 / 255.0, - 0x25 as f32 / 255.0, - ); - pub struct Container; impl container::StyleSheet for Container { @@ -76,52 +49,4 @@ mod dark { } } } - - pub struct Scrollable; - - impl scrollable::StyleSheet for Scrollable { - fn active(&self) -> scrollable::Scrollbar { - scrollable::Scrollbar { - background: Color { - a: 0.8, - ..SCROLLBAR - } - .into(), - border_radius: 2.0, - border_width: 0.0, - border_color: Color::TRANSPARENT, - scroller: scrollable::Scroller { - color: Color { a: 0.7, ..SCROLLER }, - border_radius: 2.0, - border_width: 0.0, - border_color: Color::TRANSPARENT, - }, - } - } - - fn hovered(&self) -> scrollable::Scrollbar { - let active = self.active(); - - scrollable::Scrollbar { - background: SCROLLBAR.into(), - scroller: scrollable::Scroller { - color: SCROLLER, - ..active.scroller - }, - ..active - } - } - - fn dragging(&self) -> scrollable::Scrollbar { - let hovered = self.hovered(); - - scrollable::Scrollbar { - scroller: scrollable::Scroller { - color: ACCENT, - ..hovered.scroller - }, - ..hovered - } - } - } } -- cgit