Update assistant header

This commit is contained in:
Nate Butler 2023-12-19 10:57:36 -05:00
parent 57efaa92cf
commit 286f654517
3 changed files with 51 additions and 36 deletions

View File

@ -55,7 +55,7 @@ use std::{
use theme::ThemeSettings; use theme::ThemeSettings;
use ui::{ use ui::{
h_stack, prelude::*, v_stack, Button, ButtonLike, Icon, IconButton, IconElement, Label, TabBar, h_stack, prelude::*, v_stack, Button, ButtonLike, Icon, IconButton, IconElement, Label, TabBar,
Tooltip, Tooltip, TAB_HEIGHT_IN_REMS,
}; };
use util::{paths::CONVERSATIONS_DIR, post_inc, ResultExt, TryFutureExt}; use util::{paths::CONVERSATIONS_DIR, post_inc, ResultExt, TryFutureExt};
use uuid::Uuid; use uuid::Uuid;
@ -1129,45 +1129,36 @@ impl Render for AssistantPanel {
.border() .border()
.border_color(gpui::red()) .border_color(gpui::red())
} else { } else {
let title = self
.active_editor()
.map(|editor| Label::new(editor.read(cx).title(cx)));
// let mut header = h_stack()
// .p_1()
// .border_b()
// .border_color(cx.theme().colors().border_variant)
// .bg(cx.theme().colors().toolbar_background)
// .child(div().flex_1());
let header = TabBar::new("assistant_header") let header = TabBar::new("assistant_header")
.start_child( .start_child(
h_stack() h_stack().gap_1().child(Self::render_hamburger_button(cx)), // .children(title),
.gap_1()
.child(Self::render_hamburger_button(cx))
.children(title),
) )
.children(self.active_editor().map(|editor| {
h_stack()
.h(rems(TAB_HEIGHT_IN_REMS))
.flex_1()
.px_2()
.child(Label::new(editor.read(cx).title(cx)).into_element())
}))
.end_child(if self.focus_handle.contains_focused(cx) { .end_child(if self.focus_handle.contains_focused(cx) {
h_stack()
.gap_2()
.child(h_stack().gap_1().children(self.render_editor_tools(cx)))
.child(
ui::Divider::vertical()
.inset()
.color(ui::DividerColor::Border),
)
.child(
h_stack() h_stack()
.gap_1() .gap_1()
.children(self.render_editor_tools(cx))
.child(Self::render_plus_button(cx)) .child(Self::render_plus_button(cx))
.child(self.render_zoom_button(cx)) .child(self.render_zoom_button(cx)),
)
} else { } else {
div() div()
}); });
// if self.focus_handle.contains_focused(cx) {
// header = header.child(
// div()
// .flex()
// .gap_1()
// .children(self.render_editor_tools(cx))
// .child(Self::render_plus_button(cx))
// .child(self.render_zoom_button(cx)),
// );
// }
v_stack() v_stack()
.size_full() .size_full()
.on_action(cx.listener(|this, _: &workspace::NewFile, cx| { .on_action(cx.listener(|this, _: &workspace::NewFile, cx| {

View File

@ -1,4 +1,4 @@
use gpui::{Div, IntoElement}; use gpui::{Div, Hsla, IntoElement};
use crate::prelude::*; use crate::prelude::*;
@ -7,9 +7,26 @@ enum DividerDirection {
Vertical, Vertical,
} }
#[derive(Default)]
pub enum DividerColor {
Border,
#[default]
BorderVariant,
}
impl DividerColor {
pub fn hsla(self, cx: &WindowContext) -> Hsla {
match self {
DividerColor::Border => cx.theme().colors().border,
DividerColor::BorderVariant => cx.theme().colors().border_variant,
}
}
}
#[derive(IntoElement)] #[derive(IntoElement)]
pub struct Divider { pub struct Divider {
direction: DividerDirection, direction: DividerDirection,
color: DividerColor,
inset: bool, inset: bool,
} }
@ -26,7 +43,7 @@ impl RenderOnce for Divider {
this.w_px().h_full().when(self.inset, |this| this.my_1p5()) this.w_px().h_full().when(self.inset, |this| this.my_1p5())
} }
}) })
.bg(cx.theme().colors().border_variant) .bg(self.color.hsla(cx))
} }
} }
@ -34,6 +51,7 @@ impl Divider {
pub fn horizontal() -> Self { pub fn horizontal() -> Self {
Self { Self {
direction: DividerDirection::Horizontal, direction: DividerDirection::Horizontal,
color: DividerColor::default(),
inset: false, inset: false,
} }
} }
@ -41,6 +59,7 @@ impl Divider {
pub fn vertical() -> Self { pub fn vertical() -> Self {
Self { Self {
direction: DividerDirection::Vertical, direction: DividerDirection::Vertical,
color: DividerColor::default(),
inset: false, inset: false,
} }
} }
@ -49,4 +68,9 @@ impl Divider {
self.inset = true; self.inset = true;
self self
} }
pub fn color(mut self, color: DividerColor) -> Self {
self.color = color;
self
}
} }

View File

@ -3,6 +3,8 @@ use gpui::{AnyElement, IntoElement, Stateful};
use smallvec::SmallVec; use smallvec::SmallVec;
use std::cmp::Ordering; use std::cmp::Ordering;
pub const TAB_HEIGHT_IN_REMS: f32 = 30. / 16.;
/// The position of a [`Tab`] within a list of tabs. /// The position of a [`Tab`] within a list of tabs.
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum TabPosition { pub enum TabPosition {
@ -94,8 +96,6 @@ impl RenderOnce for Tab {
type Rendered = Stateful<Div>; type Rendered = Stateful<Div>;
fn render(self, cx: &mut WindowContext) -> Self::Rendered { fn render(self, cx: &mut WindowContext) -> Self::Rendered {
const HEIGHT_IN_REMS: f32 = 30. / 16.;
let (text_color, tab_bg, _tab_hover_bg, _tab_active_bg) = match self.selected { let (text_color, tab_bg, _tab_hover_bg, _tab_active_bg) = match self.selected {
false => ( false => (
cx.theme().colors().text_muted, cx.theme().colors().text_muted,
@ -112,7 +112,7 @@ impl RenderOnce for Tab {
}; };
self.div self.div
.h(rems(HEIGHT_IN_REMS)) .h(rems(TAB_HEIGHT_IN_REMS))
.bg(tab_bg) .bg(tab_bg)
.border_color(cx.theme().colors().border) .border_color(cx.theme().colors().border)
.map(|this| match self.position { .map(|this| match self.position {