layoutcss_parser/components/
slider.rs

1use indoc::formatdoc;
2use crate::harmonic::get_harmonic;
3use std::collections::HashSet;
4const SLIDER_STYLE: &str = r#"
5  slider-l{
6    display: flex;
7    block-size: auto;
8    overflow-x: auto;
9    overflow-y: hidden;
10  }
11
12  slider-l > *:not(outsider-l[layout~="disinherit"]) {
13      flex-shrink: 0;
14      flex-grow: 0;
15      height: auto;
16      min-width: 0px;
17  }
18
19  slider-l > img{
20      object-fit: cover;
21  }
22"#;
23
24const SLIDER_HIDE_BAR_STYLE: &str = r#"
25  slider-l[layout~="hide-bar"]{
26    overflow: hidden;
27  }
28"#;
29
30fn slider_item_width_style(value: &str) -> String {
31    formatdoc!(
32        r#"
33        slider-l[layout~="item-width:{value}"] > *:not(outsider-l[layout~="disinherit"]){{
34            flex-basis:{value};
35        }}
36        "#,
37    )
38}
39
40fn slider_height_style(value: &str) -> String {
41    formatdoc!(
42        r#"
43        slider-l[layout~="height:{value}"] > *:not(outsider-l[layout~="disinherit"]){{
44            block-size:{value};
45        }}
46        "#,
47    )
48}
49
50fn slider_gap_style(value: &str, harmonic: String) -> String {
51    formatdoc!(
52        r#"
53        slider-l[layout~="gap:{value}"] {{
54            gap: {harmonic};
55        }}
56        "#,
57    )
58}
59
60pub fn slider_css(
61    hide_bar: bool,
62    item_width: Option<&str>,
63    height: Option<&str>,
64    gap: Option<&str>,
65    harmonic_ratio: f64,
66    set: &mut HashSet<String>,
67) {
68    set.insert(SLIDER_STYLE.to_string());
69    if hide_bar {
70        set.insert(SLIDER_HIDE_BAR_STYLE.to_string());
71    }
72    if let Some(value) = item_width {
73        set.insert(slider_item_width_style(value));
74    }
75    if let Some(value) = height {
76        set.insert(slider_height_style(value));
77    }
78
79    if let Some(value) = gap {
80        let harmonic_value = get_harmonic(value, harmonic_ratio);
81        set.insert(slider_gap_style(value, harmonic_value));
82    }
83}