ferrite_config/ui/
selection.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
use crate::{
    defaults::selection::*,
    error::{ConfigError, Result},
    types::{ColorRGBA, MouseButton},
};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SelectionConfig {
    pub enabled:             bool,
    pub show_box:            bool,
    pub trigger_button:      MouseButton,
    pub zoom_to_longer_side: bool,
    pub box_color:           ColorRGBA,
    pub box_thickness:       f64,
}

impl Default for SelectionConfig {
    fn default() -> Self {
        Self {
            enabled:             ENABLED,
            show_box:            SHOW_BOX,
            trigger_button:      TRIGGER_BUTTON,
            zoom_to_longer_side: ZOOM_TO_LONGER_SIDE,
            box_color:           ColorRGBA::new(
                BOX_COLOR.0,
                BOX_COLOR.1,
                BOX_COLOR.2,
                BOX_COLOR.3,
            ),
            box_thickness:       BOX_THICKNESS,
        }
    }
}
impl SelectionConfig {
    pub fn validate(&self) -> Result<()> {
        if self.box_thickness <= 0.0 {
            return Err(ConfigError::ValidationError(
                "Box thickness must be positive".into(),
            ));
        }
        Ok(())
    }
}