indicator.rs

 1use gpui::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    pub 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    fn render(self, cx: &mut WindowContext) -> impl IntoElement {
49        div()
50            .flex_none()
51            .map(|this| match self.style {
52                IndicatorStyle::Dot => this.w_1p5().h_1p5().rounded_full(),
53                IndicatorStyle::Bar => this.w_full().h_1p5().rounded_t_md(),
54            })
55            .when(self.position == Position::Absolute, |this| this.absolute())
56            .bg(self.color.color(cx))
57    }
58}