BlueGit

ict rusty-teams

Files

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

call_view_menu.rs

feat(calls): Hide meeting timer
metis Daniel Däschle · pushed by metis · 3 weeks ago
85506f7a History
call_view_menu.rs 4.5 KiB Download Raw
1use gpui_kit::assets::IconName;
2use gpui_kit::component::{
3 button::{Button, ButtonVariants as _},
4 h_flex,
5 menu::{DropdownMenu as _, PopupMenu, PopupMenuItem},
6 switch::Switch,
7};
8use gpui_kit::prelude::FluentBuilder as _;
9use gpui_kit::*;
10
11use super::call_view::{CONTROL_SIZE, DISABLED_OPACITY, MENU_WIDTH, round_control};
12use super::shortcuts::keys_for_label;
13use crate::app_state::AppState;
14use crate::call::{CallLayout, CallModel};
15use crate::theme;
16
17pub const FULL_SCREEN_LABEL: &str = "Full screen";
18const CONTENT_HINT: &str = "Only while someone shares";
19
20fn hint_row(label: &'static str, hint: String, dimmed: bool) -> Div {
21 h_flex()
22 .w_full()
23 .gap(px(16.))
24 .items_center()
25 .justify_between()
26 .when(dimmed, |row| row.opacity(DISABLED_OPACITY))
27 .child(label)
28 .child(
29 div()
30 .text_size(px(12.))
31 .text_color(theme::text_muted())
32 .child(hint),
33 )
34}
35
36fn layout_item(app: &Entity<AppState>, model: &CallModel, layout: CallLayout) -> PopupMenuItem {
37 let unavailable = layout == CallLayout::Content && !model.has_content();
38 let item = if unavailable {
39 PopupMenuItem::element(move |_, _| hint_row(layout.label(), CONTENT_HINT.to_owned(), true))
40 } else {
41 PopupMenuItem::new(layout.label())
42 };
43 let app = app.clone();
44 item.checked(layout == model.effective_layout())
45 .disabled(unavailable)
46 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_layout(layout, cx)))
47}
48
49fn switch_item(
50 id: &'static str,
51 label: &'static str,
52 on: bool,
53 toggle: impl Fn(&mut AppState, &mut Context<AppState>) + Clone + 'static,
54 app: &Entity<AppState>,
55) -> PopupMenuItem {
56 let app = app.clone();
57 PopupMenuItem::element(move |_, _| {
58 h_flex()
59 .w_full()
60 .gap(px(16.))
61 .items_center()
62 .justify_between()
63 .child(label)
64 .child(Switch::new(id).checked(on))
65 })
66 .on_click(move |_, _, cx| app.update(cx, |state, cx| toggle(state, cx)))
67}
68
69pub(super) fn view_items(
70 popup: PopupMenu,
71 app: &Entity<AppState>,
72 model: &CallModel,
73 fullscreen: bool,
74) -> PopupMenu {
75 let hide_me = model.view.hide_me;
76 let full_screen_app = app.clone();
77 let mut popup = popup
78 .min_w(px(MENU_WIDTH))
79 .item(PopupMenuItem::label("Layout"));
80 for layout in [
81 CallLayout::Gallery,
82 CallLayout::Speaker,
83 CallLayout::Content,
84 ] {
85 popup = popup.item(layout_item(app, model, layout));
86 }
87 popup
88 .separator()
89 .item(switch_item(
90 "call-view-hide-no-video",
91 "Hide people without video",
92 model.view.hide_no_video,
93 |state, cx| state.toggle_call_hide_no_video(cx),
94 app,
95 ))
96 .item(switch_item(
97 "call-view-hide-me",
98 "Hide me",
99 hide_me,
100 move |state, cx| state.set_call_hide_me(!hide_me, cx),
101 app,
102 ))
103 .item(switch_item(
104 "call-view-hide-timer",
105 "Hide meeting timer",
106 model.view.hide_timer,
107 |state, cx| state.toggle_call_hide_timer(cx),
108 app,
109 ))
110 .item(switch_item(
111 "call-view-chat-bubbles",
112 "Chat bubbles",
113 model.view.chat_bubbles,
114 |state, cx| state.toggle_call_chat_bubbles(cx),
115 app,
116 ))
117 .separator()
118 .item(
119 PopupMenuItem::element(move |_, _| {
120 hint_row(
121 FULL_SCREEN_LABEL,
122 keys_for_label(FULL_SCREEN_LABEL).unwrap_or_default(),
123 false,
124 )
125 })
126 .checked(fullscreen)
127 .on_click(move |_, _, cx| {
128 full_screen_app.update(cx, |state, cx| state.toggle_call_fullscreen(cx))
129 }),
130 )
131}
132
133pub(super) fn view_button(
134 app: &Entity<AppState>,
135 model: &CallModel,
136 fullscreen: bool,
137) -> AnyElement {
138 let app = app.clone();
139 let model = model.clone();
140 Button::new("call-view")
141 .ghost()
142 .p_0()
143 .size(px(CONTROL_SIZE))
144 .rounded_full()
145 .child(round_control(
146 "call-view-face",
147 IconName::LayoutGrid,
148 theme::surface_raised(),
149 theme::text(),
150 ))
151 .dropdown_menu_with_anchor(Anchor::BottomRight, move |popup, _, _| {
152 view_items(popup, &app, &model, fullscreen)
153 })
154 .into_any_element()
155}