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