1use crate::{prelude::*, AnyIcon};
2
3#[derive(Default)]
4enum IndicatorKind {
5 #[default]
6 Dot,
7 Bar,
8 Icon(AnyIcon),
9}
10
11#[derive(IntoElement)]
12pub struct Indicator {
13 kind: IndicatorKind,
14 pub color: Color,
15}
16
17impl Indicator {
18 pub fn dot() -> Self {
19 Self {
20 kind: IndicatorKind::Dot,
21 color: Color::Default,
22 }
23 }
24
25 pub fn bar() -> Self {
26 Self {
27 kind: IndicatorKind::Bar,
28 color: Color::Default,
29 }
30 }
31
32 pub fn icon(icon: impl Into<AnyIcon>) -> Self {
33 Self {
34 kind: IndicatorKind::Icon(icon.into()),
35 color: Color::Default,
36 }
37 }
38
39 pub fn color(mut self, color: Color) -> Self {
40 self.color = color;
41 self
42 }
43}
44
45impl RenderOnce for Indicator {
46 fn render(self, cx: &mut WindowContext) -> impl IntoElement {
47 let container = div().flex_none();
48
49 match self.kind {
50 IndicatorKind::Icon(icon) => container
51 .child(icon.map(|icon| icon.custom_size(rems_from_px(8.)).color(self.color))),
52 IndicatorKind::Dot => container
53 .w_1p5()
54 .h_1p5()
55 .rounded_full()
56 .bg(self.color.color(cx)),
57 IndicatorKind::Bar => container
58 .w_full()
59 .h_1p5()
60 .rounded_t_md()
61 .bg(self.color.color(cx)),
62 }
63 }
64}