BlueGit

ict rusty-teams

Files

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

call_card.rs

chore: cargo fmt the workspace
metis Daniel Däschle · pushed by metis · 2 weeks ago
a6592765 History
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(), "radio_button_checked", theme::accent_text())
49 }
50 CallIcon::RecordStop => (theme::popup(), "stop_circle", theme::text()),
51 CallIcon::Roster => (theme::popup(), "group", theme::text()),
52 };
53 h_flex()
54 .size(px(ICON_CIRCLE))
55 .flex_none()
56 .items_center()
57 .justify_center()
58 .rounded_full()
59 .bg(fill)
60 .child(symbol(glyph, ICON_SIZE, tint))
61}
62
63fn detail_line(call: &CallCard) -> Div {
64 div()
65 .text_size(px(DETAIL_SIZE))
66 .text_color(theme::text_muted())
67 .child(call.detail.clone())
68}
69
70fn join_button(index: usize, join: RowAction) -> Stateful<Div> {
71 h_flex()
72 .id(ElementId::Name(format!("call-join-{index}").into()))
73 .h(px(JOIN_HEIGHT))
74 .px(px(12.))
75 .flex_none()
76 .items_center()
77 .rounded(px(CARD_RADIUS))
78 .bg(theme::accent())
79 .text_color(theme::white())
80 .text_size(px(DETAIL_SIZE + 1.))
81 .font_weight(FontWeight::SEMIBOLD)
82 .cursor_pointer()
83 .hover(|button| button.opacity(0.85))
84 .child("Join")
85 .when_some(join, |button, join| {
86 button.on_click(move |_, _, cx| join(cx))
87 })
88}
89
90fn participant_stack(
91 participants: &[CallParticipant],
92 extra: usize,
93 directory: &Directory,
94) -> Option<Div> {
95 if participants.is_empty() {
96 return None;
97 }
98 let tint = theme::text_muted();
99 Some(
100 h_flex()
101 .pt(px(4.))
102 .gap(px(PARTICIPANT_GAP))
103 .items_center()
104 .children(participants.iter().map(|person| {
105 person_avatar(
106 directory,
107 Some(&person.user_id),
108 &person.name,
109 PARTICIPANT_AVATAR,
110 )
111 }))
112 .when(extra > 0, |stack| {
113 stack.child(
114 div()
115 .pl(px(4.))
116 .text_size(px(DETAIL_SIZE))
117 .text_color(tint)
118 .child(format!("+{extra}")),
119 )
120 }),
121 )
122}
123
124fn card(call: &CallCard, index: usize, actions: CallActions, directory: &Directory) -> Div {
125 let CallActions { join, .. } = actions;
126 let show_join = call.started && join.is_some();
127 let summary = h_flex()
128 .gap(px(8.))
129 .items_center()
130 .child(icon_circle(call))
131 .child(
132 v_flex()
133 .flex_1()
134 .gap(px(2.))
135 .child(
136 div()
137 .text_size(px(TITLE_SIZE))
138 .font_weight(FontWeight::SEMIBOLD)
139 .text_color(if call.missed {
140 theme::red_soft()
141 } else {
142 theme::text()
143 })
144 .child(call.title.clone()),
145 )
146 .child(detail_line(call))
147 .children(participant_stack(
148 &call.participants,
149 call.extra_participants,
150 directory,
151 )),
152 )
153 .when(show_join, |card| card.child(join_button(index, join)));
154 v_flex()
155 .min_w(px(CARD_MIN_WIDTH))
156 .gap(px(4.))
157 .pt(px(8.))
158 .pr(px(12.))
159 .pb(px(8.))
160 .pl(px(8.))
161 .rounded(px(CARD_RADIUS))
162 .bg(theme::bubble_other())
163 .child(summary)
164}
165
166pub(super) fn post_call_card(
167 call: &CallCard,
168 index: usize,
169 actions: CallActions,
170 directory: &Directory,
171) -> Div {
172 h_flex().child(card(call, index, actions, directory))
173}
174
175pub(super) fn call_card_row(
176 row: &MessageRow,
177 call: &CallCard,
178 index: usize,
179 directory: &Directory,
180 actions: CallActions,
181) -> AnyElement {
182 notice_row(row, call, index, directory, actions.recap)
183}