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