diff --git a/crates/storybook2/src/story_selector.rs b/crates/storybook2/src/story_selector.rs index f8b70aaf07..0f6159d40f 100644 --- a/crates/storybook2/src/story_selector.rs +++ b/crates/storybook2/src/story_selector.rs @@ -153,10 +153,7 @@ impl ComponentStory { ui::ThemeSelectorStory::new().into_any() }) .into_any(), - Self::TitleBar => view(cx.entity(|cx| ()), |_, _| { - ui::TitleBarStory::new().into_any() - }) - .into_any(), + Self::TitleBar => ui::TitleBarStory::view(cx).into_any(), Self::Toast => { view(cx.entity(|cx| ()), |_, _| ui::ToastStory::new().into_any()).into_any() } diff --git a/crates/ui2/src/components/title_bar.rs b/crates/ui2/src/components/title_bar.rs index 5b15e9db08..449a10864c 100644 --- a/crates/ui2/src/components/title_bar.rs +++ b/crates/ui2/src/components/title_bar.rs @@ -1,11 +1,12 @@ -use std::marker::PhantomData; use std::sync::atomic::AtomicBool; use std::sync::Arc; +use gpui3::{view, Context, View}; + use crate::prelude::*; use crate::{ - theme, Avatar, Button, Icon, IconButton, IconColor, PlayerStack, PlayerWithCallStatus, - ToolDivider, TrafficLights, + random_players_with_call_status, theme, Avatar, Button, Icon, IconButton, IconColor, + PlayerStack, PlayerWithCallStatus, ToolDivider, TrafficLights, }; #[derive(Clone)] @@ -15,16 +16,15 @@ pub struct Livestream { // windows } -#[derive(Element)] -pub struct TitleBar { - state_type: PhantomData, +#[derive(Clone)] +pub struct TitleBar { /// If the window is active from the OS's perspective. is_active: Arc, livestream: Option, } -impl TitleBar { - pub fn new(cx: &mut ViewContext) -> Self { +impl TitleBar { + pub fn new(cx: &mut ViewContext) -> Self { let is_active = Arc::new(AtomicBool::new(true)); let active = is_active.clone(); @@ -35,7 +35,6 @@ impl TitleBar { // .detach(); Self { - state_type: PhantomData, is_active, livestream: None, } @@ -46,7 +45,19 @@ impl TitleBar { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + pub fn view(cx: &mut WindowContext) -> View { + view( + cx.entity(|cx| { + Self::new(cx).set_livestream(Some(Livestream { + players: random_players_with_call_status(7), + channel: Some("gpui2-ui".to_string()), + })) + }), + Self::render, + ) + } + + fn render(&mut self, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); // let has_focus = cx.window_is_active(); let has_focus = true; @@ -127,23 +138,25 @@ mod stories { use super::*; - #[derive(Element)] - pub struct TitleBarStory { - state_type: PhantomData, + pub struct TitleBarStory { + title_bar: View, } - impl TitleBarStory { - pub fn new() -> Self { - Self { - state_type: PhantomData, - } + impl TitleBarStory { + pub fn view(cx: &mut WindowContext) -> View { + view( + cx.entity(|cx| Self { + title_bar: TitleBar::view(cx), + }), + Self::render, + ) } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, cx: &mut ViewContext) -> impl Element { Story::container(cx) - .child(Story::title_for::<_, TitleBar>(cx)) + .child(Story::title_for::<_, TitleBar>(cx)) .child(Story::label(cx, "Default")) - .child(TitleBar::new(cx)) + .child(self.title_bar.clone()) } } } diff --git a/crates/ui2/src/components/workspace.rs b/crates/ui2/src/components/workspace.rs index 6db5345aa8..d1b2835536 100644 --- a/crates/ui2/src/components/workspace.rs +++ b/crates/ui2/src/components/workspace.rs @@ -2,15 +2,16 @@ use chrono::DateTime; use gpui3::{px, relative, rems, view, Context, Size, View}; use crate::{ - hello_world_rust_editor_with_status_example, random_players_with_call_status, theme, v_stack, - AssistantPanel, Button, ChatMessage, ChatPanel, CollabPanel, EditorPane, Label, - LanguageSelector, Livestream, Pane, PaneGroup, Panel, PanelAllowedSides, PanelSide, - ProjectPanel, SplitDirection, StatusBar, Terminal, TitleBar, Toast, ToastOrigin, + hello_world_rust_editor_with_status_example, theme, v_stack, AssistantPanel, Button, + ChatMessage, ChatPanel, CollabPanel, EditorPane, Label, LanguageSelector, Pane, PaneGroup, + Panel, PanelAllowedSides, PanelSide, ProjectPanel, SplitDirection, StatusBar, Terminal, + TitleBar, Toast, ToastOrigin, }; use crate::{prelude::*, NotificationToast}; #[derive(Clone)] pub struct Workspace { + title_bar: View, show_project_panel: bool, show_collab_panel: bool, show_chat_panel: bool, @@ -24,8 +25,9 @@ pub struct Workspace { } impl Workspace { - pub fn new() -> Self { + pub fn new(cx: &mut ViewContext) -> Self { Self { + title_bar: TitleBar::view(cx), show_project_panel: true, show_collab_panel: false, show_chat_panel: true, @@ -106,7 +108,7 @@ impl Workspace { } pub fn view(cx: &mut WindowContext) -> View { - view(cx.entity(|cx| Self::new()), Self::render) + view(cx.entity(|cx| Self::new(cx)), Self::render) } pub fn render(&mut self, cx: &mut ViewContext) -> impl Element { @@ -167,10 +169,7 @@ impl Workspace { .items_start() .text_color(theme.lowest.base.default.foreground) .fill(theme.lowest.base.default.background) - .child(TitleBar::new(cx).set_livestream(Some(Livestream { - players: random_players_with_call_status(7), - channel: Some("gpui2-ui".to_string()), - }))) + .child(self.title_bar.clone()) .child( div() .flex_1()