| 1 | use gpui_kit::assets::IconName; |
| 2 | use gpui_kit::component::{ |
| 3 | h_flex, |
| 4 | menu::{DropdownMenu as _, PopupMenu, PopupMenuItem}, |
| 5 | switch::Switch, |
| 6 | }; |
| 7 | use gpui_kit::prelude::FluentBuilder as _; |
| 8 | use gpui_kit::*; |
| 9 | |
| 10 | use super::call_toolbar::{tool_face, tool_trigger}; |
| 11 | use super::call_view::{DISABLED_OPACITY, MENU_WIDTH}; |
| 12 | use super::shortcuts::keys_for_label; |
| 13 | use crate::app_state::AppState; |
| 14 | use crate::call::{CallLayout, CallModel}; |
| 15 | use crate::theme; |
| 16 | |
| 17 | pub const FULL_SCREEN_LABEL: &str = "Full screen"; |
| 18 | const CONTENT_HINT: &str = "Only while someone shares"; |
| 19 | |
| 20 | fn 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 | |
| 36 | fn 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 | |
| 49 | fn 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 | |
| 69 | pub(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 | |
| 133 | pub(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 | tool_trigger( |
| 141 | "call-view", |
| 142 | tool_face("call-view-face", IconName::LayoutGrid, "View", false), |
| 143 | ) |
| 144 | .dropdown_menu_with_anchor(Anchor::TopRight, move |popup, _, _| { |
| 145 | view_items(popup, &app, &model, fullscreen) |
| 146 | }) |
| 147 | .into_any_element() |
| 148 | } |