1use super::{Status, StyleFn, colors};
6use iced_core::{Background, Color, Theme};
7
8#[derive(Clone, Copy, Debug)]
10pub struct Style {
11 pub background: Background,
13
14 pub border_radius: f32,
16
17 pub border_width: f32,
19
20 pub border_color: Color,
22
23 pub head_background: Background,
25
26 pub head_text_color: Color,
28
29 pub body_background: Background,
31
32 pub body_text_color: Color,
34
35 pub foot_background: Background,
37
38 pub foot_text_color: Color,
40
41 pub close_color: Color,
43}
44
45pub trait Catalog {
47 type Class<'a>;
49
50 fn default<'a>() -> Self::Class<'a>;
52
53 fn style(&self, class: &Self::Class<'_>, status: Status) -> Style;
55}
56
57impl Default for Style {
58 fn default() -> Self {
59 Self {
60 background: Color::WHITE.into(),
61 border_radius: 10.0,
62 border_width: 1.0,
63 border_color: [0.87, 0.87, 0.87].into(),
64 head_background: Background::Color([0.87, 0.87, 0.87].into()),
65 head_text_color: Color::BLACK,
66 body_background: Color::TRANSPARENT.into(),
67 body_text_color: Color::BLACK,
68 foot_background: Color::TRANSPARENT.into(),
69 foot_text_color: Color::BLACK,
70 close_color: Color::BLACK,
71 }
72 }
73}
74
75impl Catalog for Theme {
76 type Class<'a> = StyleFn<'a, Self, Style>;
77
78 fn default<'a>() -> Self::Class<'a> {
79 Box::new(primary)
80 }
81
82 fn style(&self, class: &Self::Class<'_>, status: Status) -> Style {
83 class(self, status)
84 }
85}
86
87#[must_use]
89pub fn primary(theme: &Theme, _status: Status) -> Style {
90 backing_with_text(theme, colors::PRIMARY, colors::WHITE)
91}
92
93#[must_use]
95pub fn secondary(theme: &Theme, _status: Status) -> Style {
96 backing_with_text(theme, colors::SECONDARY, colors::WHITE)
97}
98
99#[must_use]
101pub fn success(theme: &Theme, _status: Status) -> Style {
102 backing_with_text(theme, colors::SUCCESS, colors::WHITE)
103}
104
105#[must_use]
107pub fn danger(theme: &Theme, _status: Status) -> Style {
108 backing_with_text(theme, colors::DANGER, colors::WHITE)
109}
110
111#[must_use]
113pub fn warning(theme: &Theme, _status: Status) -> Style {
114 backing_only(theme, colors::WARNING)
115}
116
117#[must_use]
119pub fn info(theme: &Theme, _status: Status) -> Style {
120 backing_only(theme, colors::INFO)
121}
122
123#[must_use]
125pub fn light(theme: &Theme, _status: Status) -> Style {
126 backing_only(theme, colors::LIGHT)
127}
128
129#[must_use]
131pub fn dark(theme: &Theme, _status: Status) -> Style {
132 backing_with_text(theme, colors::DARK, colors::WHITE)
133}
134
135#[must_use]
137pub fn white(theme: &Theme, _status: Status) -> Style {
138 backing_only(theme, colors::WHITE)
139}
140
141fn backing_with_text(theme: &Theme, color: Color, text_color: Color) -> Style {
142 let palette = theme.extended_palette();
143 let foreground = theme.palette();
144
145 Style {
146 border_color: color,
147 head_background: color.into(),
148 head_text_color: text_color,
149 close_color: text_color,
150 background: palette.background.base.color.into(),
151 body_text_color: foreground.text,
152 foot_text_color: foreground.text,
153 ..Style::default()
154 }
155}
156
157fn backing_only(theme: &Theme, color: Color) -> Style {
158 let palette = theme.extended_palette();
159 let foreground = theme.palette();
160
161 Style {
162 border_color: color,
163 head_background: color.into(),
164 background: palette.background.base.color.into(),
165 body_text_color: foreground.text,
166 foot_text_color: foreground.text,
167 ..Style::default()
168 }
169}