BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / src / views / call_card.rs

call_card.rs

call_card.rs 5.2 KiB Download Raw
1use gpui_kit::component::{h_flex, v_flex};
2use gpui_kit::prelude::FluentBuilder as _;
3use gpui_kit::*;
4
5use super::avatar::person_avatar;
6use super::call_notice::{RecapActions, notice_row};
7use super::message_row::RowAction;
8use super::widgets::symbol;
9use crate::data::Directory;
10use crate::rows::{CallCard, CallIcon, CallParticipant, MessageRow};
11use crate::theme;
12
13const CARD_RADIUS: f32 = 12.;
14const CARD_MIN_WIDTH: f32 = 200.;
15const ICON_CIRCLE: f32 = 30.;
16const ICON_SIZE: f32 = 18.;
17const TITLE_SIZE: f32 = 13.;
18const DETAIL_SIZE: f32 = 11.;
19const JOIN_HEIGHT: f32 = 24.;
20const PARTICIPANT_AVATAR: f32 = 20.;
21const PARTICIPANT_GAP: f32 = 2.;
22
23pub struct CallActions {
24 pub join: RowAction,
25 pub recap: RecapActions,
26}
27
28impl CallActions {
29 pub fn none() -> Self {
30 CallActions {
31 join: None,
32 recap: RecapActions {
33 view_recap: None,
34 open_recording: None,
35 transcript: None,
36 share: None,
37 },
38 }
39 }
40}
41
42fn icon_circle(call: &CallCard) -> Div {
43 let (fill, glyph, tint) = match call.icon {
44 CallIcon::Missed => (theme::red().opacity(0.2), "call_missed", theme::red_soft()),
45 CallIcon::Call => (theme::popup(), "call", theme::text()),
46 CallIcon::Video => (theme::popup(), "videocam", theme::text()),
47 CallIcon::Record | CallIcon::Saved => (
48 theme::popup(),
49 "fluent_record",
50 theme::accent_text(),
51 ),
52 CallIcon::RecordStop => (theme::popup(), "fluent_record_stop", theme::text()),
53 CallIcon::Roster => (theme::popup(), "group", theme::text()),
54 };
55 h_flex()
56 .size(px(ICON_CIRCLE))
57 .flex_none()
58 .items_center()
59 .justify_center()
60 .rounded_full()
61 .bg(fill)
62 .child(symbol(glyph, ICON_SIZE, tint))
63}
64
65fn detail_line(call: &CallCard) -> Div {
66 div()
67 .text_size(px(DETAIL_SIZE))
68 .text_color(theme::text_muted())
69 .child(call.detail.clone())
70}
71
72fn join_button(index: usize, join: RowAction) -> Stateful<Div> {
73 h_flex()
74 .id(ElementId::Name(format!("call-join-{index}").into()))
75 .h(px(JOIN_HEIGHT))
76 .px(px(12.))
77 .flex_none()
78 .items_center()
79 .rounded(px(CARD_RADIUS))
80 .bg(theme::accent())
81 .text_color(theme::white())
82 .text_size(px(DETAIL_SIZE + 1.))
83 .font_weight(FontWeight::SEMIBOLD)
84 .cursor_pointer()
85 .hover(|button| button.opacity(0.85))
86 .child("Join")
87 .when_some(join, |button, join| {
88 button.on_click(move |_, _, cx| join(cx))
89 })
90}
91
92fn participant_stack(
93 participants: &[CallParticipant],
94 extra: usize,
95 directory: &Directory,
96) -> Option<Div> {
97 if participants.is_empty() {
98 return None;
99 }
100 let tint = theme::text_muted();
101 Some(
102 h_flex()
103 .pt(px(4.))
104 .gap(px(PARTICIPANT_GAP))
105 .items_center()
106 .children(participants.iter().map(|person| {
107 person_avatar(
108 directory,
109 Some(&person.user_id),
110 &person.name,
111 PARTICIPANT_AVATAR,
112 )
113 }))
114 .when(extra > 0, |stack| {
115 stack.child(
116 div()
117 .pl(px(4.))
118 .text_size(px(DETAIL_SIZE))
119 .text_color(tint)
120 .child(format!("+{extra}")),
121 )
122 }),
123 )
124}
125
126fn card(call: &CallCard, index: usize, actions: CallActions, directory: &Directory) -> Div {
127 let CallActions { join, .. } = actions;
128 let show_join = call.started && join.is_some();
129 let summary = h_flex()
130 .gap(px(8.))
131 .items_center()
132 .child(icon_circle(call))
133 .child(
134 v_flex()
135 .flex_1()
136 .gap(px(2.))
137 .child(
138 div()
139 .text_size(px(TITLE_SIZE))
140 .font_weight(FontWeight::SEMIBOLD)
141 .text_color(if call.missed {
142 theme::red_soft()
143 } else {
144 theme::text()
145 })
146 .child(call.title.clone()),
147 )
148 .child(detail_line(call))
149 .children(participant_stack(
150 &call.participants,
151 call.extra_participants,
152 directory,
153 )),
154 )
155 .when(show_join, |card| card.child(join_button(index, join)));
156 v_flex()
157 .min_w(px(CARD_MIN_WIDTH))
158 .gap(px(4.))
159 .pt(px(8.))
160 .pr(px(12.))
161 .pb(px(8.))
162 .pl(px(8.))
163 .rounded(px(CARD_RADIUS))
164 .bg(theme::bubble_other())
165 .child(summary)
166}
167
168pub(super) fn post_call_card(
169 call: &CallCard,
170 index: usize,
171 actions: CallActions,
172 directory: &Directory,
173) -> Div {
174 h_flex().child(card(call, index, actions, directory))
175}
176
177pub(super) fn call_card_row(
178 row: &MessageRow,
179 call: &CallCard,
180 index: usize,
181 directory: &Directory,
182 actions: CallActions,
183) -> AnyElement {
184 notice_row(row, call, index, directory, actions.recap)
185}