| 1 | use std::sync::{Arc, OnceLock}; |
| 2 | |
| 3 | use gpui_kit::assets::IconName; |
| 4 | use gpui_kit::component::{TitleBar, h_flex}; |
| 5 | use gpui_kit::*; |
| 6 | |
| 7 | use super::widgets::icon; |
| 8 | use crate::theme; |
| 9 | |
| 10 | pub const TITLE_BAR_HEIGHT: f32 = 40.; |
| 11 | const SEARCH_WIDTH: f32 = 380.; |
| 12 | const SEARCH_HINT: &str = "Search chats, people and channels"; |
| 13 | const SHORTCUT_HINT: &str = "Ctrl K"; |
| 14 | const APP_ICON_SIZE: f32 = 18.; |
| 15 | const APP_ICON_PNG: &[u8] = include_bytes!("../../assets/icon/teams-fast-256.png"); |
| 16 | |
| 17 | fn 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 | |
| 23 | pub 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 | .debug_selector(|| "shell/title-bar/search".into()) |
| 30 | .occlude() |
| 31 | .w(px(SEARCH_WIDTH)) |
| 32 | .h(px(28.)) |
| 33 | .px(px(10.)) |
| 34 | .gap(px(8.)) |
| 35 | .items_center() |
| 36 | .rounded(px(6.)) |
| 37 | .bg(theme::surface()) |
| 38 | .cursor_pointer() |
| 39 | .text_size(px(12.)) |
| 40 | .text_color(theme::text_muted()) |
| 41 | .child(icon(IconName::Search, 14., theme::text_muted())) |
| 42 | .child(div().flex_1().child(SEARCH_HINT)) |
| 43 | .child( |
| 44 | div() |
| 45 | .px(px(6.)) |
| 46 | .py(px(1.)) |
| 47 | .rounded(px(4.)) |
| 48 | .bg(theme::surface_raised()) |
| 49 | .text_size(px(11.)) |
| 50 | .child(SHORTCUT_HINT), |
| 51 | ) |
| 52 | .on_click(on_search); |
| 53 | let bar = TitleBar::new() |
| 54 | .h(px(TITLE_BAR_HEIGHT)) |
| 55 | .bg(theme::background()) |
| 56 | .child( |
| 57 | h_flex() |
| 58 | .flex_1() |
| 59 | .h_full() |
| 60 | .gap(px(12.)) |
| 61 | .items_center() |
| 62 | .child(img(app_icon()).size(px(APP_ICON_SIZE)).flex_none()) |
| 63 | .child( |
| 64 | div() |
| 65 | .text_size(px(13.)) |
| 66 | .font_weight(FontWeight::SEMIBOLD) |
| 67 | .text_color(theme::text()) |
| 68 | .child(crate::APP_NAME), |
| 69 | ) |
| 70 | .child(div().flex_1().flex().justify_center().child(search)) |
| 71 | .children(own) |
| 72 | .child(div().w(px(4.))), |
| 73 | ); |
| 74 | div() |
| 75 | .debug_selector(|| "shell/title-bar".into()) |
| 76 | .flex_none() |
| 77 | .w_full() |
| 78 | .child(bar) |
| 79 | } |