BlueGit

ict rusty-teams

Files

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

call_extras.rs

call_extras.rs 12.2 KiB Download Raw
1use std::path::PathBuf;
2
3use calling::HoldState;
4use gpui_kit::assets::IconName;
5use gpui_kit::component::button::{Button, ButtonVariants as _};
6use gpui_kit::component::dialog::DialogFooter;
7use gpui_kit::component::menu::{PopupMenu, PopupMenuItem};
8use gpui_kit::component::tooltip::Tooltip;
9use gpui_kit::component::{WindowExt as _, h_flex, v_flex};
10use gpui_kit::*;
11
12use super::call_organizer::pill;
13use super::call_view::{BANNER_HEIGHT, MENU_WIDTH};
14use super::transfer_picker::TransferPicker;
15use super::widgets::icon;
16use crate::app_state::AppState;
17use crate::call::{BackgroundPick, CallModel};
18use crate::theme;
19
20const STAGE_RADIUS: f32 = 12.;
21const THUMBNAIL_WIDTH: f32 = 64.;
22const THUMBNAIL_HEIGHT: f32 = 36.;
23const THUMBNAIL_GAP: f32 = 6.;
24const MENU_PADDING: f32 = 24.;
25const BACKDROP_OPACITY: f32 = 0.55;
26const CARD_WIDTH: f32 = 420.;
27
28fn dark_text() -> Hsla {
29 hsla(0., 0., 0.08, 1.)
30}
31
32pub fn recording_chip(model: &CallModel) -> Option<AnyElement> {
33 model.recording.then(|| {
34 h_flex()
35 .id("call-recording")
36 .flex_none()
37 .gap(px(6.))
38 .items_center()
39 .text_size(px(13.))
40 .font_weight(FontWeight::SEMIBOLD)
41 .text_color(theme::red())
42 .child(div().size(px(9.)).rounded_full().bg(theme::red()))
43 .child("Recording")
44 .into_any_element()
45 })
46}
47
48pub fn return_button(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElement> {
49 model.breakout.as_ref().filter(|room| room.main.is_some())?;
50 let app = app.clone();
51 Some(
52 Button::new("call-return-main")
53 .label("Return to main meeting")
54 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.return_to_main_meeting(cx)))
55 .into_any_element(),
56 )
57}
58
59pub fn room_chip(model: &CallModel) -> Option<AnyElement> {
60 model.breakout.as_ref()?;
61 Some(div().flex_none().text_size(px(13.)).text_color(theme::text_muted()).child("Breakout room").into_any_element())
62}
63
64pub fn hold_panel(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElement> {
65 let (title, detail) = match model.hold {
66 HoldState::Active => return None,
67 HoldState::Local => ("On hold".to_owned(), format!("{} cannot hear you and you cannot hear them.", model.peer_name)),
68 HoldState::Remote => ("You're on hold".to_owned(), format!("{} put the call on hold.", model.peer_name)),
69 };
70 let resume = (model.hold == HoldState::Local).then(|| {
71 let app = app.clone();
72 Button::new("call-resume").label("Resume").on_click(move |_, _, cx| app.update(cx, |state, cx| state.toggle_call_hold(cx)))
73 });
74 Some(
75 v_flex()
76 .id("call-hold")
77 .flex_1()
78 .min_h_0()
79 .items_center()
80 .justify_center()
81 .gap(px(14.))
82 .child(
83 div()
84 .size(px(96.))
85 .flex()
86 .items_center()
87 .justify_center()
88 .rounded_full()
89 .bg(theme::surface_raised())
90 .child(icon(IconName::Clock, 48., theme::text())),
91 )
92 .child(div().text_size(px(22.)).font_weight(FontWeight::SEMIBOLD).child(title))
93 .child(div().text_size(px(14.)).text_color(theme::text_muted()).child(detail))
94 .children(resume)
95 .into_any_element(),
96 )
97}
98
99pub fn whiteboard_stage(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElement> {
100 let label = model.whiteboard_label()?;
101 let open = model.whiteboard_url().is_some().then(|| {
102 let app = app.clone();
103 Button::new("call-whiteboard-open")
104 .label("Open in browser")
105 .icon(IconName::ExternalLink)
106 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.open_call_whiteboard(cx)))
107 });
108 Some(
109 v_flex()
110 .id("call-whiteboard-stage")
111 .flex_1()
112 .min_w_0()
113 .h_full()
114 .items_center()
115 .justify_center()
116 .gap(px(14.))
117 .rounded(px(STAGE_RADIUS))
118 .bg(hsla(0., 0., 0.04, 1.))
119 .text_color(theme::white())
120 .child(icon(IconName::Pencil, 56., theme::white()))
121 .child(div().text_size(px(18.)).font_weight(FontWeight::SEMIBOLD).child(label))
122 .children(open)
123 .into_any_element(),
124 )
125}
126
127pub fn consult_banner(app: &Entity<AppState>, state: &AppState) -> Option<AnyElement> {
128 let consult = state.call.as_ref()?.consult.as_ref()?;
129 let text = consult.status_text();
130 let ready = consult.ready_to_transfer();
131 let (transfer_app, cancel_app) = (app.clone(), app.clone());
132 let transfer = pill("call-consult-transfer", "Transfer now", true);
133 let transfer = if ready {
134 transfer.on_click(move |_, _, cx| transfer_app.update(cx, |state, cx| state.transfer_consulted(cx)))
135 } else {
136 transfer.opacity(0.5).cursor_default()
137 };
138 Some(
139 h_flex()
140 .id("call-consult-banner")
141 .w_full()
142 .h(px(BANNER_HEIGHT))
143 .flex_none()
144 .px(px(20.))
145 .gap(px(12.))
146 .items_center()
147 .justify_center()
148 .bg(theme::amber())
149 .text_color(dark_text())
150 .text_size(px(13.))
151 .font_weight(FontWeight::SEMIBOLD)
152 .child(text)
153 .child(transfer)
154 .child(pill("call-consult-cancel", "Cancel", false).on_click(move |_, _, cx| cancel_app.update(cx, |state, cx| state.cancel_consult(cx))))
155 .into_any_element(),
156 )
157}
158
159pub fn consent_overlay(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElement> {
160 if !model.consent_required {
161 return None;
162 }
163 let app = app.clone();
164 Some(
165 div()
166 .id("call-consent-layer")
167 .absolute()
168 .top_0()
169 .left_0()
170 .size_full()
171 .flex()
172 .items_center()
173 .justify_center()
174 .child(div().id("call-consent-backdrop").absolute().top_0().left_0().size_full().bg(black().opacity(BACKDROP_OPACITY)).occlude())
175 .child(
176 v_flex()
177 .id("call-consent-card")
178 .w(px(CARD_WIDTH))
179 .max_w(relative(1.))
180 .p(px(20.))
181 .gap(px(12.))
182 .rounded(px(12.))
183 .bg(theme::background())
184 .border_1()
185 .border_color(theme::border_strong())
186 .text_color(theme::text())
187 .shadow_lg()
188 .occlude()
189 .child(
190 h_flex()
191 .gap(px(8.))
192 .items_center()
193 .child(div().size(px(10.)).rounded_full().bg(theme::red()))
194 .child(div().text_size(px(16.)).font_weight(FontWeight::SEMIBOLD).child("This meeting is being recorded")),
195 )
196 .child(
197 div()
198 .text_size(px(13.))
199 .text_color(theme::text_muted())
200 .child("Your microphone and camera stay off until you accept."),
201 )
202 .child(
203 h_flex().w_full().justify_end().child(
204 Button::new("call-consent-ok")
205 .label("OK")
206 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.accept_recording_notice(cx))),
207 ),
208 ),
209 )
210 .into_any_element(),
211 )
212}
213
214pub fn confirm_stop_recording(app: &Entity<AppState>, window: &mut Window, cx: &mut App) {
215 let app = app.clone();
216 window.open_alert_dialog(cx, move |alert, _, _| {
217 let app = app.clone();
218 let cancel = Button::new("recording-cancel").label("Cancel").on_click(|_, window, cx| window.close_dialog(cx));
219 let stop = Button::new("recording-stop").label("Stop").danger().on_click(move |_, window, cx| {
220 app.update(cx, |state, cx| state.set_call_recording(false, cx));
221 window.close_dialog(cx);
222 });
223 alert
224 .title("Stop recording and transcription?")
225 .description("The recording is saved to the organizer's OneDrive and the link arrives in the meeting chat.")
226 .footer(DialogFooter::new().child(cancel).child(stop))
227 .on_ok(|_, _, _| false)
228 });
229}
230
231pub fn open_transfer_picker(app: &Entity<AppState>, window: &mut Window, cx: &mut App) {
232 let candidates = app.read(cx).transfer_candidates();
233 let picker_app = app.clone();
234 let picker = cx.new(|cx| TransferPicker::new(picker_app, candidates, window, cx));
235 app.update(cx, |state, cx| state.open_transfer_picker(picker, cx));
236}
237
238#[derive(Clone)]
239pub struct BackgroundMenu {
240 pub pick: BackgroundPick,
241 pub images: Vec<(String, String, Option<PathBuf>)>,
242 pub customs: Vec<PathBuf>,
243}
244
245impl BackgroundMenu {
246 pub fn of(state: &AppState) -> Self {
247 let library = &state.call_backgrounds;
248 BackgroundMenu {
249 pick: state.call_background.clone(),
250 images: library.shown().iter().map(|image| (image.id.clone(), image.name.clone(), library.thumbnail(image))).collect(),
251 customs: library.customs.clone(),
252 }
253 }
254}
255
256fn thumbnail(app: &Entity<AppState>, index: usize, label: String, path: Option<PathBuf>, selected: bool, pick: BackgroundPick) -> AnyElement {
257 let app = app.clone();
258 let tooltip = label.clone();
259 div()
260 .id(("call-background", index))
261 .w(px(THUMBNAIL_WIDTH))
262 .h(px(THUMBNAIL_HEIGHT))
263 .flex_none()
264 .overflow_hidden()
265 .rounded(px(6.))
266 .border_2()
267 .border_color(if selected { theme::accent() } else { transparent_black() })
268 .bg(theme::surface())
269 .cursor_pointer()
270 .tooltip(move |window, cx| Tooltip::new(tooltip.clone()).build(window, cx))
271 .child(match path {
272 Some(path) => img(path).size_full().object_fit(ObjectFit::Cover).into_any_element(),
273 None => div().size_full().into_any_element(),
274 })
275 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_background(pick.clone(), cx)))
276 .into_any_element()
277}
278
279pub fn background_items(popup: PopupMenu, app: &Entity<AppState>, menu: &BackgroundMenu) -> PopupMenu {
280 let (none_app, blur_app, add_app, grid_app) = (app.clone(), app.clone(), app.clone(), app.clone());
281 let grid_menu = menu.clone();
282 let mut popup = popup
283 .separator()
284 .item(PopupMenuItem::label("Background"))
285 .item(PopupMenuItem::new("None").checked(menu.pick == BackgroundPick::None).on_click(move |_, _, cx| none_app.update(cx, |state, cx| state.set_call_background(BackgroundPick::None, cx))))
286 .item(PopupMenuItem::new("Blur").checked(menu.pick.is_blur()).on_click(move |_, _, cx| blur_app.update(cx, |state, cx| state.set_call_background(BackgroundPick::Blur, cx))));
287 if !menu.images.is_empty() || !menu.customs.is_empty() {
288 popup = popup.item(PopupMenuItem::element(move |_, _| {
289 let defaults = grid_menu.images.iter().enumerate().map(|(index, (id, name, path))| {
290 let pick = BackgroundPick::Default(id.clone());
291 thumbnail(&grid_app, index, name.clone(), path.clone(), grid_menu.pick == pick, pick)
292 });
293 let customs = grid_menu.customs.iter().enumerate().map(|(index, path)| {
294 let pick = BackgroundPick::Custom(path.clone());
295 let name = path.file_name().map_or_else(String::new, |name| name.to_string_lossy().into_owned());
296 thumbnail(&grid_app, grid_menu.images.len() + index, name, Some(path.clone()), grid_menu.pick == pick, pick)
297 });
298 h_flex().w(px(MENU_WIDTH - MENU_PADDING)).flex_wrap().gap(px(THUMBNAIL_GAP)).children(defaults.chain(customs))
299 }));
300 }
301 popup.item(
302 PopupMenuItem::new("Add image...")
303 .icon(IconName::Plus)
304 .on_click(move |_, _, cx| add_app.update(cx, |state, cx| state.add_call_background(cx))),
305 )
306}