Files
novem/src/titlebar.rs

84 lines
2.1 KiB
Rust
Raw Normal View History

2026-04-21 11:50:04 +01:00
use gpui::prelude::FluentBuilder;
use gpui::{ParentElement, Styled, div};
2026-04-20 15:13:26 +01:00
2026-04-21 11:50:04 +01:00
use crate::component::button::button;
2026-04-21 20:30:41 +01:00
use crate::query::{self, QueryStatus, read_query, use_query};
2026-04-21 11:50:04 +01:00
use crate::{
api, app,
component::{
font_icon::{FontIcon, font_icon},
text::text,
},
};
2026-04-20 15:13:26 +01:00
2026-04-21 20:30:41 +01:00
pub struct TitleBar {
fetch_user_query: query::Entity<api::user::Fetch>,
}
2026-04-20 15:13:26 +01:00
pub struct RepoSelector {}
2026-04-21 11:50:04 +01:00
impl TitleBar {
pub fn new(cx: &mut gpui::Context<Self>) -> Self {
2026-04-21 20:30:41 +01:00
Self {
fetch_user_query: use_query(api::user::Fetch, cx),
}
2026-04-21 11:50:04 +01:00
}
}
2026-04-20 15:13:26 +01:00
impl gpui::Render for TitleBar {
fn render(
&mut self,
_window: &mut gpui::Window,
cx: &mut gpui::Context<Self>,
) -> impl gpui::IntoElement {
let g = cx.global::<app::Global>();
2026-04-21 20:30:41 +01:00
let user = read_query(&self.fetch_user_query, cx);
2026-04-21 11:50:04 +01:00
let user_avatar = match user {
2026-04-21 20:30:41 +01:00
QueryStatus::Err(api::Error::Unauthenticated) => div().absolute().right_2p5().child(
button("login-btn", cx)
.leading(font_icon(FontIcon::Github, cx))
.label("Login"),
),
2026-04-21 11:50:04 +01:00
_ => div(),
};
2026-04-20 15:13:26 +01:00
div()
2026-04-21 11:50:04 +01:00
.flex_row()
.justify_center()
.items_center()
2026-04-20 15:13:26 +01:00
.w_full()
2026-04-21 11:50:04 +01:00
.h_10()
2026-04-20 15:13:26 +01:00
.flex()
.px(g.safe_area.size.width)
.py_2()
2026-04-21 11:50:04 +01:00
.bg(g.current_theme.colors.background)
2026-04-20 15:13:26 +01:00
.text_color(g.current_theme.colors.text)
2026-04-21 11:50:04 +01:00
.relative()
2026-04-20 15:13:26 +01:00
.child(repo_selector(cx))
2026-04-21 11:50:04 +01:00
.child(user_avatar)
2026-04-20 15:13:26 +01:00
}
}
impl RepoSelector {
pub fn new(cx: &mut gpui::Context<Self>) -> Self {
use_query(api::repo::List, cx);
2026-04-21 11:50:04 +01:00
use_query(api::user::Fetch, cx);
2026-04-20 15:13:26 +01:00
Self {}
}
}
2026-04-21 11:50:04 +01:00
fn repo_selector<T: 'static>(cx: &gpui::Context<T>) -> gpui::Div {
2026-04-20 15:13:26 +01:00
div()
.flex()
.flex_row()
.items_center()
.gap_1()
.text_xs()
.child(font_icon(FontIcon::FolderGit, cx).size_3())
.child(text("test/repo", cx))
.child(font_icon(FontIcon::ChevronDown, cx).size_3())
}