Implement theme styling for Radio

This commit is contained in:
Héctor Ramón Jiménez 2022-05-27 01:26:57 +02:00
parent d988d813d7
commit 28d09bfff1
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
10 changed files with 86 additions and 157 deletions

View file

@ -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<Theme> for Box<dyn radio::StyleSheet + 'a> {
fn from(theme: Theme) -> Self {
match theme {
Theme::Light => Default::default(),
Theme::Dark => dark::Radio.into(),
}
}
}
impl<'a> From<Theme> for Box<dyn text_input::StyleSheet + 'a> {
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 {