Implement styling for Radio

This commit is contained in:
Héctor Ramón Jiménez 2020-01-07 02:25:57 +01:00
parent 48b3b78a38
commit 387fc0be26
9 changed files with 145 additions and 38 deletions

View file

@ -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 {