Skip to main content

boltz_theme/
ui_density.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4/// Specifies the density of the UI.
5/// Note: This setting is still experimental.
6#[derive(
7    Debug,
8    Default,
9    PartialEq,
10    Eq,
11    PartialOrd,
12    Ord,
13    Hash,
14    Clone,
15    Copy,
16    Serialize,
17    Deserialize,
18    JsonSchema,
19)]
20#[serde(rename_all = "snake_case")]
21pub enum UiDensity {
22    /// A denser UI with tighter spacing and smaller elements.
23    #[serde(alias = "compact")]
24    Compact,
25    #[default]
26    #[serde(alias = "default")]
27    /// The default UI density.
28    Default,
29    #[serde(alias = "comfortable")]
30    /// A looser UI with more spacing and larger elements.
31    Comfortable,
32}
33
34impl UiDensity {
35    /// The spacing ratio of a given density.
36    /// TODO: Standardize usage throughout the app or remove
37    pub fn spacing_ratio(self) -> f32 {
38        match self {
39            UiDensity::Compact => 0.75,
40            UiDensity::Default => 1.0,
41            UiDensity::Comfortable => 1.25,
42        }
43    }
44}
45
46impl From<String> for UiDensity {
47    fn from(s: String) -> Self {
48        match s.as_str() {
49            "compact" => Self::Compact,
50            "default" => Self::Default,
51            "comfortable" => Self::Comfortable,
52            _ => Self::default(),
53        }
54    }
55}
56
57impl From<UiDensity> for String {
58    fn from(val: UiDensity) -> Self {
59        match val {
60            UiDensity::Compact => "compact".to_string(),
61            UiDensity::Default => "default".to_string(),
62            UiDensity::Comfortable => "comfortable".to_string(),
63        }
64    }
65}