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