diff options
author | 2022-09-07 11:56:11 -0400 | |
---|---|---|
committer | 2022-11-03 03:23:35 +0100 | |
commit | e2166ecad020662d246b364637efc4e6ee3bc1db (patch) | |
tree | 2bd7bbb86747390012b9e4b26b081a3eb1d1ba91 /examples/styling | |
parent | 231d2fd8454eb9d24ba970131d4d7339cc0c8d51 (diff) | |
download | iced-e2166ecad020662d246b364637efc4e6ee3bc1db.tar.gz iced-e2166ecad020662d246b364637efc4e6ee3bc1db.tar.bz2 iced-e2166ecad020662d246b364637efc4e6ee3bc1db.zip |
wip: Custom palette for built in theme
Diffstat (limited to 'examples/styling')
-rw-r--r-- | examples/styling/Cargo.toml | 1 | ||||
-rw-r--r-- | examples/styling/src/main.rs | 24 |
2 files changed, 22 insertions, 3 deletions
diff --git a/examples/styling/Cargo.toml b/examples/styling/Cargo.toml index f771708c..344cd0d6 100644 --- a/examples/styling/Cargo.toml +++ b/examples/styling/Cargo.toml @@ -7,3 +7,4 @@ publish = false [dependencies] iced = { path = "../.." } +once_cell = "1.14.0"
\ No newline at end of file diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index cda53e87..36ab0c0c 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -1,14 +1,28 @@ +use iced::theme::Palette; +use iced::theme::palette::Extended; use iced::widget::{ button, checkbox, column, container, horizontal_rule, progress_bar, radio, row, scrollable, slider, text, text_input, toggler, vertical_rule, vertical_space, }; -use iced::{Alignment, Element, Length, Sandbox, Settings, Theme}; +use iced::{Alignment, Element, Length, Sandbox, Settings, Theme, Color}; +use once_cell::sync::OnceCell; pub fn main() -> iced::Result { + let palette = Palette { + background: Color::from_rgb(1.0, 0.9, 1.0), + text: Color::BLACK, + primary: Color::from_rgb(0.5, 0.5, 0.0), + success: Color::from_rgb(0.0, 1.0, 0.0), + danger: Color::from_rgb(1.0, 0.0, 0.0), + }; + let extended = Extended::generate(palette); + CUSTOM_THEME.set(Theme::Custom { palette, extended }).unwrap(); Styling::run(Settings::default()) } +static CUSTOM_THEME: OnceCell<Theme> = OnceCell::new(); + #[derive(Default)] struct Styling { theme: Theme, @@ -51,11 +65,15 @@ impl Sandbox for Styling { } fn view(&self) -> Element<Message> { - let choose_theme = [Theme::Light, Theme::Dark].iter().fold( + let choose_theme = [Theme::Light, Theme::Dark, *CUSTOM_THEME.get().unwrap()].iter().fold( column![text("Choose a theme:")].spacing(10), |column, theme| { column.push(radio( - format!("{:?}", theme), + match theme { + Theme::Light => "Light", + Theme::Dark => "Dark", + Theme::Custom { .. } => "Custom", + }, *theme, Some(self.theme), Message::ThemeChanged, |