iced_aw/style/
date_picker.rs1use super::{Status, StyleFn};
5use iced_core::{Background, Color, Theme};
6
7#[derive(Clone, Copy, Debug)]
9pub struct Style {
10 pub background: Background,
12
13 pub border_radius: f32,
15
16 pub border_width: f32,
18
19 pub border_color: Color,
21
22 pub text_color: Color,
24
25 pub text_attenuated_color: Color,
28
29 pub day_background: Background,
32}
33
34pub trait Catalog {
36 type Class<'a>;
38
39 fn default<'a>() -> Self::Class<'a>;
41
42 fn style(&self, class: &Self::Class<'_>, status: Status) -> Style;
44}
45
46impl Catalog for Theme {
47 type Class<'a> = StyleFn<'a, Self, Style>;
48
49 fn default<'a>() -> Self::Class<'a> {
50 Box::new(primary)
51 }
52
53 fn style(&self, class: &Self::Class<'_>, status: Status) -> Style {
54 class(self, status)
55 }
56}
57
58#[must_use]
60pub fn primary(theme: &Theme, status: Status) -> Style {
61 let palette = theme.extended_palette();
62 let foreground = theme.palette();
63
64 let base = Style {
65 background: palette.background.base.color.into(),
66 border_radius: 15.0,
67 border_width: 1.0,
68 border_color: foreground.text,
69 text_color: foreground.text,
70 text_attenuated_color: Color {
71 a: foreground.text.a * 0.5,
72 ..foreground.text
73 },
74 day_background: palette.background.base.color.into(),
75 };
76
77 match status {
78 Status::Selected => Style {
79 day_background: palette.primary.strong.color.into(),
80 text_color: palette.primary.strong.text,
81 ..base
82 },
83 Status::Hovered => Style {
84 day_background: palette.primary.weak.color.into(),
85 text_color: palette.primary.weak.text,
86 ..base
87 },
88 Status::Focused => Style {
89 border_color: Color::from_rgb(0.5, 0.5, 0.5),
90 ..base
91 },
92 _ => base,
93 }
94}