1use gpui::AnyView;
2
3use crate::prelude::*;
4
5#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
6pub enum AudioStatus {
7 Muted,
8 Deafened,
9}
10
11#[derive(IntoElement)]
12pub struct AvatarAudioStatusIndicator {
13 audio_status: AudioStatus,
14 tooltip: Option<Box<dyn Fn(&mut WindowContext) -> AnyView>>,
15}
16
17impl AvatarAudioStatusIndicator {
18 pub fn new(audio_status: AudioStatus) -> Self {
19 Self {
20 audio_status,
21 tooltip: None,
22 }
23 }
24
25 pub fn tooltip(mut self, tooltip: impl Fn(&mut WindowContext) -> AnyView + 'static) -> Self {
26 self.tooltip = Some(Box::new(tooltip));
27 self
28 }
29}
30
31impl RenderOnce for AvatarAudioStatusIndicator {
32 fn render(self, cx: &mut WindowContext) -> impl IntoElement {
33 let icon_size = IconSize::Indicator;
34
35 let width_in_px = icon_size.rems() * cx.rem_size();
36 let padding_x = px(4.);
37
38 div()
39 .absolute()
40 .bottom(rems(-3. / 16.))
41 .right(rems(-6. / 16.))
42 .w(width_in_px + padding_x)
43 .h(icon_size.rems())
44 .child(
45 h_flex()
46 .id("muted-indicator")
47 .justify_center()
48 .px(padding_x)
49 .py(px(2.))
50 .bg(cx.theme().status().error_background)
51 .rounded_md()
52 .child(
53 Icon::new(match self.audio_status {
54 AudioStatus::Muted => IconName::MicMute,
55 AudioStatus::Deafened => IconName::AudioOff,
56 })
57 .size(icon_size)
58 .color(Color::Error),
59 )
60 .when_some(self.tooltip, |this, tooltip| {
61 this.tooltip(move |cx| tooltip(cx))
62 }),
63 )
64 }
65}