BlueGit

ict rusty-teams

Files

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

share_bar.rs

share_bar.rs 5.2 KiB Download Raw
1use gpui_kit::assets::IconName;
2use gpui_kit::component::{h_flex, tooltip::Tooltip};
3use gpui_kit::*;
4
5use super::call_view::{camera_button, mute_button, round_control};
6use crate::app_state::AppState;
7use crate::call::CallWindows;
8use crate::theme;
9
10const BUTTON_SIZE: f32 = 26.;
11const BAR_RADIUS: f32 = 10.;
12const HANDLE_RADIUS: f32 = 3.;
13const STOP_HEIGHT: f32 = 26.;
14
15pub struct ShareBarView {
16 windows: Entity<CallWindows>,
17 app: Entity<AppState>,
18 _windows_subscription: Subscription,
19 _app_subscription: Subscription,
20}
21
22impl ShareBarView {
23 pub fn new(windows: Entity<CallWindows>, cx: &mut Context<Self>) -> Self {
24 let app = windows.read(cx).app().clone();
25 let windows_subscription = cx.observe(&windows, |_, _, cx| cx.notify());
26 let app_subscription = cx.observe(&app, |_, _, cx| cx.notify());
27 ShareBarView {
28 windows,
29 app,
30 _windows_subscription: windows_subscription,
31 _app_subscription: app_subscription,
32 }
33 }
34}
35
36fn stop_button(app: &Entity<AppState>) -> Stateful<Div> {
37 let app = app.clone();
38 h_flex()
39 .id("share-bar-stop")
40 .h(px(STOP_HEIGHT))
41 .px(px(10.))
42 .flex_none()
43 .items_center()
44 .rounded_full()
45 .bg(theme::red())
46 .text_color(theme::white())
47 .text_size(px(12.))
48 .font_weight(FontWeight::SEMIBOLD)
49 .cursor_pointer()
50 .hover(|button| button.opacity(0.85))
51 .child("Stop sharing")
52 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.stop_call_share(cx)))
53}
54
55fn sound_button(app: &Entity<AppState>, sound: bool) -> Stateful<Div> {
56 let app = app.clone();
57 let (glyph, background, foreground) = if sound {
58 (IconName::Volume2, theme::accent(), theme::on_accent())
59 } else {
60 (IconName::VolumeOff, theme::surface(), theme::text())
61 };
62 round_control("share-bar-sound", glyph, background, foreground)
63 .size(px(BUTTON_SIZE))
64 .tooltip(|window, cx| Tooltip::new("Include computer sound").build(window, cx))
65 .on_click(move |_, _, cx| {
66 app.update(cx, |state, cx| state.set_call_share_sound(!sound, cx))
67 })
68}
69
70fn pin_button(windows: &Entity<CallWindows>, pinned: bool) -> Stateful<Div> {
71 let windows = windows.clone();
72 let (glyph, background, foreground) = if pinned {
73 (IconName::PinOff, theme::accent(), theme::on_accent())
74 } else {
75 (IconName::Pin, theme::surface(), theme::text())
76 };
77 round_control("share-bar-pin", glyph, background, foreground)
78 .size(px(BUTTON_SIZE))
79 .tooltip(move |window, cx| {
80 Tooltip::new(if pinned {
81 "Unpin the bar"
82 } else {
83 "Keep the bar visible"
84 })
85 .build(window, cx)
86 })
87 .on_click(move |_, _, cx| windows.update(cx, |windows, cx| windows.toggle_pin(cx)))
88}
89
90impl Render for ShareBarView {
91 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
92 let windows = self.windows.read(cx);
93 let wake = self.windows.clone();
94 let wake_on_move = move |_: &MouseMoveEvent, _: &mut Window, cx: &mut App| {
95 wake.update(cx, |windows, cx| windows.wake_bar(cx))
96 };
97 if windows.bar_collapsed() {
98 return div()
99 .id("share-bar-handle")
100 .size_full()
101 .on_mouse_move(wake_on_move)
102 .child(
103 div()
104 .size_full()
105 .rounded_b(px(HANDLE_RADIUS))
106 .bg(theme::red()),
107 )
108 .into_any_element();
109 }
110 let text = windows.share_text();
111 let pinned = windows.pinned();
112 let state = self.app.read(cx);
113 let Some(call) = state.call.as_ref() else {
114 return div().into_any_element();
115 };
116 h_flex()
117 .id("share-bar")
118 .size_full()
119 .px(px(10.))
120 .gap(px(6.))
121 .items_center()
122 .rounded_b(px(BAR_RADIUS))
123 .bg(theme::surface_raised())
124 .border_1()
125 .border_color(theme::red())
126 .text_color(theme::text())
127 .text_size(px(12.))
128 .font_weight(FontWeight::SEMIBOLD)
129 .on_mouse_move(wake_on_move)
130 .child(
131 div()
132 .size(px(8.))
133 .flex_none()
134 .rounded_full()
135 .bg(theme::red()),
136 )
137 .child(div().flex_1().min_w_0().truncate().child(text))
138 .child(mute_button(
139 &self.app,
140 &call.model,
141 "share-bar-mute",
142 BUTTON_SIZE,
143 ))
144 .child(camera_button(&self.app, &call.model).size(px(BUTTON_SIZE)))
145 .child(sound_button(&self.app, state.call_share_sound))
146 .child(stop_button(&self.app))
147 .child(pin_button(&self.windows, pinned))
148 .into_any_element()
149 }
150}
151
152pub struct ShareBorderView;
153
154impl Render for ShareBorderView {
155 fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
156 div().size_full().bg(theme::red())
157 }
158}