BlueGit

ict rusty-teams

Files

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

title_bar.rs

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