diff options
author | 2020-01-07 02:25:57 +0100 | |
---|---|---|
committer | 2020-01-07 02:26:39 +0100 | |
commit | 387fc0be26ccd1adc66c1dc80420f9b08d0c023a (patch) | |
tree | d7bcc53ac945e3f52af6de9af29726f224e6d2bd /examples/styling.rs | |
parent | 48b3b78a3840778eef1035f4585d5ba9dd3d6291 (diff) | |
download | iced-387fc0be26ccd1adc66c1dc80420f9b08d0c023a.tar.gz iced-387fc0be26ccd1adc66c1dc80420f9b08d0c023a.tar.bz2 iced-387fc0be26ccd1adc66c1dc80420f9b08d0c023a.zip |
Implement styling for `Radio`
Diffstat (limited to 'examples/styling.rs')
-rw-r--r-- | examples/styling.rs | 50 |
1 files changed, 41 insertions, 9 deletions
diff --git a/examples/styling.rs b/examples/styling.rs index 426e0638..b5600e85 100644 --- a/examples/styling.rs +++ b/examples/styling.rs @@ -51,12 +51,15 @@ 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, - )) + column.push( + Radio::new( + *theme, + &format!("{:?}", theme), + Some(self.theme), + Message::ThemeChanged, + ) + .style(self.theme), + ) }, ); @@ -110,7 +113,7 @@ impl Sandbox for Styling { mod style { use iced::{ - button, container, progress_bar, scrollable, slider, text_input, + button, container, progress_bar, radio, scrollable, slider, text_input, }; #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -138,6 +141,15 @@ mod style { } } + impl From<Theme> for Box<dyn radio::StyleSheet> { + fn from(theme: Theme) -> Self { + match theme { + Theme::Light => Default::default(), + Theme::Dark => dark::Radio.into(), + } + } + } + impl From<Theme> for Box<dyn text_input::StyleSheet> { fn from(theme: Theme) -> Self { match theme { @@ -213,8 +225,8 @@ mod style { mod dark { use iced::{ - button, container, progress_bar, scrollable, slider, text_input, - Background, Color, + button, container, progress_bar, radio, scrollable, slider, + text_input, Background, Color, }; const SURFACE: Color = Color::from_rgb( @@ -255,6 +267,26 @@ mod style { } } + pub struct Radio; + + impl radio::StyleSheet for Radio { + fn active(&self) -> radio::Style { + radio::Style { + background: Background::Color(SURFACE), + dot_color: Color::WHITE, + border_width: 0, + border_color: Color::TRANSPARENT, + } + } + + fn hovered(&self) -> radio::Style { + radio::Style { + background: Background::Color(Color { a: 0.5, ..SURFACE }), + ..self.active() + } + } + } + pub struct TextInput; impl text_input::StyleSheet for TextInput { |