ferrite_config/ui/
indicator.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use crate::{
    defaults::indicator::*,
    error::{ConfigError, Result},
    types::{ColorRGBA, Corner, Vector2D},
};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct IndicatorConfig {
    pub font_size:        f64,
    pub font_family:      String,
    pub background_color: ColorRGBA,
    pub text_color:       ColorRGBA,
    pub padding:          Vector2D,
    pub corner:           Corner,
    pub show_percentage:  bool,
}
impl Default for IndicatorConfig {
    fn default() -> Self {
        Self {
            font_size:        FONT_SIZE,
            font_family:      FONT_FAMILY.to_string(),
            background_color: ColorRGBA::new(
                BACKGROUND_COLOR.0,
                BACKGROUND_COLOR.1,
                BACKGROUND_COLOR.2,
                BACKGROUND_COLOR.3,
            ),
            text_color:       ColorRGBA::new(
                TEXT_COLOR.0,
                TEXT_COLOR.1,
                TEXT_COLOR.2,
                TEXT_COLOR.3,
            ),
            padding:          Vector2D::new(PADDING_X, PADDING_Y)
                .expect("Default padding must be valid"),
            corner:           CORNER,
            show_percentage:  SHOW_PERCENTAGE,
        }
    }
}

impl IndicatorConfig {
    pub fn validate(&self) -> Result<()> {
        if self.font_size <= 0.0 {
            return Err(ConfigError::ValidationError(
                "Font size must be positive".into(),
            ));
        }
        if self.font_family.trim().is_empty() {
            return Err(ConfigError::ValidationError(
                "Font family cannot be empty".into(),
            ));
        }
        Ok(())
    }
}