cosmic/widget/progress_bar/
style.rs1use iced::Color;
2
3#[derive(Debug, Clone, Copy)]
4pub struct Appearance {
5 pub track_color: Color,
7 pub bar_color: Color,
9 pub border_color: Option<Color>,
11 pub border_radius: f32,
13}
14
15impl std::default::Default for Appearance {
16 fn default() -> Self {
17 Self {
18 track_color: Color::TRANSPARENT,
19 bar_color: Color::BLACK,
20 border_color: None,
21 border_radius: 0.0,
22 }
23 }
24}
25
26pub trait StyleSheet {
28 type Style: Default;
30
31 fn appearance(
33 &self,
34 style: &Self::Style,
35 is_determinate: bool,
36 is_circular: bool,
37 ) -> Appearance;
38}
39
40impl StyleSheet for iced::Theme {
41 type Style = ();
42
43 fn appearance(
44 &self,
45 _style: &Self::Style,
46 _is_determinate: bool,
47 _is_circular: bool,
48 ) -> Appearance {
49 let palette = self.extended_palette();
50
51 Appearance {
52 track_color: palette.background.weak.color,
53 bar_color: palette.primary.base.color,
54 border_color: None,
55 border_radius: 0.0,
56 }
57 }
58}
59
60impl StyleSheet for crate::Theme {
61 type Style = ();
62
63 fn appearance(
64 &self,
65 _style: &Self::Style,
66 is_determinate: bool,
67 is_circular: bool,
68 ) -> Appearance {
69 let cur = self.current_container();
70 let mut cur_divider = cur.divider;
71 cur_divider.alpha = 0.5;
72 let theme = self.cosmic();
73
74 let (mut track_color, bar_color) = if theme.is_dark && theme.is_high_contrast {
75 (
76 theme.palette.neutral_6.into(),
77 theme.accent_text_color().into(),
78 )
79 } else if theme.is_dark {
80 (theme.palette.neutral_5.into(), theme.accent_color().into())
81 } else if theme.is_high_contrast {
82 (
83 theme.palette.neutral_4.into(),
84 theme.accent_text_color().into(),
85 )
86 } else {
87 (theme.palette.neutral_3.into(), theme.accent_color().into())
88 };
89
90 if !is_determinate && is_circular {
91 track_color = Color::TRANSPARENT;
92 }
93
94 Appearance {
95 track_color,
96 bar_color,
97 border_color: if is_determinate && theme.is_high_contrast {
98 Some(cur_divider.into())
99 } else {
100 None
101 },
102 border_radius: theme.corner_radii.radius_xl[0],
103 }
104 }
105}