layoutcss_parser/components/
rack.rs

1use indoc::formatdoc;
2use crate::harmonic::get_harmonic;
3
4use std::collections::HashSet;
5const RACK_STYLE: &str = r#"
6  rack-l{
7    display:flex;
8    flex-direction:column;
9  }
10
11  rack-l > [layout~="centered"]{
12      margin-block: auto;
13  }
14
15  rack-l > :first-child:not([layout~="centered"]):not(outsider-l[layout~="disinherit"]) {
16      margin-block-start: 0;
17  }
18
19  rack-l > :last-child:not([layout~="centered"]):not(outsider-l[layout~="disinherit"]) {
20      margin-block-end: 0;
21  }
22"#;
23
24fn rack_height_style(value: &str, harmonic: String) -> String {
25    formatdoc!(
26        r#"
27        rack-l[layout~="height:{value}"]{{
28            height: {harmonic};
29            overflow-y: auto;
30        }}
31        "#,
32    )
33}
34
35fn rack_min_height_style(value: &str, harmonic: String) -> String {
36    formatdoc!(
37        r#"
38        rack-l[layout~="min-height:{value}"]{{
39            min-height: {harmonic};
40        }}
41        "#,
42    )
43}
44
45fn rack_max_height_style(value: &str, harmonic: String) -> String {
46    formatdoc!(
47        r#"
48        rack-l[layout~="max-height:{value}"]{{
49            max-height: {harmonic};
50        }}
51        "#,
52    )
53}
54
55fn rack_gap_style(value: &str, harmonic: String) -> String {
56    formatdoc!(
57        r#"
58        rack-l[layout~="gap:{value}"]{{
59            gap: {harmonic};
60        }}
61        "#,
62    )
63}
64
65pub fn rack_css(
66    height: Option<&str>,
67    min_height: Option<&str>,
68    max_height: Option<&str>,
69    gap: Option<&str>,
70    harmonic_ratio: f64,
71    set: &mut HashSet<String>,
72) {
73    set.insert(RACK_STYLE.to_string());
74    if let Some(value) = height {
75        let harmonic_value = get_harmonic(value, harmonic_ratio);
76        set.insert(rack_height_style(value, harmonic_value));
77    }
78    if let Some(value) = min_height {
79        let harmonic_value = get_harmonic(value, harmonic_ratio);
80        set.insert(rack_min_height_style(value, harmonic_value));
81    }
82    if let Some(value) = max_height {
83        let harmonic_value = get_harmonic(value, harmonic_ratio);
84        set.insert(rack_max_height_style(value, harmonic_value));
85    }
86    if let Some(value) = gap {
87        let harmonic_value = get_harmonic(&value, harmonic_ratio);
88        set.insert(rack_gap_style(value, harmonic_value));
89    }
90}