layoutcss_parser/components/
outsider.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use indoc::formatdoc;
use std::collections::HashSet;
use crate::harmonic::get_harmonic;

const OUTSIDER_STYLE: &str = r#"
  outsider-l{
    display:block;
  }
"#;

fn outsider_position_style(value: &str) -> String {
    formatdoc!(
        r#"
        outsider-l[layout~="position:{value}"]{{
            position:{value};
        }}
        "#,
    )
}

fn outsider_top_style(value: &str, harmonic: String) -> String {
    formatdoc!(
        r#"
        outsider-l[layout~="top:{value}"]{{
            top:{harmonic};
        }}
        "#,
    )
}

fn outsider_bottom_style(value: &str, harmonic: String) -> String {
    formatdoc!(
        r#"
        outsider-l[layout~="bottom:{value}"]{{
            bottom:{harmonic};
        }}
        "#,
    )
}

fn outsider_left_style(value: &str, harmonic: String) -> String {
    formatdoc!(
        r#"
        outsider-l[layout~="left:{value}"]{{
            left:{harmonic};
        }}
        "#,
    )
}

fn outsider_right_style(value: &str, harmonic: String) -> String {
    formatdoc!(
        r#"
        outsider-l[layout~="right:{value}"]{{
            right:{harmonic};
        }}
        "#,
    )
}

pub fn outsider_css(
    position: Option<&str>,
    top: Option<&str>,
    bottom: Option<&str>,
    left: Option<&str>,
    right: Option<&str>,
    harmonic_ratio: f64,
    set: &mut HashSet<String>,
) {
    set.insert(OUTSIDER_STYLE.to_string());

    if let Some(value) = position {
        set.insert(outsider_position_style(value));
    }

    if let Some(value) = top {
        let harmonic_value = get_harmonic(value, harmonic_ratio);
        set.insert(outsider_top_style(value, harmonic_value));
    }
    if let Some(value) = bottom {
        let harmonic_value = get_harmonic(value, harmonic_ratio);
        set.insert(outsider_bottom_style(value, harmonic_value));
    }
    if let Some(value) = left {
        let harmonic_value = get_harmonic(value, harmonic_ratio);
        set.insert(outsider_left_style(value, harmonic_value));
    }
    if let Some(value) = right {
        let harmonic_value = get_harmonic(value, harmonic_ratio);
        set.insert(outsider_right_style(value, harmonic_value));
    }
}