From 664251f3f5c7b76f69a97683af1468094bba887f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 14 May 2022 01:47:55 +0200 Subject: Draft first-class `Theme` support RFC: https://github.com/iced-rs/rfcs/pull/6 --- examples/styling/src/main.rs | 85 +++++++------------------------------------- 1 file changed, 12 insertions(+), 73 deletions(-) (limited to 'examples/styling') diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index b4ef3e87..e6c4ac37 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -1,7 +1,11 @@ +use iced::button; +use iced::scrollable; +use iced::slider; +use iced::text_input; use iced::{ - button, scrollable, slider, text_input, Alignment, Button, Checkbox, - Column, Container, Element, Length, ProgressBar, Radio, Row, Rule, Sandbox, - Scrollable, Settings, Slider, Space, Text, TextInput, Toggler, + Alignment, Button, Checkbox, Column, Container, Element, Length, + ProgressBar, Radio, Row, Rule, Sandbox, Scrollable, Settings, Slider, + Space, Text, TextInput, Toggler, }; pub fn main() -> iced::Result { @@ -81,8 +85,7 @@ impl Sandbox for Styling { let button = Button::new(&mut self.button, Text::new("Submit")) .padding(10) - .on_press(Message::ButtonPressed) - .style(self.theme); + .on_press(Message::ButtonPressed); let slider = Slider::new( &mut self.slider, @@ -156,8 +159,8 @@ impl Sandbox for Styling { mod style { use iced::{ - button, checkbox, container, progress_bar, radio, rule, scrollable, - slider, text_input, toggler, + checkbox, container, progress_bar, radio, rule, scrollable, slider, + text_input, toggler, }; #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -203,15 +206,6 @@ mod style { } } - impl<'a> From for Box { - fn from(theme: Theme) -> Self { - match theme { - Theme::Light => light::Button.into(), - Theme::Dark => dark::Button.into(), - } - } - } - impl<'a> From for Box { fn from(theme: Theme) -> Self { match theme { @@ -266,36 +260,10 @@ mod style { } } - mod light { - use iced::{button, Color, Vector}; - - pub struct Button; - - impl button::StyleSheet for Button { - fn active(&self) -> button::Style { - button::Style { - background: Color::from_rgb(0.11, 0.42, 0.87).into(), - border_radius: 12.0, - shadow_offset: Vector::new(1.0, 1.0), - text_color: Color::from_rgb8(0xEE, 0xEE, 0xEE), - ..button::Style::default() - } - } - - fn hovered(&self) -> button::Style { - button::Style { - text_color: Color::WHITE, - shadow_offset: Vector::new(1.0, 2.0), - ..self.active() - } - } - } - } - mod dark { use iced::{ - button, checkbox, container, progress_bar, radio, rule, scrollable, - slider, text_input, toggler, Color, + checkbox, container, progress_bar, radio, rule, scrollable, slider, + text_input, toggler, Color, }; const SURFACE: Color = Color::from_rgb( @@ -396,35 +364,6 @@ mod style { } } - pub struct Button; - - impl button::StyleSheet for Button { - fn active(&self) -> button::Style { - button::Style { - background: ACTIVE.into(), - border_radius: 3.0, - text_color: Color::WHITE, - ..button::Style::default() - } - } - - fn hovered(&self) -> button::Style { - button::Style { - background: HOVERED.into(), - text_color: Color::WHITE, - ..self.active() - } - } - - fn pressed(&self) -> button::Style { - button::Style { - border_width: 1.0, - border_color: Color::WHITE, - ..self.hovered() - } - } - } - pub struct Scrollable; impl scrollable::StyleSheet for Scrollable { -- cgit From d5bc610d0139fb331a59fc904a932d156f637391 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 26 May 2022 23:12:11 +0200 Subject: Fix examples and doc-tests --- examples/styling/src/main.rs | 58 +++----------------------------------------- 1 file changed, 4 insertions(+), 54 deletions(-) (limited to 'examples/styling') diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index e6c4ac37..82876cb4 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -92,8 +92,7 @@ impl Sandbox for Styling { 0.0..=100.0, self.slider_value, Message::SliderChanged, - ) - .style(self.theme); + ); let progress_bar = ProgressBar::new(0.0..=100.0, self.slider_value).style(self.theme); @@ -159,8 +158,8 @@ impl Sandbox for Styling { mod style { use iced::{ - checkbox, container, progress_bar, radio, rule, scrollable, slider, - text_input, toggler, + checkbox, container, progress_bar, radio, rule, scrollable, text_input, + toggler, }; #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -215,15 +214,6 @@ mod style { } } - impl<'a> From for Box { - fn from(theme: Theme) -> Self { - match theme { - Theme::Light => Default::default(), - Theme::Dark => dark::Slider.into(), - } - } - } - impl From for Box { fn from(theme: Theme) -> Self { match theme { @@ -262,7 +252,7 @@ mod style { mod dark { use iced::{ - checkbox, container, progress_bar, radio, rule, scrollable, slider, + checkbox, container, progress_bar, radio, rule, scrollable, text_input, toggler, Color, }; @@ -408,46 +398,6 @@ mod style { } } - pub struct Slider; - - impl slider::StyleSheet for Slider { - fn active(&self) -> slider::Style { - slider::Style { - rail_colors: (ACTIVE, Color { a: 0.1, ..ACTIVE }), - handle: slider::Handle { - shape: slider::HandleShape::Circle { radius: 9.0 }, - color: ACTIVE, - border_width: 0.0, - border_color: Color::TRANSPARENT, - }, - } - } - - fn hovered(&self) -> slider::Style { - let active = self.active(); - - slider::Style { - handle: slider::Handle { - color: HOVERED, - ..active.handle - }, - ..active - } - } - - fn dragging(&self) -> slider::Style { - let active = self.active(); - - slider::Style { - handle: slider::Handle { - color: Color::from_rgb(0.85, 0.85, 0.85), - ..active.handle - }, - ..active - } - } - } - pub struct ProgressBar; impl progress_bar::StyleSheet for ProgressBar { -- cgit From 28d09bfff1dde55190986bab10d7aaeb0ceb49de Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 27 May 2022 01:26:57 +0200 Subject: Implement theme styling for `Radio` --- examples/styling/src/main.rs | 51 ++++++++------------------------------------ 1 file changed, 9 insertions(+), 42 deletions(-) (limited to 'examples/styling') diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index 82876cb4..27b3ead4 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -61,15 +61,12 @@ impl Sandbox for Styling { let choose_theme = style::Theme::ALL.iter().fold( Column::new().spacing(10).push(Text::new("Choose a theme:")), |column, theme| { - column.push( - Radio::new( - *theme, - format!("{:?}", theme), - Some(self.theme), - Message::ThemeChanged, - ) - .style(self.theme), - ) + column.push(Radio::new( + *theme, + format!("{:?}", theme), + Some(self.theme), + Message::ThemeChanged, + )) }, ); @@ -158,7 +155,7 @@ impl Sandbox for Styling { mod style { use iced::{ - checkbox, container, progress_bar, radio, rule, scrollable, text_input, + checkbox, container, progress_bar, rule, scrollable, text_input, toggler, }; @@ -187,15 +184,6 @@ mod style { } } - impl<'a> From for Box { - fn from(theme: Theme) -> Self { - match theme { - Theme::Light => Default::default(), - Theme::Dark => dark::Radio.into(), - } - } - } - impl<'a> From for Box { fn from(theme: Theme) -> Self { match theme { @@ -252,8 +240,8 @@ mod style { mod dark { use iced::{ - checkbox, container, progress_bar, radio, rule, scrollable, - text_input, toggler, Color, + checkbox, container, progress_bar, rule, scrollable, text_input, + toggler, Color, }; const SURFACE: Color = Color::from_rgb( @@ -292,27 +280,6 @@ mod style { } } - pub struct Radio; - - impl radio::StyleSheet for Radio { - fn active(&self) -> radio::Style { - radio::Style { - background: SURFACE.into(), - dot_color: ACTIVE, - border_width: 1.0, - border_color: ACTIVE, - text_color: None, - } - } - - fn hovered(&self) -> radio::Style { - radio::Style { - background: Color { a: 0.5, ..SURFACE }.into(), - ..self.active() - } - } - } - pub struct TextInput; impl text_input::StyleSheet for TextInput { -- cgit From 3e2b6247f72815b6e928237f242c2d66478cf15d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 31 May 2022 05:13:57 +0200 Subject: Implement theme styling for `Toggler` ... and wire up theming to the `styling` example. --- examples/styling/src/main.rs | 53 +++++++++----------------------------------- 1 file changed, 10 insertions(+), 43 deletions(-) (limited to 'examples/styling') diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index 27b3ead4..044f75a9 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -5,7 +5,7 @@ use iced::text_input; use iced::{ Alignment, Button, Checkbox, Column, Container, Element, Length, ProgressBar, Radio, Row, Rule, Sandbox, Scrollable, Settings, Slider, - Space, Text, TextInput, Toggler, + Space, Text, TextInput, Theme, Toggler, }; pub fn main() -> iced::Result { @@ -115,8 +115,7 @@ impl Sandbox for Styling { Message::TogglerToggled, ) .width(Length::Shrink) - .spacing(10) - .style(self.theme); + .spacing(10); let content = Column::new() .spacing(20) @@ -151,12 +150,18 @@ impl Sandbox for Styling { .style(self.theme) .into() } + + fn theme(&self) -> Theme { + match self.theme { + style::Theme::Light => Theme::Light, + style::Theme::Dark => Theme::Dark, + } + } } mod style { use iced::{ checkbox, container, progress_bar, rule, scrollable, text_input, - toggler, }; #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -220,15 +225,6 @@ mod style { } } - impl From for Box { - fn from(theme: Theme) -> Self { - match theme { - Theme::Light => Default::default(), - Theme::Dark => dark::Toggler.into(), - } - } - } - impl From for Box { fn from(theme: Theme) -> Self { match theme { @@ -241,7 +237,7 @@ mod style { mod dark { use iced::{ checkbox, container, progress_bar, rule, scrollable, text_input, - toggler, Color, + Color, }; const SURFACE: Color = Color::from_rgb( @@ -404,35 +400,6 @@ mod style { } } - pub struct Toggler; - - impl toggler::StyleSheet for Toggler { - fn active(&self, is_active: bool) -> toggler::Style { - toggler::Style { - background: if is_active { ACTIVE } else { SURFACE }, - background_border: None, - foreground: if is_active { Color::WHITE } else { ACTIVE }, - foreground_border: None, - } - } - - fn hovered(&self, is_active: bool) -> toggler::Style { - toggler::Style { - background: if is_active { ACTIVE } else { SURFACE }, - background_border: None, - foreground: if is_active { - Color { - a: 0.5, - ..Color::WHITE - } - } else { - Color { a: 0.5, ..ACTIVE } - }, - foreground_border: None, - } - } - } - pub struct Rule; impl rule::StyleSheet for Rule { -- cgit From a206d22670eda60d6364444f690633dc11e75a41 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 31 May 2022 05:27:27 +0200 Subject: Use `Theme` background in `styling` example --- examples/styling/src/main.rs | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) (limited to 'examples/styling') diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index 044f75a9..3109d7fb 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -147,7 +147,6 @@ impl Sandbox for Styling { .height(Length::Fill) .center_x() .center_y() - .style(self.theme) .into() } @@ -160,9 +159,7 @@ impl Sandbox for Styling { } mod style { - use iced::{ - checkbox, container, progress_bar, rule, scrollable, text_input, - }; + use iced::{checkbox, progress_bar, rule, scrollable, text_input}; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Theme { @@ -180,15 +177,6 @@ mod style { } } - impl<'a> From for Box { - fn from(theme: Theme) -> Self { - match theme { - Theme::Light => Default::default(), - Theme::Dark => dark::Container.into(), - } - } - } - impl<'a> From for Box { fn from(theme: Theme) -> Self { match theme { @@ -236,8 +224,7 @@ mod style { mod dark { use iced::{ - checkbox, container, progress_bar, rule, scrollable, text_input, - Color, + checkbox, progress_bar, rule, scrollable, text_input, Color, }; const SURFACE: Color = Color::from_rgb( @@ -264,18 +251,6 @@ mod style { 0xC4 as f32 / 255.0, ); - pub struct Container; - - impl container::StyleSheet for Container { - fn style(&self) -> container::Style { - container::Style { - background: Color::from_rgb8(0x36, 0x39, 0x3F).into(), - text_color: Color::WHITE.into(), - ..container::Style::default() - } - } - } - pub struct TextInput; impl text_input::StyleSheet for TextInput { -- cgit From c275fde67a7f5d1d5789540dc7905250a2f01fe7 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 1 Jun 2022 01:56:46 +0200 Subject: Implement theme styling for `Rule` --- examples/styling/src/main.rs | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) (limited to 'examples/styling') diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index 3109d7fb..e6e4681a 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -122,7 +122,7 @@ impl Sandbox for Styling { .padding(20) .max_width(600) .push(choose_theme) - .push(Rule::horizontal(38).style(self.theme)) + .push(Rule::horizontal(38)) .push(Row::new().spacing(10).push(text_input).push(button)) .push(slider) .push(progress_bar) @@ -132,7 +132,7 @@ impl Sandbox for Styling { .height(Length::Units(100)) .align_items(Alignment::Center) .push(scrollable) - .push(Rule::vertical(38).style(self.theme)) + .push(Rule::vertical(38)) .push( Column::new() .width(Length::Shrink) @@ -159,7 +159,7 @@ impl Sandbox for Styling { } mod style { - use iced::{checkbox, progress_bar, rule, scrollable, text_input}; + use iced::{checkbox, progress_bar, scrollable, text_input}; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Theme { @@ -213,19 +213,8 @@ mod style { } } - impl From for Box { - fn from(theme: Theme) -> Self { - match theme { - Theme::Light => Default::default(), - Theme::Dark => dark::Rule.into(), - } - } - } - mod dark { - use iced::{ - checkbox, progress_bar, rule, scrollable, text_input, Color, - }; + use iced::{checkbox, progress_bar, scrollable, text_input, Color}; const SURFACE: Color = Color::from_rgb( 0x40 as f32 / 255.0, @@ -374,18 +363,5 @@ mod style { } } } - - pub struct Rule; - - impl rule::StyleSheet for Rule { - fn style(&self) -> rule::Style { - rule::Style { - color: SURFACE, - width: 2, - radius: 1.0, - fill_mode: rule::FillMode::Padded(15), - } - } - } } } -- cgit From 77dc9dc2cb4ac092ce88c2700253fbfc54292e2b Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 1 Jun 2022 02:40:42 +0200 Subject: Implement theme styling for `ProgressBar` --- examples/styling/src/main.rs | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) (limited to 'examples/styling') diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index e6e4681a..e19b4279 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -91,8 +91,7 @@ impl Sandbox for Styling { Message::SliderChanged, ); - let progress_bar = - ProgressBar::new(0.0..=100.0, self.slider_value).style(self.theme); + let progress_bar = ProgressBar::new(0.0..=100.0, self.slider_value); let scrollable = Scrollable::new(&mut self.scroll) .width(Length::Fill) @@ -159,7 +158,7 @@ impl Sandbox for Styling { } mod style { - use iced::{checkbox, progress_bar, scrollable, text_input}; + use iced::{checkbox, scrollable, text_input}; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Theme { @@ -195,15 +194,6 @@ mod style { } } - impl From for Box { - fn from(theme: Theme) -> Self { - match theme { - Theme::Light => Default::default(), - Theme::Dark => dark::ProgressBar.into(), - } - } - } - impl<'a> From for Box { fn from(theme: Theme) -> Self { match theme { @@ -214,7 +204,7 @@ mod style { } mod dark { - use iced::{checkbox, progress_bar, scrollable, text_input, Color}; + use iced::{checkbox, scrollable, text_input, Color}; const SURFACE: Color = Color::from_rgb( 0x40 as f32 / 255.0, @@ -325,18 +315,6 @@ mod style { } } - pub struct ProgressBar; - - impl progress_bar::StyleSheet for ProgressBar { - fn style(&self) -> progress_bar::Style { - progress_bar::Style { - background: SURFACE.into(), - bar: ACTIVE.into(), - border_radius: 10.0, - } - } - } - pub struct Checkbox; impl checkbox::StyleSheet for Checkbox { -- cgit From 835877fc636d71c1faaa4826cbfde8e09b3c82ba Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 4 Jun 2022 03:26:53 +0200 Subject: Implement theme styling for `Checkbox` --- examples/styling/src/main.rs | 43 +++---------------------------------------- 1 file changed, 3 insertions(+), 40 deletions(-) (limited to 'examples/styling') diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index e19b4279..8cd17a6c 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -105,8 +105,7 @@ impl Sandbox for Styling { self.checkbox_value, "Check me!", Message::CheckboxToggled, - ) - .style(self.theme); + ); let toggler = Toggler::new( self.toggler_value, @@ -158,7 +157,7 @@ impl Sandbox for Styling { } mod style { - use iced::{checkbox, scrollable, text_input}; + use iced::{scrollable, text_input}; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Theme { @@ -194,17 +193,8 @@ mod style { } } - impl<'a> From for Box { - fn from(theme: Theme) -> Self { - match theme { - Theme::Light => Default::default(), - Theme::Dark => dark::Checkbox.into(), - } - } - } - mod dark { - use iced::{checkbox, scrollable, text_input, Color}; + use iced::{scrollable, text_input, Color}; const SURFACE: Color = Color::from_rgb( 0x40 as f32 / 255.0, @@ -314,32 +304,5 @@ mod style { } } } - - pub struct Checkbox; - - impl checkbox::StyleSheet for Checkbox { - fn active(&self, is_checked: bool) -> checkbox::Style { - checkbox::Style { - background: if is_checked { ACTIVE } else { SURFACE } - .into(), - checkmark_color: Color::WHITE, - border_radius: 2.0, - border_width: 1.0, - border_color: ACTIVE, - text_color: None, - } - } - - fn hovered(&self, is_checked: bool) -> checkbox::Style { - checkbox::Style { - background: Color { - a: 0.8, - ..if is_checked { ACTIVE } else { SURFACE } - } - .into(), - ..self.active(is_checked) - } - } - } } } -- cgit From ce53d3933c860cd958636cce415ac97c04aee746 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 7 Jun 2022 01:11:35 +0200 Subject: Implement theme styling for `TextInput` --- examples/styling/src/main.rs | 63 +++----------------------------------------- 1 file changed, 3 insertions(+), 60 deletions(-) (limited to 'examples/styling') diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index 8cd17a6c..e2a4b492 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -77,8 +77,7 @@ impl Sandbox for Styling { Message::InputChanged, ) .padding(10) - .size(20) - .style(self.theme); + .size(20); let button = Button::new(&mut self.button, Text::new("Submit")) .padding(10) @@ -157,7 +156,7 @@ impl Sandbox for Styling { } mod style { - use iced::{scrollable, text_input}; + use iced::scrollable; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Theme { @@ -175,15 +174,6 @@ mod style { } } - impl<'a> From for Box { - fn from(theme: Theme) -> Self { - match theme { - Theme::Light => Default::default(), - Theme::Dark => dark::TextInput.into(), - } - } - } - impl<'a> From for Box { fn from(theme: Theme) -> Self { match theme { @@ -194,7 +184,7 @@ mod style { } mod dark { - use iced::{scrollable, text_input, Color}; + use iced::{scrollable, Color}; const SURFACE: Color = Color::from_rgb( 0x40 as f32 / 255.0, @@ -202,12 +192,6 @@ mod style { 0x4B 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 ACTIVE: Color = Color::from_rgb( 0x72 as f32 / 255.0, 0x89 as f32 / 255.0, @@ -220,47 +204,6 @@ mod style { 0xC4 as f32 / 255.0, ); - pub struct TextInput; - - impl text_input::StyleSheet for TextInput { - fn active(&self) -> text_input::Style { - text_input::Style { - background: SURFACE.into(), - border_radius: 2.0, - border_width: 0.0, - border_color: Color::TRANSPARENT, - } - } - - fn focused(&self) -> text_input::Style { - text_input::Style { - border_width: 1.0, - border_color: ACCENT, - ..self.active() - } - } - - fn hovered(&self) -> text_input::Style { - text_input::Style { - border_width: 1.0, - border_color: Color { a: 0.3, ..ACCENT }, - ..self.focused() - } - } - - fn placeholder_color(&self) -> Color { - Color::from_rgb(0.4, 0.4, 0.4) - } - - fn value_color(&self) -> Color { - Color::WHITE - } - - fn selection_color(&self) -> Color { - ACTIVE - } - } - pub struct Scrollable; impl scrollable::StyleSheet for Scrollable { -- cgit 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/styling/src/main.rs | 107 ++----------------------------------------- 1 file changed, 4 insertions(+), 103 deletions(-) (limited to 'examples/styling') diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index e2a4b492..aa90d17c 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -14,7 +14,7 @@ pub fn main() -> iced::Result { #[derive(Default)] struct Styling { - theme: style::Theme, + theme: Theme, scroll: scrollable::State, input: text_input::State, input_value: String, @@ -27,7 +27,7 @@ struct Styling { #[derive(Debug, Clone)] enum Message { - ThemeChanged(style::Theme), + ThemeChanged(Theme), InputChanged(String), ButtonPressed, SliderChanged(f32), @@ -58,7 +58,7 @@ impl Sandbox for Styling { } fn view(&mut self) -> Element { - let choose_theme = style::Theme::ALL.iter().fold( + let choose_theme = [Theme::Light, Theme::Dark].iter().fold( Column::new().spacing(10).push(Text::new("Choose a theme:")), |column, theme| { column.push(Radio::new( @@ -95,7 +95,6 @@ impl Sandbox for Styling { let scrollable = Scrollable::new(&mut self.scroll) .width(Length::Fill) .height(Length::Units(100)) - .style(self.theme) .push(Text::new("Scroll me!")) .push(Space::with_height(Length::Units(800))) .push(Text::new("You did it!")); @@ -148,104 +147,6 @@ impl Sandbox for Styling { } fn theme(&self) -> Theme { - match self.theme { - style::Theme::Light => Theme::Light, - style::Theme::Dark => Theme::Dark, - } - } -} - -mod style { - use iced::scrollable; - - #[derive(Debug, Clone, Copy, PartialEq, Eq)] - pub enum Theme { - Light, - Dark, - } - - impl Theme { - pub const ALL: [Theme; 2] = [Theme::Light, Theme::Dark]; - } - - impl Default for Theme { - fn default() -> Theme { - Theme::Light - } - } - - 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::{scrollable, Color}; - - const SURFACE: Color = Color::from_rgb( - 0x40 as f32 / 255.0, - 0x44 as f32 / 255.0, - 0x4B as f32 / 255.0, - ); - - const ACTIVE: Color = Color::from_rgb( - 0x72 as f32 / 255.0, - 0x89 as f32 / 255.0, - 0xDA as f32 / 255.0, - ); - - const HOVERED: Color = Color::from_rgb( - 0x67 as f32 / 255.0, - 0x7B as f32 / 255.0, - 0xC4 as f32 / 255.0, - ); - - pub struct Scrollable; - - impl scrollable::StyleSheet for Scrollable { - fn active(&self) -> scrollable::Scrollbar { - scrollable::Scrollbar { - background: SURFACE.into(), - border_radius: 2.0, - border_width: 0.0, - border_color: Color::TRANSPARENT, - scroller: scrollable::Scroller { - color: ACTIVE, - border_radius: 2.0, - border_width: 0.0, - border_color: Color::TRANSPARENT, - }, - } - } - - fn hovered(&self) -> scrollable::Scrollbar { - let active = self.active(); - - scrollable::Scrollbar { - background: Color { a: 0.5, ..SURFACE }.into(), - scroller: scrollable::Scroller { - color: HOVERED, - ..active.scroller - }, - ..active - } - } - - fn dragging(&self) -> scrollable::Scrollbar { - let hovered = self.hovered(); - - scrollable::Scrollbar { - scroller: scrollable::Scroller { - color: Color::from_rgb(0.85, 0.85, 0.85), - ..hovered.scroller - }, - ..hovered - } - } - } + self.theme } } -- cgit