diff options
| author | 2024-02-03 19:07:06 +0100 | |
|---|---|---|
| committer | 2024-02-03 19:07:06 +0100 | |
| commit | 878134883e5298aa8e12261a3ebd85879eae1d19 (patch) | |
| tree | fe8fcec55cce4d8ff74bbf234e1e250bc55bcc1c /style | |
| parent | 6756594fc6edc699f8a254c369aabdecc4e2dcea (diff) | |
| parent | ed02c1b24d22122e292b54950381589f29c5b21e (diff) | |
| download | iced-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 'style')
| -rw-r--r-- | style/src/theme.rs | 46 | ||||
| -rw-r--r-- | style/src/theme/palette.rs | 92 | 
2 files changed, 134 insertions, 4 deletions
| diff --git a/style/src/theme.rs b/style/src/theme.rs index 166410ae..96f91260 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -25,6 +25,7 @@ use crate::core::{Background, Border, Color, Shadow, Vector};  use std::fmt;  use std::rc::Rc; +use std::sync::Arc;  /// A built-in theme.  #[derive(Debug, Clone, PartialEq, Default)] @@ -34,13 +35,34 @@ pub enum Theme {      Light,      /// The built-in dark variant.      Dark, +    /// The built-in Dracula variant. +    Dracula, +    /// The built-in Nord variant. +    Nord, +    /// The built-in Solarized Light variant. +    SolarizedLight, +    /// The built-in Solarized Dark variant. +    SolarizedDark, +    /// The built-in Gruvbox Light variant. +    GruvboxLight, +    /// The built-in Gruvbox Dark variant. +    GruvboxDark,      /// A [`Theme`] that uses a [`Custom`] palette. -    Custom(Box<Custom>), +    Custom(Arc<Custom>),  }  impl Theme {      /// A list with all the defined themes. -    pub const ALL: &'static [Self] = &[Self::Light, Self::Dark]; +    pub const ALL: &'static [Self] = &[ +        Self::Light, +        Self::Dark, +        Self::Dracula, +        Self::Nord, +        Self::SolarizedLight, +        Self::SolarizedDark, +        Self::GruvboxLight, +        Self::GruvboxDark, +    ];      /// Creates a new custom [`Theme`] from the given [`Palette`].      pub fn custom(name: String, palette: Palette) -> Self { @@ -54,7 +76,7 @@ impl Theme {          palette: Palette,          generate: impl FnOnce(Palette) -> palette::Extended,      ) -> Self { -        Self::Custom(Box::new(Custom::with_fn(name, palette, generate))) +        Self::Custom(Arc::new(Custom::with_fn(name, palette, generate)))      }      /// Returns the [`Palette`] of the [`Theme`]. @@ -62,6 +84,12 @@ impl Theme {          match self {              Self::Light => Palette::LIGHT,              Self::Dark => Palette::DARK, +            Self::Dracula => Palette::DRACULA, +            Self::Nord => Palette::NORD, +            Self::SolarizedLight => Palette::SOLARIZED_LIGHT, +            Self::SolarizedDark => Palette::SOLARIZED_DARK, +            Self::GruvboxLight => Palette::GRUVBOX_LIGHT, +            Self::GruvboxDark => Palette::GRUVBOX_DARK,              Self::Custom(custom) => custom.palette,          }      } @@ -71,6 +99,12 @@ impl Theme {          match self {              Self::Light => &palette::EXTENDED_LIGHT,              Self::Dark => &palette::EXTENDED_DARK, +            Self::Dracula => &palette::EXTENDED_DRACULA, +            Self::Nord => &palette::EXTENDED_NORD, +            Self::SolarizedLight => &palette::EXTENDED_SOLARIZED_LIGHT, +            Self::SolarizedDark => &palette::EXTENDED_SOLARIZED_DARK, +            Self::GruvboxLight => &palette::EXTENDED_GRUVBOX_LIGHT, +            Self::GruvboxDark => &palette::EXTENDED_GRUVBOX_DARK,              Self::Custom(custom) => &custom.extended,          }      } @@ -81,6 +115,12 @@ impl fmt::Display for Theme {          match self {              Self::Light => write!(f, "Light"),              Self::Dark => write!(f, "Dark"), +            Self::Dracula => write!(f, "Dracula"), +            Self::Nord => write!(f, "Nord"), +            Self::SolarizedLight => write!(f, "Solarized Light"), +            Self::SolarizedDark => write!(f, "Solarized Dark"), +            Self::GruvboxLight => write!(f, "Gruvbox Light"), +            Self::GruvboxDark => write!(f, "Gruvbox Dark"),              Self::Custom(custom) => custom.fmt(f),          }      } diff --git a/style/src/theme/palette.rs b/style/src/theme/palette.rs index 76977a29..d5a1a5d9 100644 --- a/style/src/theme/palette.rs +++ b/style/src/theme/palette.rs @@ -1,5 +1,5 @@  //! Define the colors of a theme. -use iced_core::Color; +use crate::core::{color, Color};  use once_cell::sync::Lazy;  use palette::color_difference::Wcag21RelativeContrast; @@ -67,6 +67,72 @@ impl Palette {              0x3F as f32 / 255.0,          ),      }; + +    /// The built-in Dracula variant of a [`Palette`]. +    /// +    /// Source: https://draculatheme.com +    pub const DRACULA: Self = Self { +        background: color!(0x282A36), // BACKGROUND +        text: color!(0xf8f8f2),       // FOREGROUND +        primary: color!(0xbd93f9),    // PURPLE +        success: color!(0x50fa7b),    // GREEN +        danger: color!(0xff5555),     // RED +    }; + +    /// The built-in Nord variant of a [`Palette`]. +    /// +    /// Source: https://www.nordtheme.com/docs/colors-and-palettes +    pub const NORD: Self = Self { +        background: color!(0x2e3440), // nord0 +        text: color!(0xeceff4),       // nord6 +        primary: color!(0x8fbcbb),    // nord7 +        success: color!(0xa3be8c),    // nord14 +        danger: color!(0xbf616a),     // nord11 +    }; + +    /// The built-in Solarized Light variant of a [`Palette`]. +    /// +    /// Source: https://ethanschoonover.com/solarized +    pub const SOLARIZED_LIGHT: Self = Self { +        background: color!(0xfdf6e3), // base3 +        text: color!(0x657b83),       // base00 +        primary: color!(0x2aa198),    // cyan +        success: color!(0x859900),    // green +        danger: color!(0xdc322f),     // red +    }; + +    /// The built-in Solarized Dark variant of a [`Palette`]. +    /// +    /// Source: https://ethanschoonover.com/solarized +    pub const SOLARIZED_DARK: Self = Self { +        background: color!(0x002b36), // base03 +        text: color!(0x839496),       // base0 +        primary: color!(0x2aa198),    // cyan +        success: color!(0x859900),    // green +        danger: color!(0xdc322f),     // red +    }; + +    /// The built-in Gruvbox Light variant of a [`Palette`]. +    /// +    /// Source: https://github.com/morhetz/gruvbox +    pub const GRUVBOX_LIGHT: Self = Self { +        background: color!(0xfbf1c7), // light BG_0 +        text: color!(0x282828),       // light FG0_29 +        primary: color!(0x458588),    // light BLUE_4 +        success: color!(0x98971a),    // light GREEN_2 +        danger: color!(0xcc241d),     // light RED_1 +    }; + +    /// The built-in Gruvbox Dark variant of a [`Palette`]. +    /// +    /// Source: https://github.com/morhetz/gruvbox +    pub const GRUVBOX_DARK: Self = Self { +        background: color!(0x282828), // dark BG_0 +        text: color!(0xfbf1c7),       // dark FG0_29 +        primary: color!(0x458588),    // dark BLUE_4 +        success: color!(0x98971a),    // dark GREEN_2 +        danger: color!(0xcc241d),     // dark RED_1 +    };  }  /// An extended set of colors generated from a [`Palette`]. @@ -94,6 +160,30 @@ pub static EXTENDED_LIGHT: Lazy<Extended> =  pub static EXTENDED_DARK: Lazy<Extended> =      Lazy::new(|| Extended::generate(Palette::DARK)); +/// The built-in Dracula variant of an [`Extended`] palette. +pub static EXTENDED_DRACULA: Lazy<Extended> = +    Lazy::new(|| Extended::generate(Palette::DRACULA)); + +/// The built-in Nord variant of an [`Extended`] palette. +pub static EXTENDED_NORD: Lazy<Extended> = +    Lazy::new(|| Extended::generate(Palette::NORD)); + +/// The built-in Solarized Light variant of an [`Extended`] palette. +pub static EXTENDED_SOLARIZED_LIGHT: Lazy<Extended> = +    Lazy::new(|| Extended::generate(Palette::SOLARIZED_LIGHT)); + +/// The built-in Solarized Dark variant of an [`Extended`] palette. +pub static EXTENDED_SOLARIZED_DARK: Lazy<Extended> = +    Lazy::new(|| Extended::generate(Palette::SOLARIZED_DARK)); + +/// The built-in Gruvbox Light variant of an [`Extended`] palette. +pub static EXTENDED_GRUVBOX_LIGHT: Lazy<Extended> = +    Lazy::new(|| Extended::generate(Palette::GRUVBOX_LIGHT)); + +/// The built-in Gruvbox Dark variant of an [`Extended`] palette. +pub static EXTENDED_GRUVBOX_DARK: Lazy<Extended> = +    Lazy::new(|| Extended::generate(Palette::GRUVBOX_DARK)); +  impl Extended {      /// Generates an [`Extended`] palette from a simple [`Palette`].      pub fn generate(palette: Palette) -> Self { | 
