layoutcss_parser/components/
outsider.rs1use indoc::formatdoc;
2use std::collections::HashSet;
3use crate::harmonic::get_harmonic;
4
5const OUTSIDER_STYLE: &str = r#"
6 outsider-l{
7 display:block;
8 }
9"#;
10
11fn outsider_position_style(value: &str) -> String {
12 formatdoc!(
13 r#"
14 outsider-l[layout~="position:{value}"]{{
15 position:{value};
16 }}
17 "#,
18 )
19}
20
21fn outsider_top_style(value: &str, harmonic: String) -> String {
22 formatdoc!(
23 r#"
24 outsider-l[layout~="top:{value}"]{{
25 top:{harmonic};
26 }}
27 "#,
28 )
29}
30
31fn outsider_bottom_style(value: &str, harmonic: String) -> String {
32 formatdoc!(
33 r#"
34 outsider-l[layout~="bottom:{value}"]{{
35 bottom:{harmonic};
36 }}
37 "#,
38 )
39}
40
41fn outsider_left_style(value: &str, harmonic: String) -> String {
42 formatdoc!(
43 r#"
44 outsider-l[layout~="left:{value}"]{{
45 left:{harmonic};
46 }}
47 "#,
48 )
49}
50
51fn outsider_right_style(value: &str, harmonic: String) -> String {
52 formatdoc!(
53 r#"
54 outsider-l[layout~="right:{value}"]{{
55 right:{harmonic};
56 }}
57 "#,
58 )
59}
60
61pub fn outsider_css(
62 position: Option<&str>,
63 top: Option<&str>,
64 bottom: Option<&str>,
65 left: Option<&str>,
66 right: Option<&str>,
67 harmonic_ratio: f64,
68 set: &mut HashSet<String>,
69) {
70 set.insert(OUTSIDER_STYLE.to_string());
71
72 if let Some(value) = position {
73 set.insert(outsider_position_style(value));
74 }
75
76 if let Some(value) = top {
77 let harmonic_value = get_harmonic(value, harmonic_ratio);
78 set.insert(outsider_top_style(value, harmonic_value));
79 }
80 if let Some(value) = bottom {
81 let harmonic_value = get_harmonic(value, harmonic_ratio);
82 set.insert(outsider_bottom_style(value, harmonic_value));
83 }
84 if let Some(value) = left {
85 let harmonic_value = get_harmonic(value, harmonic_ratio);
86 set.insert(outsider_left_style(value, harmonic_value));
87 }
88 if let Some(value) = right {
89 let harmonic_value = get_harmonic(value, harmonic_ratio);
90 set.insert(outsider_right_style(value, harmonic_value));
91 }
92}