summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector@hecrj.dev>2024-02-03 19:07:06 +0100
committerLibravatar GitHub <noreply@github.com>2024-02-03 19:07:06 +0100
commit878134883e5298aa8e12261a3ebd85879eae1d19 (patch)
treefe8fcec55cce4d8ff74bbf234e1e250bc55bcc1c /examples
parent6756594fc6edc699f8a254c369aabdecc4e2dcea (diff)
parented02c1b24d22122e292b54950381589f29c5b21e (diff)
downloadiced-878134883e5298aa8e12261a3ebd85879eae1d19.tar.gz
iced-878134883e5298aa8e12261a3ebd85879eae1d19.tar.bz2
iced-878134883e5298aa8e12261a3ebd85879eae1d19.zip
Merge pull request #2170 from varbhat/vbt/colorpalettes
Add Nord, Dracula, Solarized and Gruvbox themes
Diffstat (limited to 'examples')
-rw-r--r--examples/styling/src/main.rs61
1 files changed, 16 insertions, 45 deletions
diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs
index 4718a123..cf2dcb8a 100644
--- a/examples/styling/src/main.rs
+++ b/examples/styling/src/main.rs
@@ -1,10 +1,9 @@
-use iced::theme::{self, Theme};
use iced::widget::{
- button, checkbox, column, container, horizontal_rule, progress_bar, radio,
- row, scrollable, slider, text, text_input, toggler, vertical_rule,
- vertical_space,
+ button, checkbox, column, container, horizontal_rule, pick_list,
+ progress_bar, row, scrollable, slider, text, text_input, toggler,
+ vertical_rule, vertical_space,
};
-use iced::{Alignment, Color, Element, Length, Sandbox, Settings};
+use iced::{Alignment, Element, Length, Sandbox, Settings, Theme};
pub fn main() -> iced::Result {
Styling::run(Settings::default())
@@ -19,16 +18,9 @@ struct Styling {
toggler_value: bool,
}
-#[derive(Debug, PartialEq, Eq, Clone, Copy)]
-enum ThemeType {
- Light,
- Dark,
- Custom,
-}
-
#[derive(Debug, Clone)]
enum Message {
- ThemeChanged(ThemeType),
+ ThemeChanged(Theme),
InputChanged(String),
ButtonPressed,
SliderChanged(f32),
@@ -50,20 +42,7 @@ impl Sandbox for Styling {
fn update(&mut self, message: Message) {
match message {
Message::ThemeChanged(theme) => {
- self.theme = match theme {
- ThemeType::Light => Theme::Light,
- ThemeType::Dark => Theme::Dark,
- ThemeType::Custom => Theme::custom(
- String::from("Custom"),
- theme::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),
- },
- ),
- }
+ self.theme = theme;
}
Message::InputChanged(value) => self.input_value = value,
Message::ButtonPressed => {}
@@ -74,24 +53,16 @@ impl Sandbox for Styling {
}
fn view(&self) -> Element<Message> {
- let choose_theme =
- [ThemeType::Light, ThemeType::Dark, ThemeType::Custom]
- .iter()
- .fold(
- column![text("Choose a theme:")].spacing(10),
- |column, theme| {
- column.push(radio(
- format!("{theme:?}"),
- *theme,
- Some(match self.theme {
- Theme::Light => ThemeType::Light,
- Theme::Dark => ThemeType::Dark,
- Theme::Custom { .. } => ThemeType::Custom,
- }),
- Message::ThemeChanged,
- ))
- },
- );
+ let choose_theme = column![
+ text("Theme:"),
+ pick_list(
+ Theme::ALL,
+ Some(self.theme.clone()),
+ Message::ThemeChanged
+ )
+ .width(Length::Fill),
+ ]
+ .spacing(10);
let text_input = text_input("Type something...", &self.input_value)
.on_input(Message::InputChanged)