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