//! Style, Theme, style_index, Color use rgb::RGBA8; use lmfu::json::{JsonFile, Value, Path}; use crate::{Error, error, ArcStr, Vec}; fn parse_color(string: &str) -> Result { let len = string.len(); let (double, grain, times) = match len { 3 | 4 => Ok((true, 1, len)), 6 | 8 => Ok((false, 2, len / 2)), _ => Err(error!("Theme JSON: Invalid color: {:?}", string)), }?; let mut color = [0, 0, 0, 255]; for i in 0..times { let sub = &string[i * grain..][..grain]; let mut c = u8::from_str_radix(sub, 16).map_err(|_| { error!("Theme JSON: Invalid color: {:?}", string) })?; if double { c |= c << 4; } color[i] = c; } Ok(color.into()) } /// Represent a node's visual style. #[derive(Debug, Copy, Clone)] pub struct Style { pub background: RGBA8, pub foreground: RGBA8, pub outline: RGBA8, } pub const DEFAULT_STYLE: &'static str = "default"; /// A theme which can be used by the app. #[derive(Debug, Clone)] pub struct Theme { pub name: ArcStr, pub styles: Vec