From 8a015e051d2f8fbc37937e32c1b2b41af6a21e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Thebault?= Date: Wed, 27 May 2026 23:55:45 +0200 Subject: [PATCH] dracula theme --- examples/common/mod.rs | 2 + src/style.rs | 17 +++++++++ src/style/dracula.rs | 84 ++++++++++++++++++++++++++++++++++++++++++ src/style/series.rs | 8 +++- src/style/theme.rs | 14 ++++++- 5 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 src/style/dracula.rs diff --git a/examples/common/mod.rs b/examples/common/mod.rs index bd2d3e1..7ff8e20 100644 --- a/examples/common/mod.rs +++ b/examples/common/mod.rs @@ -60,6 +60,8 @@ fn parse_args() -> Args { "frappe" => args.style = Some(Style::catppuccin_frappe()), "macchiato" => args.style = Some(Style::catppuccin_macchiato()), "mocha" => args.style = Some(Style::catppuccin_mocha()), + "dracula" => args.style = Some(Style::dracula()), + "alucard" => args.style = Some(Style::alucard()), "catppuccin-latte" => args.style = Some(Style::catppuccin_latte()), "catppuccin-frappe" => args.style = Some(Style::catppuccin_frappe()), "catppuccin-macchiato" => args.style = Some(Style::catppuccin_macchiato()), diff --git a/src/style.rs b/src/style.rs index 98c332e..407ff67 100644 --- a/src/style.rs +++ b/src/style.rs @@ -1,6 +1,7 @@ //! Style definitions for lines, fills, markers, and themes. mod catppuccin; pub(crate) mod defaults; +mod dracula; pub mod series; pub mod theme; @@ -74,6 +75,22 @@ impl Style { } } + /// Create a Dracula theme and palette + pub const fn dracula() -> Self { + Style { + theme: Theme::Dracula, + palette: Palette::Dracula, + } + } + + /// Create an Alucard theme and palette + pub const fn alucard() -> Self { + Style { + theme: Theme::Alucard, + palette: Palette::Alucard, + } + } + /// Create a Catppuccin Mocha theme and palette pub const fn catppuccin_mocha() -> Self { Style { diff --git a/src/style/dracula.rs b/src/style/dracula.rs new file mode 100644 index 0000000..4fbab89 --- /dev/null +++ b/src/style/dracula.rs @@ -0,0 +1,84 @@ +use plotive_base::Rgba8; + +use crate::style; + +/// Dracula theme +#[derive(Debug, Clone, Copy)] +pub struct Dracula; + +/// Alucard theme +#[derive(Debug, Clone, Copy)] +pub struct Alucard; + +pub trait Colors { + const BACKGROUND: Rgba8; + const _CURRENT_LINE: Rgba8; + const SELECTION: Rgba8; + const FOREGROUND: Rgba8; + const _COMMENT: Rgba8; + const CYAN: Rgba8; + const GREEN: Rgba8; + const ORANGE: Rgba8; + const PINK: Rgba8; + const PURPLE: Rgba8; + const RED: Rgba8; + const YELLOW: Rgba8; +} + +pub const fn theme_palette() -> style::theme::ThemePalette +where + C: Colors, +{ + style::theme::ThemePalette { + background: C::BACKGROUND, + foreground: C::FOREGROUND, + grid: C::FOREGROUND, + legend_fill: C::SELECTION, + legend_border: C::FOREGROUND, + } +} + +pub const fn series_colors() -> &'static [Rgba8] +where + F: Colors, +{ + &[ + F::CYAN, + F::RED, + F::YELLOW, + F::PINK, + F::PURPLE, + F::GREEN, + F::ORANGE, + ] +} + +impl Colors for Dracula { + const BACKGROUND: Rgba8 = Rgba8::from_hex(b"#282a36"); + const _CURRENT_LINE: Rgba8 = Rgba8::from_hex(b"#44475a"); + const SELECTION: Rgba8 = Rgba8::from_hex(b"#44475a"); + const FOREGROUND: Rgba8 = Rgba8::from_hex(b"#f8f8f2"); + const _COMMENT: Rgba8 = Rgba8::from_hex(b"#6272a4"); + const CYAN: Rgba8 = Rgba8::from_hex(b"#8be9fd"); + const GREEN: Rgba8 = Rgba8::from_hex(b"#50fa7b"); + const ORANGE: Rgba8 = Rgba8::from_hex(b"#ffb86c"); + const PINK: Rgba8 = Rgba8::from_hex(b"#ff79c6"); + const PURPLE: Rgba8 = Rgba8::from_hex(b"#bd93f9"); + const RED: Rgba8 = Rgba8::from_hex(b"#ff5555"); + const YELLOW: Rgba8 = Rgba8::from_hex(b"#f1fa8c"); +} + +impl Colors for Alucard { + const BACKGROUND: Rgba8 = Rgba8::from_hex(b"#fffbeb"); + const _CURRENT_LINE: Rgba8 = Rgba8::from_hex(b"#6c664b"); + const SELECTION: Rgba8 = Rgba8::from_hex(b"#cfcfde"); + const FOREGROUND: Rgba8 = Rgba8::from_hex(b"#1f1f1f"); + const _COMMENT: Rgba8 = Rgba8::from_hex(b"#6c664b"); + const CYAN: Rgba8 = Rgba8::from_hex(b"#036a96"); + const GREEN: Rgba8 = Rgba8::from_hex(b"#14710a"); + const ORANGE: Rgba8 = Rgba8::from_hex(b"#a34d14"); + const PINK: Rgba8 = Rgba8::from_hex(b"#a3144d"); + const PURPLE: Rgba8 = Rgba8::from_hex(b"#644ac9"); + const RED: Rgba8 = Rgba8::from_hex(b"#cb3a2a"); + const YELLOW: Rgba8 = Rgba8::from_hex(b"#846e15"); +} diff --git a/src/style/series.rs b/src/style/series.rs index 4629c3f..2772a15 100644 --- a/src/style/series.rs +++ b/src/style/series.rs @@ -1,7 +1,7 @@ /*! * This module deals with colors and style of data series. */ -use crate::style::{self, catppuccin, defaults}; +use crate::style::{self, catppuccin, defaults, dracula}; use crate::{ResolveColor, Rgba8}; /// A palette for data series. @@ -21,6 +21,10 @@ pub enum Palette { TolBright, /// Okabe & Ito colorblind-safe palette OkabeIto, + /// Dracula palette + Dracula, + /// Alucard palette + Alucard, /// Catppuccin Mocha palette CatppuccinMocha, /// Catppuccin Macchiato palette @@ -42,6 +46,8 @@ impl Palette { Palette::Pastel => palettes::PASTEL, Palette::TolBright => palettes::TOL_BRIGHT, Palette::OkabeIto => palettes::OKABE_ITO, + Palette::Dracula => dracula::series_colors::(), + Palette::Alucard => dracula::series_colors::(), Palette::CatppuccinMocha => catppuccin::series_colors::(), Palette::CatppuccinMacchiato => catppuccin::series_colors::(), Palette::CatppuccinFrappe => catppuccin::series_colors::(), diff --git a/src/style/theme.rs b/src/style/theme.rs index dbbc213..b72a4ed 100644 --- a/src/style/theme.rs +++ b/src/style/theme.rs @@ -1,7 +1,7 @@ //! Theme definitions and implementations use crate::color::{self, Rgb8, Rgba8}; -use crate::style::catppuccin; +use crate::style::{catppuccin, dracula}; use crate::{style, text}; /// A theme, for styling figures @@ -12,6 +12,10 @@ pub enum Theme { Light, /// Dark theme Dark, + /// Dracula theme + Dracula, + /// Alucard theme (Dracula light) + Alucard, /// Catppuccin Mocha theme CatppuccinMocha, /// Catppuccin Macchiato theme @@ -55,6 +59,8 @@ impl Theme { match self { Theme::Light => &ThemePalette::LIGHT, Theme::Dark => &ThemePalette::DARK, + Theme::Dracula => &ThemePalette::DRACULA, + Theme::Alucard => &ThemePalette::ALUCARD, Theme::CatppuccinLatte => &ThemePalette::CATPPUCCIN_LATTE, Theme::CatppuccinFrappe => &ThemePalette::CATPPUCCIN_FRAPPE, Theme::CatppuccinMacchiato => &ThemePalette::CATPPUCCIN_MACCHIATO, @@ -104,6 +110,12 @@ impl ThemePalette { legend_border: color::WHITE, }; + /// The Dracula built-in theme palette + pub const DRACULA: Self = dracula::theme_palette::(); + + /// The Alucard built-in theme palette + pub const ALUCARD: Self = dracula::theme_palette::(); + /// The catppuccin mocha built-in theme palette pub const CATPPUCCIN_MOCHA: Self = catppuccin::theme_palette::();