chore: audit components
This commit is contained in:
@@ -9,37 +9,37 @@ use crate::ThemeVariant;
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
|
||||
pub struct ThemeDefinition {
|
||||
pub mode: Option<ThemeVariant>,
|
||||
pub control_radius: Option<f32>,
|
||||
pub overlay_radius: Option<f32>,
|
||||
pub sm_radius: Option<f32>,
|
||||
pub accent: Option<String>,
|
||||
pub accent_foreground: Option<String>,
|
||||
pub background: Option<String>,
|
||||
pub foreground: Option<String>,
|
||||
pub surface: Option<String>,
|
||||
pub surface_foreground: Option<String>,
|
||||
pub primary: Option<String>,
|
||||
pub primary_foreground: Option<String>,
|
||||
pub secondary: Option<String>,
|
||||
pub secondary_foreground: Option<String>,
|
||||
pub muted: Option<String>,
|
||||
pub muted_hover: Option<String>,
|
||||
pub muted_foreground: Option<String>,
|
||||
pub destructive: Option<String>,
|
||||
pub destructive_foreground: Option<String>,
|
||||
pub success: Option<String>,
|
||||
pub success_foreground: Option<String>,
|
||||
pub warning: Option<String>,
|
||||
pub warning_foreground: Option<String>,
|
||||
pub info: Option<String>,
|
||||
pub info_foreground: Option<String>,
|
||||
pub border: Option<String>,
|
||||
pub input: Option<String>,
|
||||
pub ring: Option<String>,
|
||||
pub selection: Option<String>,
|
||||
pub overlay: Option<String>,
|
||||
pub scrollbar_thumb: Option<String>,
|
||||
mode: Option<ThemeVariant>,
|
||||
control_radius: Option<f32>,
|
||||
overlay_radius: Option<f32>,
|
||||
sm_radius: Option<f32>,
|
||||
accent: Option<String>,
|
||||
accent_foreground: Option<String>,
|
||||
background: Option<String>,
|
||||
foreground: Option<String>,
|
||||
surface: Option<String>,
|
||||
surface_foreground: Option<String>,
|
||||
primary: Option<String>,
|
||||
primary_foreground: Option<String>,
|
||||
secondary: Option<String>,
|
||||
secondary_foreground: Option<String>,
|
||||
muted: Option<String>,
|
||||
muted_hover: Option<String>,
|
||||
muted_foreground: Option<String>,
|
||||
destructive: Option<String>,
|
||||
destructive_foreground: Option<String>,
|
||||
success: Option<String>,
|
||||
success_foreground: Option<String>,
|
||||
warning: Option<String>,
|
||||
warning_foreground: Option<String>,
|
||||
info: Option<String>,
|
||||
info_foreground: Option<String>,
|
||||
border: Option<String>,
|
||||
input: Option<String>,
|
||||
ring: Option<String>,
|
||||
selection: Option<String>,
|
||||
overlay: Option<String>,
|
||||
scrollbar_thumb: Option<String>,
|
||||
}
|
||||
|
||||
impl ThemeDefinition {
|
||||
@@ -47,112 +47,140 @@ impl ThemeDefinition {
|
||||
Ok(toml::from_str(source)?)
|
||||
}
|
||||
|
||||
pub fn mode(&self) -> Option<ThemeVariant> {
|
||||
self.mode
|
||||
}
|
||||
|
||||
pub fn control_radius(&self) -> Option<f32> {
|
||||
self.control_radius
|
||||
}
|
||||
|
||||
pub fn overlay_radius(&self) -> Option<f32> {
|
||||
self.overlay_radius
|
||||
}
|
||||
|
||||
pub fn sm_radius(&self) -> Option<f32> {
|
||||
self.sm_radius
|
||||
}
|
||||
|
||||
pub fn accent(&self) -> Option<Hsla> {
|
||||
parse_hex(self.accent.as_deref()?)
|
||||
self.color(&self.accent, "accent")
|
||||
}
|
||||
|
||||
pub fn accent_foreground(&self) -> Option<Hsla> {
|
||||
parse_hex(self.accent_foreground.as_deref()?)
|
||||
self.color(&self.accent_foreground, "accent_foreground")
|
||||
}
|
||||
|
||||
pub fn background(&self) -> Option<Hsla> {
|
||||
parse_hex(self.background.as_deref()?)
|
||||
self.color(&self.background, "background")
|
||||
}
|
||||
|
||||
pub fn foreground(&self) -> Option<Hsla> {
|
||||
parse_hex(self.foreground.as_deref()?)
|
||||
self.color(&self.foreground, "foreground")
|
||||
}
|
||||
|
||||
pub fn surface(&self) -> Option<Hsla> {
|
||||
parse_hex(self.surface.as_deref()?)
|
||||
self.color(&self.surface, "surface")
|
||||
}
|
||||
|
||||
pub fn surface_foreground(&self) -> Option<Hsla> {
|
||||
parse_hex(self.surface_foreground.as_deref()?)
|
||||
self.color(&self.surface_foreground, "surface_foreground")
|
||||
}
|
||||
|
||||
pub fn primary(&self) -> Option<Hsla> {
|
||||
parse_hex(self.primary.as_deref()?)
|
||||
self.color(&self.primary, "primary")
|
||||
}
|
||||
|
||||
pub fn primary_foreground(&self) -> Option<Hsla> {
|
||||
parse_hex(self.primary_foreground.as_deref()?)
|
||||
self.color(&self.primary_foreground, "primary_foreground")
|
||||
}
|
||||
|
||||
pub fn secondary(&self) -> Option<Hsla> {
|
||||
parse_hex(self.secondary.as_deref()?)
|
||||
self.color(&self.secondary, "secondary")
|
||||
}
|
||||
|
||||
pub fn secondary_foreground(&self) -> Option<Hsla> {
|
||||
parse_hex(self.secondary_foreground.as_deref()?)
|
||||
self.color(&self.secondary_foreground, "secondary_foreground")
|
||||
}
|
||||
|
||||
pub fn muted(&self) -> Option<Hsla> {
|
||||
parse_hex(self.muted.as_deref()?)
|
||||
self.color(&self.muted, "muted")
|
||||
}
|
||||
|
||||
pub fn muted_hover(&self) -> Option<Hsla> {
|
||||
parse_hex(self.muted_hover.as_deref()?)
|
||||
self.color(&self.muted_hover, "muted_hover")
|
||||
}
|
||||
|
||||
pub fn muted_foreground(&self) -> Option<Hsla> {
|
||||
parse_hex(self.muted_foreground.as_deref()?)
|
||||
self.color(&self.muted_foreground, "muted_foreground")
|
||||
}
|
||||
|
||||
pub fn destructive(&self) -> Option<Hsla> {
|
||||
parse_hex(self.destructive.as_deref()?)
|
||||
self.color(&self.destructive, "destructive")
|
||||
}
|
||||
|
||||
pub fn destructive_foreground(&self) -> Option<Hsla> {
|
||||
parse_hex(self.destructive_foreground.as_deref()?)
|
||||
self.color(&self.destructive_foreground, "destructive_foreground")
|
||||
}
|
||||
|
||||
pub fn success(&self) -> Option<Hsla> {
|
||||
parse_hex(self.success.as_deref()?)
|
||||
self.color(&self.success, "success")
|
||||
}
|
||||
|
||||
pub fn success_foreground(&self) -> Option<Hsla> {
|
||||
parse_hex(self.success_foreground.as_deref()?)
|
||||
self.color(&self.success_foreground, "success_foreground")
|
||||
}
|
||||
|
||||
pub fn warning(&self) -> Option<Hsla> {
|
||||
parse_hex(self.warning.as_deref()?)
|
||||
self.color(&self.warning, "warning")
|
||||
}
|
||||
|
||||
pub fn warning_foreground(&self) -> Option<Hsla> {
|
||||
parse_hex(self.warning_foreground.as_deref()?)
|
||||
self.color(&self.warning_foreground, "warning_foreground")
|
||||
}
|
||||
|
||||
pub fn info(&self) -> Option<Hsla> {
|
||||
parse_hex(self.info.as_deref()?)
|
||||
self.color(&self.info, "info")
|
||||
}
|
||||
|
||||
pub fn info_foreground(&self) -> Option<Hsla> {
|
||||
parse_hex(self.info_foreground.as_deref()?)
|
||||
self.color(&self.info_foreground, "info_foreground")
|
||||
}
|
||||
|
||||
pub fn border(&self) -> Option<Hsla> {
|
||||
parse_hex(self.border.as_deref()?)
|
||||
self.color(&self.border, "border")
|
||||
}
|
||||
|
||||
pub fn input(&self) -> Option<Hsla> {
|
||||
parse_hex(self.input.as_deref()?)
|
||||
self.color(&self.input, "input")
|
||||
}
|
||||
|
||||
pub fn ring(&self) -> Option<Hsla> {
|
||||
parse_hex(self.ring.as_deref()?)
|
||||
self.color(&self.ring, "ring")
|
||||
}
|
||||
|
||||
pub fn selection(&self) -> Option<Hsla> {
|
||||
parse_hex(self.selection.as_deref()?)
|
||||
self.color(&self.selection, "selection")
|
||||
}
|
||||
|
||||
pub fn overlay(&self) -> Option<Hsla> {
|
||||
parse_hex(self.overlay.as_deref()?)
|
||||
self.color(&self.overlay, "overlay")
|
||||
}
|
||||
|
||||
pub fn scrollbar_thumb(&self) -> Option<Hsla> {
|
||||
parse_hex(self.scrollbar_thumb.as_deref()?)
|
||||
self.color(&self.scrollbar_thumb, "scrollbar_thumb")
|
||||
}
|
||||
|
||||
/// Parses a color field, warning when a stated value is malformed.
|
||||
fn color(&self, field: &Option<String>, role: &str) -> Option<Hsla> {
|
||||
let value = field.as_deref()?;
|
||||
match parse_hex(value) {
|
||||
Some(color) => Some(color),
|
||||
None => {
|
||||
log::warn!("theme definition {role} is not #rgb/#rrggbb: {value:?}");
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,12 +254,12 @@ mod tests {
|
||||
"mode = \"dark\"\naccent = \"#7aa2f7\"\nbackground = \"#1a1b26\"\ninfo = \"#38bdf8\"\noverlay_radius = 15.0\nsm_radius = 6.0\n",
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(def.mode, Some(crate::ThemeVariant::Dark));
|
||||
assert_eq!(def.mode(), Some(crate::ThemeVariant::Dark));
|
||||
assert!(def.accent().is_some());
|
||||
assert!(def.info().is_some());
|
||||
assert!(def.foreground().is_none());
|
||||
assert_eq!(def.overlay_radius, Some(15.0));
|
||||
assert_eq!(def.sm_radius, Some(6.0));
|
||||
assert_eq!(def.overlay_radius(), Some(15.0));
|
||||
assert_eq!(def.sm_radius(), Some(6.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user