luthien_plugin/
theme.rs

1use crate::palette::Srgb;
2use serde::{Deserialize, Serialize};
3use std::path::PathBuf;
4
5/// Colored palette of generic data.
6///
7/// Here, this is only used for [`Srgb`], but it can also be used to further process the
8/// given colors.
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
10pub struct Palette<T> {
11    pub black: T,
12    pub red: T,
13    pub green: T,
14    pub yellow: T,
15    pub blue: T,
16    pub purple: T,
17    pub cyan: T,
18    pub white: T,
19}
20
21impl<T> Palette<T> {
22    /// Returns a [`Palette`] where every element is one value.
23    pub fn uniform(v: T) -> Self
24    where
25        T: Clone,
26    {
27        Self {
28            black: v.clone(),
29            red: v.clone(),
30            green: v.clone(),
31            yellow: v.clone(),
32            blue: v.clone(),
33            purple: v.clone(),
34            cyan: v.clone(),
35            white: v,
36        }
37    }
38
39    /// Convert a reference to a [`Palette<T>`] to a [`Palette<&T>`].
40    pub fn as_ref(&self) -> Palette<&T> {
41        Palette {
42            black: &self.black,
43            red: &self.red,
44            green: &self.green,
45            yellow: &self.yellow,
46            blue: &self.blue,
47            purple: &self.purple,
48            cyan: &self.cyan,
49            white: &self.white,
50        }
51    }
52
53    /// Zip this [`Palette`] with another, returning a [`Palette`] of tuples.
54    pub fn zip<U>(self, other: Palette<U>) -> Palette<(T, U)> {
55        Palette {
56            black: (self.black, other.black),
57            red: (self.red, other.red),
58            green: (self.green, other.green),
59            yellow: (self.yellow, other.yellow),
60            blue: (self.blue, other.blue),
61            purple: (self.purple, other.purple),
62            cyan: (self.cyan, other.cyan),
63            white: (self.white, other.white),
64        }
65    }
66
67    /// Apply a function to each element of this [`Palette`], creating another palette with the
68    /// return values.
69    pub fn map<F, U>(self, mut f: F) -> Palette<U>
70    where
71        F: FnMut(T) -> U,
72    {
73        Palette {
74            black: f(self.black),
75            red: f(self.red),
76            green: f(self.green),
77            yellow: f(self.yellow),
78            blue: f(self.blue),
79            purple: f(self.purple),
80            cyan: f(self.cyan),
81            white: f(self.white),
82        }
83    }
84}
85
86/// The [`Theme`]'s colors.
87#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
88pub struct Colors<Color = Srgb> {
89    pub palette: Palette<Color>,
90    pub accents: Vec<Color>,
91    pub foreground: Color,
92    pub background: Color,
93}
94
95/// A theme passed to the plugin.
96#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
97pub struct Theme {
98    pub wallpaper: Option<PathBuf>,
99    pub colors: Colors,
100}