BlueGit

ict rusty-teams

Files

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

title_bar.rs

title_bar.rs 3.9 KiB Download Raw
1use std::sync::{Arc, OnceLock};
2
3use gpui_kit::assets::IconName;
4use gpui_kit::component::{TitleBar, h_flex};
5use gpui_kit::prelude::FluentBuilder as _;
6use gpui_kit::*;
7
8use super::avatar::{person_avatar, with_presence};
9use super::widgets::{count_badge, icon, symbol};
10use crate::data::Directory;
11use crate::theme;
12
13pub const TITLE_BAR_HEIGHT: f32 = 40.;
14const SEARCH_WIDTH: f32 = 380.;
15const SEARCH_HINT: &str = "Search chats, people and channels";
16const SHORTCUT_HINT: &str = "Ctrl K";
17const OWN_AVATAR_SIZE: f32 = 26.;
18const APP_ICON_SIZE: f32 = 18.;
19const APP_ICON_PNG: &[u8] = include_bytes!("../../assets/icon/teams-fast-256.png");
20
21fn app_icon() -> Arc<Image> {
22 static ICON: OnceLock<Arc<Image>> = OnceLock::new();
23 ICON.get_or_init(|| Arc::new(Image::from_bytes(ImageFormat::Png, APP_ICON_PNG.to_vec())))
24 .clone()
25}
26
27pub fn render_title_bar(
28 directory: &Directory,
29 activity_unread: usize,
30 on_search: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
31 on_notifications: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
32) -> impl IntoElement {
33 let notifications = div()
34 .id("title-notifications")
35 .relative()
36 .occlude()
37 .size(px(28.))
38 .flex()
39 .flex_none()
40 .items_center()
41 .justify_center()
42 .rounded(px(6.))
43 .cursor_pointer()
44 .hover(|button| button.bg(theme::surface()))
45 .child(symbol("notifications", 18., theme::text_muted()))
46 .when(activity_unread > 0, |bell| {
47 bell.child(
48 div()
49 .absolute()
50 .top(px(-4.))
51 .right(px(-6.))
52 .child(count_badge(
53 activity_unread.min(u32::MAX as usize) as u32,
54 false,
55 )),
56 )
57 })
58 .on_click(on_notifications);
59 let search = h_flex()
60 .id("title-search")
61 .occlude()
62 .w(px(SEARCH_WIDTH))
63 .h(px(28.))
64 .px(px(10.))
65 .gap(px(8.))
66 .items_center()
67 .rounded(px(6.))
68 .bg(theme::surface())
69 .border_1()
70 .border_color(theme::border())
71 .cursor_pointer()
72 .text_size(px(12.))
73 .text_color(theme::text_muted())
74 .hover(|field| field.border_color(theme::border_strong()))
75 .child(icon(IconName::Search, 14., theme::text_muted()))
76 .child(div().flex_1().child(SEARCH_HINT))
77 .child(
78 div()
79 .px(px(6.))
80 .py(px(1.))
81 .rounded(px(4.))
82 .border_1()
83 .border_color(theme::border_strong())
84 .text_size(px(11.))
85 .child(SHORTCUT_HINT),
86 )
87 .on_click(on_search);
88 let own = directory.me.as_ref().map(|me| {
89 let avatar = person_avatar(
90 directory,
91 Some(&me.user_id),
92 &me.display_name,
93 OWN_AVATAR_SIZE,
94 );
95 with_presence(
96 avatar,
97 directory.presence_of(&me.user_id),
98 OWN_AVATAR_SIZE,
99 theme::background(),
100 )
101 });
102 TitleBar::new()
103 .h(px(TITLE_BAR_HEIGHT))
104 .bg(theme::background())
105 .child(
106 h_flex()
107 .flex_1()
108 .h_full()
109 .gap(px(12.))
110 .items_center()
111 .child(img(app_icon()).size(px(APP_ICON_SIZE)).flex_none())
112 .child(
113 div()
114 .text_size(px(13.))
115 .font_weight(FontWeight::SEMIBOLD)
116 .text_color(theme::text())
117 .child(crate::APP_NAME),
118 )
119 .child(div().flex_1().flex().justify_center().child(search))
120 .child(notifications)
121 .children(own)
122 .child(div().w(px(4.))),
123 )
124}