Stats sheet as two columns over the call bar (connection numbers and ping spark, traffic sparks, machine tracks, sending layers, watching per stream)
Browse files at this commit62f41caa99ac848770abd478a034c49e3be8fd42Parent: 06e6d99- feat
- stats sheet as two columns over the call bar (connection numbers and ping spark, traffic sparks, machine tracks, sending layers, watching per stream)
- stage keeps voice lines above shares
- each person picks a hue (Appearance → Your hue), sent with the user
- sequential default hues
- popovers open on first click (no fade inside popover content)
- sidebar animates only on toggle
- friend requests stay visible while searching
22 changed files +855 -1032
- crates/client/src/gui.rs +2 -1
- crates/client/src/gui/camera_view.rs +13 -11
- crates/client/src/gui/chat.rs +129 -109
- crates/client/src/gui/composer.rs +157 -173
- crates/client/src/gui/message_actions.rs +58 -75
- crates/client/src/gui/parts.rs +0 -32
- crates/client/src/gui/poll.rs +10 -14
- crates/client/src/gui/profile.rs +3 -11
- crates/client/src/gui/settings_page.rs +49 -3
- crates/client/src/gui/share_view.rs +2 -6
- crates/client/src/gui/sidebar.rs +12 -11
- crates/client/src/gui/snippet.rs +1 -0
- crates/client/src/gui/social.rs +8 -0
- crates/client/src/gui/style.rs +22 -6
- crates/client/src/gui/voice_stats.rs +348 -573
- crates/client/src/usage/drm.rs +4 -4
- crates/common/src/call.rs +7 -0
- crates/common/src/model.rs +1 -0
- crates/server/src/call/mod.rs +1 -0
- crates/server/src/call/user.rs +11 -1
- crates/server/src/db/schema.sql +1 -0
- crates/server/src/db/user.rs +16 -2
crates/client/src/gui.rsmodified+2 -1
| @@ -304,7 +304,7 @@ pub fn millis_time(millis: u64, format: &str) -> String { | ||
| 304 | 304 | .to_string() |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | -pub use parts::{motion, pop_in, swap_in}; | |
| 307 | +pub use parts::motion; | |
| 308 | 308 | |
| 309 | 309 | pub fn hoverable(id: impl Into<ElementId>, element: Div, palette: Palette) -> Stateful<Div> { |
| 310 | 310 | hoverable_with(id, element, palette.hover) |
| @@ -655,6 +655,7 @@ impl Yumush { | ||
| 655 | 655 | self.accounts.sign_in(&user, token); |
| 656 | 656 | self.request_user_avatar(&user, cx); |
| 657 | 657 | self.chat.muted = mutes::load(user.id); |
| 658 | + style::remember(&[&user]); | |
| 658 | 659 | self.user = Some(user); |
| 659 | 660 | self.change_page(Route::Chat, window, cx); |
| 660 | 661 | self.load_communities(window, cx); |
crates/client/src/gui/camera_view.rsmodified+13 -11
| @@ -226,24 +226,26 @@ impl Yumush { | ||
| 226 | 226 | .into_iter() |
| 227 | 227 | .map(|source| stage_tile(entity, self, palette, source)) |
| 228 | 228 | .collect(); |
| 229 | - if tiles.is_empty() { | |
| 230 | - return Some(self.voices(palette).into_any_element()); | |
| 231 | - } | |
| 232 | - | |
| 233 | - Some( | |
| 229 | + let strip = (!tiles.is_empty()).then(|| { | |
| 234 | 230 | div() |
| 235 | 231 | .id("stage_strip") |
| 236 | 232 | .flex() |
| 237 | 233 | .flex_shrink_0() |
| 238 | 234 | .h(px(STRIP_H)) |
| 239 | 235 | .gap(px(space::SM)) |
| 240 | - .p(px(space::SM)) | |
| 241 | - .bg(palette.window) | |
| 236 | + .px(px(space::XL)) | |
| 237 | + .pb(px(space::SM)) | |
| 242 | 238 | .overflow_x_scroll() |
| 243 | - .border_b_1() | |
| 244 | - .border_color(palette.border) | |
| 245 | 239 | .children(tiles) |
| 246 | - .into_any_element(), | |
| 240 | + }); | |
| 241 | + | |
| 242 | + Some( | |
| 243 | + div() | |
| 244 | + .flex() | |
| 245 | + .flex_col() | |
| 246 | + .flex_shrink_0() | |
| 247 | + .child(self.voices(palette)) | |
| 248 | + .children(strip), | |
| 247 | 249 | ) |
| 248 | 250 | } |
| 249 | 251 | |
| @@ -254,7 +256,7 @@ impl Yumush { | ||
| 254 | 256 | .voice_community() |
| 255 | 257 | .map(|community_id| self.chat.voice_ids(community_id)) |
| 256 | 258 | .unwrap_or_default() |
| 257 | - .into_iter() | |
| 259 | + .iter() | |
| 258 | 260 | .filter_map(|id| self.chat.author(*id)) |
| 259 | 261 | .map(|user| { |
| 260 | 262 | let speaking = self.chat.waves.speaking.contains(&user.id); |
crates/client/src/gui/chat.rsmodified+129 -109
| @@ -1,4 +1,4 @@ | ||
| 1 | -use super::style::{radius, size, space, stroke, text}; | |
| 1 | +use super::style::{self, radius, size, space, stroke, text}; | |
| 2 | 2 | use super::text; |
| 3 | 3 | use crate::gui::CLOCK; |
| 4 | 4 | use std::{ |
| @@ -19,7 +19,7 @@ use crate::gui::{ | ||
| 19 | 19 | composer::{self, Composer}, |
| 20 | 20 | entity_action, hoverable, |
| 21 | 21 | media_view::{self, Media}, |
| 22 | - message_actions, millis_time, new_input, notify_error, palette, poll, pop_in, presence_avatar, | |
| 22 | + message_actions, millis_time, new_input, notify_error, palette, poll, presence_avatar, | |
| 23 | 23 | primary_button, |
| 24 | 24 | profile::profile_popover, |
| 25 | 25 | rank_tag, |
| @@ -145,6 +145,7 @@ pub struct Chat { | ||
| 145 | 145 | pub(super) found: Option<User>, |
| 146 | 146 | pub(super) invite: InviteLookup, |
| 147 | 147 | pub(super) sidebar_collapsed: bool, |
| 148 | + pub(super) sidebar_toggled: Option<std::time::Instant>, | |
| 148 | 149 | pub(super) composer: Composer, |
| 149 | 150 | pub(super) drafts: HashMap<Id, String>, |
| 150 | 151 | pub(super) poll_question: Entity<InputState>, |
| @@ -390,6 +391,7 @@ impl Chat { | ||
| 390 | 391 | found: None, |
| 391 | 392 | invite: InviteLookup::Idle, |
| 392 | 393 | sidebar_collapsed: false, |
| 394 | + sidebar_toggled: None, | |
| 393 | 395 | view: View::Chat, |
| 394 | 396 | section: 0, |
| 395 | 397 | username_input: editable_input("Username...", Yumush::save_username, window, cx), |
| @@ -617,7 +619,17 @@ impl Chat { | ||
| 617 | 619 | Event::CommunityUpdated(community) | Event::CommunityAdded(community) => { |
| 618 | 620 | self.insert_community(community) |
| 619 | 621 | } |
| 620 | - Event::FriendsUpdated(friends) => self.friends = friends, | |
| 622 | + Event::FriendsUpdated(friends) => { | |
| 623 | + style::remember( | |
| 624 | + &friends | |
| 625 | + .friends | |
| 626 | + .iter() | |
| 627 | + .chain(&friends.incoming) | |
| 628 | + .chain(&friends.outgoing) | |
| 629 | + .collect::<Vec<_>>(), | |
| 630 | + ); | |
| 631 | + self.friends = friends; | |
| 632 | + } | |
| 621 | 633 | Event::InvitationsUpdated(invitations) => self.invitations = invitations, |
| 622 | 634 | Event::CommunityDeleted { community_id } | Event::Removed { community_id, .. } => { |
| 623 | 635 | self.remove_community(community_id) |
| @@ -882,6 +894,7 @@ impl Chat { | ||
| 882 | 894 | } |
| 883 | 895 | |
| 884 | 896 | fn insert_member(&mut self, member: Member) { |
| 897 | + style::remember(&[&member.user]); | |
| 885 | 898 | self.remove_member(member.user.id); |
| 886 | 899 | self.members.push(member); |
| 887 | 900 | self.members.sort_by_key(|member| member.user.id); |
| @@ -995,6 +1008,7 @@ impl Chat { | ||
| 995 | 1008 | } |
| 996 | 1009 | |
| 997 | 1010 | pub fn update_member(&mut self, user: &User) { |
| 1011 | + style::remember(&[user]); | |
| 998 | 1012 | let peers = self |
| 999 | 1013 | .communities |
| 1000 | 1014 | .iter_mut() |
| @@ -1322,6 +1336,7 @@ impl Yumush { | ||
| 1322 | 1336 | .min_w_0() |
| 1323 | 1337 | .flex() |
| 1324 | 1338 | .flex_col() |
| 1339 | + .relative() | |
| 1325 | 1340 | .bg(palette.window) |
| 1326 | 1341 | .overflow_hidden() |
| 1327 | 1342 | .children(self.announcement_banner(entity, palette)) |
| @@ -1343,40 +1358,42 @@ impl Yumush { | ||
| 1343 | 1358 | .children(self.stage_strip(entity, themed)) |
| 1344 | 1359 | .children(self.unread_bar(entity, themed)) |
| 1345 | 1360 | .children(self.poll_banner(entity, themed)) |
| 1346 | - .child( | |
| 1347 | - div() | |
| 1348 | - .flex_1() | |
| 1349 | - .min_h_0() | |
| 1350 | - .flex() | |
| 1351 | - .child(div().flex_1().min_w_0().flex().flex_col().map(|panel| { | |
| 1352 | - match self.inline_viewer(entity, themed) { | |
| 1353 | - Some(viewer) => panel.child(viewer), | |
| 1354 | - None => match self.stage_grid(entity, themed) { | |
| 1355 | - Some(grid) => panel.child(grid), | |
| 1356 | - None => panel | |
| 1357 | - .child(self.message_area(entity, themed)) | |
| 1358 | - .child(self.composer(entity, themed, cx)), | |
| 1359 | - }, | |
| 1360 | - } | |
| 1361 | - })) | |
| 1362 | - .children(self.stats_side(palette)), | |
| 1363 | - ), | |
| 1361 | + .child(div().flex_1().min_h_0().flex().child( | |
| 1362 | + div().flex_1().min_w_0().flex().flex_col().map(|panel| { | |
| 1363 | + match self.inline_viewer(entity, themed) { | |
| 1364 | + Some(viewer) => panel.child(viewer), | |
| 1365 | + None => match self.stage_grid(entity, themed) { | |
| 1366 | + Some(grid) => panel.child(grid), | |
| 1367 | + None => panel | |
| 1368 | + .child(self.message_area(entity, themed)) | |
| 1369 | + .child(self.composer(entity, themed, cx)), | |
| 1370 | + }, | |
| 1371 | + } | |
| 1372 | + }), | |
| 1373 | + )), | |
| 1364 | 1374 | None => panel.child(empty_state(palette)), |
| 1365 | 1375 | }, |
| 1366 | 1376 | }) |
| 1377 | + .children(self.stats_sheet(palette)) | |
| 1367 | 1378 | .children(self.dock(entity, palette, cx)) |
| 1368 | 1379 | } |
| 1369 | 1380 | |
| 1370 | - fn stats_side(&self, palette: Palette) -> Option<impl IntoElement> { | |
| 1371 | - (self.chat.stats_open && self.in_stage_chat()).then(|| { | |
| 1381 | + fn stats_sheet(&self, palette: Palette) -> Option<impl IntoElement> { | |
| 1382 | + (self.chat.stats_open && self.chat.voice_community().is_some()).then(|| { | |
| 1372 | 1383 | div() |
| 1373 | - .id("stats_side") | |
| 1374 | - .w(px(size::SHEET)) | |
| 1375 | - .flex_shrink_0() | |
| 1376 | - .p(px(space::MD)) | |
| 1377 | - .border_l_1() | |
| 1378 | - .border_color(palette.border) | |
| 1384 | + .id("stats_sheet") | |
| 1385 | + .absolute() | |
| 1386 | + .right(px(space::LG)) | |
| 1387 | + .bottom(px(size::ROW + space::MD + space::SM)) | |
| 1388 | + .max_w(relative(0.95)) | |
| 1389 | + .max_h(relative(0.8)) | |
| 1379 | 1390 | .overflow_y_scroll() |
| 1391 | + .p(px(space::XL)) | |
| 1392 | + .rounded(px(radius::LG)) | |
| 1393 | + .border_1() | |
| 1394 | + .border_color(palette.border) | |
| 1395 | + .bg(palette.tokens.raise()) | |
| 1396 | + .shadow_lg() | |
| 1380 | 1397 | .child(voice_stats::stats_panel(&self.chat, palette)) |
| 1381 | 1398 | }) |
| 1382 | 1399 | } |
| @@ -1835,6 +1852,12 @@ impl Yumush { | ||
| 1835 | 1852 | .users |
| 1836 | 1853 | .insert(member.user.id, member.user.clone()); |
| 1837 | 1854 | } |
| 1855 | + style::remember( | |
| 1856 | + &members | |
| 1857 | + .iter() | |
| 1858 | + .map(|member| &member.user) | |
| 1859 | + .collect::<Vec<_>>(), | |
| 1860 | + ); | |
| 1838 | 1861 | let old = std::mem::replace(&mut yumush.chat.members, members); |
| 1839 | 1862 | yumush |
| 1840 | 1863 | .chat |
| @@ -1864,6 +1887,7 @@ impl Yumush { | ||
| 1864 | 1887 | }; |
| 1865 | 1888 | let _ = this.update(cx, |yumush, cx| { |
| 1866 | 1889 | yumush.request_user_avatar(&user, cx); |
| 1890 | + style::remember(&[&user]); | |
| 1867 | 1891 | yumush.chat.users.insert(user.id, user); |
| 1868 | 1892 | cx.notify(); |
| 1869 | 1893 | }); |
| @@ -2662,88 +2686,84 @@ fn members_popover(entity: &Entity<Yumush>, yumush: &Yumush, palette: Palette) - | ||
| 2662 | 2686 | .content(move |_, _, _| { |
| 2663 | 2687 | let entity = entity.clone(); |
| 2664 | 2688 | |
| 2665 | - pop_in( | |
| 2666 | - "members_list", | |
| 2667 | - div() | |
| 2668 | - .w(px(size::SIDEBAR)) | |
| 2669 | - .p(px(space::XS)) | |
| 2670 | - .flex() | |
| 2671 | - .flex_col() | |
| 2672 | - .rounded(px(radius::LG)) | |
| 2673 | - .bg(palette.field) | |
| 2674 | - .children(members.iter().map( | |
| 2675 | - |MemberRow { | |
| 2676 | - user, | |
| 2677 | - rank, | |
| 2678 | - in_voice, | |
| 2679 | - muted, | |
| 2680 | - presence, | |
| 2681 | - }| { | |
| 2682 | - profile_popover( | |
| 2683 | - format!("member_{}", user.id), | |
| 2684 | - Anchor::TopRight, | |
| 2685 | - user, | |
| 2686 | - &entity, | |
| 2687 | - hoverable( | |
| 2688 | - format!("member_trigger_{}", user.id), | |
| 2689 | - div() | |
| 2690 | - .h(px(size::CONTROL)) | |
| 2691 | - .px(px(space::SM)) | |
| 2692 | - .flex() | |
| 2693 | - .items_center() | |
| 2694 | - .gap(px(space::SM)) | |
| 2695 | - .rounded(px(radius::MD)) | |
| 2696 | - .child(presence_avatar( | |
| 2697 | - avatar( | |
| 2698 | - palette, | |
| 2699 | - user, | |
| 2700 | - px(size::ICON), | |
| 2701 | - text(text::CAPTION), | |
| 2702 | - &avatars, | |
| 2703 | - ), | |
| 2704 | - *presence, | |
| 2705 | - px(size::ICON), | |
| 2689 | + div() | |
| 2690 | + .w(px(size::SIDEBAR)) | |
| 2691 | + .p(px(space::XS)) | |
| 2692 | + .flex() | |
| 2693 | + .flex_col() | |
| 2694 | + .rounded(px(radius::LG)) | |
| 2695 | + .bg(palette.field) | |
| 2696 | + .children(members.iter().map( | |
| 2697 | + |MemberRow { | |
| 2698 | + user, | |
| 2699 | + rank, | |
| 2700 | + in_voice, | |
| 2701 | + muted, | |
| 2702 | + presence, | |
| 2703 | + }| { | |
| 2704 | + profile_popover( | |
| 2705 | + format!("member_{}", user.id), | |
| 2706 | + Anchor::TopRight, | |
| 2707 | + user, | |
| 2708 | + &entity, | |
| 2709 | + hoverable( | |
| 2710 | + format!("member_trigger_{}", user.id), | |
| 2711 | + div() | |
| 2712 | + .h(px(size::CONTROL)) | |
| 2713 | + .px(px(space::SM)) | |
| 2714 | + .flex() | |
| 2715 | + .items_center() | |
| 2716 | + .gap(px(space::SM)) | |
| 2717 | + .rounded(px(radius::MD)) | |
| 2718 | + .child(presence_avatar( | |
| 2719 | + avatar( | |
| 2706 | 2720 | palette, |
| 2707 | - )) | |
| 2708 | - .child( | |
| 2709 | - div() | |
| 2710 | - .flex_1() | |
| 2711 | - .min_w_0() | |
| 2712 | - .flex() | |
| 2713 | - .flex_col() | |
| 2714 | - .child( | |
| 2715 | - div() | |
| 2716 | - .flex() | |
| 2717 | - .items_center() | |
| 2718 | - .gap(px(space::SM)) | |
| 2719 | - .child(user.username.clone()) | |
| 2720 | - .children(rank_tag(*rank, palette)) | |
| 2721 | - .children(in_voice.then(|| { | |
| 2722 | - Icon::new(IconName::Headphones) | |
| 2723 | - .size(px(size::ICON_SM)) | |
| 2724 | - .text_color(palette.muted) | |
| 2725 | - })) | |
| 2726 | - .children(muted.then(|| { | |
| 2727 | - Icon::new(IconName::MicOff) | |
| 2728 | - .size(px(size::ICON_SM)) | |
| 2729 | - .text_color(palette.danger) | |
| 2730 | - })), | |
| 2731 | - ) | |
| 2732 | - .children((!user.status.is_empty()).then(|| { | |
| 2733 | - div() | |
| 2734 | - .text_size(text(text::CAPTION)) | |
| 2735 | - .text_color(palette.muted) | |
| 2736 | - .truncate() | |
| 2737 | - .child(user.status.clone()) | |
| 2738 | - })), | |
| 2721 | + user, | |
| 2722 | + px(size::ICON), | |
| 2723 | + text(text::CAPTION), | |
| 2724 | + &avatars, | |
| 2739 | 2725 | ), |
| 2740 | - palette, | |
| 2741 | - ), | |
| 2742 | - ) | |
| 2743 | - }, | |
| 2744 | - )), | |
| 2745 | - Anchor::TopRight, | |
| 2746 | - ) | |
| 2726 | + *presence, | |
| 2727 | + px(size::ICON), | |
| 2728 | + palette, | |
| 2729 | + )) | |
| 2730 | + .child( | |
| 2731 | + div() | |
| 2732 | + .flex_1() | |
| 2733 | + .min_w_0() | |
| 2734 | + .flex() | |
| 2735 | + .flex_col() | |
| 2736 | + .child( | |
| 2737 | + div() | |
| 2738 | + .flex() | |
| 2739 | + .items_center() | |
| 2740 | + .gap(px(space::SM)) | |
| 2741 | + .child(user.username.clone()) | |
| 2742 | + .children(rank_tag(*rank, palette)) | |
| 2743 | + .children(in_voice.then(|| { | |
| 2744 | + Icon::new(IconName::Headphones) | |
| 2745 | + .size(px(size::ICON_SM)) | |
| 2746 | + .text_color(palette.muted) | |
| 2747 | + })) | |
| 2748 | + .children(muted.then(|| { | |
| 2749 | + Icon::new(IconName::MicOff) | |
| 2750 | + .size(px(size::ICON_SM)) | |
| 2751 | + .text_color(palette.danger) | |
| 2752 | + })), | |
| 2753 | + ) | |
| 2754 | + .children((!user.status.is_empty()).then(|| { | |
| 2755 | + div() | |
| 2756 | + .text_size(text(text::CAPTION)) | |
| 2757 | + .text_color(palette.muted) | |
| 2758 | + .truncate() | |
| 2759 | + .child(user.status.clone()) | |
| 2760 | + })), | |
| 2761 | + ), | |
| 2762 | + palette, | |
| 2763 | + ), | |
| 2764 | + ) | |
| 2765 | + }, | |
| 2766 | + )) | |
| 2747 | 2767 | }) |
| 2748 | 2768 | } |
| 2749 | 2769 |
crates/client/src/gui/composer.rsmodified+157 -173
| @@ -33,7 +33,7 @@ use gpui_kit::{ | ||
| 33 | 33 | use super::{ |
| 34 | 34 | Palette, Trigger, Yumush, |
| 35 | 35 | chat::{Chat, TYPING_SEND_INTERVAL}, |
| 36 | - clickable, hoverable, new_input, notify_error, pop_in, primary_button, | |
| 36 | + clickable, hoverable, new_input, notify_error, primary_button, | |
| 37 | 37 | }; |
| 38 | 38 | |
| 39 | 39 | actions!(composer, [Bold, Italic, Code, Strike]); |
| @@ -550,35 +550,31 @@ pub fn format_popover(palette: Palette) -> impl IntoElement { | ||
| 550 | 550 | palette, |
| 551 | 551 | )) |
| 552 | 552 | .content(move |_, _, _| { |
| 553 | - pop_in( | |
| 554 | - "format_list", | |
| 555 | - panel(palette) | |
| 556 | - .w(px(size::SHEET)) | |
| 557 | - .p(px(space::SM)) | |
| 558 | - .flex() | |
| 559 | - .flex_col() | |
| 560 | - .gap(px(space::SM)) | |
| 561 | - .text_size(text(text::CAPTION)) | |
| 562 | - .children(FORMAT_ROWS.map(|(syntax, shortcut)| { | |
| 563 | - div() | |
| 564 | - .flex() | |
| 565 | - .items_center() | |
| 566 | - .gap(px(space::MD)) | |
| 567 | - .child( | |
| 568 | - div() | |
| 569 | - .w(px(size::THUMB)) | |
| 570 | - .text_color(palette.muted) | |
| 571 | - .child(syntax), | |
| 572 | - ) | |
| 573 | - .child(div().flex_1().child(TextView::markdown(syntax, syntax))) | |
| 574 | - .child( | |
| 575 | - div() | |
| 576 | - .text_color(palette.muted) | |
| 577 | - .child(shortcut_label(shortcut)), | |
| 578 | - ) | |
| 579 | - })), | |
| 580 | - Anchor::BottomLeft, | |
| 581 | - ) | |
| 553 | + panel(palette) | |
| 554 | + .w(px(size::SHEET)) | |
| 555 | + .p(px(space::SM)) | |
| 556 | + .flex() | |
| 557 | + .flex_col() | |
| 558 | + .gap(px(space::SM)) | |
| 559 | + .text_size(text(text::CAPTION)) | |
| 560 | + .children(FORMAT_ROWS.map(|(syntax, shortcut)| { | |
| 561 | + div() | |
| 562 | + .flex() | |
| 563 | + .items_center() | |
| 564 | + .gap(px(space::MD)) | |
| 565 | + .child( | |
| 566 | + div() | |
| 567 | + .w(px(size::THUMB)) | |
| 568 | + .text_color(palette.muted) | |
| 569 | + .child(syntax), | |
| 570 | + ) | |
| 571 | + .child(div().flex_1().child(TextView::markdown(syntax, syntax))) | |
| 572 | + .child( | |
| 573 | + div() | |
| 574 | + .text_color(palette.muted) | |
| 575 | + .child(shortcut_label(shortcut)), | |
| 576 | + ) | |
| 577 | + })) | |
| 582 | 578 | }) |
| 583 | 579 | } |
| 584 | 580 | |
| @@ -645,160 +641,148 @@ pub fn plus_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> i | ||
| 645 | 641 | if entity.read(cx).chat.plus_menu == PlusMenu::Menu { |
| 646 | 642 | let file = entity.clone(); |
| 647 | 643 | let poll = entity.clone(); |
| 648 | - return pop_in( | |
| 649 | - "plus_menu", | |
| 650 | - panel(palette) | |
| 651 | - .w(px(size::SIDEBAR)) | |
| 652 | - .p(px(space::XS)) | |
| 653 | - .flex() | |
| 654 | - .flex_col() | |
| 655 | - .gap(px(space::XS)) | |
| 656 | - .child(plus_row( | |
| 657 | - "plus_file", | |
| 658 | - IconName::File, | |
| 659 | - "File", | |
| 660 | - palette, | |
| 661 | - move |window, cx| { | |
| 662 | - popover.update(cx, |state, cx| state.dismiss(window, cx)); | |
| 663 | - file.update(cx, |yumush, cx| yumush.attach_files(window, cx)); | |
| 664 | - }, | |
| 665 | - )) | |
| 666 | - .child(plus_row( | |
| 667 | - "plus_poll", | |
| 668 | - IconName::ChartBar, | |
| 669 | - "Poll", | |
| 670 | - palette, | |
| 671 | - move |_, cx| { | |
| 672 | - poll.update(cx, |yumush, cx| { | |
| 673 | - yumush.chat.plus_menu = PlusMenu::Poll; | |
| 674 | - cx.notify(); | |
| 675 | - }) | |
| 676 | - }, | |
| 677 | - )), | |
| 678 | - Anchor::BottomLeft, | |
| 679 | - ) | |
| 680 | - .into_any_element(); | |
| 644 | + return panel(palette) | |
| 645 | + .w(px(size::SIDEBAR)) | |
| 646 | + .p(px(space::XS)) | |
| 647 | + .flex() | |
| 648 | + .flex_col() | |
| 649 | + .gap(px(space::XS)) | |
| 650 | + .child(plus_row( | |
| 651 | + "plus_file", | |
| 652 | + IconName::File, | |
| 653 | + "File", | |
| 654 | + palette, | |
| 655 | + move |window, cx| { | |
| 656 | + popover.update(cx, |state, cx| state.dismiss(window, cx)); | |
| 657 | + file.update(cx, |yumush, cx| yumush.attach_files(window, cx)); | |
| 658 | + }, | |
| 659 | + )) | |
| 660 | + .child(plus_row( | |
| 661 | + "plus_poll", | |
| 662 | + IconName::ChartBar, | |
| 663 | + "Poll", | |
| 664 | + palette, | |
| 665 | + move |_, cx| { | |
| 666 | + poll.update(cx, |yumush, cx| { | |
| 667 | + yumush.chat.plus_menu = PlusMenu::Poll; | |
| 668 | + cx.notify(); | |
| 669 | + }) | |
| 670 | + }, | |
| 671 | + )) | |
| 672 | + .into_any_element(); | |
| 681 | 673 | } |
| 682 | 674 | let toggle = entity.clone(); |
| 683 | 675 | let toggle_public = entity.clone(); |
| 684 | 676 | let duration_entity = entity.clone(); |
| 685 | 677 | let submit = entity.clone(); |
| 686 | - pop_in( | |
| 687 | - "poll_form", | |
| 688 | - panel(palette) | |
| 689 | - .w(px(size::POPOVER)) | |
| 690 | - .p(px(space::SM)) | |
| 691 | - .flex() | |
| 692 | - .flex_col() | |
| 693 | - .gap(px(space::SM)) | |
| 694 | - .text_size(text(text::CAPTION)) | |
| 695 | - .child(compact_field(palette, &question)) | |
| 696 | - .children(options.iter().enumerate().map(|(index, option)| { | |
| 697 | - let remove = entity.clone(); | |
| 698 | - let trailing_blank = | |
| 699 | - index + 1 == options.len() && option_text(option, cx).is_empty(); | |
| 678 | + panel(palette) | |
| 679 | + .w(px(size::POPOVER)) | |
| 680 | + .p(px(space::SM)) | |
| 681 | + .flex() | |
| 682 | + .flex_col() | |
| 683 | + .gap(px(space::SM)) | |
| 684 | + .text_size(text(text::CAPTION)) | |
| 685 | + .child(compact_field(palette, &question)) | |
| 686 | + .children(options.iter().enumerate().map(|(index, option)| { | |
| 687 | + let remove = entity.clone(); | |
| 688 | + let trailing_blank = | |
| 689 | + index + 1 == options.len() && option_text(option, cx).is_empty(); | |
| 690 | + div() | |
| 691 | + .flex() | |
| 692 | + .items_center() | |
| 693 | + .gap(px(space::SM)) | |
| 694 | + .child( | |
| 695 | + div() | |
| 696 | + .flex_1() | |
| 697 | + .min_w_0() | |
| 698 | + .child(compact_field(palette, option)), | |
| 699 | + ) | |
| 700 | + .children( | |
| 701 | + (options.len() > MINIMUM_POLL_OPTIONS && !trailing_blank).then(|| { | |
| 702 | + icon_button( | |
| 703 | + format!("poll_remove_{index}"), | |
| 704 | + palette, | |
| 705 | + IconName::Close, | |
| 706 | + "Remove option", | |
| 707 | + move |_, cx| { | |
| 708 | + remove.update(cx, |yumush, cx| { | |
| 709 | + yumush.remove_poll_option(index, cx) | |
| 710 | + }); | |
| 711 | + }, | |
| 712 | + ) | |
| 713 | + }), | |
| 714 | + ) | |
| 715 | + })) | |
| 716 | + .child( | |
| 717 | + div() | |
| 718 | + .flex() | |
| 719 | + .items_center() | |
| 720 | + .gap(px(space::XS)) | |
| 721 | + .text_color(palette.muted) | |
| 722 | + .child(Icon::new(IconName::Timer).size(px(size::ICON_SM))) | |
| 723 | + .children(POLL_DURATIONS.map(|(label, seconds)| { | |
| 724 | + let set = duration_entity.clone(); | |
| 725 | + let active = duration == seconds; | |
| 726 | + clickable(label, palette, move |_, cx| { | |
| 727 | + set.update(cx, |yumush, cx| { | |
| 728 | + yumush.chat.poll_duration = seconds; | |
| 729 | + cx.notify(); | |
| 730 | + }) | |
| 731 | + }) | |
| 732 | + .px(px(space::SM)) | |
| 733 | + .py(px(space::XXS)) | |
| 734 | + .rounded(px(radius::SM)) | |
| 735 | + .text_color(if active { | |
| 736 | + palette.accent | |
| 737 | + } else { | |
| 738 | + palette.muted | |
| 739 | + }) | |
| 740 | + .when(active, |this| this.bg(palette.tokens.press())) | |
| 741 | + .child(label) | |
| 742 | + })), | |
| 743 | + ) | |
| 744 | + .child( | |
| 745 | + div().flex().items_center().justify_between().child( | |
| 700 | 746 | div() |
| 701 | 747 | .flex() |
| 702 | 748 | .items_center() |
| 703 | - .gap(px(space::SM)) | |
| 749 | + .gap(px(space::MD)) | |
| 704 | 750 | .child( |
| 705 | - div() | |
| 706 | - .flex_1() | |
| 707 | - .min_w_0() | |
| 708 | - .child(compact_field(palette, option)), | |
| 709 | - ) | |
| 710 | - .children( | |
| 711 | - (options.len() > MINIMUM_POLL_OPTIONS && !trailing_blank).then( | |
| 712 | - || { | |
| 713 | - icon_button( | |
| 714 | - format!("poll_remove_{index}"), | |
| 715 | - palette, | |
| 716 | - IconName::Close, | |
| 717 | - "Remove option", | |
| 718 | - move |_, cx| { | |
| 719 | - remove.update(cx, |yumush, cx| { | |
| 720 | - yumush.remove_poll_option(index, cx) | |
| 721 | - }); | |
| 722 | - }, | |
| 723 | - ) | |
| 724 | - }, | |
| 725 | - ), | |
| 751 | + Checkbox::new("poll_multiple") | |
| 752 | + .label("Multiple answers") | |
| 753 | + .checked(multiple) | |
| 754 | + .on_click(move |_, _, cx| { | |
| 755 | + toggle.update(cx, |yumush, cx| { | |
| 756 | + yumush.chat.poll_multiple = !yumush.chat.poll_multiple; | |
| 757 | + cx.notify(); | |
| 758 | + }) | |
| 759 | + }), | |
| 726 | 760 | ) |
| 727 | - })) | |
| 728 | - .child( | |
| 729 | - div() | |
| 730 | - .flex() | |
| 731 | - .items_center() | |
| 732 | - .gap(px(space::XS)) | |
| 733 | - .text_color(palette.muted) | |
| 734 | - .child(Icon::new(IconName::Timer).size(px(size::ICON_SM))) | |
| 735 | - .children(POLL_DURATIONS.map(|(label, seconds)| { | |
| 736 | - let set = duration_entity.clone(); | |
| 737 | - let active = duration == seconds; | |
| 738 | - clickable(label, palette, move |_, cx| { | |
| 739 | - set.update(cx, |yumush, cx| { | |
| 740 | - yumush.chat.poll_duration = seconds; | |
| 741 | - cx.notify(); | |
| 742 | - }) | |
| 743 | - }) | |
| 744 | - .px(px(space::SM)) | |
| 745 | - .py(px(space::XXS)) | |
| 746 | - .rounded(px(radius::SM)) | |
| 747 | - .text_color(if active { | |
| 748 | - palette.accent | |
| 749 | - } else { | |
| 750 | - palette.muted | |
| 751 | - }) | |
| 752 | - .when(active, |this| this.bg(palette.tokens.press())) | |
| 753 | - .child(label) | |
| 754 | - })), | |
| 755 | - ) | |
| 756 | - .child( | |
| 757 | - div().flex().items_center().justify_between().child( | |
| 758 | - div() | |
| 759 | - .flex() | |
| 760 | - .items_center() | |
| 761 | - .gap(px(space::MD)) | |
| 762 | - .child( | |
| 763 | - Checkbox::new("poll_multiple") | |
| 764 | - .label("Multiple answers") | |
| 765 | - .checked(multiple) | |
| 766 | - .on_click(move |_, _, cx| { | |
| 767 | - toggle.update(cx, |yumush, cx| { | |
| 768 | - yumush.chat.poll_multiple = | |
| 769 | - !yumush.chat.poll_multiple; | |
| 770 | - cx.notify(); | |
| 771 | - }) | |
| 772 | - }), | |
| 773 | - ) | |
| 774 | - .child( | |
| 775 | - Checkbox::new("poll_public") | |
| 776 | - .label("Show voters") | |
| 777 | - .checked(public) | |
| 778 | - .on_click(move |_, _, cx| { | |
| 779 | - toggle_public.update(cx, |yumush, cx| { | |
| 780 | - yumush.toggle_poll_public(cx) | |
| 781 | - }) | |
| 782 | - }), | |
| 783 | - ), | |
| 784 | - ), | |
| 785 | - ) | |
| 786 | - .child( | |
| 787 | - primary_button("poll_create", palette, move |window, cx| { | |
| 788 | - if submit.update(cx, |yumush, cx| yumush.send_poll(window, cx)) { | |
| 789 | - popover.update(cx, |state, cx| state.dismiss(window, cx)); | |
| 790 | - } | |
| 791 | - }) | |
| 792 | - .h(px(size::CONTROL_SM)) | |
| 793 | - .flex() | |
| 794 | - .items_center() | |
| 795 | - .justify_center() | |
| 796 | - .rounded(px(radius::MD)) | |
| 797 | - .child("Create"), | |
| 761 | + .child( | |
| 762 | + Checkbox::new("poll_public") | |
| 763 | + .label("Show voters") | |
| 764 | + .checked(public) | |
| 765 | + .on_click(move |_, _, cx| { | |
| 766 | + toggle_public | |
| 767 | + .update(cx, |yumush, cx| yumush.toggle_poll_public(cx)) | |
| 768 | + }), | |
| 769 | + ), | |
| 798 | 770 | ), |
| 799 | - Anchor::BottomLeft, | |
| 800 | - ) | |
| 801 | - .into_any_element() | |
| 771 | + ) | |
| 772 | + .child( | |
| 773 | + primary_button("poll_create", palette, move |window, cx| { | |
| 774 | + if submit.update(cx, |yumush, cx| yumush.send_poll(window, cx)) { | |
| 775 | + popover.update(cx, |state, cx| state.dismiss(window, cx)); | |
| 776 | + } | |
| 777 | + }) | |
| 778 | + .h(px(size::CONTROL_SM)) | |
| 779 | + .flex() | |
| 780 | + .items_center() | |
| 781 | + .justify_center() | |
| 782 | + .rounded(px(radius::MD)) | |
| 783 | + .child("Create"), | |
| 784 | + ) | |
| 785 | + .into_any_element() | |
| 802 | 786 | }) |
| 803 | 787 | } |
| 804 | 788 |
crates/client/src/gui/message_actions.rsmodified+58 -75
| @@ -24,7 +24,7 @@ use super::{ | ||
| 24 | 24 | chat::{Chat, ReportTarget}, |
| 25 | 25 | clickable, |
| 26 | 26 | composer::trigger_icon, |
| 27 | - entity_action, millis_time, notify_error, pop_in, primary_button, sidebar, | |
| 27 | + entity_action, millis_time, notify_error, primary_button, sidebar, | |
| 28 | 28 | style::{radius, size, space, text}, |
| 29 | 29 | widget::{field, icon_button, panel, spawn_done}, |
| 30 | 30 | }; |
| @@ -99,40 +99,31 @@ pub fn react_popover( | ||
| 99 | 99 | )) |
| 100 | 100 | .content(move |_, _, cx| { |
| 101 | 101 | let popover = cx.entity(); |
| 102 | - pop_in( | |
| 103 | - "react_list", | |
| 104 | - panel(palette) | |
| 102 | + panel(palette) | |
| 103 | + .flex() | |
| 104 | + .gap(px(space::XXS)) | |
| 105 | + .p(px(space::XS)) | |
| 106 | + .children(REACTIONS.map(|emoji| { | |
| 107 | + let entity = entity.clone(); | |
| 108 | + let popover = popover.clone(); | |
| 109 | + clickable( | |
| 110 | + format!("react_{emoji}_{message_id}"), | |
| 111 | + palette, | |
| 112 | + move |window, cx| { | |
| 113 | + popover.update(cx, |state, cx| state.dismiss(window, cx)); | |
| 114 | + entity.update(cx, |yumush, cx| { | |
| 115 | + yumush.toggle_reaction(message_id, emoji.to_string(), window, cx) | |
| 116 | + }); | |
| 117 | + }, | |
| 118 | + ) | |
| 119 | + .size(px(size::CONTROL_SM)) | |
| 105 | 120 | .flex() |
| 106 | - .gap(px(space::XXS)) | |
| 107 | - .p(px(space::XS)) | |
| 108 | - .children(REACTIONS.map(|emoji| { | |
| 109 | - let entity = entity.clone(); | |
| 110 | - let popover = popover.clone(); | |
| 111 | - clickable( | |
| 112 | - format!("react_{emoji}_{message_id}"), | |
| 113 | - palette, | |
| 114 | - move |window, cx| { | |
| 115 | - popover.update(cx, |state, cx| state.dismiss(window, cx)); | |
| 116 | - entity.update(cx, |yumush, cx| { | |
| 117 | - yumush.toggle_reaction( | |
| 118 | - message_id, | |
| 119 | - emoji.to_string(), | |
| 120 | - window, | |
| 121 | - cx, | |
| 122 | - ) | |
| 123 | - }); | |
| 124 | - }, | |
| 125 | - ) | |
| 126 | - .size(px(size::CONTROL_SM)) | |
| 127 | - .flex() | |
| 128 | - .items_center() | |
| 129 | - .justify_center() | |
| 130 | - .rounded(px(radius::MD)) | |
| 131 | - .text_size(text(text::BODY)) | |
| 132 | - .child(emoji) | |
| 133 | - })), | |
| 134 | - Anchor::TopRight, | |
| 135 | - ) | |
| 121 | + .items_center() | |
| 122 | + .justify_center() | |
| 123 | + .rounded(px(radius::MD)) | |
| 124 | + .text_size(text(text::BODY)) | |
| 125 | + .child(emoji) | |
| 126 | + })) | |
| 136 | 127 | }) |
| 137 | 128 | } |
| 138 | 129 | |
| @@ -295,27 +286,23 @@ pub fn search_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> | ||
| 295 | 286 | )) |
| 296 | 287 | .content(move |_, _, cx| { |
| 297 | 288 | let popover = cx.entity(); |
| 298 | - pop_in( | |
| 299 | - "search_list", | |
| 300 | - panel(palette) | |
| 301 | - .w(px(size::POPOVER)) | |
| 302 | - .p(px(space::XS)) | |
| 303 | - .flex() | |
| 304 | - .flex_col() | |
| 305 | - .gap(px(space::XS)) | |
| 306 | - .child(sidebar::input_box(&input, palette)) | |
| 307 | - .children(hits.iter().map(|hit| { | |
| 308 | - jump_row("search_hit", hit, &entity, &popover, palette) | |
| 309 | - .children(hit.time.as_ref().map(|time| { | |
| 310 | - div() | |
| 311 | - .flex_shrink_0() | |
| 312 | - .text_color(palette.muted) | |
| 313 | - .child(time.clone()) | |
| 314 | - })) | |
| 315 | - .child(div().flex_1().min_w_0().truncate().child(hit.body.clone())) | |
| 316 | - })), | |
| 317 | - Anchor::TopRight, | |
| 318 | - ) | |
| 289 | + panel(palette) | |
| 290 | + .w(px(size::POPOVER)) | |
| 291 | + .p(px(space::XS)) | |
| 292 | + .flex() | |
| 293 | + .flex_col() | |
| 294 | + .gap(px(space::XS)) | |
| 295 | + .child(sidebar::input_box(&input, palette)) | |
| 296 | + .children(hits.iter().map(|hit| { | |
| 297 | + jump_row("search_hit", hit, &entity, &popover, palette) | |
| 298 | + .children(hit.time.as_ref().map(|time| { | |
| 299 | + div() | |
| 300 | + .flex_shrink_0() | |
| 301 | + .text_color(palette.muted) | |
| 302 | + .child(time.clone()) | |
| 303 | + })) | |
| 304 | + .child(div().flex_1().min_w_0().truncate().child(hit.body.clone())) | |
| 305 | + })) | |
| 319 | 306 | }) |
| 320 | 307 | } |
| 321 | 308 | |
| @@ -341,26 +328,22 @@ pub fn pins_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> i | ||
| 341 | 328 | .trigger(trigger_icon("pins_trigger", IconName::Pin, 24., palette)) |
| 342 | 329 | .content(move |_, _, cx| { |
| 343 | 330 | let popover = cx.entity(); |
| 344 | - pop_in( | |
| 345 | - "pins_list", | |
| 346 | - panel(palette) | |
| 347 | - .w(px(size::POPOVER)) | |
| 348 | - .p(px(space::XS)) | |
| 349 | - .flex() | |
| 350 | - .flex_col() | |
| 351 | - .gap(px(space::XXS)) | |
| 352 | - .children(pins.iter().map(|hit| { | |
| 353 | - jump_row("pin_hit", hit, &entity, &popover, palette).child( | |
| 354 | - div() | |
| 355 | - .flex_1() | |
| 356 | - .min_w_0() | |
| 357 | - .truncate() | |
| 358 | - .text_color(palette.muted) | |
| 359 | - .child(hit.body.clone()), | |
| 360 | - ) | |
| 361 | - })), | |
| 362 | - Anchor::TopRight, | |
| 363 | - ) | |
| 331 | + panel(palette) | |
| 332 | + .w(px(size::POPOVER)) | |
| 333 | + .p(px(space::XS)) | |
| 334 | + .flex() | |
| 335 | + .flex_col() | |
| 336 | + .gap(px(space::XXS)) | |
| 337 | + .children(pins.iter().map(|hit| { | |
| 338 | + jump_row("pin_hit", hit, &entity, &popover, palette).child( | |
| 339 | + div() | |
| 340 | + .flex_1() | |
| 341 | + .min_w_0() | |
| 342 | + .truncate() | |
| 343 | + .text_color(palette.muted) | |
| 344 | + .child(hit.body.clone()), | |
| 345 | + ) | |
| 346 | + })) | |
| 364 | 347 | }) |
| 365 | 348 | } |
| 366 | 349 |
crates/client/src/gui/parts.rsmodified+0 -32
| @@ -413,38 +413,6 @@ pub fn spark(values: Vec<f32>, slots: usize, color: Hsla) -> AnyElement { | ||
| 413 | 413 | super::wave::line_of(values, slots, color).into_any_element() |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | -const MOTION_TRAVEL: f32 = 6.; | |
| 417 | - | |
| 418 | 416 | pub fn motion() -> gpui_kit::Animation { |
| 419 | 417 | gpui_kit::Animation::new(Duration::from_millis(160)).with_easing(gpui_kit::ease_out_quint()) |
| 420 | 418 | } |
| 421 | - | |
| 422 | -pub fn pop_in<E: IntoElement + Styled + 'static>( | |
| 423 | - id: impl Into<ElementId>, | |
| 424 | - element: E, | |
| 425 | - anchor: gpui_kit::Anchor, | |
| 426 | -) -> gpui_kit::AnimationElement<E> { | |
| 427 | - let travel = if anchor.is_bottom() { | |
| 428 | - MOTION_TRAVEL | |
| 429 | - } else { | |
| 430 | - -MOTION_TRAVEL | |
| 431 | - }; | |
| 432 | - gpui_kit::AnimationExt::with_animation(element, id, motion(), move |element, delta| { | |
| 433 | - element.top(px(travel * (1. - delta))).opacity(delta) | |
| 434 | - }) | |
| 435 | -} | |
| 436 | - | |
| 437 | -pub fn swap_in<E: IntoElement + Styled + 'static>( | |
| 438 | - id: impl Into<ElementId>, | |
| 439 | - element: E, | |
| 440 | - forward: bool, | |
| 441 | -) -> gpui_kit::AnimationElement<E> { | |
| 442 | - let travel = if forward { | |
| 443 | - MOTION_TRAVEL | |
| 444 | - } else { | |
| 445 | - -MOTION_TRAVEL | |
| 446 | - }; | |
| 447 | - gpui_kit::AnimationExt::with_animation(element, id, motion(), move |element, delta| { | |
| 448 | - element.left(px(travel * (1. - delta))).opacity(delta) | |
| 449 | - }) | |
| 450 | -} |
crates/client/src/gui/poll.rsmodified+10 -14
| @@ -11,7 +11,7 @@ use gpui_kit::{ | ||
| 11 | 11 | use super::{ |
| 12 | 12 | Palette, Tooltip as _, Trigger, Yumush, avatar, |
| 13 | 13 | chat::Chat, |
| 14 | - clickable, hoverable, pop_in, | |
| 14 | + clickable, hoverable, | |
| 15 | 15 | style::{radius, size, space, text}, |
| 16 | 16 | text, |
| 17 | 17 | widget::{icon_button, panel, spawn_done}, |
| @@ -143,19 +143,15 @@ fn voters_popover(key: &str, poll: &Poll, entity: &Entity<Yumush>, palette: Pale | ||
| 143 | 143 | }) |
| 144 | 144 | })) |
| 145 | 145 | }); |
| 146 | - pop_in( | |
| 147 | - list.clone(), | |
| 148 | - panel(palette) | |
| 149 | - .w(px(size::SIDEBAR)) | |
| 150 | - .id(list.clone()) | |
| 151 | - .max_h(px(size::POPOVER)) | |
| 152 | - .overflow_y_scroll() | |
| 153 | - .p(px(space::SM)) | |
| 154 | - .flex() | |
| 155 | - .flex_col() | |
| 156 | - .children(rows), | |
| 157 | - Anchor::BottomLeft, | |
| 158 | - ) | |
| 146 | + panel(palette) | |
| 147 | + .w(px(size::SIDEBAR)) | |
| 148 | + .id(list.clone()) | |
| 149 | + .max_h(px(size::POPOVER)) | |
| 150 | + .overflow_y_scroll() | |
| 151 | + .p(px(space::SM)) | |
| 152 | + .flex() | |
| 153 | + .flex_col() | |
| 154 | + .children(rows) | |
| 159 | 155 | }) |
| 160 | 156 | .into_any_element() |
| 161 | 157 | } |
crates/client/src/gui/profile.rsmodified+3 -11
| @@ -27,7 +27,7 @@ use super::style::{radius, size, space, stroke, text}; | ||
| 27 | 27 | use super::widget::{panel, spawn_done}; |
| 28 | 28 | use super::{ |
| 29 | 29 | DAY_YEAR, Palette, Trigger, Yumush, avatar, clickable, entity_action, input_dialog, |
| 30 | - millis_time, notify_error, palette, pop_in, presence_color, rank_tag, swap_in, text, | |
| 30 | + millis_time, notify_error, palette, presence_color, rank_tag, text, | |
| 31 | 31 | }; |
| 32 | 32 | |
| 33 | 33 | const ACCOUNTS_MAX_H: f32 = 180.; |
| @@ -117,11 +117,7 @@ pub(super) fn profile_popover( | ||
| 117 | 117 | user: user.clone(), |
| 118 | 118 | }; |
| 119 | 119 | |
| 120 | - pop_in( | |
| 121 | - "profile_card", | |
| 122 | - card.render(&entity, cx.entity(), palette(cx), &yumush.chat.avatars), | |
| 123 | - anchor, | |
| 124 | - ) | |
| 120 | + card.render(&entity, cx.entity(), palette(cx), &yumush.chat.avatars) | |
| 125 | 121 | }) |
| 126 | 122 | } |
| 127 | 123 | |
| @@ -302,11 +298,7 @@ impl Card { | ||
| 302 | 298 | .then(|| report_bar(&self.reason, entity, palette)), |
| 303 | 299 | ) |
| 304 | 300 | .children(divider) |
| 305 | - .child(swap_in( | |
| 306 | - ("profile_rows", self.card_menu as usize), | |
| 307 | - div().flex().flex_col().gap(px(space::MD)).children(rows), | |
| 308 | - self.card_menu != CardMenu::Main, | |
| 309 | - )) | |
| 301 | + .child(div().flex().flex_col().gap(px(space::MD)).children(rows)) | |
| 310 | 302 | } |
| 311 | 303 | |
| 312 | 304 | fn moderation_rows( |
crates/client/src/gui/settings_page.rsmodified+49 -3
| @@ -2,8 +2,8 @@ use std::future::Future; | ||
| 2 | 2 | |
| 3 | 3 | use crate::net::Fail; |
| 4 | 4 | use common::{ |
| 5 | - call::{DeleteUser, RemoveAvatar, UpdateAvatar, UpdateStatus, UpdateUser}, | |
| 6 | - model::User, | |
| 5 | + call::{DeleteUser, RemoveAvatar, UpdateAvatar, UpdateHue, UpdateStatus, UpdateUser}, | |
| 6 | + model::{Hue, User}, | |
| 7 | 7 | }; |
| 8 | 8 | use gpui_kit::{ |
| 9 | 9 | AnyElement, App, AsyncWindowContext, Context, Div, Entity, FontWeight, Hsla, |
| @@ -21,7 +21,7 @@ use super::{ | ||
| 21 | 21 | primary_button, text, widget::field, |
| 22 | 22 | }; |
| 23 | 23 | use crate::{ |
| 24 | - gui::style::{Theme, radius, size, space, stroke, text}, | |
| 24 | + gui::style::{self, Theme, radius, size, space, stroke, text}, | |
| 25 | 25 | settings::{self, FontSize}, |
| 26 | 26 | }; |
| 27 | 27 | |
| @@ -107,6 +107,14 @@ impl Yumush { | ||
| 107 | 107 | Yumush::set_theme, |
| 108 | 108 | ), |
| 109 | 109 | ), |
| 110 | + row( | |
| 111 | + "Your hue", | |
| 112 | + hue_picker( | |
| 113 | + self.user.as_ref().map(|user| style::hue_of(user.id)), | |
| 114 | + entity, | |
| 115 | + palette, | |
| 116 | + ), | |
| 117 | + ), | |
| 110 | 118 | row( |
| 111 | 119 | "Font size", |
| 112 | 120 | segmented( |
| @@ -180,6 +188,16 @@ impl Yumush { | ||
| 180 | 188 | .detach(); |
| 181 | 189 | } |
| 182 | 190 | |
| 191 | + pub(super) fn save_hue(&mut self, hue: Hue, window: &mut Window, cx: &mut Context<Self>) { | |
| 192 | + let network = self.network.clone(); | |
| 193 | + | |
| 194 | + cx.spawn_in(window, async move |this, cx| { | |
| 195 | + let result = network.call(UpdateHue { hue: Some(hue) }).await; | |
| 196 | + apply_user(&this, cx, result); | |
| 197 | + }) | |
| 198 | + .detach(); | |
| 199 | + } | |
| 200 | + | |
| 183 | 201 | pub(super) fn save_status(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 184 | 202 | let status = self.chat.status_input.read(cx).text().to_string(); |
| 185 | 203 | let network = self.network.clone(); |
| @@ -280,6 +298,34 @@ fn apply_user(this: &WeakEntity<Yumush>, cx: &mut AsyncWindowContext, result: Re | ||
| 280 | 298 | } |
| 281 | 299 | } |
| 282 | 300 | |
| 301 | +fn hue_picker(current: Option<Hue>, entity: &Entity<Yumush>, palette: Palette) -> Div { | |
| 302 | + let t = palette.tokens; | |
| 303 | + div() | |
| 304 | + .flex() | |
| 305 | + .items_center() | |
| 306 | + .gap(px(space::XS)) | |
| 307 | + .children(style::PICKS.iter().map(|&hue| { | |
| 308 | + let entity = entity.clone(); | |
| 309 | + let on = current == Some(hue); | |
| 310 | + div() | |
| 311 | + .id(hue.as_str()) | |
| 312 | + .flex() | |
| 313 | + .items_center() | |
| 314 | + .h(px(size::CONTROL_SM)) | |
| 315 | + .px(px(space::XS)) | |
| 316 | + .cursor_pointer() | |
| 317 | + .child( | |
| 318 | + div() | |
| 319 | + .w(px(size::CHIP)) | |
| 320 | + .h(px(if on { stroke::LINE * 2. } else { stroke::LINE })) | |
| 321 | + .bg(t.hue(hue)), | |
| 322 | + ) | |
| 323 | + .on_click(move |_, window, cx| { | |
| 324 | + entity.update(cx, |yumush, cx| yumush.save_hue(hue, window, cx)) | |
| 325 | + }) | |
| 326 | + })) | |
| 327 | +} | |
| 328 | + | |
| 283 | 329 | pub(super) fn picked_avatar( |
| 284 | 330 | cx: &App, |
| 285 | 331 | maximum: u64, |
crates/client/src/gui/share_view.rsmodified+2 -6
| @@ -34,7 +34,7 @@ use super::{ | ||
| 34 | 34 | chat::View, |
| 35 | 35 | clickable, entity_action, |
| 36 | 36 | media_view::into_render_image, |
| 37 | - notify_error, pop_in, | |
| 37 | + notify_error, | |
| 38 | 38 | settings_page::segmented, |
| 39 | 39 | stream_stats::{stream_card, watch_stats}, |
| 40 | 40 | style::{radius, size, space, text}, |
| @@ -504,11 +504,7 @@ impl Yumush { | ||
| 504 | 504 | )) |
| 505 | 505 | .content(move |_, _, cx| { |
| 506 | 506 | let entity = settings.clone(); |
| 507 | - pop_in( | |
| 508 | - "share_settings_card", | |
| 509 | - settings_card(&entity, entity.read(cx), palette), | |
| 510 | - Anchor::BottomRight, | |
| 511 | - ) | |
| 507 | + settings_card(&entity, entity.read(cx), palette) | |
| 512 | 508 | }) |
| 513 | 509 | } |
| 514 | 510 |
crates/client/src/gui/sidebar.rsmodified+12 -11
| @@ -48,14 +48,19 @@ impl Yumush { | ||
| 48 | 48 | self.expanded_sidebar(entity, palette) |
| 49 | 49 | }; |
| 50 | 50 | |
| 51 | - div() | |
| 51 | + let sidebar = div() | |
| 52 | 52 | .h_full() |
| 53 | 53 | .flex_shrink_0() |
| 54 | 54 | .overflow_hidden() |
| 55 | - .child(content) | |
| 56 | - .with_animation(id, motion(), move |sidebar, delta| { | |
| 57 | - sidebar.w(px(from + (to - from) * delta)) | |
| 58 | - }) | |
| 55 | + .child(content); | |
| 56 | + match self.chat.sidebar_toggled { | |
| 57 | + Some(at) if at.elapsed() < motion().duration => sidebar | |
| 58 | + .with_animation(id, motion(), move |sidebar, delta| { | |
| 59 | + sidebar.w(px(from + (to - from) * delta)) | |
| 60 | + }) | |
| 61 | + .into_any_element(), | |
| 62 | + _ => sidebar.w(px(to)).into_any_element(), | |
| 63 | + } | |
| 59 | 64 | } |
| 60 | 65 | |
| 61 | 66 | fn collapsed_sidebar(&self, entity: &Entity<Self>, palette: Palette) -> Div { |
| @@ -371,6 +376,7 @@ impl Yumush { | ||
| 371 | 376 | tip, |
| 372 | 377 | entity_action(entity, |yumush, _, cx| { |
| 373 | 378 | yumush.chat.sidebar_collapsed = !yumush.chat.sidebar_collapsed; |
| 379 | + yumush.chat.sidebar_toggled = Some(std::time::Instant::now()); | |
| 374 | 380 | cx.notify(); |
| 375 | 381 | }), |
| 376 | 382 | ) |
| @@ -413,12 +419,7 @@ impl Yumush { | ||
| 413 | 419 | .gap(px(space::XL)) |
| 414 | 420 | .child(input_box(&self.chat.search_input, palette)) |
| 415 | 421 | .children(found.map(|user| self.found_row(entity, user, palette))) |
| 416 | - .children( | |
| 417 | - query | |
| 418 | - .is_empty() | |
| 419 | - .then(|| self.requests(entity, palette)) | |
| 420 | - .flatten(), | |
| 421 | - ) | |
| 422 | + .children(self.requests(entity, palette)) | |
| 422 | 423 | .children(group( |
| 423 | 424 | "Friends", |
| 424 | 425 | palette, |
crates/client/src/gui/snippet.rsmodified+1 -0
| @@ -55,6 +55,7 @@ fn snippet_row( | ||
| 55 | 55 | username: item.username.clone(), |
| 56 | 56 | role: Role::User, |
| 57 | 57 | status: String::new(), |
| 58 | + hue: None, | |
| 58 | 59 | avatar_id: item.avatar_id, |
| 59 | 60 | created_at: item.created_at, |
| 60 | 61 | }); |
crates/client/src/gui/social.rsmodified+8 -0
| @@ -142,6 +142,14 @@ impl Yumush { | ||
| 142 | 142 | }; |
| 143 | 143 | |
| 144 | 144 | let _ = this.update(cx, |yumush, cx| { |
| 145 | + super::style::remember( | |
| 146 | + &friends | |
| 147 | + .friends | |
| 148 | + .iter() | |
| 149 | + .chain(&friends.incoming) | |
| 150 | + .chain(&friends.outgoing) | |
| 151 | + .collect::<Vec<_>>(), | |
| 152 | + ); | |
| 145 | 153 | yumush.chat.friends = friends; |
| 146 | 154 | yumush.chat.invitations = invitations; |
| 147 | 155 | yumush.chat.presences = presences.into_iter().collect(); |
crates/client/src/gui/style.rsmodified+22 -6
| @@ -1,6 +1,6 @@ | ||
| 1 | -use std::hash::{DefaultHasher, Hash, Hasher}; | |
| 1 | +use std::{cell::RefCell, collections::HashMap}; | |
| 2 | 2 | |
| 3 | -use common::model::{Hue, Id}; | |
| 3 | +use common::model::{Hue, Id, User}; | |
| 4 | 4 | use gpui_kit::{App, Global, Hsla, Rems, rems, rgb}; |
| 5 | 5 | |
| 6 | 6 | use crate::settings::FontSize; |
| @@ -104,11 +104,27 @@ impl Tokens { | ||
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | +pub const PICKS: &[Hue] = Hue::ALL.split_last().unwrap().1; | |
| 108 | + | |
| 109 | +thread_local! { | |
| 110 | + static CHOSEN: RefCell<HashMap<Id, Hue>> = RefCell::default(); | |
| 111 | +} | |
| 112 | + | |
| 113 | +pub fn remember(users: &[&User]) { | |
| 114 | + CHOSEN.with_borrow_mut(|chosen| { | |
| 115 | + for user in users { | |
| 116 | + match user.hue { | |
| 117 | + Some(hue) => chosen.insert(user.id, hue), | |
| 118 | + None => chosen.remove(&user.id), | |
| 119 | + }; | |
| 120 | + } | |
| 121 | + }); | |
| 122 | +} | |
| 123 | + | |
| 107 | 124 | pub fn hue_of(id: Id) -> Hue { |
| 108 | - let mut hasher = DefaultHasher::new(); | |
| 109 | - id.hash(&mut hasher); | |
| 110 | - let picks = &Hue::ALL[..Hue::ALL.len() - 1]; | |
| 111 | - picks[hasher.finish() as usize % picks.len()] | |
| 125 | + CHOSEN | |
| 126 | + .with_borrow(|chosen| chosen.get(&id).copied()) | |
| 127 | + .unwrap_or(PICKS[id.rem_euclid(PICKS.len() as Id) as usize]) | |
| 112 | 128 | } |
| 113 | 129 | |
| 114 | 130 | fn color(value: u32) -> Hsla { |
crates/client/src/gui/voice_stats.rsmodified+348 -573
| @@ -1,32 +1,26 @@ | ||
| 1 | 1 | use std::collections::VecDeque; |
| 2 | 2 | |
| 3 | 3 | use common::{ |
| 4 | - model::{Hue, Id}, | |
| 4 | + model::Id, | |
| 5 | 5 | share::{Kind, Layer}, |
| 6 | 6 | }; |
| 7 | -use gpui_kit::{ | |
| 8 | - Div, FontWeight, Hsla, ParentElement, Styled, assets::IconName, component::Icon, div, | |
| 9 | - prelude::FluentBuilder as _, px, relative, | |
| 10 | -}; | |
| 7 | +use gpui_kit::{AnyElement, Div, FontWeight, Hsla, IntoElement, ParentElement, Styled, div, px}; | |
| 11 | 8 | |
| 12 | 9 | use super::{ |
| 13 | 10 | Palette, |
| 14 | 11 | chat::Chat, |
| 15 | - share_view::kind_icon, | |
| 16 | - style::{radius, size, space, stroke, text}, | |
| 17 | - text as text_size, wave, | |
| 12 | + parts::{Fill, Ink, Text, band, grow, spark, stack, track, words}, | |
| 13 | + style::{Tokens, size, space}, | |
| 18 | 14 | }; |
| 19 | 15 | use crate::media::decode::Engine; |
| 20 | 16 | use crate::share::session::{LayerStats, WatchStats}; |
| 21 | -use crate::usage::{Gpu, Usage}; | |
| 17 | +use crate::usage::Usage; | |
| 22 | 18 | use crate::voice::VoiceSample; |
| 23 | 19 | |
| 24 | 20 | pub const SAMPLE_HISTORY: usize = 60; |
| 25 | -const MIRROR_HALF: f32 = size::CHIP; | |
| 26 | -const LAYER_W: f32 = 70.; | |
| 27 | -const WATCH_LAYER_W: f32 = 64.; | |
| 28 | -const RATE_W: f32 = 52.; | |
| 29 | -const VALUE_W: f32 = 76.; | |
| 21 | +const LABEL_W: f32 = size::ROW * 2.; | |
| 22 | +const VALUE_W: f32 = size::THUMB; | |
| 23 | +const COLUMN_W: f32 = size::TALK + size::ROW * 2.; | |
| 30 | 24 | const PING_SCALE: f32 = 150.; |
| 31 | 25 | const GOOD_LOSS: f32 = 2.; |
| 32 | 26 | const FAIR_LOSS: f32 = 8.; |
| @@ -68,14 +62,6 @@ impl Quality { | ||
| 68 | 62 | Self::Poor => "poor", |
| 69 | 63 | } |
| 70 | 64 | } |
| 71 | - | |
| 72 | - pub fn color(self, palette: Palette) -> Hsla { | |
| 73 | - match self { | |
| 74 | - Self::Good => palette.ok, | |
| 75 | - Self::Fair => palette.tokens.hue(Hue::Gold), | |
| 76 | - Self::Poor => palette.danger, | |
| 77 | - } | |
| 78 | - } | |
| 79 | 65 | } |
| 80 | 66 | |
| 81 | 67 | pub fn quality(samples: &VecDeque<VoiceSample>) -> Option<Quality> { |
| @@ -83,487 +69,386 @@ pub fn quality(samples: &VecDeque<VoiceSample>) -> Option<Quality> { | ||
| 83 | 69 | } |
| 84 | 70 | |
| 85 | 71 | pub fn stats_panel(chat: &Chat, palette: Palette) -> Div { |
| 72 | + let t = palette.tokens; | |
| 86 | 73 | let share = &chat.share_sample; |
| 87 | - div() | |
| 88 | - .flex() | |
| 89 | - .flex_col() | |
| 90 | - .gap(px(space::LG)) | |
| 91 | - .child(network_block(chat, palette)) | |
| 92 | - .children(sending_blocks(&share.sending, palette)) | |
| 93 | - .child(receiving_block(&share.watching, chat, palette)) | |
| 94 | - .children(chat.usage.as_ref().map(|usage| usage_block(usage, palette))) | |
| 95 | -} | |
| 96 | - | |
| 97 | -fn network_block(chat: &Chat, palette: Palette) -> Div { | |
| 98 | - let latest = chat.voice_samples.back(); | |
| 99 | - let color = latest.map_or(palette.ok, |sample| Quality::of(sample).color(palette)); | |
| 100 | - let word = latest.map_or("…", |sample| Quality::of(sample).word()); | |
| 101 | - let ping = latest.map_or("…".into(), |sample| format!("{:.0} ms", sample.ping_ms)); | |
| 102 | - let jitter = latest.map_or("…".into(), |sample| { | |
| 103 | - format!("{:.0} ms", sample.traffic.jitter_ms) | |
| 104 | - }); | |
| 105 | - let loss = latest.map_or("…".into(), |sample| { | |
| 106 | - format!("{:.1} %", sample.traffic.loss * 100.) | |
| 107 | - }); | |
| 108 | - let buffer = latest.map_or("…".into(), |sample| { | |
| 109 | - format!("{:.0} ms", sample.traffic.buffer_ms) | |
| 110 | - }); | |
| 111 | - | |
| 112 | - div() | |
| 113 | - .flex() | |
| 114 | - .flex_col() | |
| 115 | - .gap(px(space::SM)) | |
| 116 | - .child(header(IconName::Activity, "Network", color).child(chip(word, color, palette))) | |
| 74 | + band(space::XXL) | |
| 75 | + .items_start() | |
| 76 | + .flex_wrap() | |
| 117 | 77 | .child( |
| 118 | - div() | |
| 119 | - .flex() | |
| 120 | - .gap(px(space::SM)) | |
| 121 | - .child(stat_cell("ping", ping, color, palette)) | |
| 122 | - .child(stat_cell("jitter", jitter, color, palette)) | |
| 123 | - .child(stat_cell("loss", loss, color, palette)) | |
| 124 | - .child(stat_cell("buffer", buffer, palette.text, palette)), | |
| 78 | + stack(space::XL) | |
| 79 | + .w(px(COLUMN_W)) | |
| 80 | + .child(connection(chat, t)) | |
| 81 | + .child(traffic(chat, t)) | |
| 82 | + .children(chat.usage.as_ref().map(|usage| machine(usage, t))), | |
| 125 | 83 | ) |
| 126 | 84 | .child( |
| 127 | - div() | |
| 128 | - .h(px(size::CONTROL)) | |
| 129 | - .p(px(space::XXS)) | |
| 130 | - .rounded(px(radius::SM)) | |
| 131 | - .bg(palette.window) | |
| 132 | - .child(wave::line( | |
| 133 | - chat.voice_samples | |
| 134 | - .iter() | |
| 135 | - .map(|sample| (sample.ping_ms / PING_SCALE).clamp(0., 1.)) | |
| 136 | - .collect(), | |
| 137 | - color, | |
| 138 | - )), | |
| 85 | + stack(space::XL) | |
| 86 | + .w(px(COLUMN_W)) | |
| 87 | + .children(sending(&share.sending, t)) | |
| 88 | + .children(watching(&share.watching, chat, t)), | |
| 139 | 89 | ) |
| 140 | - .child(traffic(chat, palette)) | |
| 141 | 90 | } |
| 142 | 91 | |
| 143 | -fn traffic(chat: &Chat, palette: Palette) -> Div { | |
| 144 | - let up: Vec<f32> = chat.traffic.iter().map(|(up, _)| *up).collect(); | |
| 145 | - let down: Vec<f32> = chat.traffic.iter().map(|(_, down)| *down).collect(); | |
| 146 | - let up_latest = up.last().copied().unwrap_or_default(); | |
| 147 | - let down_latest = down.last().copied().unwrap_or_default(); | |
| 148 | - let max = up.iter().chain(&down).copied().fold(1., f32::max); | |
| 149 | - | |
| 150 | - div() | |
| 151 | - .flex() | |
| 152 | - .flex_col() | |
| 153 | - .gap(px(space::XXS)) | |
| 154 | - .text_size(text_size(text::CAPTION)) | |
| 92 | +fn title(name: &'static str, sub: String, trailing: Option<Div>, t: Tokens) -> Div { | |
| 93 | + band(space::SM) | |
| 155 | 94 | .child( |
| 156 | - div() | |
| 157 | - .text_color(up_color(palette)) | |
| 158 | - .child(format!("↑ {}", rate(up_latest as u32))), | |
| 159 | - ) | |
| 160 | - .child( | |
| 161 | - div() | |
| 162 | - .h(px(MIRROR_HALF * 2.)) | |
| 163 | - .flex() | |
| 164 | - .flex_col() | |
| 165 | - .child( | |
| 166 | - div() | |
| 167 | - .h(px(MIRROR_HALF)) | |
| 168 | - .flex() | |
| 169 | - .items_end() | |
| 170 | - .gap(px(space::XXS)) | |
| 171 | - .children(bars(&up, max, up_color(palette))), | |
| 172 | - ) | |
| 173 | - .child(div().h(px(stroke::LINE)).bg(palette.border)) | |
| 174 | - .child( | |
| 175 | - div() | |
| 176 | - .h(px(MIRROR_HALF)) | |
| 177 | - .flex() | |
| 178 | - .items_start() | |
| 179 | - .gap(px(space::XXS)) | |
| 180 | - .children(bars(&down, max, down_color(palette))), | |
| 181 | - ), | |
| 182 | - ) | |
| 183 | - .child( | |
| 184 | - div() | |
| 185 | - .text_color(down_color(palette)) | |
| 186 | - .child(format!("↓ {}", rate(down_latest as u32))), | |
| 95 | + words(name, Text::Label, Ink::Paper, t) | |
| 96 | + .font_weight(FontWeight::MEDIUM) | |
| 97 | + .flex_none(), | |
| 187 | 98 | ) |
| 99 | + .child(words(sub, Text::Caption, Ink::Faint, t)) | |
| 100 | + .child(grow()) | |
| 101 | + .children(trailing) | |
| 188 | 102 | } |
| 189 | 103 | |
| 190 | -fn bars(values: &[f32], max: f32, color: Hsla) -> Vec<Div> { | |
| 191 | - let empty = SAMPLE_HISTORY.saturating_sub(values.len()); | |
| 192 | - (0..empty) | |
| 193 | - .map(|_| div().flex_1()) | |
| 194 | - .chain( | |
| 195 | - values | |
| 196 | - .iter() | |
| 197 | - .map(|value| div().flex_1().h(px(value / max * MIRROR_HALF)).bg(color)), | |
| 104 | +fn line_row(label: AnyElement, fill: AnyElement, value: String, bad: bool, t: Tokens) -> Div { | |
| 105 | + band(space::MD) | |
| 106 | + .h(px(size::CONTROL_SM)) | |
| 107 | + .child(div().w(px(LABEL_W)).flex_none().min_w_0().child(label)) | |
| 108 | + .child(div().flex_1().min_w_0().child(fill)) | |
| 109 | + .child( | |
| 110 | + words( | |
| 111 | + value, | |
| 112 | + Text::Label, | |
| 113 | + if bad { Ink::Bad } else { Ink::Paper }, | |
| 114 | + t, | |
| 115 | + ) | |
| 116 | + .w(px(VALUE_W)) | |
| 117 | + .flex_none() | |
| 118 | + .text_right(), | |
| 198 | 119 | ) |
| 199 | - .collect() | |
| 200 | -} | |
| 201 | - | |
| 202 | -fn up_color(palette: Palette) -> Hsla { | |
| 203 | - palette.tokens.hue(Hue::Violet) | |
| 204 | 120 | } |
| 205 | 121 | |
| 206 | -fn down_color(palette: Palette) -> Hsla { | |
| 207 | - palette.tokens.hue(Hue::Teal) | |
| 122 | +fn label(text: &'static str, t: Tokens) -> AnyElement { | |
| 123 | + words(text, Text::Caption, Ink::Dim, t).into_any_element() | |
| 208 | 124 | } |
| 209 | 125 | |
| 210 | -fn sending_blocks(sending: &[(Kind, LayerStats)], palette: Palette) -> Vec<Div> { | |
| 211 | - [Kind::Screen, Kind::Camera] | |
| 212 | - .into_iter() | |
| 213 | - .filter_map(|kind| { | |
| 214 | - let layers: Vec<&LayerStats> = sending | |
| 215 | - .iter() | |
| 216 | - .filter(|(sent, _)| *sent == kind) | |
| 217 | - .map(|(_, stats)| stats) | |
| 218 | - .collect(); | |
| 219 | - (!layers.is_empty()).then(|| sending_block(kind, &layers, palette)) | |
| 220 | - }) | |
| 221 | - .collect() | |
| 222 | -} | |
| 223 | - | |
| 224 | -fn sending_block(kind: Kind, layers: &[&LayerStats], palette: Palette) -> Div { | |
| 225 | - let color = kind_color(kind, palette); | |
| 226 | - let max = largest(layers.iter().map(|stats| stats.kbps)); | |
| 227 | - let engine = layers | |
| 228 | - .last() | |
| 229 | - .map_or("…", |stats| engine_label(stats.engine)); | |
| 230 | - div() | |
| 231 | - .flex() | |
| 232 | - .flex_col() | |
| 233 | - .gap(px(space::SM)) | |
| 234 | - .child(header(kind_icon(kind), kind_name(kind), color).child(label(engine, color))) | |
| 235 | - .children( | |
| 236 | - layers | |
| 237 | - .iter() | |
| 238 | - .enumerate() | |
| 239 | - .rev() | |
| 240 | - .map(|(index, stats)| layer_row(index, stats, max, kind, palette)), | |
| 241 | - ) | |
| 242 | -} | |
| 243 | - | |
| 244 | -fn layer_row(index: usize, stats: &LayerStats, max: f32, kind: Kind, palette: Palette) -> Div { | |
| 245 | - let color = kind_color(kind, palette); | |
| 246 | - div() | |
| 247 | - .flex() | |
| 248 | - .items_center() | |
| 249 | - .gap(px(space::SM)) | |
| 250 | - .h(px(size::CONTROL_SM)) | |
| 251 | - .px(px(space::SM)) | |
| 252 | - .rounded(px(radius::MD)) | |
| 253 | - .bg(palette.hover) | |
| 254 | - .text_size(text_size(text::CAPTION)) | |
| 255 | - .when(stats.kbps == 0, |this| { | |
| 256 | - this.text_color(palette.tokens.faint()) | |
| 257 | - }) | |
| 258 | - .child( | |
| 259 | - div() | |
| 260 | - .w(px(size::CHIP)) | |
| 261 | - .flex_none() | |
| 262 | - .font_weight(FontWeight::SEMIBOLD) | |
| 263 | - .text_color(color) | |
| 264 | - .child(format!("L{index}")), | |
| 265 | - ) | |
| 266 | - .child( | |
| 267 | - div() | |
| 268 | - .w(px(LAYER_W)) | |
| 269 | - .flex_none() | |
| 270 | - .text_color(palette.text) | |
| 271 | - .child(resolution_text(stats.layer, stats.fps)), | |
| 272 | - ) | |
| 273 | - .child( | |
| 274 | - div() | |
| 275 | - .w(px(size::CONTROL)) | |
| 276 | - .flex_none() | |
| 277 | - .text_color(palette.muted) | |
| 278 | - .child(stats.layer.codec.name()), | |
| 279 | - ) | |
| 280 | - .child(bar(stats.kbps as f32 / max, color, palette)) | |
| 126 | +fn number(value: String, name: &'static str, bad: bool, t: Tokens) -> Div { | |
| 127 | + stack(space::XXS) | |
| 128 | + .flex_1() | |
| 281 | 129 | .child( |
| 282 | - div() | |
| 283 | - .w(px(RATE_W)) | |
| 284 | - .flex_none() | |
| 285 | - .text_right() | |
| 286 | - .text_color(palette.text) | |
| 287 | - .child(rate(stats.kbps)), | |
| 130 | + words( | |
| 131 | + value, | |
| 132 | + Text::Title, | |
| 133 | + if bad { Ink::Bad } else { Ink::Paper }, | |
| 134 | + t, | |
| 135 | + ) | |
| 136 | + .font_weight(FontWeight::MEDIUM), | |
| 288 | 137 | ) |
| 138 | + .child(words(name, Text::Caption, Ink::Faint, t)) | |
| 289 | 139 | } |
| 290 | 140 | |
| 291 | -fn receiving_block(watching: &[(Id, Kind, WatchStats)], chat: &Chat, palette: Palette) -> Div { | |
| 292 | - div() | |
| 293 | - .flex() | |
| 294 | - .flex_col() | |
| 295 | - .gap(px(space::XS)) | |
| 296 | - .child(header(IconName::Eye, "Receiving", palette.text)) | |
| 297 | - .children( | |
| 298 | - watching | |
| 299 | - .iter() | |
| 300 | - .map(|(user_id, kind, stats)| watch_row(chat, *user_id, *kind, stats, palette)), | |
| 141 | +fn connection(chat: &Chat, t: Tokens) -> Div { | |
| 142 | + let latest = chat.voice_samples.back(); | |
| 143 | + let quality = latest.map(Quality::of); | |
| 144 | + let bad = quality == Some(Quality::Poor); | |
| 145 | + let field = |value: Option<String>| value.unwrap_or_else(|| "…".into()); | |
| 146 | + let ping = latest.map(|sample| sample.ping_ms); | |
| 147 | + let loss = latest.map(|sample| sample.traffic.loss * 100.); | |
| 148 | + let word = quality.map(|quality| { | |
| 149 | + words( | |
| 150 | + quality.word(), | |
| 151 | + Text::Caption, | |
| 152 | + if bad { Ink::Bad } else { Ink::Dim }, | |
| 153 | + t, | |
| 301 | 154 | ) |
| 302 | -} | |
| 155 | + }); | |
| 303 | 156 | |
| 304 | -fn watch_row(chat: &Chat, user_id: Id, kind: Kind, stats: &WatchStats, palette: Palette) -> Div { | |
| 305 | - let name = chat | |
| 306 | - .author(user_id) | |
| 307 | - .map_or_else(|| user_id.to_string(), |user| user.username.clone()); | |
| 308 | - let color = palette.tinted(user_id); | |
| 309 | - let loss = stats.loss * 100.; | |
| 310 | - let loss_color = Quality::of_loss(loss).color(palette); | |
| 311 | - let latency = stats | |
| 312 | - .latency_ms | |
| 313 | - .map_or("…".to_string(), |ms| format!("{ms} ms")); | |
| 314 | - div() | |
| 315 | - .flex() | |
| 316 | - .items_center() | |
| 317 | - .gap(px(space::XS)) | |
| 318 | - .h(px(size::CONTROL)) | |
| 319 | - .px(px(space::SM)) | |
| 320 | - .rounded(px(radius::MD)) | |
| 321 | - .bg(palette.hover) | |
| 322 | - .text_size(text_size(text::CAPTION)) | |
| 323 | - .child(avatar_dot(&name, color, palette)) | |
| 324 | - .child( | |
| 325 | - div() | |
| 326 | - .flex_1() | |
| 327 | - .min_w_0() | |
| 328 | - .truncate() | |
| 329 | - .font_weight(FontWeight::SEMIBOLD) | |
| 330 | - .text_color(color) | |
| 331 | - .child(name), | |
| 332 | - ) | |
| 333 | - .child( | |
| 334 | - Icon::new(kind_icon(kind)) | |
| 335 | - .size(px(size::ICON_SM)) | |
| 336 | - .flex_none() | |
| 337 | - .text_color(kind_color(kind, palette)), | |
| 338 | - ) | |
| 339 | - .child( | |
| 340 | - div() | |
| 341 | - .w(px(WATCH_LAYER_W)) | |
| 342 | - .flex_none() | |
| 343 | - .text_color(palette.text) | |
| 344 | - .child( | |
| 345 | - stats | |
| 346 | - .layer | |
| 347 | - .map_or("…".to_string(), |layer| resolution_text(layer, stats.fps)), | |
| 348 | - ), | |
| 349 | - ) | |
| 157 | + stack(space::MD) | |
| 158 | + .child(title("Connection", String::new(), word, t)) | |
| 350 | 159 | .child( |
| 351 | - div() | |
| 352 | - .w(px(RATE_W)) | |
| 353 | - .flex_none() | |
| 354 | - .text_color(palette.muted) | |
| 355 | - .child(format!( | |
| 356 | - "{} {}", | |
| 357 | - stats.layer.map_or("…", |layer| layer.codec.name()), | |
| 358 | - stats.engine.map_or("…", engine_label) | |
| 160 | + band(space::LG) | |
| 161 | + .child(number( | |
| 162 | + field(ping.map(|ping| format!("{ping:.0}"))), | |
| 163 | + "ping ms", | |
| 164 | + ping.is_some_and(|ping| ping > PING_SCALE), | |
| 165 | + t, | |
| 166 | + )) | |
| 167 | + .child(number( | |
| 168 | + field(latest.map(|sample| format!("{:.0}", sample.traffic.jitter_ms))), | |
| 169 | + "jitter ms", | |
| 170 | + false, | |
| 171 | + t, | |
| 172 | + )) | |
| 173 | + .child(number( | |
| 174 | + field(loss.map(|loss| format!("{loss:.1}"))), | |
| 175 | + "loss %", | |
| 176 | + loss.is_some_and(|loss| loss > GOOD_LOSS), | |
| 177 | + t, | |
| 178 | + )) | |
| 179 | + .child(number( | |
| 180 | + field(latest.map(|sample| format!("{:.0}", sample.traffic.buffer_ms))), | |
| 181 | + "buffer ms", | |
| 182 | + false, | |
| 183 | + t, | |
| 359 | 184 | )), |
| 360 | 185 | ) |
| 361 | 186 | .child( |
| 362 | - div() | |
| 363 | - .w(px(size::ROW)) | |
| 364 | - .flex_none() | |
| 365 | - .text_right() | |
| 366 | - .text_color(palette.text) | |
| 367 | - .child(rate(stats.kbps)), | |
| 368 | - ) | |
| 369 | - .child( | |
| 370 | - div() | |
| 371 | - .w(px(RATE_W)) | |
| 372 | - .flex_none() | |
| 373 | - .text_right() | |
| 374 | - .text_color(palette.muted) | |
| 375 | - .child(latency), | |
| 187 | + div().h(px(size::CONTROL_SM)).child(spark( | |
| 188 | + chat.voice_samples | |
| 189 | + .iter() | |
| 190 | + .map(|sample| (sample.ping_ms / PING_SCALE).clamp(0., 1.)) | |
| 191 | + .collect(), | |
| 192 | + SAMPLE_HISTORY, | |
| 193 | + if bad { t.bad() } else { t.paper() }, | |
| 194 | + )), | |
| 376 | 195 | ) |
| 377 | - .child(chip(format!("{loss:.1}%"), loss_color, palette)) | |
| 378 | 196 | } |
| 379 | 197 | |
| 380 | -fn usage_block(usage: &Usage, palette: Palette) -> Div { | |
| 381 | - let memory = usage.memory; | |
| 382 | - let total_mb = memory.total_mb.max(1) as f32; | |
| 383 | - let cpu = column() | |
| 384 | - .child(model_header( | |
| 385 | - IconName::Cpu, | |
| 386 | - "CPU", | |
| 387 | - &usage.cpu_model, | |
| 388 | - palette, | |
| 198 | +fn traffic(chat: &Chat, t: Tokens) -> Div { | |
| 199 | + let up: Vec<f32> = chat.traffic.iter().map(|(up, _)| *up).collect(); | |
| 200 | + let down: Vec<f32> = chat.traffic.iter().map(|(_, down)| *down).collect(); | |
| 201 | + let max = up.iter().chain(&down).copied().fold(1., f32::max); | |
| 202 | + let line = |values: &[f32], ink: Hsla| { | |
| 203 | + div() | |
| 204 | + .h(px(space::MD)) | |
| 205 | + .child(spark( | |
| 206 | + values.iter().map(|value| value / max).collect(), | |
| 207 | + SAMPLE_HISTORY, | |
| 208 | + ink, | |
| 209 | + )) | |
| 210 | + .into_any_element() | |
| 211 | + }; | |
| 212 | + let latest = |values: &[f32]| rate(values.last().copied().unwrap_or_default() as u32); | |
| 213 | + | |
| 214 | + stack(space::XS) | |
| 215 | + .child(title("Traffic", String::new(), None, t)) | |
| 216 | + .child(line_row( | |
| 217 | + label("up", t), | |
| 218 | + line(&up, t.paper()), | |
| 219 | + latest(&up), | |
| 220 | + false, | |
| 221 | + t, | |
| 389 | 222 | )) |
| 390 | - .child(dual( | |
| 391 | - "total", | |
| 392 | - usage.total, | |
| 393 | - usage.machine, | |
| 394 | - palette.text, | |
| 395 | - palette, | |
| 223 | + .child(line_row( | |
| 224 | + label("down", t), | |
| 225 | + line(&down, t.dim()), | |
| 226 | + latest(&down), | |
| 227 | + false, | |
| 228 | + t, | |
| 396 | 229 | )) |
| 397 | - .children( | |
| 398 | - usage | |
| 399 | - .threads | |
| 400 | - .map(|threads| { | |
| 401 | - [ | |
| 402 | - meter("gui", threads.gui, palette.accent, palette), | |
| 403 | - meter("camera", threads.camera, palette.camera, palette), | |
| 404 | - meter("encode", threads.encode, palette.screen, palette), | |
| 405 | - meter("decode", threads.decode, palette.ok, palette), | |
| 406 | - ] | |
| 407 | - }) | |
| 408 | - .into_iter() | |
| 409 | - .flatten(), | |
| 410 | - ) | |
| 411 | - .child(dual_value( | |
| 412 | - "ram", | |
| 413 | - format!("{} / {}", gb(memory.own_mb), gb(memory.used_mb)), | |
| 414 | - memory.own_mb as f32 / total_mb, | |
| 415 | - memory.used_mb as f32 / total_mb, | |
| 416 | - palette.muted, | |
| 417 | - palette, | |
| 418 | - )); | |
| 419 | - div() | |
| 420 | - .flex() | |
| 421 | - .gap(px(space::XL)) | |
| 422 | - .child(cpu) | |
| 423 | - .children(usage.gpu.as_ref().map(|gpu| gpu_column(gpu, palette))) | |
| 424 | -} | |
| 425 | - | |
| 426 | -fn column() -> Div { | |
| 427 | - div() | |
| 428 | - .flex() | |
| 429 | - .flex_col() | |
| 430 | - .gap(px(space::SM)) | |
| 431 | - .flex_1() | |
| 432 | - .min_w_0() | |
| 433 | -} | |
| 434 | - | |
| 435 | -fn model_header(icon: IconName, title: &'static str, model: &str, palette: Palette) -> Div { | |
| 436 | - div() | |
| 437 | - .flex() | |
| 438 | - .flex_col() | |
| 439 | - .gap(px(space::XXS)) | |
| 440 | - .child(header(icon, title, palette.text)) | |
| 441 | - .child( | |
| 442 | - div() | |
| 443 | - .text_size(text_size(text::CAPTION)) | |
| 444 | - .text_color(palette.muted) | |
| 445 | - .truncate() | |
| 446 | - .child(model.to_string()), | |
| 447 | - ) | |
| 448 | 230 | } |
| 449 | 231 | |
| 450 | -fn gpu_column(gpu: &Gpu, palette: Palette) -> Div { | |
| 451 | - let machine = gpu.machine; | |
| 452 | - let vram_total = machine.vram_total_mb.max(machine.vram_used_mb).max(1) as f32; | |
| 453 | - column() | |
| 454 | - .child(model_header( | |
| 455 | - IconName::MemoryStick, | |
| 456 | - "GPU", | |
| 457 | - &gpu.model, | |
| 458 | - palette, | |
| 459 | - )) | |
| 460 | - .child(dual("3d", gpu.gfx, machine.gfx, palette.accent, palette)) | |
| 461 | - .child(dual( | |
| 462 | - "video", | |
| 463 | - gpu.video, | |
| 464 | - machine.video, | |
| 465 | - palette.screen, | |
| 466 | - palette, | |
| 232 | +fn machine(usage: &Usage, t: Tokens) -> Div { | |
| 233 | + let memory = usage.memory; | |
| 234 | + let total_mb = memory.total_mb.max(1) as f32; | |
| 235 | + let over = |own: f32, total: f32| track(Fill::Over { own, total }, false, t).into_any_element(); | |
| 236 | + let model = match usage.gpu.as_ref() { | |
| 237 | + Some(gpu) => format!("{} · {}", usage.cpu_model, gpu.model), | |
| 238 | + None => usage.cpu_model.to_string(), | |
| 239 | + }; | |
| 240 | + | |
| 241 | + stack(space::XS) | |
| 242 | + .child(title("This machine", model, None, t)) | |
| 243 | + .child(line_row( | |
| 244 | + label("CPU", t), | |
| 245 | + over(usage.total / 100., usage.machine / 100.), | |
| 246 | + format!("{:.0} / {:.0} %", usage.total, usage.machine), | |
| 247 | + false, | |
| 248 | + t, | |
| 467 | 249 | )) |
| 468 | - .child(dual_value( | |
| 469 | - "vram", | |
| 470 | - format!("{} / {}", gb(gpu.vram_mb), gb(machine.vram_used_mb)), | |
| 471 | - gpu.vram_mb as f32 / vram_total, | |
| 472 | - machine.vram_used_mb as f32 / vram_total, | |
| 473 | - palette.muted, | |
| 474 | - palette, | |
| 250 | + .children(usage.threads.map(|threads| { | |
| 251 | + band(space::MD).children( | |
| 252 | + [ | |
| 253 | + ("gui", threads.gui), | |
| 254 | + ("camera", threads.camera), | |
| 255 | + ("encode", threads.encode), | |
| 256 | + ("decode", threads.decode), | |
| 257 | + ] | |
| 258 | + .map(|(name, value)| { | |
| 259 | + words(format!("{name} {value:.0} %"), Text::Caption, Ink::Faint, t) | |
| 260 | + }), | |
| 261 | + ) | |
| 262 | + })) | |
| 263 | + .child(line_row( | |
| 264 | + label("memory", t), | |
| 265 | + over( | |
| 266 | + memory.own_mb as f32 / total_mb, | |
| 267 | + memory.used_mb as f32 / total_mb, | |
| 268 | + ), | |
| 269 | + format!("{} / {}", gb(memory.own_mb), gb(memory.total_mb)), | |
| 270 | + false, | |
| 271 | + t, | |
| 475 | 272 | )) |
| 273 | + .children(usage.gpu.as_ref().map(|gpu| { | |
| 274 | + let machine = gpu.machine; | |
| 275 | + let vram_total = machine.vram_total_mb.max(machine.vram_used_mb).max(1) as f32; | |
| 276 | + stack(space::XS) | |
| 277 | + .child(line_row( | |
| 278 | + label("GPU 3d", t), | |
| 279 | + over(gpu.gfx / 100., machine.gfx / 100.), | |
| 280 | + format!("{:.0} / {:.0} %", gpu.gfx, machine.gfx), | |
| 281 | + false, | |
| 282 | + t, | |
| 283 | + )) | |
| 284 | + .child(line_row( | |
| 285 | + label("video", t), | |
| 286 | + over(gpu.video / 100., machine.video / 100.), | |
| 287 | + format!("{:.0} / {:.0} %", gpu.video, machine.video), | |
| 288 | + false, | |
| 289 | + t, | |
| 290 | + )) | |
| 291 | + .child(line_row( | |
| 292 | + label("vram", t), | |
| 293 | + over( | |
| 294 | + gpu.vram_mb as f32 / vram_total, | |
| 295 | + machine.vram_used_mb as f32 / vram_total, | |
| 296 | + ), | |
| 297 | + format!("{} / {}", gb(gpu.vram_mb), gb(machine.vram_total_mb)), | |
| 298 | + false, | |
| 299 | + t, | |
| 300 | + )) | |
| 301 | + })) | |
| 302 | +} | |
| 303 | + | |
| 304 | +fn sending(sending: &[(Kind, LayerStats)], t: Tokens) -> Vec<Div> { | |
| 305 | + [Kind::Screen, Kind::Camera] | |
| 306 | + .into_iter() | |
| 307 | + .filter_map(|kind| { | |
| 308 | + let layers: Vec<&LayerStats> = sending | |
| 309 | + .iter() | |
| 310 | + .filter(|(sent, _)| *sent == kind) | |
| 311 | + .map(|(_, stats)| stats) | |
| 312 | + .collect(); | |
| 313 | + let last = layers.last()?; | |
| 314 | + let max = largest(layers.iter().map(|stats| stats.kbps)); | |
| 315 | + let name = match kind { | |
| 316 | + Kind::Screen => "Sending screen", | |
| 317 | + Kind::Camera => "Sending camera", | |
| 318 | + }; | |
| 319 | + Some( | |
| 320 | + stack(space::XS) | |
| 321 | + .child(title( | |
| 322 | + name, | |
| 323 | + format!( | |
| 324 | + "{} · {}", | |
| 325 | + last.layer.codec.name(), | |
| 326 | + engine_label(last.engine) | |
| 327 | + ), | |
| 328 | + None, | |
| 329 | + t, | |
| 330 | + )) | |
| 331 | + .children(layers.iter().rev().map(|stats| { | |
| 332 | + line_row( | |
| 333 | + words( | |
| 334 | + resolution_text(stats.layer, stats.fps), | |
| 335 | + Text::Caption, | |
| 336 | + Ink::Dim, | |
| 337 | + t, | |
| 338 | + ) | |
| 339 | + .into_any_element(), | |
| 340 | + track(Fill::Part(stats.kbps as f32 / max), false, t).into_any_element(), | |
| 341 | + rate(stats.kbps), | |
| 342 | + false, | |
| 343 | + t, | |
| 344 | + ) | |
| 345 | + })), | |
| 346 | + ) | |
| 347 | + }) | |
| 348 | + .collect() | |
| 476 | 349 | } |
| 477 | 350 | |
| 478 | -fn gb(mb: u32) -> String { | |
| 479 | - match mb { | |
| 480 | - 0..1000 => format!("{mb} M"), | |
| 481 | - _ => format!("{:.1} G", mb as f32 / 1024.), | |
| 351 | +fn watching(watching: &[(Id, Kind, WatchStats)], chat: &Chat, t: Tokens) -> Option<Div> { | |
| 352 | + if watching.is_empty() { | |
| 353 | + return None; | |
| 482 | 354 | } |
| 483 | -} | |
| 484 | - | |
| 485 | -fn dual(label: &'static str, own: f32, machine: f32, color: Hsla, palette: Palette) -> Div { | |
| 486 | - dual_value( | |
| 487 | - label, | |
| 488 | - format!("{own:.0} / {machine:.0} %"), | |
| 489 | - own / 100., | |
| 490 | - machine / 100., | |
| 491 | - color, | |
| 492 | - palette, | |
| 493 | - ) | |
| 494 | -} | |
| 495 | - | |
| 496 | -fn dual_value( | |
| 497 | - label: &'static str, | |
| 498 | - value: String, | |
| 499 | - own: f32, | |
| 500 | - machine: f32, | |
| 501 | - color: Hsla, | |
| 502 | - palette: Palette, | |
| 503 | -) -> Div { | |
| 504 | - row( | |
| 505 | - label, | |
| 506 | - value, | |
| 507 | - dual_bar(own, machine, color, palette), | |
| 508 | - palette, | |
| 509 | - ) | |
| 510 | -} | |
| 511 | - | |
| 512 | -fn meter(label: &'static str, percent: f32, color: Hsla, palette: Palette) -> Div { | |
| 513 | - meter_value( | |
| 514 | - label, | |
| 515 | - format!("{percent:.1} %"), | |
| 516 | - percent / 100., | |
| 517 | - color, | |
| 518 | - palette, | |
| 355 | + let max = largest(watching.iter().map(|(_, _, stats)| stats.kbps)); | |
| 356 | + let latency = watching | |
| 357 | + .iter() | |
| 358 | + .filter_map(|(_, _, stats)| stats.latency_ms) | |
| 359 | + .max(); | |
| 360 | + let loss = watching | |
| 361 | + .iter() | |
| 362 | + .map(|(_, _, stats)| stats.loss) | |
| 363 | + .fold(0., f32::max) | |
| 364 | + * 100.; | |
| 365 | + let keyframes: u32 = watching.iter().map(|(_, _, stats)| stats.keyframes).sum(); | |
| 366 | + let nacks: u32 = watching.iter().map(|(_, _, stats)| stats.nacks).sum(); | |
| 367 | + let count = watching.len(); | |
| 368 | + | |
| 369 | + Some( | |
| 370 | + stack(space::XS) | |
| 371 | + .child(title( | |
| 372 | + "Watching", | |
| 373 | + format!("{count} {}", if count == 1 { "stream" } else { "streams" }), | |
| 374 | + None, | |
| 375 | + t, | |
| 376 | + )) | |
| 377 | + .children(watching.iter().map(|(user_id, kind, stats)| { | |
| 378 | + let name = chat | |
| 379 | + .author(*user_id) | |
| 380 | + .map_or_else(|| user_id.to_string(), |user| user.username.clone()); | |
| 381 | + let detail = format!( | |
| 382 | + "{} · {}", | |
| 383 | + kind_word(*kind), | |
| 384 | + stats | |
| 385 | + .layer | |
| 386 | + .map_or("…".to_string(), |layer| resolution_text(layer, stats.fps)) | |
| 387 | + ); | |
| 388 | + let bad = Quality::of_loss(stats.loss * 100.) == Quality::Poor; | |
| 389 | + line_row( | |
| 390 | + band(space::XS) | |
| 391 | + .child( | |
| 392 | + words(name, Text::Label, Ink::Paper, t) | |
| 393 | + .text_color(t.person(*user_id)) | |
| 394 | + .flex_none(), | |
| 395 | + ) | |
| 396 | + .child(words(detail, Text::Caption, Ink::Faint, t)) | |
| 397 | + .into_any_element(), | |
| 398 | + track(Fill::Part(stats.kbps as f32 / max), bad, t).into_any_element(), | |
| 399 | + rate(stats.kbps), | |
| 400 | + bad, | |
| 401 | + t, | |
| 402 | + ) | |
| 403 | + })) | |
| 404 | + .child( | |
| 405 | + band(space::MD) | |
| 406 | + .child(words( | |
| 407 | + format!( | |
| 408 | + "latency {}", | |
| 409 | + latency.map_or("…".into(), |ms| format!("{ms} ms")) | |
| 410 | + ), | |
| 411 | + Text::Caption, | |
| 412 | + Ink::Faint, | |
| 413 | + t, | |
| 414 | + )) | |
| 415 | + .child(words( | |
| 416 | + format!("loss {loss:.1} %"), | |
| 417 | + Text::Caption, | |
| 418 | + if loss > GOOD_LOSS { | |
| 419 | + Ink::Bad | |
| 420 | + } else { | |
| 421 | + Ink::Faint | |
| 422 | + }, | |
| 423 | + t, | |
| 424 | + )) | |
| 425 | + .child(words( | |
| 426 | + format!("keyframes {keyframes}"), | |
| 427 | + Text::Caption, | |
| 428 | + Ink::Faint, | |
| 429 | + t, | |
| 430 | + )) | |
| 431 | + .child(words( | |
| 432 | + format!("NACKs {nacks}"), | |
| 433 | + Text::Caption, | |
| 434 | + Ink::Faint, | |
| 435 | + t, | |
| 436 | + )), | |
| 437 | + ), | |
| 519 | 438 | ) |
| 520 | 439 | } |
| 521 | 440 | |
| 522 | -fn meter_value( | |
| 523 | - label: &'static str, | |
| 524 | - value: String, | |
| 525 | - fraction: f32, | |
| 526 | - color: Hsla, | |
| 527 | - palette: Palette, | |
| 528 | -) -> Div { | |
| 529 | - row(label, value, bar(fraction, color, palette), palette) | |
| 530 | -} | |
| 531 | - | |
| 532 | -fn row(label: &'static str, value: String, bar: Div, palette: Palette) -> Div { | |
| 533 | - div() | |
| 534 | - .flex() | |
| 535 | - .items_center() | |
| 536 | - .gap(px(space::SM)) | |
| 537 | - .text_size(text_size(text::CAPTION)) | |
| 538 | - .child( | |
| 539 | - div() | |
| 540 | - .w(px(size::ROW)) | |
| 541 | - .flex_none() | |
| 542 | - .text_color(palette.muted) | |
| 543 | - .child(label), | |
| 544 | - ) | |
| 545 | - .child(bar) | |
| 546 | - .child( | |
| 547 | - div() | |
| 548 | - .w(px(VALUE_W)) | |
| 549 | - .flex_none() | |
| 550 | - .text_right() | |
| 551 | - .text_color(palette.text) | |
| 552 | - .child(value), | |
| 553 | - ) | |
| 554 | -} | |
| 555 | - | |
| 556 | -fn kind_color(kind: Kind, palette: Palette) -> Hsla { | |
| 441 | +fn kind_word(kind: Kind) -> &'static str { | |
| 557 | 442 | match kind { |
| 558 | - Kind::Camera => palette.camera, | |
| 559 | - Kind::Screen => palette.screen, | |
| 443 | + Kind::Camera => "camera", | |
| 444 | + Kind::Screen => "screen", | |
| 560 | 445 | } |
| 561 | 446 | } |
| 562 | 447 | |
| 563 | -fn kind_name(kind: Kind) -> &'static str { | |
| 564 | - match kind { | |
| 565 | - Kind::Camera => "Camera", | |
| 566 | - Kind::Screen => "Screen", | |
| 448 | +fn gb(mb: u32) -> String { | |
| 449 | + match mb { | |
| 450 | + 0..1000 => format!("{mb} MB"), | |
| 451 | + _ => format!("{:.1} GB", mb as f32 / 1024.), | |
| 567 | 452 | } |
| 568 | 453 | } |
| 569 | 454 | |
| @@ -573,132 +458,22 @@ fn largest(values: impl Iterator<Item = u32>) -> f32 { | ||
| 573 | 458 | |
| 574 | 459 | pub fn rate(kbps: u32) -> String { |
| 575 | 460 | match kbps { |
| 576 | - 0..1000 => format!("{kbps} kbps"), | |
| 577 | - _ => format!("{:.1} Mbps", kbps as f32 / 1000.), | |
| 461 | + 0..1000 => format!("{kbps} kb/s"), | |
| 462 | + _ => format!("{:.1} Mb/s", kbps as f32 / 1000.), | |
| 578 | 463 | } |
| 579 | 464 | } |
| 580 | 465 | |
| 581 | 466 | fn engine_label(engine: Engine) -> &'static str { |
| 582 | 467 | match engine { |
| 583 | - Engine::Hardware => "HW", | |
| 584 | - Engine::Software => "SW", | |
| 468 | + Engine::Hardware => "hardware", | |
| 469 | + Engine::Software => "software", | |
| 585 | 470 | } |
| 586 | 471 | } |
| 587 | 472 | |
| 588 | 473 | fn resolution_text(layer: Layer, fps: f32) -> String { |
| 589 | 474 | format!( |
| 590 | - "{}p{}", | |
| 475 | + "{}p {}", | |
| 591 | 476 | layer.quality.resolution.height(), |
| 592 | 477 | fps.round() as u32 |
| 593 | 478 | ) |
| 594 | 479 | } |
| 595 | - | |
| 596 | -fn header(icon: IconName, title: &'static str, color: Hsla) -> Div { | |
| 597 | - div() | |
| 598 | - .flex() | |
| 599 | - .items_center() | |
| 600 | - .gap(px(space::SM)) | |
| 601 | - .child( | |
| 602 | - Icon::new(icon) | |
| 603 | - .size(px(size::ICON_SM)) | |
| 604 | - .flex_none() | |
| 605 | - .text_color(color), | |
| 606 | - ) | |
| 607 | - .child( | |
| 608 | - div() | |
| 609 | - .font_weight(FontWeight::SEMIBOLD) | |
| 610 | - .text_size(text_size(text::CAPTION)) | |
| 611 | - .text_color(color) | |
| 612 | - .child(title), | |
| 613 | - ) | |
| 614 | - .child(div().flex_1()) | |
| 615 | -} | |
| 616 | - | |
| 617 | -fn label(value: &'static str, color: Hsla) -> Div { | |
| 618 | - div() | |
| 619 | - .text_size(text_size(text::CAPTION)) | |
| 620 | - .text_color(color) | |
| 621 | - .child(value) | |
| 622 | -} | |
| 623 | - | |
| 624 | -fn chip(value: impl gpui_kit::IntoElement, color: Hsla, palette: Palette) -> Div { | |
| 625 | - div() | |
| 626 | - .flex_none() | |
| 627 | - .px(px(space::SM)) | |
| 628 | - .py(px(space::XXS)) | |
| 629 | - .rounded(px(radius::SM)) | |
| 630 | - .bg(palette.hover) | |
| 631 | - .text_size(text_size(text::CAPTION)) | |
| 632 | - .text_color(color) | |
| 633 | - .child(value) | |
| 634 | -} | |
| 635 | - | |
| 636 | -fn stat_cell(label: &'static str, value: String, color: Hsla, palette: Palette) -> Div { | |
| 637 | - div() | |
| 638 | - .flex_1() | |
| 639 | - .min_w_0() | |
| 640 | - .flex() | |
| 641 | - .flex_col() | |
| 642 | - .gap(px(space::XXS)) | |
| 643 | - .child( | |
| 644 | - div() | |
| 645 | - .text_size(text_size(text::CAPTION)) | |
| 646 | - .text_color(palette.muted) | |
| 647 | - .child(label), | |
| 648 | - ) | |
| 649 | - .child( | |
| 650 | - div() | |
| 651 | - .text_size(text_size(text::UI)) | |
| 652 | - .text_color(color) | |
| 653 | - .child(value), | |
| 654 | - ) | |
| 655 | -} | |
| 656 | - | |
| 657 | -fn avatar_dot(name: &str, color: Hsla, palette: Palette) -> Div { | |
| 658 | - let initial = name | |
| 659 | - .chars() | |
| 660 | - .next() | |
| 661 | - .map_or('?', |letter| letter.to_ascii_uppercase()); | |
| 662 | - div() | |
| 663 | - .size(px(size::CHIP)) | |
| 664 | - .flex_none() | |
| 665 | - .rounded_full() | |
| 666 | - .flex() | |
| 667 | - .items_center() | |
| 668 | - .justify_center() | |
| 669 | - .bg(color) | |
| 670 | - .text_size(text_size(text::CAPTION)) | |
| 671 | - .font_weight(FontWeight::BOLD) | |
| 672 | - .text_color(palette.on_accent) | |
| 673 | - .child(initial.to_string()) | |
| 674 | -} | |
| 675 | - | |
| 676 | -fn dual_bar(own: f32, machine: f32, color: Hsla, palette: Palette) -> Div { | |
| 677 | - bar(machine, palette.tokens.faint(), palette).child( | |
| 678 | - div() | |
| 679 | - .absolute() | |
| 680 | - .top_0() | |
| 681 | - .left_0() | |
| 682 | - .h_full() | |
| 683 | - .w(relative(own.clamp(0., 1.))) | |
| 684 | - .rounded_full() | |
| 685 | - .bg(color), | |
| 686 | - ) | |
| 687 | -} | |
| 688 | - | |
| 689 | -fn bar(fraction: f32, color: Hsla, palette: Palette) -> Div { | |
| 690 | - div() | |
| 691 | - .relative() | |
| 692 | - .flex_1() | |
| 693 | - .min_w_0() | |
| 694 | - .h(px(space::XS)) | |
| 695 | - .rounded_full() | |
| 696 | - .bg(palette.border) | |
| 697 | - .child( | |
| 698 | - div() | |
| 699 | - .h_full() | |
| 700 | - .w(relative(fraction.clamp(0., 1.))) | |
| 701 | - .rounded_full() | |
| 702 | - .bg(color), | |
| 703 | - ) | |
| 704 | -} |
crates/client/src/usage/drm.rsmodified+4 -4
| @@ -167,10 +167,10 @@ fn machine_clients(pdev: &str) -> Vec<Client> { | ||
| 167 | 167 | let Ok(info) = fs::read_to_string(path.join("fdinfo").join(fd.file_name())) else { |
| 168 | 168 | continue; |
| 169 | 169 | }; |
| 170 | - if let Some(client) = client(&info) { | |
| 171 | - if client.pdev == pdev { | |
| 172 | - clients.push(client); | |
| 173 | - } | |
| 170 | + if let Some(client) = client(&info) | |
| 171 | + && client.pdev == pdev | |
| 172 | + { | |
| 173 | + clients.push(client); | |
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | } |
crates/common/src/call.rsmodified+7 -0
| @@ -3,6 +3,7 @@ use bitcode::{Decode, DecodeOwned, Encode}; | ||
| 3 | 3 | use crate::{ |
| 4 | 4 | constant::{MAXIMUM_AVATAR_BYTES, MAXIMUM_MESSAGE_LENGTH}, |
| 5 | 5 | error::Error, |
| 6 | + model::Hue, | |
| 6 | 7 | model::{ |
| 7 | 8 | Account, AdminActionKind, AdminLogEntry, AttachmentInfo, BackupInfo, Ban, BanScope, |
| 8 | 9 | Community, CommunitySummary, CommunityUsage, DayStat, Friends, Id, Invitation, InviteCode, |
| @@ -80,6 +81,11 @@ pub struct UpdateStatus { | ||
| 80 | 81 | pub status: String, |
| 81 | 82 | } |
| 82 | 83 | |
| 84 | +#[derive(Debug, Clone, Encode, Decode)] | |
| 85 | +pub struct UpdateHue { | |
| 86 | + pub hue: Option<Hue>, | |
| 87 | +} | |
| 88 | + | |
| 83 | 89 | #[derive(Debug, Clone, Encode, Decode)] |
| 84 | 90 | pub struct UpdatePresence { |
| 85 | 91 | pub presence: Presence, |
| @@ -635,6 +641,7 @@ calls! { | ||
| 635 | 641 | GetUser: User -> User; |
| 636 | 642 | UpdateUser: User -> User, |c| validate_username(&c.username); |
| 637 | 643 | UpdateStatus: User -> User, |c| validate_status(&c.status); |
| 644 | + UpdateHue: User -> User; | |
| 638 | 645 | UpdatePresence: User -> (); |
| 639 | 646 | ListPresences: User -> Vec<(Id, Presence)>; |
| 640 | 647 | UpdateAvatar: User -> User, |c| validate_avatar_size(&c.image, MAXIMUM_AVATAR_BYTES as u64); |
crates/common/src/model.rsmodified+1 -0
| @@ -127,6 +127,7 @@ pub struct User { | ||
| 127 | 127 | pub username: String, |
| 128 | 128 | pub role: Role, |
| 129 | 129 | pub status: String, |
| 130 | + pub hue: Option<Hue>, | |
| 130 | 131 | pub avatar_id: Option<Id>, |
| 131 | 132 | pub created_at: u64, |
| 132 | 133 | } |
crates/server/src/call/mod.rsmodified+1 -0
| @@ -110,6 +110,7 @@ pub(crate) async fn dispatch(request: Request, cx: &mut Cx<'_>) -> Vec<u8> { | ||
| 110 | 110 | Request::GetUser(call) => serve(call, cx).await, |
| 111 | 111 | Request::UpdateUser(call) => serve(call, cx).await, |
| 112 | 112 | Request::UpdateStatus(call) => serve(call, cx).await, |
| 113 | + Request::UpdateHue(call) => serve(call, cx).await, | |
| 113 | 114 | Request::UpdatePresence(call) => serve(call, cx).await, |
| 114 | 115 | Request::ListPresences(call) => serve(call, cx).await, |
| 115 | 116 | Request::UpdateAvatar(call) => serve(call, cx).await, |
crates/server/src/call/user.rsmodified+11 -1
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | use common::{ |
| 2 | 2 | call::{ |
| 3 | 3 | GetAvatar, GetSettings, GetUser, ListPresences, ListSessions, RemoveAvatar, RevokeSession, |
| 4 | - UpdateAvatar, UpdatePresence, UpdateStatus, UpdateUser, | |
| 4 | + UpdateAvatar, UpdateHue, UpdatePresence, UpdateStatus, UpdateUser, | |
| 5 | 5 | }, |
| 6 | 6 | event::Event, |
| 7 | 7 | model::{AdminAction, Id, Presence, ServerSettings, SessionInfo, User}, |
| @@ -54,6 +54,16 @@ impl Handle for UpdateStatus { | ||
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | +impl Handle for UpdateHue { | |
| 58 | + async fn handle(self, me: Me, cx: &mut Cx<'_>) -> Result<User, ServerError> { | |
| 59 | + let me = me.user()?; | |
| 60 | + let user = db::user::update_hue(me.id, self.hue, cx.db).await?; | |
| 61 | + user_updated(&user, cx); | |
| 62 | + | |
| 63 | + Ok(user) | |
| 64 | + } | |
| 65 | +} | |
| 66 | + | |
| 57 | 67 | impl Handle for UpdatePresence { |
| 58 | 68 | async fn handle(self, me: Me, cx: &mut Cx<'_>) -> Result<(), ServerError> { |
| 59 | 69 | let me = me.user()?; |
crates/server/src/db/schema.sqlmodified+1 -0
| @@ -4,6 +4,7 @@ CREATE TABLE user ( | ||
| 4 | 4 | password_hash TEXT NOT NULL, |
| 5 | 5 | role TEXT NOT NULL, |
| 6 | 6 | status TEXT NOT NULL DEFAULT '', |
| 7 | + hue TEXT, | |
| 7 | 8 | presence TEXT NOT NULL, |
| 8 | 9 | suspended INTEGER NOT NULL DEFAULT 0, |
| 9 | 10 | suspended_until INTEGER, |
crates/server/src/db/user.rsmodified+16 -2
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | use common::{ |
| 2 | 2 | error::Error, |
| 3 | - model::{Account, Id, Presence, Role, User}, | |
| 3 | + model::{Account, Hue, Id, Presence, Role, User}, | |
| 4 | 4 | permission, |
| 5 | 5 | time::now_ms, |
| 6 | 6 | }; |
| @@ -8,7 +8,7 @@ use common::{ | ||
| 8 | 8 | use super::{Connection, Reader, all, maybe, one, run}; |
| 9 | 9 | use crate::error::{ServerError, ensure_with}; |
| 10 | 10 | |
| 11 | -pub const COLUMNS: &str = "user.id, user.username, user.role, user.status, (SELECT avatar.id FROM avatar WHERE avatar.user_id = user.id), user.created_at"; | |
| 11 | +pub const COLUMNS: &str = "user.id, user.username, user.role, user.status, user.hue, (SELECT avatar.id FROM avatar WHERE avatar.user_id = user.id), user.created_at"; | |
| 12 | 12 | |
| 13 | 13 | pub fn row(r: &mut Reader) -> Result<User, ServerError> { |
| 14 | 14 | Ok(User { |
| @@ -16,6 +16,9 @@ pub fn row(r: &mut Reader) -> Result<User, ServerError> { | ||
| 16 | 16 | username: r.get()?, |
| 17 | 17 | role: r.named()?, |
| 18 | 18 | status: r.get()?, |
| 19 | + hue: r | |
| 20 | + .get::<Option<String>>()? | |
| 21 | + .and_then(|text| Hue::parse(&text)), | |
| 19 | 22 | avatar_id: r.get()?, |
| 20 | 23 | created_at: r.get()?, |
| 21 | 24 | }) |
| @@ -92,6 +95,17 @@ pub async fn update(id: Id, username: &str, db: &Connection) -> Result<User, Ser | ||
| 92 | 95 | read(id, db).await |
| 93 | 96 | } |
| 94 | 97 | |
| 98 | +pub async fn update_hue(id: Id, hue: Option<Hue>, db: &Connection) -> Result<User, ServerError> { | |
| 99 | + run( | |
| 100 | + db, | |
| 101 | + "UPDATE user SET hue = ?2 WHERE id = ?1", | |
| 102 | + (id, hue.map(|hue| hue.as_str())), | |
| 103 | + ) | |
| 104 | + .await?; | |
| 105 | + | |
| 106 | + read(id, db).await | |
| 107 | +} | |
| 108 | + | |
| 95 | 109 | pub async fn update_status(id: Id, status: &str, db: &Connection) -> Result<User, ServerError> { |
| 96 | 110 | run( |
| 97 | 111 | db, |