Skip to main content

iced_resizable_split/
style.rs

1pub struct Style {
2    pub divider_color: iced_core::Color,
3    pub divider_width: f32,
4}
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum Status {
8    Idle,
9    Hovering,
10    Dragging,
11}
12
13pub trait Catalog {
14    type Class<'a>;
15
16    fn default<'a>() -> Self::Class<'a>;
17    fn style(&self, class: &Self::Class<'_>, status: Status) -> Style;
18}
19
20pub type StyleFn<'a, Theme> = Box<dyn Fn(&Theme, Status) -> Style + 'a>;
21
22impl Catalog for iced_core::Theme {
23    type Class<'a> = StyleFn<'a, Self>;
24
25    fn default<'a>() -> Self::Class<'a> {
26        Box::new(default_style)
27    }
28
29    fn style(&self, class: &Self::Class<'_>, status: Status) -> Style {
30        class(self, status)
31    }
32}
33
34fn default_style(theme: &iced_core::Theme, status: Status) -> Style {
35    let palette = theme.extended_palette();
36    match status {
37        Status::Idle => Style {
38            divider_color: palette.background.strong.color,
39            divider_width: 1.0,
40        },
41        Status::Hovering => Style {
42            divider_color: palette.primary.weak.color,
43            divider_width: 1.0,
44        },
45        Status::Dragging => Style {
46            divider_color: palette.primary.strong.color,
47            divider_width: 1.0,
48        },
49    }
50}