From 8f0f5a9ba1393eab1d506daa5440078866bc6131 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Thu, 2 Nov 2023 11:18:11 -0600 Subject: [PATCH] Render status bar Co-Authored-By: Antonio --- crates/workspace2/src/dock.rs | 13 ++++++--- crates/workspace2/src/status_bar.rs | 41 ++++++++++++++++++++++++++++- crates/workspace2/src/workspace2.rs | 8 +++--- 3 files changed, 53 insertions(+), 9 deletions(-) diff --git a/crates/workspace2/src/dock.rs b/crates/workspace2/src/dock.rs index b95c534257..727d777c46 100644 --- a/crates/workspace2/src/dock.rs +++ b/crates/workspace2/src/dock.rs @@ -1,7 +1,7 @@ use crate::{status_bar::StatusItemView, Axis, Workspace}; use gpui2::{ - Action, AnyView, AppContext, Div, Entity, EntityId, EventEmitter, Render, Subscription, View, - ViewContext, WeakView, WindowContext, + div, Action, AnyView, AppContext, Div, Entity, EntityId, EventEmitter, ParentElement, Render, + Subscription, View, ViewContext, WeakView, WindowContext, }; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -605,8 +605,13 @@ impl EventEmitter for PanelButtons { impl Render for PanelButtons { type Element = Div; - fn render(&mut self, _cx: &mut ViewContext) -> Self::Element { - todo!() + fn render(&mut self, cx: &mut ViewContext) -> Self::Element { + let dock = self.dock.read(cx); + div().children( + dock.panel_entries + .iter() + .map(|panel| panel.panel.persistent_name(cx)), + ) } } diff --git a/crates/workspace2/src/status_bar.rs b/crates/workspace2/src/status_bar.rs index 21f20e9761..52134683d8 100644 --- a/crates/workspace2/src/status_bar.rs +++ b/crates/workspace2/src/status_bar.rs @@ -1,7 +1,11 @@ use std::any::TypeId; use crate::{ItemHandle, Pane}; -use gpui2::{AnyView, Render, Subscription, View, ViewContext, WindowContext}; +use gpui2::{ + div, AnyView, Component, Div, Element, ParentElement, Render, Styled, Subscription, View, + ViewContext, WindowContext, +}; +use theme2::ActiveTheme; use util::ResultExt; pub trait StatusItemView: Render { @@ -29,6 +33,41 @@ pub struct StatusBar { _observe_active_pane: Subscription, } +impl Render for StatusBar { + type Element = Div; + + fn render(&mut self, cx: &mut ViewContext) -> Self::Element { + div() + .py_0p5() + .px_1() + .flex() + .items_center() + .justify_between() + .w_full() + .bg(cx.theme().colors().status_bar) + .child(self.render_left_tools(cx)) + .child(self.render_right_tools(cx)) + } +} + +impl StatusBar { + fn render_left_tools(&self, cx: &mut ViewContext) -> impl Component { + div() + .flex() + .items_center() + .gap_1() + .children(self.left_items.iter().map(|item| item.to_any())) + } + + fn render_right_tools(&self, cx: &mut ViewContext) -> impl Component { + div() + .flex() + .items_center() + .gap_2() + .children(self.right_items.iter().map(|item| item.to_any())) + } +} + // todo!() // impl View for StatusBar { // fn ui_name() -> &'static str { diff --git a/crates/workspace2/src/workspace2.rs b/crates/workspace2/src/workspace2.rs index 38e01e10b0..61b9243894 100644 --- a/crates/workspace2/src/workspace2.rs +++ b/crates/workspace2/src/workspace2.rs @@ -555,7 +555,7 @@ pub struct Workspace { active_pane: View, last_active_center_pane: Option>, last_active_view_id: Option, - // status_bar: View, + status_bar: View, // titlebar_item: Option, notifications: Vec<(TypeId, usize, Box)>, project: Model, @@ -704,7 +704,7 @@ impl Workspace { cx.build_view(|cx| PanelButtons::new(bottom_dock.clone(), weak_handle.clone(), cx)); let right_dock_buttons = cx.build_view(|cx| PanelButtons::new(right_dock.clone(), weak_handle.clone(), cx)); - let _status_bar = cx.build_view(|cx| { + let status_bar = cx.build_view(|cx| { let mut status_bar = StatusBar::new(¢er_pane.clone(), cx); status_bar.add_left_item(left_dock_buttons, cx); status_bar.add_right_item(right_dock_buttons, cx); @@ -771,7 +771,7 @@ impl Workspace { active_pane: center_pane.clone(), last_active_center_pane: Some(center_pane.downgrade()), last_active_view_id: None, - // status_bar, + status_bar, // titlebar_item: None, notifications: Default::default(), left_dock, @@ -3856,7 +3856,7 @@ impl Render for Workspace { // .filter(|_| self.is_assistant_panel_open()), // ), ) - // .child(StatusBar::new()) + .child(self.status_bar.clone()) // .when(self.debug.show_toast, |this| { // this.child(Toast::new(ToastOrigin::Bottom).child(Label::new("A toast"))) // })