diff options
author | 2022-05-14 01:47:55 +0200 | |
---|---|---|
committer | 2022-05-14 01:56:32 +0200 | |
commit | 664251f3f5c7b76f69a97683af1468094bba887f (patch) | |
tree | f43a495036ed117ce5dbb479c62652d872a6d273 /examples/styling | |
parent | 5de337f214530faab1d5fe47784afd7006c3f7f0 (diff) | |
download | iced-664251f3f5c7b76f69a97683af1468094bba887f.tar.gz iced-664251f3f5c7b76f69a97683af1468094bba887f.tar.bz2 iced-664251f3f5c7b76f69a97683af1468094bba887f.zip |
Draft first-class `Theme` support
RFC: https://github.com/iced-rs/rfcs/pull/6
Diffstat (limited to 'examples/styling')
-rw-r--r-- | examples/styling/src/main.rs | 85 |
1 files changed, 12 insertions, 73 deletions
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<Theme> for Box<dyn button::StyleSheet + 'a> { - fn from(theme: Theme) -> Self { - match theme { - Theme::Light => light::Button.into(), - Theme::Dark => dark::Button.into(), - } - } - } - impl<'a> From<Theme> for Box<dyn scrollable::StyleSheet + 'a> { 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 { |