sunbeam_ir/
sunbeam_config.rs

1use crate::color::{ColorName, CssColor};
2use crate::font::FontName;
3use std::collections::{HashMap, HashSet};
4
5/// Configuration for Sunbeam.
6#[derive(serde::Serialize, serde::Deserialize)]
7pub struct SunbeamConfig {
8    /// Colors that can be used for text and backgrounds.
9    #[serde(default)]
10    pub colors: HashMap<ColorName, CssColor>,
11    /// Fonts that can be used for text.
12    #[serde(default)]
13    pub fonts: HashMap<FontName, Vec<String>>,
14    /// Pre-defined screen widths that can be used for media queries
15    #[serde(default)]
16    pub screen_widths: HashSet<u32>,
17}
18
19impl Default for SunbeamConfig {
20    fn default() -> Self {
21        SunbeamConfig {
22            colors: HashMap::new(),
23            fonts: HashMap::new(),
24            screen_widths: HashSet::default(),
25        }
26    }
27}
28
29pub(crate) trait ConfigLookup {
30    fn get_color(&self, color_name: &ColorName) -> Option<&CssColor>;
31
32    fn get_font(&self, font_name: &FontName) -> Option<&Vec<String>>;
33}
34
35impl ConfigLookup for SunbeamConfig {
36    fn get_color(&self, color_name: &ColorName) -> Option<&CssColor> {
37        self.colors.get(color_name)
38    }
39
40    fn get_font(&self, font_name: &FontName) -> Option<&Vec<String>> {
41        self.fonts.get(font_name)
42    }
43}