BlueGit

ict rusty-teams

Files

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

call_view_menu.rs

call_view_menu.rs 4.3 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-chat-bubbles",
105 "Chat bubbles",
106 model.view.chat_bubbles,
107 |state, cx| state.toggle_call_chat_bubbles(cx),
108 app,
109 ))
110 .separator()
111 .item(
112 PopupMenuItem::element(move |_, _| {
113 hint_row(
114 FULL_SCREEN_LABEL,
115 keys_for_label(FULL_SCREEN_LABEL).unwrap_or_default(),
116 false,
117 )
118 })
119 .checked(fullscreen)
120 .on_click(move |_, _, cx| {
121 full_screen_app.update(cx, |state, cx| state.toggle_call_fullscreen(cx))
122 }),
123 )
124}
125
126pub(super) fn view_button(
127 app: &Entity<AppState>,
128 model: &CallModel,
129 fullscreen: bool,
130) -> AnyElement {
131 let app = app.clone();
132 let model = model.clone();
133 Button::new("call-view")
134 .ghost()
135 .p_0()
136 .size(px(CONTROL_SIZE))
137 .rounded_full()
138 .child(round_control(
139 "call-view-face",
140 IconName::LayoutGrid,
141 theme::surface_raised(),
142 theme::text(),
143 ))
144 .dropdown_menu_with_anchor(Anchor::BottomRight, move |popup, _, _| {
145 view_items(popup, &app, &model, fullscreen)
146 })
147 .into_any_element()
148}