iced_aw/style/
selection_list.rs1use super::{Status, StyleFn};
6use iced_core::{Background, Color, Theme};
7
8#[derive(Debug, Clone, Copy)]
10pub struct Style {
11 pub text_color: Color,
13 pub background: Background,
15 pub border_width: f32,
17 pub border_color: Color,
19}
20
21pub trait Catalog {
23 type Class<'a>;
25
26 fn default<'a>() -> Self::Class<'a>;
28
29 fn style(&self, class: &Self::Class<'_>, status: Status) -> Style;
31}
32
33impl Catalog for Theme {
34 type Class<'a> = StyleFn<'a, Self, Style>;
35
36 fn default<'a>() -> Self::Class<'a> {
37 Box::new(primary)
38 }
39
40 fn style(&self, class: &Self::Class<'_>, status: Status) -> Style {
41 class(self, status)
42 }
43}
44
45#[must_use]
47pub fn primary(theme: &Theme, status: Status) -> Style {
48 let palette = theme.extended_palette();
49
50 let base = Style {
51 text_color: palette.background.base.text,
52 background: palette.background.base.color.into(),
53 border_width: 1.0,
54 border_color: palette.background.weak.color,
55 };
56
57 match status {
58 Status::Hovered => Style {
59 text_color: palette.primary.base.text,
60 background: palette.primary.base.color.into(),
61 ..base
62 },
63 Status::Selected => Style {
64 text_color: palette.primary.strong.text,
65 background: palette.primary.strong.color.into(),
66 ..base
67 },
68 _ => base,
69 }
70}