iced_aw/style/
number_input.rs1use super::{Status, StyleFn};
6use iced::{widget, Background, Color, Theme};
7
8#[derive(Clone, Copy, Debug)]
10pub struct Style {
11 pub button_background: Option<Background>,
13 pub icon_color: Color,
15}
16
17impl Default for Style {
18 fn default() -> Self {
19 Self {
20 button_background: None,
21 icon_color: Color::BLACK,
22 }
23 }
24}
25
26pub trait Catalog {
28 type Class<'a>;
30
31 fn default<'a>() -> Self::Class<'a>;
33
34 fn style(&self, class: &Self::Class<'_>, status: Status) -> Style;
36}
37
38impl Catalog for Theme {
39 type Class<'a> = StyleFn<'a, Self, Style>;
40
41 fn default<'a>() -> Self::Class<'a> {
42 Box::new(primary)
43 }
44
45 fn style(&self, class: &Self::Class<'_>, status: Status) -> Style {
46 class(self, status)
47 }
48}
49
50pub trait ExtendedCatalog:
52 widget::text_input::Catalog + widget::container::Catalog + widget::text::Catalog + self::Catalog
53{
54 #[must_use]
56 fn default_input<'a>() -> <Self as widget::text_input::Catalog>::Class<'a> {
57 <Self as widget::text_input::Catalog>::default()
58 }
59
60 fn style(&self, class: &<Self as self::Catalog>::Class<'_>, status: Status) -> Style;
62}
63
64impl ExtendedCatalog for Theme {
65 fn style(&self, class: &<Self as self::Catalog>::Class<'_>, status: Status) -> Style {
66 class(self, status)
67 }
68}
69
70#[must_use]
72pub fn primary(theme: &Theme, status: Status) -> Style {
73 let palette = theme.extended_palette();
74 let base = Style {
75 button_background: Some(palette.primary.strong.color.into()),
76 icon_color: palette.primary.strong.text,
77 };
78
79 match status {
80 Status::Disabled => Style {
81 button_background: base.button_background.map(|bg| match bg {
82 Background::Color(color) => Background::Color(Color {
83 a: color.a * 0.5,
84 ..color
85 }),
86 Background::Gradient(grad) => Background::Gradient(grad),
87 }),
88 icon_color: Color {
89 a: base.icon_color.a * 0.5,
90 ..base.icon_color
91 },
92 },
93 _ => base,
94 }
95}