1use gpui::{Div, Position};
2
3use crate::prelude::*;
4
5#[derive(Default)]
6pub enum IndicatorStyle {
7 #[default]
8 Dot,
9 Bar,
10}
11
12#[derive(IntoElement)]
13pub struct Indicator {
14 position: Position,
15 style: IndicatorStyle,
16 color: Color,
17}
18
19impl Indicator {
20 pub fn dot() -> Self {
21 Self {
22 position: Position::Relative,
23 style: IndicatorStyle::Dot,
24 color: Color::Default,
25 }
26 }
27
28 pub fn bar() -> Self {
29 Self {
30 position: Position::Relative,
31 style: IndicatorStyle::Dot,
32 color: Color::Default,
33 }
34 }
35
36 pub fn color(mut self, color: Color) -> Self {
37 self.color = color;
38 self
39 }
40
41 pub fn absolute(mut self) -> Self {
42 self.position = Position::Absolute;
43 self
44 }
45}
46
47impl RenderOnce for Indicator {
48 type Rendered = Div;
49
50 fn render(self, cx: &mut WindowContext) -> Self::Rendered {
51 div()
52 .flex_none()
53 .map(|this| match self.style {
54 IndicatorStyle::Dot => this.w_1p5().h_1p5().rounded_full(),
55 IndicatorStyle::Bar => this.w_full().h_1p5().rounded_t_md(),
56 })
57 .when(self.position == Position::Absolute, |this| this.absolute())
58 .bg(self.color.color(cx))
59 }
60}