diff --git a/config/src/background.rs b/config/src/background.rs index 338d952be..5be517e0c 100644 --- a/config/src/background.rs +++ b/config/src/background.rs @@ -44,13 +44,104 @@ impl Default for GradientOrientation { } } +#[derive(Debug, Copy, Clone, Deserialize, Serialize)] +pub enum GradientPreset { + Blues, + BrBg, + BuGn, + BuPu, + Cividis, + Cool, + CubeHelixDefault, + GnBu, + Greens, + Greys, + Inferno, + Magma, + OrRd, + Oranges, + PiYg, + Plasma, + PrGn, + PuBu, + PuBuGn, + PuOr, + PuRd, + Purples, + Rainbow, + RdBu, + RdGy, + RdPu, + RdYlBu, + RdYlGn, + Reds, + Sinebow, + Spectral, + Turbo, + Viridis, + Warm, + YlGn, + YlGnBu, + YlOrBr, + YlOrRd, +} + +impl GradientPreset { + fn build(self) -> colorgrad::Gradient { + match self { + Self::Blues => colorgrad::blues(), + Self::BrBg => colorgrad::br_bg(), + Self::BuGn => colorgrad::bu_gn(), + Self::BuPu => colorgrad::bu_pu(), + Self::Cividis => colorgrad::cividis(), + Self::Cool => colorgrad::cool(), + Self::CubeHelixDefault => colorgrad::cubehelix_default(), + Self::GnBu => colorgrad::gn_bu(), + Self::Greens => colorgrad::greens(), + Self::Greys => colorgrad::greys(), + Self::Inferno => colorgrad::inferno(), + Self::Magma => colorgrad::magma(), + Self::OrRd => colorgrad::or_rd(), + Self::Oranges => colorgrad::oranges(), + Self::PiYg => colorgrad::pi_yg(), + Self::Plasma => colorgrad::plasma(), + Self::PrGn => colorgrad::pr_gn(), + Self::PuBu => colorgrad::pu_bu(), + Self::PuBuGn => colorgrad::pu_bu_gn(), + Self::PuOr => colorgrad::pu_or(), + Self::PuRd => colorgrad::pu_rd(), + Self::Purples => colorgrad::purples(), + Self::Rainbow => colorgrad::rainbow(), + Self::RdBu => colorgrad::rd_bu(), + Self::RdGy => colorgrad::rd_gy(), + Self::RdPu => colorgrad::rd_pu(), + Self::RdYlBu => colorgrad::rd_yl_bu(), + Self::RdYlGn => colorgrad::rd_yl_gn(), + Self::Reds => colorgrad::reds(), + Self::Sinebow => colorgrad::sinebow(), + Self::Spectral => colorgrad::spectral(), + Self::Turbo => colorgrad::turbo(), + Self::Viridis => colorgrad::viridis(), + Self::Warm => colorgrad::warm(), + Self::YlGn => colorgrad::yl_gn(), + Self::YlGnBu => colorgrad::yl_gn_bu(), + Self::YlOrBr => colorgrad::yl_or_br(), + Self::YlOrRd => colorgrad::yl_or_rd(), + } + } +} + #[derive(Debug, Clone, Deserialize, Serialize)] pub struct Gradient { #[serde(default)] pub orientation: GradientOrientation, + #[serde(default)] pub colors: Vec, + #[serde(default)] + pub preset: Option, + #[serde(default)] pub interpolation: Interpolation, @@ -70,21 +161,26 @@ pub struct Gradient { impl Gradient { pub fn build(&self) -> anyhow::Result { use colorgrad::{BlendMode as CGMode, Interpolation as CGInterp}; - let colors: Vec<&str> = self.colors.iter().map(|s| s.as_str()).collect(); - let mut g = colorgrad::CustomGradient::new(); - g.html_colors(&colors); - g.mode(match self.blend { - BlendMode::Rgb => CGMode::Rgb, - BlendMode::LinearRgb => CGMode::LinearRgb, - BlendMode::Hsv => CGMode::Hsv, - BlendMode::Oklab => CGMode::Oklab, - }); - g.interpolation(match self.interpolation { - Interpolation::Linear => CGInterp::Linear, - Interpolation::Basis => CGInterp::Basis, - Interpolation::CatmullRom => CGInterp::CatmullRom, - }); - let g = g.build()?; + let g = match &self.preset { + Some(p) => p.build(), + None => { + let colors: Vec<&str> = self.colors.iter().map(|s| s.as_str()).collect(); + let mut g = colorgrad::CustomGradient::new(); + g.html_colors(&colors); + g.mode(match self.blend { + BlendMode::Rgb => CGMode::Rgb, + BlendMode::LinearRgb => CGMode::LinearRgb, + BlendMode::Hsv => CGMode::Hsv, + BlendMode::Oklab => CGMode::Oklab, + }); + g.interpolation(match self.interpolation { + Interpolation::Linear => CGInterp::Linear, + Interpolation::Basis => CGInterp::Basis, + Interpolation::CatmullRom => CGInterp::CatmullRom, + }); + g.build()? + } + }; match (self.segment_size, self.segment_smoothness) { (Some(size), Some(smoothness)) => Ok(g.sharp(size, smoothness)), (None, None) => Ok(g), diff --git a/docs/config/lua/config/window_background_gradient.md b/docs/config/lua/config/window_background_gradient.md index dbd74ec16..49c6a71a8 100644 --- a/docs/config/lua/config/window_background_gradient.md +++ b/docs/config/lua/config/window_background_gradient.md @@ -26,6 +26,11 @@ return { "#24243e" }, + -- Instead of specifying `colors`, you can use one of a number of + -- predefined, preset gradients. + -- A list of presets is shown in a section below. + -- preset = "Warm", + -- Specifies the interpolation style to be used. -- "Linear", "Basis" and "CatmullRom" as supported. -- The default is "Linear". @@ -98,3 +103,48 @@ return { ``` + +## Presets + +The following presets are available: + +|Preset|Gradient| +|------+--------| +|Blues|| +|BrBg|| +|BuGn|| +|BuPu|| +|Cividis|| +|Cool|| +|CubeHelixDefault|| +|GnBu|| +|Greens|| +|Greys|| +|Inferno|| +|Magma|| +|OrRd|| +|Oranges|| +|PiYg|| +|Plasma|| +|PrGn|| +|PuBu|| +|PuBuGn|| +|PuOr|| +|PuRd|| +|Purples|| +|Rainbow|| +|RdBu|| +|RdGy|| +|RdPu|| +|RdYlBu|| +|RdYlGn|| +|Reds|| +|Sinebow|| +|Spectral|| +|Turbo|| +|Viridis|| +|Warm|| +|YlGn|| +|YlGnBu|| +|YlOrBr|| +|YlOrRd||