layoutcss_parser/components/
stack.rs1use indoc::formatdoc;
2use crate::harmonic::get_harmonic;
3
4use std::collections::HashSet;
5const STACK_STYLE: &str = r#"
6 stack-l{
7 display: block;
8 }
9
10 stack-l > *{
11 margin-block: 0;
12 }
13"#;
14
15fn stack_gap_style(value: &str, harmonic: String) -> String {
16 formatdoc!(
17 r#"
18 stack-l[layout~="gap:{value}"] > * + *:not(outsider-l[layout~="disinherit"]){{
19 margin-block-start: {harmonic};
20 }}
21 "#,
22 )
23}
24
25fn stack_recursive_style(harmonic: String) -> String {
26 formatdoc!(
27 r#"
28 stack-l[layout~="recursive"] * + *:not(outsider-l[layout~="disinherit"]){{
29 margin-block-start: {harmonic};
30 }}
31 "#,
32 )
33}
34
35pub fn stack_css(
36 gap: Option<&str>,
37 recursive: bool,
38 harmonic_ratio: f64,
39 set: &mut HashSet<String>,
40) {
41 set.insert(STACK_STYLE.to_string());
42 if let Some(value) = gap {
43 let harmonic_value = get_harmonic(value, harmonic_ratio);
44 set.insert(stack_gap_style(value, harmonic_value.clone()));
45 if recursive {
46 set.insert(stack_recursive_style(harmonic_value));
47 }
48 }
49}