iced_aw/style/
time_picker.rs

1//! Use a time picker as an input element for picking times.
2//!
3//! *This API requires the following crate features to be activated: `time_picker`*
4#![allow(clippy::doc_markdown)]
5use super::{Status, StyleFn};
6use iced_core::{Background, Color, Theme};
7
8/// The style of a [`TimePicker`](crate::widget::TimePicker).
9#[derive(Clone, Copy, Debug)]
10pub struct Style {
11    /// The background of the [`TimePicker`](crate::widget::TimePicker).
12    pub background: Background,
13
14    /// The border radius of the [`TimePicker`](crate::widget::TimePicker).
15    pub border_radius: f32,
16
17    /// The border width of the [`TimePicker`](crate::widget::TimePicker).
18    pub border_width: f32,
19
20    /// The border color of the [`TimePicker`](crate::widget::TimePicker).
21    pub border_color: Color,
22
23    /// The text color of the [`TimePicker`](crate::widget::TimePicker).
24    pub text_color: Color,
25
26    /// The color of the clock numbers of the
27    /// [`TimePicker`](crate::widget::TimePicker).
28    pub clock_number_color: Color,
29
30    /// The background of the clock numbers of the
31    /// [`TimePicker`](crate::widget::TimePicker).
32    pub clock_number_background: Color,
33
34    /// The color of the dots on the clock of the
35    /// [`TimePicker`](crate::widget::TimePicker).
36    pub clock_dots_color: Color,
37
38    /// The color of the hands of the clock of the
39    /// [`TimePicker`](crate::widget::TimePicker).
40    pub clock_hand_color: Color,
41
42    /// The with of the hands of the clock of the
43    /// [`TimePicker](crate::widget::TimePicker).
44    pub clock_hand_width: f32,
45}
46
47/// The Catalog of a [`TimePicker`](crate::widget::TimePicker).
48pub trait Catalog {
49    ///Style for the trait to use.
50    type Class<'a>;
51
52    /// The default class produced by the [`Catalog`].
53    fn default<'a>() -> Self::Class<'a>;
54
55    /// The [`Style`] of a class with the given status.
56    fn style(&self, class: &Self::Class<'_>, status: Status) -> Style;
57}
58
59impl Catalog for Theme {
60    type Class<'a> = StyleFn<'a, Self, Style>;
61
62    fn default<'a>() -> Self::Class<'a> {
63        Box::new(primary)
64    }
65
66    fn style(&self, class: &Self::Class<'_>, status: Status) -> Style {
67        class(self, status)
68    }
69}
70
71/// The primary theme of a [`TimePicker`](crate::widget::TimePicker).
72#[must_use]
73pub fn primary(theme: &Theme, status: Status) -> Style {
74    let palette = theme.extended_palette();
75    let foreground = theme.palette();
76
77    let base = Style {
78        background: palette.background.base.color.into(),
79        border_radius: 15.0,
80        border_width: 1.0,
81        border_color: foreground.text,
82        text_color: foreground.text,
83        clock_number_color: foreground.text,
84        clock_number_background: palette.background.base.color,
85        clock_dots_color: [0.87, 0.87, 0.87].into(),
86        clock_hand_color: [0.87, 0.87, 0.87].into(),
87        clock_hand_width: 3.0,
88    };
89
90    match status {
91        Status::Focused => Style {
92            border_color: Color::from_rgb(0.5, 0.5, 0.5),
93            ..base
94        },
95        Status::Hovered => Style {
96            clock_number_color: palette.primary.weak.text,
97            clock_number_background: palette.primary.weak.color,
98            ..base
99        },
100        Status::Selected => Style {
101            clock_number_color: palette.primary.strong.text,
102            clock_number_background: palette.primary.strong.color,
103            ..base
104        },
105        _ => base,
106    }
107}