use std::sync::{Arc, OnceLock}; use gpui_kit::assets::IconName; use gpui_kit::component::{TitleBar, h_flex}; use gpui_kit::*; use super::widgets::icon; use crate::theme; pub const TITLE_BAR_HEIGHT: f32 = 40.; const SEARCH_WIDTH: f32 = 380.; const SEARCH_HINT: &str = "Search chats, people and channels"; const SHORTCUT_HINT: &str = "Ctrl K"; const APP_ICON_SIZE: f32 = 18.; const APP_ICON_PNG: &[u8] = include_bytes!("../../assets/icon/teams-fast-256.png"); fn app_icon() -> Arc { static ICON: OnceLock> = OnceLock::new(); ICON.get_or_init(|| Arc::new(Image::from_bytes(ImageFormat::Png, APP_ICON_PNG.to_vec()))) .clone() } pub fn render_title_bar( own: Option, on_search: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static, ) -> impl IntoElement { let search = h_flex() .id("title-search") .debug_selector(|| "shell/title-bar/search".into()) .occlude() .w(px(SEARCH_WIDTH)) .h(px(28.)) .px(px(10.)) .gap(px(8.)) .items_center() .rounded(px(6.)) .bg(theme::surface()) .cursor_pointer() .text_size(px(12.)) .text_color(theme::text_muted()) .child(icon(IconName::Search, 14., theme::text_muted())) .child(div().flex_1().child(SEARCH_HINT)) .child( div() .px(px(6.)) .py(px(1.)) .rounded(px(4.)) .bg(theme::surface_raised()) .text_size(px(11.)) .child(SHORTCUT_HINT), ) .on_click(on_search); let bar = TitleBar::new() .h(px(TITLE_BAR_HEIGHT)) .bg(theme::background()) .child( h_flex() .flex_1() .h_full() .gap(px(12.)) .items_center() .child(img(app_icon()).size(px(APP_ICON_SIZE)).flex_none()) .child( div() .text_size(px(13.)) .font_weight(FontWeight::SEMIBOLD) .text_color(theme::text()) .child(crate::APP_NAME), ) .child(div().flex_1().flex().justify_center().child(search)) .children(own) .child(div().w(px(4.))), ); div() .debug_selector(|| "shell/title-bar".into()) .flex_none() .w_full() .child(bar) }