use super::text; use crate::lang::w; use common::model::Id; use common::{ model::{Community, CommunityKind, Invitation, Unread, User}, permission, share::Kind, validate::validate_community_name, }; use gpui_kit::{ Anchor, AnimationExt, AnyElement, App, Context, Div, Entity, FontWeight, Hsla, InteractiveElement, IntoElement, ParentElement, PathBuilder, StatefulInteractiveElement, Styled, Window, assets::IconName, component::{ input::{Input, InputState}, popover::{Popover, PopoverState}, }, div, prelude::FluentBuilder as _, px, }; use super::{ Tooltip as _, Yumush, avatar, chat::{Armed, View, create_community}, clickable, community_icon, community_name, entity_action, hoverable, input_dialog, parts::{Scale, Tone, icon_button}, presence_avatar, profile::profile_popover, social::Relation, style::{Tokens, radius, size, space, text}, widget::{bare_input, underline}, }; const SLIDE: std::time::Duration = std::time::Duration::from_millis(320); fn slide() -> gpui_kit::Animation { gpui_kit::Animation::new(SLIDE).with_easing(gpui_kit::ease_in_out) } impl Yumush { pub(super) fn sidebar(&self, entity: &Entity, t: Tokens) -> impl IntoElement { let content = if self.chat.sidebar_collapsed && !self.sliding() { self.collapsed_sidebar(entity, t).into_any_element() } else { self.expanded_sidebar(entity, t) }; self.folding( "sidebar", div() .h_full() .flex_shrink_0() .overflow_hidden() .child(content), |sidebar, f| sidebar.w(px(lerp(size::SIDEBAR, size::RAIL, f))), ) } pub(super) fn toggle_sidebar(&mut self) { self.chat.sidebar_collapsed = !self.chat.sidebar_collapsed; self.chat.sidebar_toggled = Some(std::time::Instant::now()); } fn sliding(&self) -> bool { self.chat .sidebar_toggled .is_some_and(|at| at.elapsed() < SLIDE) } fn folding( &self, id: &'static str, element: E, style: impl Fn(E, f32) -> E + 'static, ) -> AnyElement { let collapsed = self.chat.sidebar_collapsed; let fold = move |delta: f32| if collapsed { delta } else { 1. - delta }; if self.sliding() { element .with_animation((id, collapsed as u64), slide(), move |element, delta| { style(element, fold(delta)) }) .into_any_element() } else { style(element, fold(1.)).into_any_element() } } fn collapsed_sidebar(&self, entity: &Entity, t: Tokens) -> Div { div() .h_full() .w(px(size::RAIL)) .pl(px(RAIL_SHIFT)) .flex() .flex_col() .items_center() .justify_between() .py(px(space::MD)) .child( div() .flex() .flex_col() .items_center() .gap(px(space::MD)) .child(self.logo_toggle(entity, t, logo_mark(t).size(px(size::CONTROL)))), ) .child( div() .flex() .flex_col() .items_center() .gap(px(space::MD)) .children( self.user .as_ref() .map(|user| self.account_trigger(entity, user, false, t)), ), ) } fn expanded_sidebar(&self, entity: &Entity, t: Tokens) -> AnyElement { let friends_alert = !self.chat.session.friends.incoming.is_empty() || !self.chat.session.invitations.is_empty(); div() .relative() .h_full() .w(px(size::SIDEBAR)) .flex() .flex_col() .py(px(space::LG)) .px(px(space::LG)) .gap(px(space::XL)) .child( div() .h(px(size::CONTROL)) .flex() .items_center() .gap(px(space::XS)) .child(self.folding( "logo", div().relative().child(self.logo_toggle( entity, t, self.folding( "logo_mark", logo_mark(t).when(towing(self.wordmark_flipped), |mark| { mark.path(crate::logo::NEEDLE) }), |mark, f| mark.size(px(lerp(size::CHIP, size::CONTROL, f))), ), )), |logo, f| { logo.left(px( f * (RAIL_CENTER - space::LG - size::CONTROL / 2. - space::XXS) )) .top(px(f * (space::MD + space::XXS - space::LG))) }, )) .child( self.folding( "wordmark_fold", div() .id("wordmark") .flex_1() .text_size(text(text::TITLE)) .line_height(gpui_kit::relative(LEADING)) .font_weight(FontWeight::SEMIBOLD) .text_color(t.paper()) .cursor_pointer() .on_click({ let entity = entity.clone(); move |_, window, cx| { entity.update(cx, |yumush, cx| yumush.open_jump(window, cx)) } }) .flex() .items_center() .child("yumu") .child(wordmark_tail( self.wordmark_flips, self.wordmark_flipped, t, )), |word, f| { word.relative() .left(px(-space::XXL * f)) .opacity((1. - 2. * f).max(0.)) }, ), ) .child(self.folding( "friends_fold", div().child(self.friends_button(entity, friends_alert, t)), fade, )), ) .children(self.update_control(t)) .child( self.folding( "list_fold", div() .id("sidebar_list") .flex_1() .min_h_0() .overflow_y_scroll() .flex() .flex_col() .gap(px(space::MD)) .children(self.sections(entity, t)), |list, f| fade(list, f).flex_1().min_h_0(), ), ) .children(self.build_control(entity, t)) .children(self.account_row(entity, t)) .into_any_element() } fn voice_chip(&self, community_id: Id, t: Tokens) -> AnyElement { let ids = self.chat.voice_ids(community_id); let direct = self.is_direct(community_id); let heard: Vec = ids .iter() .copied() .filter(|id| !(direct && self.is_me(*id))) .collect(); let mut speakers = heard .iter() .filter(|id| self.chat.session.waves.speaking.contains(id)); let voice = match (speakers.next(), speakers.next()) { (Some(id), None) => super::parts::Voice::Live(t.person(*id)), (Some(_), Some(_)) => super::parts::Voice::Live(t.paper()), _ => super::parts::Voice::Quiet, }; let total = self .chat .session .waves .total(&heard) .map(|bars| super::chat::to_bands(&bars)); div() .id(format!("voice_chip_{community_id}")) .tip(w().sidebar.in_call) .flex_1() .flex() .items_center() .gap(px(space::XS)) .child( div() .flex_1() .min_w(px(size::CONTROL)) .h(px(space::MD)) .child(super::parts::voice_line(total.as_ref(), voice, t)), ) .when(!direct, |this| { this.child( div() .text_size(text(text::CAPTION)) .text_color(t.dim()) .child(ids.len().to_string()), ) }) .into_any_element() } pub(super) fn new_community(&mut self, window: &mut Window, cx: &mut Context) { input_dialog( w().sidebar.new_community, w().sidebar.create, w().sidebar.name_placeholder, window, cx, |this, name, window, cx| { let name = name.trim().to_string(); if validate_community_name(&name).is_ok() { create_community(this, name, window, cx); } }, ); } fn logo_toggle(&self, entity: &Entity, t: Tokens, mark: impl IntoElement) -> AnyElement { let tip = if self.chat.sidebar_collapsed { w().sidebar.expand } else { w().sidebar.collapse }; clickable( "sidebar_toggle", t, entity_action(entity, |yumush, _, cx| { yumush.toggle_sidebar(); cx.notify(); }), ) .tip(tip) .flex_none() .p(px(space::XXS)) .rounded(px(radius::MD)) .child(mark) .into_any_element() } pub(super) fn open_friends(&mut self, window: &mut Window, cx: &mut Context) { self.chat.session.friends_open = true; self.chat .search_input .update(cx, |input, cx| input.focus(window, cx)); cx.notify(); } pub(super) fn close_friends(&mut self, window: &mut Window, cx: &mut Context) { self.chat.session.friends_open = false; window.focus(&self.focus, cx); cx.notify(); } fn friends_sheet(&self, entity: &Entity, cx: &App, t: Tokens) -> Div { let query = super::widget::search_text(&self.chat.search_input, cx); let found = self.chat.session.found.as_ref().filter(|found| { !self .chat .session .friends .friends .iter() .any(|user| user.id == found.id) }); let friends = self.friend_list(entity, &query, t); super::parts::popover(t) .w(px(size::POPOVER)) .px(px(space::MD)) .py(px(space::MD)) .gap(px(space::MD)) .child(input_box(&self.chat.search_input, t)) .children(found.map(|user| self.found_row(entity, user, t))) .children(self.requests(entity, t)) .when(!friends.is_empty(), |sheet| { sheet.child( div() .id("friends_list") .max_h(px(size::POPOVER)) .overflow_y_scroll() .flex() .flex_col() .gap(px(space::XXS)) .children(friends), ) }) } fn friends_button(&self, entity: &Entity, alert: bool, t: Tokens) -> impl IntoElement { let opened = entity.clone(); let content = entity.clone(); gpui_kit::component::popover::Popover::new("friends_sheet") .anchor(Anchor::TopLeft) .appearance(false) .open(self.chat.session.friends_open) .on_open_change(move |open, window, cx| { let open = *open; opened.update(cx, |yumush, cx| { if open { yumush.open_friends(window, cx) } else { yumush.close_friends(window, cx) } }) }) .trigger(super::Trigger::new(hoverable( "friends_button", div() .relative() .size(px(size::CONTROL_SM)) .flex() .items_center() .justify_center() .rounded_full() .text_color(t.dim()) .child(super::parts::small_icon(IconName::Users)) .children(alert.then(|| { div() .absolute() .top(px(space::XXS)) .right(px(space::XXS)) .size(px(space::XS + space::XXS)) .rounded_full() .bg(t.paper()) })), t, ))) .content(move |_, _, cx| { let yumush = content.read(cx); yumush.friends_sheet(&content, cx, t) }) } fn friend_list(&self, entity: &Entity, query: &str, t: Tokens) -> Vec { let mut friends: Vec<&User> = self .chat .session .friends .friends .iter() .filter(|user| user.username.to_lowercase().contains(query)) .collect(); friends.sort_by_key(|user| (self.doing(user.id), user.username.to_lowercase())); friends .into_iter() .map(|user| { let user_id = user.id; let open = entity.clone(); let remove = entity.clone(); let row = hoverable( format!("friend_{}", user.id), self.user_row(t, user, None), t, ) .on_click(move |_, window, cx| { open.update(cx, |yumush, cx| { yumush.close_friends(window, cx); yumush.open_direct(user_id, window, cx) }) }); let armed = Armed::RemoveFriend(user_id); right_menu( ("friend_menu", user_id as usize), entity, row, move |popover, cx| { super::parts::stack(space::XS).child(super::profile::menu_row( ("remove_friend", user_id as usize), remove .read(cx) .armed_label(armed.clone(), w().sidebar.remove_friend), super::parts::small_icon(IconName::UserMinus), t.bad(), t, super::profile::armed_action( armed.clone(), &remove, popover, move |yumush, window, cx| yumush.remove_friend(user_id, window, cx), ), )) }, ) .into_any_element() }) .collect() } fn sections(&self, entity: &Entity, t: Tokens) -> Vec { let pinned = &self.chat.session.pinned; let list = |rows: Vec| { div() .flex() .flex_col() .gap(px(space::XXS)) .children(rows) .into_any_element() }; let pins = self.rooms(entity, t, |room| pinned.contains(&room.id)); let groups = self.rooms(entity, t, |room| { room.kind.is_group() && !pinned.contains(&room.id) }); let people = std::iter::once(self.notes_row(entity, t)) .chain(self.rooms(entity, t, |room| { room.kind.is_direct() && !pinned.contains(&room.id) })) .collect(); let sections: Vec = [pins, groups, people] .into_iter() .filter(|rows| !rows.is_empty()) .map(list) .collect(); let count = sections.len(); sections .into_iter() .enumerate() .flat_map(|(index, section)| { std::iter::once(section).chain( (index + 1 < count) .then(|| super::parts::thread(t).mx(px(space::SM)).into_any_element()), ) }) .collect() } fn notes_row(&self, entity: &Entity, t: Tokens) -> AnyElement { let notes = self.chat.notes(); let active = notes.is_some_and(|notes| self.chat.is_selected(notes.id)); let unread = notes.and_then(|notes| self.chat.session.unread.get(¬es.id)); let open = entity.clone(); hoverable( "notes", room_row( t, active, notes_tile(t), w().sidebar.notes.to_string(), unread_badge(t, false, unread), ), t, ) .on_click(move |_, window, cx| open.update(cx, |yumush, cx| yumush.open_notes(window, cx))) .into_any_element() } fn rooms( &self, entity: &Entity, t: Tokens, keep: impl Fn(&Community) -> bool, ) -> Vec { self.unread_first( self.chat .session .communities .iter() .chain( self.chat .session .opened .as_ref() .filter(|opened| opened.kind.is_group()) .filter(|opened| !self.chat.joined(opened.id)), ) .filter(|community| !matches!(community.kind, CommunityKind::Notes)) .filter(|community| keep(community)), ) .into_iter() .map(|community| self.sidebar_community_row(entity, community, t)) .collect() } fn sidebar_community_row( &self, entity: &Entity, community: &Community, t: Tokens, ) -> AnyElement { let active = self.chat.is_selected(community.id); let group = community.kind.is_group(); let can_leave = group && (!active || permission::can_leave(self.actor_rank())); let can_manage = !active || permission::is_moderator(self.actor_rank()); let muted = self.chat.session.muted.contains(&community.id); let unread = self.chat.session.unread.get(&community.id); let community_id = community.id; let select = entity.clone(); let pinned = self.chat.session.pinned.contains(&community.id); let trailing = if self.chat.voice_ids(community_id).is_empty() { unread_badge(t, muted, unread).or_else(|| { pinned.then(|| { super::parts::small_icon(IconName::Pin) .text_color(t.dim()) .into_any_element() }) }) } else { Some(self.voice_chip(community_id, t)) }; let face = self .community_badge(community, px(size::AVATAR), text(text::CAPTION), t) .into_any_element(); let row = hoverable( format!("room_{}", community.id), room_row( t, active, face, community_name(community).to_string(), trailing, ), t, ) .on_click(move |_, window, cx| { select.update(cx, |yumush, cx| { yumush.select_community(community_id, window, cx) }) }); let menu = entity.clone(); right_menu( ("room_menu", community_id as usize), entity, row, move |popover, cx| { let yumush = menu.read(cx); super::community_card::room_rows( community_id, group, can_leave, can_manage, yumush, &menu, popover, t, ) }, ) .into_any_element() } fn requests(&self, entity: &Entity, t: Tokens) -> Option
{ let friends = &self.chat.session.friends; let rows: Vec = friends .incoming .iter() .map(|user| self.incoming_row(entity, user, t)) .chain( friends .outgoing .iter() .map(|user| self.outgoing_row(entity, user, t)), ) .chain( self.chat .session .invitations .iter() .map(|invitation| self.invitation_row(entity, invitation, t)), ) .collect(); (!rows.is_empty()).then(|| { div() .flex() .flex_col() .gap(px(space::XXS)) .child(super::parts::caption_head(w().sidebar.requests, t)) .children(rows) }) } fn unread_first<'a>(&self, rooms: impl Iterator) -> Vec<&'a Community> { let mut rooms: Vec<&Community> = rooms.collect(); rooms.sort_by_key(|community| { self.chat .session .unread .get(&community.id) .map_or((true, true), |unread| { (unread.mentions == 0, unread.messages == 0) }) }); rooms } pub(super) fn call_of(&self, user_id: Id) -> Option<&Community> { let community_id = self .chat .session .voice .iter() .find(|(_, ids)| ids.contains(&user_id)) .map(|(community_id, _)| *community_id)?; self.chat .session .communities .iter() .find(|community| community.id == community_id) } fn doing(&self, user_id: Id) -> Doing { if self.call_of(user_id).is_some() { Doing::Call } else if self.presence_of(user_id) == common::model::Presence::Offline { Doing::Offline } else { Doing::Online } } fn found_row(&self, entity: &Entity, user: &User, t: Tokens) -> AnyElement { let relation = self.relation(user.id); let mut trailing = Vec::new(); if relation != Relation::Myself { trailing.push(row_button( entity, "message", user.id, t, IconName::MessageSquare, w().sidebar.message, |yumush, id, window, cx| { yumush.close_friends(window, cx); yumush.open_direct(id, window, cx) }, )); } let action = match relation { Relation::Stranger | Relation::Incoming => relation.action(), _ => None, }; if let Some((label, icon)) = action { trailing.push(row_button( entity, "friend_action", user.id, t, icon, label, move |yumush, id, window, cx| yumush.friend_action(relation, id, window, cx), )); } self.user_row(t, user, trailing).into_any_element() } fn user_row( &self, t: Tokens, user: &User, trailing: impl IntoIterator, ) -> Div { entry( t, presence_avatar( avatar( t, user, px(size::AVATAR), text(text::CAPTION), &self.chat.session.avatars, ), self.presence_of(user.id), px(size::AVATAR), t, ), div().flex().flex_col().child(user.username.clone()).when( !user.status.is_empty(), |this| { this.child( div() .text_color(t.dim()) .child(super::glyph::line( user.status.clone().into(), text(text::CAPTION), )) .text_size(text(text::CAPTION)), ) }, ), trailing, ) } fn incoming_row(&self, entity: &Entity, user: &User, t: Tokens) -> AnyElement { self.user_row( t, user, [ row_button( entity, "accept_friend", user.id, t, IconName::Check, w().sidebar.accept, |yumush, id, window, cx| yumush.accept_friend(id, window, cx), ), row_button( entity, "decline_friend", user.id, t, IconName::X, w().sidebar.decline, |yumush, id, window, cx| yumush.remove_friend(id, window, cx), ), ], ) .into_any_element() } fn outgoing_row(&self, entity: &Entity, user: &User, t: Tokens) -> AnyElement { self.user_row( t, user, [row_button( entity, "cancel_friend", user.id, t, IconName::X, w().sidebar.cancel, |yumush, id, window, cx| yumush.remove_friend(id, window, cx), )], ) .into_any_element() } fn invitation_row( &self, entity: &Entity, invitation: &Invitation, t: Tokens, ) -> AnyElement { let community = &invitation.community; let label = div().flex().flex_col().child(community.name.clone()).child( div() .text_size(text(text::CAPTION)) .text_color(t.dim()) .child(w().sidebar.from_user(&invitation.inviter.username)), ); entry( t, community_icon( t, community, px(size::ICON), text(text::CAPTION), &self.chat.session.avatars, ), label, [ row_button( entity, "accept_invitation", community.id, t, IconName::Check, w().sidebar.accept, |yumush, id, window, cx| yumush.accept_invitation(id, window, cx), ), row_button( entity, "decline_invitation", community.id, t, IconName::X, w().sidebar.decline, |yumush, id, window, cx| yumush.decline_invitation(id, window, cx), ), ], ) .into_any_element() } fn account_row(&self, entity: &Entity, t: Tokens) -> Option { let user = self.user.as_ref()?; Some( div() .h(px(size::CONTROL)) .flex() .items_center() .gap(px(space::XS)) .child(self.account_trigger(entity, user, true, t)) .children((self.is_builder() && self.chat.session.ghost).then(|| { self.folding( "builder_fold", div().child( icon_button( "builder_button".to_string(), IconName::Ghost, w().sidebar.ghost_on, Tone::Idle, Scale::Small, t, entity_action(entity, |yumush, window, cx| { yumush.show_view(View::Builder, window, cx) }), ) .text_color(t.hue(super::style::my_hue())), ), fade, ) })), ) } fn account_trigger( &self, entity: &Entity, user: &User, named: bool, t: Tokens, ) -> impl IntoElement { let face = if named { size::AVATAR } else { size::CONTROL }; let picture = avatar( t, user, px(face), text(text::CAPTION), &self.chat.session.avatars, ); let picture = if named { self.folding("avatar_face", picture, |picture, f| { picture.size(px(lerp(size::AVATAR, size::CONTROL, f))) }) } else { picture.into_any_element() }; let picture = presence_avatar(picture, self.presence_of(user.id), px(face), t); let picture = if named { self.folding("avatar", picture, |picture, f| { picture .left(px( f * (RAIL_CENTER - space::LG - space::SM - size::CONTROL / 2.) )) .top(px(f * (space::LG - space::MD - space::XXS))) }) } else { picture.into_any_element() }; profile_popover( "account_profile", Anchor::BottomLeft, user, entity, hoverable( "account_trigger", div() .flex() .items_center() .when(named, |trigger| trigger.h(px(size::CONTROL))) .gap(px(space::SM)) .p(px(if named { 0. } else { space::XXS })) .when(named, |trigger| trigger.px(px(space::SM))) .rounded(px(radius::MD)) .child(picture) .when(named, |trigger| { trigger.child( self.folding( "username_fold", div() .min_w_0() .truncate() .text_color(t.dim()) .child(user.username.clone()), fade, ), ) }), t, ), ) .when(named, |trigger| trigger.flex_1().min_w_0()) } pub(super) fn open_community_settings( &mut self, community_id: Id, window: &mut Window, cx: &mut Context, ) { self.select_community(community_id, window, cx); self.show_view(View::CommunitySettings, window, cx); } } pub(super) fn watch_pill( entity: &Entity, user_id: Id, kind: Kind, watching: bool, audio: Option>, t: Tokens, ) -> impl IntoElement { let icon = match kind { Kind::Camera => IconName::Video, Kind::Screen => IconName::ScreenShare, }; let tip = match (watching, kind) { (true, _) => w().sidebar.stop_watching, (false, Kind::Camera) => w().sidebar.watch_camera, (false, Kind::Screen) => w().sidebar.watch_screen, }; clickable( format!("voice_watch_{user_id}_{kind:?}"), t, entity_action(entity, move |yumush, window, cx| { yumush.toggle_viewer(user_id, kind, window, cx) }), ) .tip(tip) .h(px(size::CHIP)) .px(px(space::XS)) .flex() .items_center() .gap(px(space::XS)) .rounded(px(radius::SM)) .children(audio.map(|audio| { div() .w(px(size::CONTROL)) .h(px(space::LG)) .child(super::parts::voice_line( Some(&audio), super::parts::Voice::Live(t.person(user_id)), t, )) })) .child(super::parts::small_icon(icon).text_color(if watching { t.paper() } else { t.dim() })) } pub(super) fn unread_badge(t: Tokens, muted: bool, unread: Option<&Unread>) -> Option { if muted { return Some( div() .text_color(t.dim()) .child(super::parts::small_icon(IconName::BellOff)) .into_any_element(), ); } let unread = unread.filter(|unread| unread.messages > 0)?; if unread.mentions == 0 { return Some( div() .size(px(space::XS + space::XXS)) .rounded_full() .bg(t.paper()) .into_any_element(), ); } let count = match unread.messages { 1..=99 => unread.messages.to_string(), _ => "99+".to_string(), }; Some( div() .text_size(text(text::CAPTION)) .text_color(t.paper()) .child(count) .into_any_element(), ) } pub(super) fn input_box(input: &Entity, t: Tokens) -> Div { underline( t, size::CONTROL_SM + space::XS, div() .flex() .items_center() .gap(px(space::SM)) .text_color(t.dim()) .child(super::parts::small_icon(IconName::Search)) .child(bare_input(t, Input::new(input).token(super::glyph::token))), ) } fn notes_tile(t: Tokens) -> AnyElement { div() .size(px(size::AVATAR)) .flex_none() .flex() .items_center() .justify_center() .rounded(px(radius::SM)) .bg(t.press()) .child(super::parts::small_icon(IconName::Bookmark).text_color(t.dim())) .into_any_element() } fn room_row( t: Tokens, active: bool, face: AnyElement, label: String, trailing: Option, ) -> Div { div() .h(px(size::CONTROL)) .px(px(space::SM)) .rounded(px(radius::MD)) .flex() .items_center() .gap(px(space::SM)) .text_color(if active { t.paper() } else { t.dim() }) .when(active, |row| row.font_weight(FontWeight::MEDIUM)) .child(face) .child(div().flex_1().min_w_0().truncate().child(label)) .children(trailing) } fn entry( t: Tokens, leading: impl IntoElement, label: impl IntoElement, trailing: impl IntoIterator, ) -> Div { div() .min_h(px(size::CONTROL)) .py(px(space::XXS)) .px(px(space::SM)) .flex() .items_center() .gap(px(space::SM)) .rounded(px(radius::MD)) .text_color(t.paper()) .child(leading) .child(div().flex_1().min_w_0().truncate().child(label)) .children(trailing) } fn row_button( entity: &Entity, key: &str, id: Id, t: Tokens, icon: IconName, tip: &'static str, run: impl Fn(&mut Yumush, Id, &mut Window, &mut Context) + 'static, ) -> AnyElement { icon_button( format!("{key}_{id}"), icon, tip, Tone::Idle, Scale::Small, t, entity_action(entity, move |yumush, window, cx| { run(yumush, id, window, cx) }), ) .into_any_element() } fn right_menu( id: impl Into, entity: &Entity, trigger: impl IntoElement, rows: impl Fn(&Entity, &App) -> Div + 'static, ) -> Popover { let disarm = entity.clone(); Popover::new(id) .mouse_button(gpui_kit::MouseButton::Right) .on_open_change(move |_, _, cx| disarm.update(cx, |yumush, cx| yumush.disarm(cx))) .anchor(Anchor::TopLeft) .appearance(false) .trigger(super::Trigger::new(trigger)) .content(move |_, _, cx| { let popover = cx.entity(); let t = Tokens::of(cx); super::parts::popover(t) .w(px(size::SIDEBAR)) .p(px(space::XS)) .child(rows(&popover, cx)) }) } #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] enum Doing { Call, Online, Offline, } const RAIL_SHIFT: f32 = space::LG; const RAIL_CENTER: f32 = (size::RAIL + RAIL_SHIFT) / 2.; const S_ADVANCE: f32 = 0.511; const LEADING: f32 = 1.4; const BASELINE: f32 = (LEADING - 0.97 - 0.305) / 2. + 0.97; const MARK_VIEW: f32 = 76.; const WANDER: std::time::Duration = std::time::Duration::from_secs(10); const LINGER: std::time::Duration = std::time::Duration::from_secs(6); const TOW: std::time::Duration = std::time::Duration::from_millis(2300); fn fade(element: E, f: f32) -> E { let shown = 1. - f; element.opacity(shown) } fn lerp(from: f32, to: f32, f: f32) -> f32 { from + (to - from) * f } fn logo_mark(t: Tokens) -> gpui_kit::Svg { gpui_kit::svg() .path(crate::logo::PATH) .size(px(size::CHIP)) .flex_none() .text_color(t.paper()) } pub(super) fn wander(cx: &mut Context) { cx.spawn(async move |this, cx| { for wait in [WANDER, LINGER].into_iter().cycle() { cx.background_executor().timer(wait).await; let flipped = this.update(cx, |yumush, cx| { yumush.wordmark_flips += 1; yumush.wordmark_flipped = Some(std::time::Instant::now()); cx.notify(); }); cx.background_executor().timer(TOW).await; if flipped.is_err() || this.update(cx, |_, cx| cx.notify()).is_err() { break; } } }) .detach(); } fn towing(flipped: Option) -> bool { flipped.is_some_and(|at| at.elapsed() < TOW) } fn wordmark_tail(flips: u32, flipped: Option, t: Tokens) -> AnyElement { let turkish = flips % 2 == 1; let em = super::style::text::TITLE / super::style::text::UI; if !towing(flipped) { return if turkish { div().child("ş") } else { div().relative().child("s").child( div() .absolute() .top_0() .left(gpui_kit::rems(S_ADVANCE * em)) .child("h"), ) } .into_any_element(); } let (ink, ground) = (t.paper(), t.ground()); div() .relative() .child("s") .with_animation( ("wordmark", flips), gpui_kit::Animation::new(TOW), move |tail, progress| { tail.child( tow_canvas(progress, turkish, ink, ground) .absolute() .top_0() .left_0() .size_full(), ) }, ) .into_any_element() } fn tow_canvas(progress: f32, turkish: bool, ink: Hsla, ground: Hsla) -> gpui_kit::Canvas<()> { gpui_kit::canvas( |_, _, _| {}, move |bounds, _, window, _| { let em = f32::from(window.rem_size()) * super::style::text::TITLE / super::style::text::UI; let unit = em / 1000.; let left = f32::from(bounds.origin.x) - super::tow::S_X * unit; let baseline = f32::from(bounds.origin.y) + BASELINE * em; let rig = super::tow::Rig { x: -(size::CHIP + space::XXS + space::XS) / unit, y: ((LEADING * em - size::CHIP) / 2. - BASELINE * em) / unit, scale: size::CHIP / MARK_VIEW / unit, }; let scene = super::tow::scene(&rig, progress, turkish, progress * TOW.as_secs_f32()); let at = |[x, y]: super::tow::Point| { gpui_kit::point(px(left + x * unit), px(baseline + y * unit)) }; trace( window, scene.gap.iter().map(|p| at(*p)), scene.halo * unit, ground, ); trace( window, scene.thread.iter().map(|p| at(*p)), scene.width * unit, ink, ); let mut glyph = PathBuilder::fill(); let mut points = scene.glyph.iter().map(|p| at(*p)); if let Some(first) = points.next() { glyph.move_to(first); points.for_each(|point| glyph.line_to(point)); glyph.close(); if let Ok(glyph) = glyph.build() { window.paint_path(glyph, ink); } } }, ) } fn trace( window: &mut Window, mut points: impl Iterator>, width: f32, color: Hsla, ) { let Some(first) = points.next() else { return; }; let mut path = PathBuilder::fill().with_style(gpui_kit::PathStyle::Stroke(gpui_kit::StrokeOptions { line_width: width, line_cap: gpui_kit::LineCap::Round, line_join: gpui_kit::LineJoin::Round, ..Default::default() })); path.move_to(first); points.for_each(|point| path.line_to(point)); if let Ok(path) = path.build() { window.paint_path(path, color); } }