BlueGit

ict rusty-teams

Files

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

title_bar.rs

title_bar.rs 2.2 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::widgets::icon;
8use crate::theme;
9
10pub const TITLE_BAR_HEIGHT: f32 = 40.;
11const SEARCH_WIDTH: f32 = 380.;
12const SEARCH_HINT: &str = "Search chats, people and channels";
13const SHORTCUT_HINT: &str = "Ctrl K";
14const APP_ICON_SIZE: f32 = 18.;
15const APP_ICON_PNG: &[u8] = include_bytes!("../../assets/icon/teams-fast-256.png");
16
17fn app_icon() -> Arc<Image> {
18 static ICON: OnceLock<Arc<Image>> = OnceLock::new();
19 ICON.get_or_init(|| Arc::new(Image::from_bytes(ImageFormat::Png, APP_ICON_PNG.to_vec())))
20 .clone()
21}
22
23pub fn render_title_bar(
24 own: Option<AnyElement>,
25 on_search: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
26) -> impl IntoElement {
27 let search = h_flex()
28 .id("title-search")
29 .occlude()
30 .w(px(SEARCH_WIDTH))
31 .h(px(28.))
32 .px(px(10.))
33 .gap(px(8.))
34 .items_center()
35 .rounded(px(6.))
36 .bg(theme::surface())
37 .cursor_pointer()
38 .text_size(px(12.))
39 .text_color(theme::text_muted())
40 .child(icon(IconName::Search, 14., theme::text_muted()))
41 .child(div().flex_1().child(SEARCH_HINT))
42 .child(
43 div()
44 .px(px(6.))
45 .py(px(1.))
46 .rounded(px(4.))
47 .bg(theme::surface_raised())
48 .text_size(px(11.))
49 .child(SHORTCUT_HINT),
50 )
51 .on_click(on_search);
52 TitleBar::new()
53 .h(px(TITLE_BAR_HEIGHT))
54 .bg(theme::background())
55 .child(
56 h_flex()
57 .flex_1()
58 .h_full()
59 .gap(px(12.))
60 .items_center()
61 .child(img(app_icon()).size(px(APP_ICON_SIZE)).flex_none())
62 .child(
63 div()
64 .text_size(px(13.))
65 .font_weight(FontWeight::SEMIBOLD)
66 .text_color(theme::text())
67 .child(crate::APP_NAME),
68 )
69 .child(div().flex_1().flex().justify_center().child(search))
70 .children(own)
71 .child(div().w(px(4.))),
72 )
73}