#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub enum Theme {
#[default]
Default,
Dark,
Forest,
Neutral,
}
#[derive(Debug, Clone)]
pub struct ThemeVars {
pub background: &'static str,
pub primary_color: &'static str,
pub primary_border: &'static str,
pub primary_text: &'static str,
pub secondary_color: &'static str,
pub secondary_border: &'static str,
pub secondary_text: &'static str,
pub tertiary_color: &'static str,
pub tertiary_border: &'static str,
pub tertiary_text: &'static str,
pub line_color: &'static str,
pub text_color: &'static str,
pub node_border: &'static str,
pub cluster_bg: &'static str,
pub cluster_border: &'static str,
pub title_color: &'static str,
pub edge_label_bg: &'static str,
pub font_family: &'static str,
pub font_size: f64,
}
impl Theme {
pub fn resolve(self) -> ThemeVars {
match self {
Theme::Default => ThemeVars {
background: "#ffffff",
primary_color: "#ECECFF",
primary_border: "#9370DB",
primary_text: "#333333",
secondary_color: "#ffffde",
secondary_border: "#aaaa33",
secondary_text: "#333333",
tertiary_color: "#fff0f0",
tertiary_border: "#ff0000",
tertiary_text: "#333333",
line_color: "#333333",
text_color: "#333333",
node_border: "#9370DB",
cluster_bg: "#ffffde",
cluster_border: "#aaaa33",
title_color: "#333333",
edge_label_bg: "#ffffff",
font_family: "Arial, sans-serif",
font_size: 14.0,
},
Theme::Dark => ThemeVars {
background: "#1e1e1e",
primary_color: "#1f2020",
primary_border: "#81B1DB",
primary_text: "#ccc",
secondary_color: "#323232",
secondary_border: "#81B1DB",
secondary_text: "#ccc",
tertiary_color: "#3a3a3a",
tertiary_border: "#81B1DB",
tertiary_text: "#ccc",
line_color: "#81B1DB",
text_color: "#ccc",
node_border: "#81B1DB",
cluster_bg: "#323232",
cluster_border: "#81B1DB",
title_color: "#F9FFFE",
edge_label_bg: "#323232",
font_family: "Arial, sans-serif",
font_size: 14.0,
},
Theme::Forest => ThemeVars {
background: "#ffffff",
primary_color: "#cde498",
primary_border: "#13540c",
primary_text: "#333333",
secondary_color: "#cdffb2",
secondary_border: "#6eaa49",
secondary_text: "#333333",
tertiary_color: "#fff",
tertiary_border: "#13540c",
tertiary_text: "#333333",
line_color: "#333333",
text_color: "#333333",
node_border: "#13540c",
cluster_bg: "#cdffb2",
cluster_border: "#6eaa49",
title_color: "#333333",
edge_label_bg: "#ffffff",
font_family: "Arial, sans-serif",
font_size: 14.0,
},
Theme::Neutral => ThemeVars {
background: "#ffffff",
primary_color: "#eee",
primary_border: "#999",
primary_text: "#333333",
secondary_color: "#f4f4f4",
secondary_border: "#999",
secondary_text: "#333333",
tertiary_color: "#fff",
tertiary_border: "#999",
tertiary_text: "#333333",
line_color: "#999",
text_color: "#333333",
node_border: "#999",
cluster_bg: "#f4f4f4",
cluster_border: "#999",
title_color: "#333333",
edge_label_bg: "#ffffff",
font_family: "Arial, sans-serif",
font_size: 14.0,
},
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_theme_has_white_bg() {
let vars = Theme::Default.resolve();
assert_eq!(vars.background, "#ffffff");
}
#[test]
fn dark_theme_has_dark_bg() {
let vars = Theme::Dark.resolve();
assert_eq!(vars.background, "#1e1e1e");
}
#[test]
fn all_themes_resolve() {
for t in [Theme::Default, Theme::Dark, Theme::Forest, Theme::Neutral] {
let v = t.resolve();
assert!(!v.font_family.is_empty());
assert!(v.font_size > 0.0);
}
}
}