diff --git a/crates/client/src/gui.rs b/crates/client/src/gui.rs index a4348a1..497943f 100644 --- a/crates/client/src/gui.rs +++ b/crates/client/src/gui.rs @@ -48,6 +48,7 @@ mod camera_view; mod chat; mod community_settings; mod composer; +mod dock; mod forward; mod media_view; mod message_actions; @@ -97,6 +98,8 @@ pub struct Palette { pub ok: Hsla, pub danger: Hsla, pub alert: Hsla, + pub screen: Hsla, + pub camera: Hsla, pub dark: bool, } @@ -163,6 +166,8 @@ pub fn palette(cx: &App) -> Palette { ok: rgb(0x3fb950).into(), danger: rgb(0xd1483f).into(), alert: rgb(alert).into(), + screen: rgb(if dark { 0x60a5fa } else { 0x2563eb }).into(), + camera: rgb(if dark { 0xf5a524 } else { 0xc2410c }).into(), dark, } } diff --git a/crates/client/src/gui/camera_view.rs b/crates/client/src/gui/camera_view.rs index 2fca337..2814999 100644 --- a/crates/client/src/gui/camera_view.rs +++ b/crates/client/src/gui/camera_view.rs @@ -3,7 +3,7 @@ use common::model::Id; use common::share::{Fps, Kind, Quality, Resolution}; use gpui_kit::{ AnyElement, AppContext as _, Context, Entity, InteractiveElement, IntoElement, ParentElement, - StatefulInteractiveElement, Styled, Task, Window, assets::IconName, component::Icon, div, px, + StatefulInteractiveElement, Styled, Task, Window, component::Icon, div, px, }; use super::{ @@ -13,7 +13,7 @@ use super::{ share_view::{self, FRAME_TICK}, surface::Surface, text, - widget::{icon_button, spawn_warn}, + widget::spawn_warn, }; use crate::share::session::WatchQuality; @@ -296,37 +296,6 @@ pub(super) fn ticker(cx: &mut Context) -> Task<()> { }) } -pub(super) fn camera_toggle( - entity: &Entity, - on: bool, - palette: Palette, -) -> impl IntoElement { - let entity = entity.clone(); - - icon_button( - if on { - "camera_toggle_on" - } else { - "camera_toggle_off" - }, - palette, - if on { - IconName::VideoOff - } else { - IconName::Video - }, - if on { - "Turn off camera" - } else { - "Turn on camera" - }, - move |window, cx| { - entity.update(cx, |yumush, cx| yumush.toggle_camera(window, cx)); - }, - ) - .text_color(if on { palette.ok } else { palette.muted }) -} - fn stage_tile( entity: &Entity, yumush: &Yumush, diff --git a/crates/client/src/gui/chat.rs b/crates/client/src/gui/chat.rs index 5c88865..a60228e 100644 --- a/crates/client/src/gui/chat.rs +++ b/crates/client/src/gui/chat.rs @@ -26,7 +26,7 @@ use crate::gui::{ sidebar::{SidebarTab, unread_badge}, snippet, voice_note::{self, VoiceNote}, - widget::{icon_button, ok_or_notify, search_text, spawn_done}, + widget::{ok_or_notify, search_text, spawn_done}, }; use crate::net::Levels; use crate::settings::VOLUME; @@ -90,6 +90,7 @@ pub enum VoiceState { community_id: Id, muted: bool, deafened: bool, + since: Instant, }, } @@ -2070,6 +2071,7 @@ impl Yumush { community_id, muted, deafened, + since: Instant::now(), }; yumush.start_voice_poll(cx); cx.notify(); @@ -2124,13 +2126,13 @@ impl Yumush { self.chat.ghost || !self.chat.joined(community_id) } - fn hidden_in_voice(&self) -> bool { + pub(super) fn hidden_in_voice(&self) -> bool { self.chat .voice_community() .is_some_and(|community_id| self.hidden_in(community_id)) } - fn toggle_mute(&mut self, window: &mut Window, cx: &mut Context) { + pub(super) fn toggle_mute(&mut self, window: &mut Window, cx: &mut Context) { if self.is_server_muted() { return; } @@ -2207,7 +2209,7 @@ impl Yumush { }); } - fn toggle_deafen(&mut self, cx: &mut Context) { + pub(super) fn toggle_deafen(&mut self, cx: &mut Context) { if let VoiceState::In { deafened, .. } = &mut self.chat.voice_state { *deafened = !*deafened; self.network.set_deafened(*deafened); @@ -2569,75 +2571,6 @@ impl Yumush { })), ) } - - pub(super) fn voice_controls( - &self, - entity: &Entity, - palette: Palette, - ) -> Option { - let (muted, deafened) = self.chat.voice_flags()?; - let mic_entity = entity.clone(); - let deafen_entity = entity.clone(); - let mic_icon = if muted { - IconName::MicOff - } else { - IconName::Mic - }; - let deafen_icon = if deafened { - IconName::HeadphoneOff - } else { - IconName::Headphones - }; - - Some( - div() - .flex() - .items_center() - .child( - icon_button( - format!("mic_button_{muted}_{}", self.hidden_in_voice()), - palette, - mic_icon, - match (muted, self.hidden_in_voice()) { - (true, true) => "Speak as ghost", - (true, false) => "Unmute", - (false, _) => "Mute", - }, - move |window, cx| { - mic_entity.update(cx, |yumush, cx| yumush.toggle_mute(window, cx)) - }, - ) - .text_color(if muted || deafened { - palette.danger - } else { - palette.muted - }), - ) - .child( - icon_button( - format!("deafen_button_{deafened}"), - palette, - deafen_icon, - if deafened { "Undeafen" } else { "Deafen" }, - move |_, cx| { - deafen_entity.update(cx, |yumush, cx| yumush.toggle_deafen(cx)) - }, - ) - .text_color(if deafened { - palette.danger - } else { - palette.muted - }), - ) - .children(self.chat.ghost.then(|| { - div() - .ml(px(4.)) - .text_size(text(11.)) - .text_color(palette.muted) - .child("Ghost") - })), - ) - } } struct MemberRow { diff --git a/crates/client/src/gui/dock.rs b/crates/client/src/gui/dock.rs new file mode 100644 index 0000000..31ddf14 --- /dev/null +++ b/crates/client/src/gui/dock.rs @@ -0,0 +1,381 @@ +use std::time::Instant; + +use common::{ + model::{Community, Id}, + share::Kind, +}; +use gpui_kit::{ + Anchor, App, Div, Entity, FontWeight, Hsla, IntoElement, MouseButton, ParentElement, Stateful, + Styled, Window, + assets::IconName, + component::{Icon, popover::Popover}, + div, px, +}; + +use super::{ + Palette, Tooltip as _, Trigger, Yumush, chat::VoiceState, clickable, community_name, + entity_action, pop_in, share_view::kind_icon, text, voice_stats, wave, widget::icon_button, +}; + +const PING_BARS: usize = 12; + +impl Yumush { + pub(super) fn dock(&self, entity: &Entity, palette: Palette) -> Option { + let community = self.chat.voice_room()?; + let VoiceState::In { since, .. } = &self.chat.voice_state else { + return None; + }; + let (muted, deafened) = self.chat.voice_flags()?; + let me = self.user.as_ref()?.id; + let tone = voice_stats::quality(&self.chat.voice_samples) + .map_or(palette.ok, |quality| quality.color(palette)); + let stats_entity = entity.clone(); + + let panel = div() + .bg(tone.opacity(0.08)) + .border_1() + .border_color(tone.opacity(0.2)) + .rounded(px(10.)) + .p(px(8.)) + .flex() + .flex_col() + .gap(px(6.)) + .child(self.dock_header(entity, community, *since, tone, palette)) + .child(self.dock_voice(entity, me, muted, deafened, palette)) + .child(self.dock_devices(entity, me, palette)); + + Some( + Popover::new("voice_stats") + .anchor(Anchor::BottomLeft) + .mouse_button(MouseButton::Right) + .appearance(false) + .trigger(Trigger::new(panel)) + .content(move |_, _, cx| { + let chat = &stats_entity.read(cx).chat; + pop_in( + "voice_stats_card", + voice_stats::stats_card(chat, &stats_entity, palette), + Anchor::BottomLeft, + ) + }), + ) + } + + fn dock_header( + &self, + entity: &Entity, + community: &Community, + since: Instant, + tone: Hsla, + palette: Palette, + ) -> Div { + let direct = community.kind.is_direct(); + let go_id = community.id; + let go = entity_action(entity, move |yumush, window, cx| { + yumush.go_to_community(go_id, direct, window, cx) + }); + + let ping = self + .chat + .voice_samples + .back() + .map_or(0., |sample| sample.ping_ms); + let start = self.chat.voice_samples.len().saturating_sub(PING_BARS); + let pings: Vec = self + .chat + .voice_samples + .iter() + .skip(start) + .map(|sample| sample.ping_ms) + .collect(); + let peak = pings.iter().copied().fold(1., f32::max); + let bars = div() + .flex() + .items_end() + .gap(px(1.)) + .h(px(12.)) + .children(pings.iter().map(|ping| { + div() + .w(px(2.)) + .h(px((12. * ping / peak).max(1.))) + .rounded(px(1.)) + .bg(tone) + })); + + div() + .flex() + .items_center() + .gap(px(7.)) + .child( + clickable("dock_go", palette, go) + .tip("Go to call") + .min_w_0() + .truncate() + .text_size(text(12.)) + .font_weight(FontWeight::SEMIBOLD) + .text_color(tone) + .child(community_name(community).to_string()), + ) + .child( + div() + .text_size(text(11.)) + .text_color(palette.muted) + .child(elapsed_text(since)), + ) + .child(div().flex_1()) + .child( + div() + .flex_shrink_0() + .h(px(22.)) + .px(px(7.)) + .rounded(px(6.)) + .bg(tone.opacity(0.12)) + .flex() + .items_center() + .gap(px(6.)) + .child(bars) + .child( + div() + .text_size(text(11.)) + .text_color(tone) + .child(format!("{ping:.0} ms")), + ), + ) + .child( + icon_button( + "dock_leave", + palette, + IconName::PhoneOff, + "Leave call", + entity_action(entity, |yumush, _, cx| { + yumush.end_voice(cx); + cx.notify(); + }), + ) + .bg(palette.danger.opacity(0.13)) + .text_color(palette.danger), + ) + } + + fn dock_voice( + &self, + entity: &Entity, + me: Id, + muted: bool, + deafened: bool, + palette: Palette, + ) -> Div { + let tone = if muted || deafened { + palette.danger + } else { + palette.ok + }; + let mic_entity = entity.clone(); + let deafen_entity = entity.clone(); + let ghost = self.hidden_in_voice(); + let mic_icon = if muted { + IconName::MicOff + } else { + IconName::Mic + }; + let mic_tip = match (muted, ghost) { + (true, true) => "Speak as ghost", + (true, false) => "Unmute", + (false, _) => "Mute", + }; + let deafen_icon = if deafened { + IconName::HeadphoneOff + } else { + IconName::Headphones + }; + let (deafen_bg, deafen_tone) = if deafened { + (palette.danger.opacity(0.13), palette.danger) + } else { + (palette.hover, palette.text) + }; + + let mic = icon_button( + format!("dock_mic_{muted}_{ghost}"), + palette, + mic_icon, + mic_tip, + move |window, cx| mic_entity.update(cx, |yumush, cx| yumush.toggle_mute(window, cx)), + ) + .text_color(tone); + let voice = div() + .flex_1() + .flex() + .justify_center() + .child(wave::wave_slot(self.chat.waves.voice(me), 14., tone)); + let group = div() + .flex_1() + .h(px(30.)) + .px(px(8.)) + .rounded(px(7.)) + .bg(tone.opacity(0.12)) + .flex() + .items_center() + .gap(px(4.)) + .child(mic) + .child(voice); + let deafen = icon_button( + format!("dock_deafen_{deafened}"), + palette, + deafen_icon, + if deafened { "Undeafen" } else { "Deafen" }, + move |_, cx| deafen_entity.update(cx, |yumush, cx| yumush.toggle_deafen(cx)), + ) + .w(px(34.)) + .h(px(30.)) + .rounded(px(7.)) + .bg(deafen_bg) + .text_color(deafen_tone); + + div() + .flex() + .items_center() + .gap(px(4.)) + .child(group) + .child(deafen) + } + + fn dock_devices(&self, entity: &Entity, me: Id, palette: Palette) -> Div { + let (on, off): (Vec, Vec) = [Kind::Camera, Kind::Screen] + .into_iter() + .partition(|kind| self.is_on(*kind)); + let mut rows: Vec
= on + .into_iter() + .map(|kind| self.device_row(entity, me, kind, palette)) + .collect(); + if !off.is_empty() { + rows.push( + div().flex().items_center().gap(px(4.)).children( + off.into_iter() + .map(|kind| start_button(entity, kind, palette)), + ), + ); + } + if let Some(last) = rows.pop() { + rows.push(last.child(self.share_settings_button(entity, palette))); + } + div().flex().flex_col().gap(px(4.)).children(rows) + } + + fn device_row(&self, entity: &Entity, me: Id, kind: Kind, palette: Palette) -> Div { + let tone = match kind { + Kind::Camera => palette.camera, + Kind::Screen => palette.screen, + }; + let stop_tip = match kind { + Kind::Camera => "Turn off camera", + Kind::Screen => "Stop sharing", + }; + let mut row = div() + .h(px(30.)) + .rounded(px(7.)) + .pl(px(8.)) + .pr(px(2.)) + .bg(tone.opacity(0.1)) + .flex() + .items_center() + .gap(px(6.)) + .child( + Icon::new(kind_icon(kind)) + .w(px(14.)) + .h(px(14.)) + .text_color(tone), + ) + .child( + div() + .text_size(text(11.5)) + .text_color(tone) + .child(self.mode_text(kind)), + ); + if let Some(history) = self.chat.waves.share(me).filter(|_| kind == Kind::Screen) { + row = row.child( + div() + .h(px(22.)) + .px(px(6.)) + .rounded(px(6.)) + .bg(tone.opacity(0.12)) + .flex() + .items_center() + .gap(px(4.)) + .child( + Icon::new(IconName::Volume2) + .w(px(14.)) + .h(px(14.)) + .text_color(tone), + ) + .child(wave::mini_wave(history, 10., tone)), + ); + } + row.child(div().flex_1()).child( + icon_button( + format!("dock_stop_{kind:?}"), + palette, + IconName::X, + stop_tip, + toggle_action(entity, kind), + ) + .text_color(palette.danger), + ) + } + + fn mode_text(&self, kind: Kind) -> String { + let best = self + .chat + .share_sample + .sending + .iter() + .filter(|(sent, _)| *sent == kind) + .map(|(_, stats)| stats) + .max_by(|a, b| a.fps.total_cmp(&b.fps)); + match best { + Some(stats) => format!( + "{}p{}", + stats.layer.quality.resolution.height(), + stats.layer.quality.fps.value() + ), + None => "…".to_string(), + } + } + + fn is_on(&self, kind: Kind) -> bool { + self.network.share_source(kind).is_some() + } +} + +fn start_button(entity: &Entity, kind: Kind, palette: Palette) -> Stateful
{ + icon_button( + format!("dock_start_{kind:?}"), + palette, + kind_icon(kind), + match kind { + Kind::Camera => "Turn on camera", + Kind::Screen => "Share screen", + }, + toggle_action(entity, kind), + ) + .flex_1() + .h(px(30.)) + .rounded(px(7.)) + .bg(palette.hover) +} + +fn toggle_action(entity: &Entity, kind: Kind) -> impl Fn(&mut Window, &mut App) + 'static { + let entity = entity.clone(); + move |window: &mut Window, cx: &mut App| match kind { + Kind::Camera => entity.update(cx, |yumush, cx| yumush.toggle_camera(window, cx)), + Kind::Screen => entity.update(cx, |yumush, cx| yumush.toggle_share(window, cx)), + } +} + +fn elapsed_text(since: Instant) -> String { + let seconds = since.elapsed().as_secs(); + let (hours, minutes, seconds) = (seconds / 3600, seconds / 60 % 60, seconds % 60); + match hours { + 0 => format!("{minutes:02}:{seconds:02}"), + _ => format!("{hours}:{minutes:02}:{seconds:02}"), + } +} diff --git a/crates/client/src/gui/share_view.rs b/crates/client/src/gui/share_view.rs index dc964c3..e7eb8c2 100644 --- a/crates/client/src/gui/share_view.rs +++ b/crates/client/src/gui/share_view.rs @@ -395,77 +395,40 @@ impl Yumush { cx.notify(); } - pub(super) fn share_controls( + pub(super) fn share_settings_button( &self, entity: &Entity, palette: Palette, ) -> impl IntoElement { - let sharing = self.network.sharing(); - let toggle = entity.clone(); let refresh = entity.clone(); let settings = entity.clone(); - div() - .flex() - .items_center() - .gap(px(2.)) - .child(camera_view::camera_toggle( - entity, - self.network.camera_on(), - palette, + Popover::new("share_settings") + .anchor(Anchor::BottomLeft) + .appearance(false) + .trigger(Trigger::new( + div() + .id("share_settings_button") + .on_mouse_down(MouseButton::Left, move |_, _, cx| { + refresh.update(cx, |yumush, cx| yumush.refresh_share_apps(cx)); + }) + .tip("Share settings") + .size(px(26.)) + .flex() + .items_center() + .justify_center() + .rounded(px(6.)) + .text_color(palette.muted) + .child(Icon::new(IconName::SlidersHorizontal).w(px(14.)).h(px(14.))), )) - .child( - icon_button( - if sharing { - "share_toggle_on" - } else { - "share_toggle_off" - }, - palette, - if sharing { - IconName::ScreenShareOff - } else { - IconName::ScreenShare - }, - if sharing { - "Stop sharing" - } else { - "Share screen" - }, - move |window, cx| { - toggle.update(cx, |yumush, cx| yumush.toggle_share(window, cx)); - }, + .content(move |_, _, cx| { + let entity = settings.clone(); + pop_in( + "share_settings_card", + settings_card(&entity, entity.read(cx), palette), + Anchor::BottomLeft, ) - .text_color(if sharing { palette.ok } else { palette.muted }), - ) - .child( - Popover::new("share_settings") - .anchor(Anchor::BottomLeft) - .appearance(false) - .trigger(Trigger::new( - div() - .id("share_settings_button") - .on_mouse_down(MouseButton::Left, move |_, _, cx| { - refresh.update(cx, |yumush, cx| yumush.refresh_share_apps(cx)); - }) - .tip("Share settings") - .size(px(26.)) - .flex() - .items_center() - .justify_center() - .rounded(px(6.)) - .text_color(palette.muted) - .child(Icon::new(IconName::SlidersHorizontal).w(px(14.)).h(px(14.))), - )) - .content(move |_, _, cx| { - let entity = settings.clone(); - pop_in( - "share_settings_card", - settings_card(&entity, entity.read(cx), palette), - Anchor::BottomLeft, - ) - }), - ) + }) } pub(super) fn inline_viewer(&self, entity: &Entity, palette: Palette) -> Option
{ diff --git a/crates/client/src/gui/sidebar.rs b/crates/client/src/gui/sidebar.rs index 7bb43ad..5c7d48b 100644 --- a/crates/client/src/gui/sidebar.rs +++ b/crates/client/src/gui/sidebar.rs @@ -1,3 +1,5 @@ +use std::collections::VecDeque; + use super::text; use common::model::Id; use common::{ @@ -8,13 +10,12 @@ use common::{ }; use gpui_kit::{ Anchor, AnimationExt, AnyElement, App, Context, Div, Entity, FontWeight, InteractiveElement, - IntoElement, MouseButton, ParentElement, Pixels, StatefulInteractiveElement, Styled, Window, + IntoElement, ParentElement, Pixels, StatefulInteractiveElement, Styled, Window, assets::IconName, component::{ Icon, input::{Input, InputState}, menu::{ContextMenuExt, PopupMenu, PopupMenuItem}, - popover::Popover, }, div, prelude::FluentBuilder as _, @@ -22,21 +23,19 @@ use gpui_kit::{ }; use super::{ - Palette, Tooltip as _, Trigger, Yumush, avatar, + Palette, Tooltip as _, Yumush, avatar, chat::{View, create_community}, clickable, community_icon, community_name, entity_action, hoverable, hoverable_with, - input_dialog, motion, pop_in, presence_avatar, + input_dialog, motion, presence_avatar, profile::profile_popover, settings_page::{segment, segment_track}, social::Relation, - voice_stats, - wave::wave_slot, + wave::mini_wave, widget::{bare_input, compact_frame, icon_button}, }; const SIDEBAR_WIDTH: f32 = 232.; const SIDEBAR_COLLAPSED_WIDTH: f32 = 48.; -const MEMBERS_HEIGHT: f32 = 160.; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum SidebarTab { @@ -136,237 +135,132 @@ impl Yumush { .overflow_y_scroll() .child(list), ) - .children(self.voice_panel(entity, palette)) + .children(self.dock(entity, palette)) .children(self.account_row(entity, palette)) .into_any_element() } - fn voice_panel(&self, entity: &Entity, palette: Palette) -> Option { - let community = self.chat.voice_room()?; - let tone = voice_stats::quality(&self.chat.voice_samples) - .map_or(palette.ok, |quality| quality.color(palette)); - let stats_entity = entity.clone(); - let members: Vec<_> = self - .chat - .voice_ids(community.id) - .iter() - .filter_map(|id| self.chat.author(*id)) - .map(|user| self.voice_member(entity, community.id, user, palette)) - .collect(); - - let controls = div() + fn voice_chip(&self, community_id: Id, palette: Palette) -> AnyElement { + let ids = self.chat.voice_ids(community_id); + let wave = ids.iter().find_map(|id| self.chat.waves.voice(*id)); + div() + .h(px(18.)) + .px(px(5.)) .flex() .items_center() .gap(px(4.)) - .child( - clickable("voice_panel_go", palette, go_to_call(entity, community)) - .tip("Go to call") - .flex_1() - .min_w_0() - .px(px(4.)) - .py(px(2.)) - .rounded(px(6.)) - .flex() - .items_center() - .gap(px(8.)) - .child( - Icon::new(IconName::AudioLines) - .w(px(16.)) - .h(px(16.)) - .text_color(tone), - ) - .child( - div() - .flex_1() - .min_w_0() - .truncate() - .text_size(text(12.)) - .font_weight(FontWeight::SEMIBOLD) - .text_color(palette.ok) - .child(community_name(community).to_string()), - ), - ) - .child(self.share_controls(entity, palette)) - .child(icon_button( - "voice_panel_leave".to_string(), - palette, - IconName::PhoneOff, - "Leave call", - entity_action(entity, |yumush, _, cx| { - yumush.end_voice(cx); - cx.notify(); - }), - )); - let panel = call_style(div(), palette) - .flex() - .flex_col() - .gap(px(2.)) - .p(px(6.)) - .rounded(px(8.)) + .rounded(px(4.)) + .bg(palette.ok.opacity(0.15)) + .children(wave.map(|history| mini_wave(history, 12., palette.ok))) .child( div() - .id("voice_members") - .max_h(px(MEMBERS_HEIGHT)) - .overflow_y_scroll() - .children(members), + .text_size(text(11.)) + .text_color(palette.ok) + .child(ids.len().to_string()), ) - .child(controls); + .into_any_element() + } + + fn call_tree(&self, entity: &Entity, community_id: Id, palette: Palette) -> Option
{ + if self.chat.voice_community() != Some(community_id) { + return None; + } + let members = self + .chat + .voice_ids(community_id) + .iter() + .filter_map(|id| self.chat.author(*id)) + .map(|user| self.call_member(entity, community_id, user, palette)); Some( - Popover::new("voice_stats") - .anchor(Anchor::BottomLeft) - .mouse_button(MouseButton::Right) - .appearance(false) - .trigger(Trigger::new(panel)) - .content(move |_, _, cx| { - let chat = &stats_entity.read(cx).chat; - pop_in( - "voice_stats_card", - voice_stats::stats_card(chat, &stats_entity, palette), - Anchor::BottomLeft, - ) - }), + div() + .ml(px(18.)) + .pl(px(10.)) + .border_l_1() + .border_color(palette.border) + .flex() + .flex_col() + .gap(px(1.)) + .mt(px(2.)) + .mb(px(4.)) + .children(members), ) } - fn voice_member( + fn call_member( &self, entity: &Entity, community_id: Id, user: &User, palette: Palette, ) -> impl IntoElement { - let speaking = self.chat.waves.speaking.contains(&user.id); - let screen = self + let user_id = user.id; + let speaking = self.chat.waves.speaking.contains(&user_id); + let wave = speaking.then(|| self.chat.waves.voice(user_id)).flatten(); + let muted = (self.is_me(user_id) + && self.chat.voice_flags().is_some_and(|(muted, _)| muted)) + || self.chat.server_muted.contains(&user_id); + let camera = self .chat - .share_of(community_id, user.id, Kind::Screen) + .share_of(community_id, user_id, Kind::Camera) .is_some(); - let camera = self + let screen = self .chat - .share_of(community_id, user.id, Kind::Camera) + .share_of(community_id, user_id, Kind::Screen) .is_some(); - - let user_id = user.id; - let watch_screen = entity.clone(); - let watch_camera = entity.clone(); let ghost = self.chat.ghost && self.is_me(user_id); - let member = profile_popover( - format!("voice_member_{user_id}"), - Anchor::BottomLeft, - user, - entity, - div() - .flex() - .items_center() - .gap(px(6.)) - .flex_1() - .min_w_0() - .cursor_pointer() - .child( - avatar(palette, user, px(18.), text(9.), &self.chat.avatars) - .border_2() - .border_color(if speaking { - palette.ok - } else { - palette.ok.opacity(0.) - }), - ) - .child( - div() - .flex_1() - .min_w_0() - .truncate() - .text_size(text(12.)) - .text_color(palette.text) - .child(user.username.clone()), - ) - .when(ghost, |row| { - row.child( - Icon::new(IconName::Ghost) - .w(px(12.)) - .h(px(12.)) - .text_color(palette.muted), - ) - }), - ); - - let row = div() + let identity = div() .flex() .items_center() - .gap(px(4.)) - .px(px(4.)) - .py(px(2.)) - .rounded(px(6.)) - .hover(move |style| style.bg(palette.hover)) - .child(div().flex_1().min_w_0().child(member)) + .gap(px(6.)) + .flex_1() + .min_w_0() + .cursor_pointer() + .child(avatar(palette, user, px(18.), text(9.), &self.chat.avatars)) .child( div() - .w(px(20.)) - .h(px(20.)) - .flex_shrink_0() - .when(camera, |slot| { - slot.child( - clickable( - format!("voice_camera_{user_id}"), - palette, - move |window, cx| { - watch_camera.update(cx, |yumush, cx| { - yumush.toggle_viewer(user_id, Kind::Camera, window, cx) - }); - }, - ) - .tip("Watch") - .size_full() - .flex() - .items_center() - .justify_center() - .rounded(px(4.)) - .child( - Icon::new(IconName::Video) - .w(px(12.)) - .h(px(12.)) - .text_color(palette.alert), - ), - ) - }), - ) - .child(wave_slot(self.chat.waves.voice(user_id), 12., palette.ok)); - - let stream = screen.then(|| { - clickable( - format!("voice_screen_{user_id}"), - palette, - move |window, cx| { - watch_screen.update(cx, |yumush, cx| { - yumush.toggle_viewer(user_id, Kind::Screen, window, cx) - }); - }, + .min_w_0() + .truncate() + .text_size(text(12.)) + .text_color(if speaking { palette.text } else { palette.body }) + .when(speaking, |name| name.font_weight(FontWeight::SEMIBOLD)) + .child(user.username.clone()), ) - .tip("Watch") - .flex() - .items_center() - .gap(px(4.)) - .h(px(20.)) - .pl(px(28.)) - .pr(px(4.)) - .rounded(px(6.)) - .child( - Icon::new(IconName::ScreenShare) + .children(wave.map(|history| mini_wave(history, 12., palette.ok))) + .children((muted && wave.is_none()).then(|| { + Icon::new(IconName::MicOff) .w(px(12.)) .h(px(12.)) - .text_color(palette.alert), - ) - .child(div().flex_1()) - .child(wave_slot(self.chat.waves.share(user_id), 12., palette.ok)) - }); + .text_color(palette.danger) + })); div() + .h(px(26.)) + .px(px(6.)) + .rounded(px(6.)) .flex() - .flex_col() - .when(ghost, |member| member.opacity(0.5)) - .child(row) - .children(stream) + .items_center() + .gap(px(6.)) + .hover(move |style| style.bg(palette.hover)) + .when(ghost, |row| row.opacity(0.5)) + .child(div().flex_1().min_w_0().child(profile_popover( + format!("call_member_{user_id}"), + Anchor::BottomLeft, + user, + entity, + identity, + ))) + .children(camera.then(|| watch_pill(entity, user_id, Kind::Camera, None, palette))) + .children(screen.then(|| { + watch_pill( + entity, + user_id, + Kind::Screen, + self.chat.waves.share(user_id), + palette, + ) + })) } fn voice_dot(&self, entity: &Entity, palette: Palette) -> Option { @@ -572,14 +466,20 @@ impl Yumush { let muted = self.chat.muted.contains(&community.id); let can_leave = !active || permission::can_leave(self.actor_rank()); - self.sidebar_community_row( + let row = self.sidebar_community_row( entity, community, palette, px(16.), "community", community_menu(entity, community.id, can_leave, muted), - ) + ); + div() + .flex() + .flex_col() + .child(row) + .children(self.call_tree(entity, community.id, palette)) + .into_any_element() }), ) } @@ -599,6 +499,11 @@ impl Yumush { let community_id = community.id; let select = entity.clone(); + let trailing = if self.chat.voice_ids(community_id).is_empty() { + unread_badge(palette, muted, unread) + } else { + Some(self.voice_chip(community_id, palette)) + }; let themed = palette.for_community(Some(community), &self.chat.hues); hoverable_with( format!("{key}_{}", community.id), @@ -607,7 +512,7 @@ impl Yumush { active, self.community_badge(community, size, text(10.), palette), community_name(community).to_string(), - unread_badge(palette, muted, unread), + trailing, ), themed.accent.opacity(0.1), ) @@ -861,8 +766,7 @@ impl Yumush { yumush.show_view(View::Builder, window, cx) }), ) - })) - .children(self.voice_controls(entity, palette)), + })), ) } @@ -941,6 +845,36 @@ fn go_to_call( }) } +fn watch_pill( + entity: &Entity, + user_id: Id, + kind: Kind, + wave: Option<&VecDeque>, + palette: Palette, +) -> impl IntoElement { + let (color, icon) = match kind { + Kind::Camera => (palette.camera, IconName::Video), + Kind::Screen => (palette.screen, IconName::ScreenShare), + }; + clickable( + format!("voice_watch_{user_id}_{kind:?}"), + palette, + entity_action(entity, move |yumush, window, cx| { + yumush.toggle_viewer(user_id, kind, window, cx) + }), + ) + .tip("Watch") + .h(px(18.)) + .px(px(5.)) + .flex() + .items_center() + .gap(px(4.)) + .rounded(px(5.)) + .bg(color.opacity(0.12)) + .child(Icon::new(icon).w(px(12.)).h(px(12.)).text_color(color)) + .children(wave.map(|history| mini_wave(history, 10., palette.screen))) +} + fn call_style(element: E, palette: Palette) -> E { element .border_1() diff --git a/crates/client/src/gui/wave.rs b/crates/client/src/gui/wave.rs index 7bd59f9..359b4b6 100644 --- a/crates/client/src/gui/wave.rs +++ b/crates/client/src/gui/wave.rs @@ -10,6 +10,7 @@ const GONE: f32 = 0.02; const AUDIBLE: f32 = 0.1; const BAR_WIDTH: f32 = 2.; const MIN_BAR: f32 = 1.5; +const MINI_BARS: usize = 8; pub struct Wave { bars: VecDeque, @@ -95,19 +96,40 @@ impl Waves { } pub fn wave_slot(history: Option<&VecDeque>, size: f32, color: Hsla) -> Div { + slot( + spectrum::BANDS, + history.map(|history| history.iter().copied().collect()), + size, + color, + ) +} + +pub fn mini_wave(history: &VecDeque, size: f32, color: Hsla) -> Div { + let group = history.len().div_ceil(MINI_BARS).max(1); + let bars: Vec = history + .iter() + .copied() + .collect::>() + .chunks(group) + .map(|chunk| chunk.iter().copied().fold(0.0, f32::max)) + .collect(); + slot(MINI_BARS, Some(bars), size, color) +} + +fn slot(count: usize, bars: Option>, size: f32, color: Hsla) -> Div { div() .flex_shrink_0() - .w(px(spectrum::BANDS as f32 * (BAR_WIDTH + 1.))) - .children(history.map(|history| wave(history, size, color))) + .w(px(count as f32 * (BAR_WIDTH + 1.) - 1.)) + .children(bars.map(|bars| wave(&bars, size, color))) } -fn wave(history: &VecDeque, size: f32, color: Hsla) -> Div { +fn wave(bars: &[f32], size: f32, color: Hsla) -> Div { div() .flex() .items_center() .gap(px(1.)) .h(px(size)) - .children(history.iter().map(|bar| { + .children(bars.iter().map(|bar| { div() .w(px(BAR_WIDTH)) .h(px((size * bar).max(MIN_BAR)))