BlueGit

ict rusty-teams

Files

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

title_bar.rs

Initial commit
metis Daniel Däschle · pushed by metis · 7 weeks ago
06e0ae51 History
title_bar.rs 2.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::*;
6
7use super::avatar::{person_avatar, with_presence};
8use super::widgets::icon;
9use crate::data::Directory;
10use crate::theme;
11
12pub const TITLE_BAR_HEIGHT: f32 = 40.;
13const SEARCH_WIDTH: f32 = 380.;
14const SEARCH_HINT: &str = "Chats, Personen, Channels suchen";
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) -> impl IntoElement {
30 let search = h_flex()
31 .id("title-search")
32 .occlude()
33 .w(px(SEARCH_WIDTH))
34 .h(px(28.))
35 .px(px(10.))
36 .gap(px(8.))
37 .items_center()
38 .rounded(px(6.))
39 .bg(theme::surface())
40 .border_1()
41 .border_color(theme::border())
42 .cursor_pointer()
43 .text_size(px(12.))
44 .text_color(theme::text_muted())
45 .hover(|field| field.border_color(theme::border_strong()))
46 .child(icon(IconName::Search, 14., theme::text_muted()))
47 .child(div().flex_1().child(SEARCH_HINT))
48 .child(
49 div()
50 .px(px(6.))
51 .py(px(1.))
52 .rounded(px(4.))
53 .border_1()
54 .border_color(theme::border_strong())
55 .text_size(px(11.))
56 .child(SHORTCUT_HINT),
57 )
58 .on_click(on_search);
59 let own = directory.me.as_ref().map(|me| {
60 let avatar = person_avatar(
61 directory,
62 Some(&me.user_id),
63 &me.display_name,
64 OWN_AVATAR_SIZE,
65 );
66 with_presence(
67 avatar,
68 directory.presence_of(&me.user_id),
69 OWN_AVATAR_SIZE,
70 theme::background(),
71 )
72 });
73 TitleBar::new()
74 .h(px(TITLE_BAR_HEIGHT))
75 .bg(theme::background())
76 .child(
77 h_flex()
78 .flex_1()
79 .h_full()
80 .gap(px(12.))
81 .items_center()
82 .child(img(app_icon()).size(px(APP_ICON_SIZE)).flex_none())
83 .child(
84 div()
85 .text_size(px(13.))
86 .font_weight(FontWeight::SEMIBOLD)
87 .text_color(theme::text())
88 .child(crate::APP_NAME),
89 )
90 .child(div().flex_1().flex().justify_center().child(search))
91 .children(own)
92 .child(div().w(px(4.))),
93 )
94}