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