Files
novem/src/titlebar.rs

80 lines
1.9 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;
use crate::query::{QueryStatus, read_query, use_query};
use crate::{
api, app,
component::{
font_icon::{FontIcon, font_icon},
text::text,
},
};
2026-04-20 15:13:26 +01:00
pub struct TitleBar {}
pub struct RepoSelector {}
2026-04-21 11:50:04 +01:00
impl TitleBar {
pub fn new(cx: &mut gpui::Context<Self>) -> Self {
use_query(api::user::Fetch, cx);
Self {}
}
}
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 11:50:04 +01:00
let user = read_query(api::user::Fetch, cx);
let user_avatar = match user {
QueryStatus::Err(api::Error::Unauthenticated) => div()
.absolute()
.right_2p5()
.child(button("login-btn", cx).label("Login")),
_ => 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())
}