Skip to repository content175 lines · 5.7 KB · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T05:35:48.430Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
indicator.rs
1use super::AnyIcon;
2use crate::prelude::*;
3
4#[derive(Default)]
5enum IndicatorKind {
6 #[default]
7 Dot,
8 Bar,
9 Icon(AnyIcon),
10}
11
12#[derive(IntoElement, RegisterComponent)]
13pub struct Indicator {
14 kind: IndicatorKind,
15 border_color: Option<Color>,
16 pub color: Color,
17}
18
19impl Indicator {
20 pub fn dot() -> Self {
21 Self {
22 kind: IndicatorKind::Dot,
23 border_color: None,
24 color: Color::Default,
25 }
26 }
27
28 pub fn bar() -> Self {
29 Self {
30 kind: IndicatorKind::Bar,
31 border_color: None,
32
33 color: Color::Default,
34 }
35 }
36
37 pub fn icon(icon: impl Into<AnyIcon>) -> Self {
38 Self {
39 kind: IndicatorKind::Icon(icon.into()),
40 border_color: None,
41
42 color: Color::Default,
43 }
44 }
45
46 pub fn color(mut self, color: Color) -> Self {
47 self.color = color;
48 self
49 }
50
51 pub fn border_color(mut self, color: Color) -> Self {
52 self.border_color = Some(color);
53 self
54 }
55}
56
57impl RenderOnce for Indicator {
58 fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
59 let container = div().flex_none();
60 let container = if let Some(border_color) = self.border_color {
61 if matches!(self.kind, IndicatorKind::Dot | IndicatorKind::Bar) {
62 container.border_1().border_color(border_color.color(cx))
63 } else {
64 container
65 }
66 } else {
67 container
68 };
69
70 match self.kind {
71 IndicatorKind::Icon(icon) => container
72 .child(icon.map(|icon| icon.custom_size(rems_from_px(8.)).color(self.color))),
73 IndicatorKind::Dot => container
74 .w_1p5()
75 .h_1p5()
76 .rounded_full()
77 .bg(self.color.color(cx)),
78 IndicatorKind::Bar => container
79 .w_full()
80 .h_1p5()
81 .rounded_t_sm()
82 .bg(self.color.color(cx)),
83 }
84 }
85}
86
87impl Component for Indicator {
88 fn scope() -> ComponentScope {
89 ComponentScope::Status
90 }
91
92 fn description() -> &'static str {
93 "Visual indicators used to represent status, notifications, \
94 or draw attention to specific elements."
95 }
96
97 fn preview(_window: &mut Window, _cx: &mut App) -> AnyElement {
98 v_flex()
99 .gap_6()
100 .children(vec![
101 example_group_with_title(
102 "Dot Indicators",
103 vec![
104 single_example("Default", Indicator::dot().into_any_element()),
105 single_example(
106 "Success",
107 Indicator::dot().color(Color::Success).into_any_element(),
108 ),
109 single_example(
110 "Warning",
111 Indicator::dot().color(Color::Warning).into_any_element(),
112 ),
113 single_example(
114 "Error",
115 Indicator::dot().color(Color::Error).into_any_element(),
116 ),
117 single_example(
118 "With Border",
119 Indicator::dot()
120 .color(Color::Accent)
121 .border_color(Color::Default)
122 .into_any_element(),
123 ),
124 ],
125 ),
126 example_group_with_title(
127 "Bar Indicators",
128 vec![
129 single_example("Default", Indicator::bar().into_any_element()),
130 single_example(
131 "Success",
132 Indicator::bar().color(Color::Success).into_any_element(),
133 ),
134 single_example(
135 "Warning",
136 Indicator::bar().color(Color::Warning).into_any_element(),
137 ),
138 single_example(
139 "Error",
140 Indicator::bar().color(Color::Error).into_any_element(),
141 ),
142 ],
143 ),
144 example_group_with_title(
145 "Icon Indicators",
146 vec![
147 single_example(
148 "Default",
149 Indicator::icon(Icon::new(IconName::Circle)).into_any_element(),
150 ),
151 single_example(
152 "Success",
153 Indicator::icon(Icon::new(IconName::Check))
154 .color(Color::Success)
155 .into_any_element(),
156 ),
157 single_example(
158 "Warning",
159 Indicator::icon(Icon::new(IconName::Warning))
160 .color(Color::Warning)
161 .into_any_element(),
162 ),
163 single_example(
164 "Error",
165 Indicator::icon(Icon::new(IconName::Close))
166 .color(Color::Error)
167 .into_any_element(),
168 ),
169 ],
170 ),
171 ])
172 .into_any_element()
173 }
174}
175