ferrite_config/
indicator.rs1use crate::{
2 defaults::indicator::*,
3 error::{ConfigError, Result},
4 types::{ColorRGBA, Position, Vector2D},
5};
6use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct IndicatorConfig {
10 pub font_size: f64,
11 pub font_family: String,
12 pub background_color: ColorRGBA,
13 pub text_color: ColorRGBA,
14 pub padding: Vector2D,
15 pub position: Position,
16 pub show_percentage: bool,
17}
18impl Default for IndicatorConfig {
19 fn default() -> Self {
20 Self {
21 font_size: FONT_SIZE,
22 font_family: FONT_FAMILY.to_string(),
23 background_color: ColorRGBA::new(
24 BACKGROUND_COLOR.0,
25 BACKGROUND_COLOR.1,
26 BACKGROUND_COLOR.2,
27 BACKGROUND_COLOR.3,
28 ),
29 text_color: ColorRGBA::new(
30 TEXT_COLOR.0,
31 TEXT_COLOR.1,
32 TEXT_COLOR.2,
33 TEXT_COLOR.3,
34 ),
35 padding: Vector2D::new(PADDING_X, PADDING_Y)
36 .expect("Default padding must be valid"),
37 position: POSITION,
38 show_percentage: SHOW_PERCENTAGE,
39 }
40 }
41}
42
43impl IndicatorConfig {
44 pub fn validate(&self) -> Result<()> {
45 if self.font_size <= 0.0 {
46 return Err(ConfigError::ValidationError(
47 "Font size must be positive".into(),
48 ));
49 }
50 if self.font_family.trim().is_empty() {
51 return Err(ConfigError::ValidationError(
52 "Font family cannot be empty".into(),
53 ));
54 }
55 Ok(())
56 }
57}