diff --git a/crates/gpui3/src/app.rs b/crates/gpui3/src/app.rs index b05a34e009997ac09cee7d9f4b9fff90f362f69c..a6ec39244b3f149ea1bc6206543408af40516a8f 100644 --- a/crates/gpui3/src/app.rs +++ b/crates/gpui3/src/app.rs @@ -1,5 +1,5 @@ use crate::{ - current_platform, Context, LayoutId, Platform, Reference, TextSystem, View, Window, + current_platform, Context, LayoutId, Platform, Reference, RootView, TextSystem, Window, WindowContext, WindowHandle, WindowId, }; use anyhow::{anyhow, Result}; @@ -68,7 +68,7 @@ impl AppContext { pub fn open_window( &mut self, options: crate::WindowOptions, - build_root_view: impl FnOnce(&mut WindowContext) -> View, + build_root_view: impl FnOnce(&mut WindowContext) -> RootView, ) -> WindowHandle { let id = self.windows.insert(None); let handle = WindowHandle::new(id); diff --git a/crates/gpui3/src/element.rs b/crates/gpui3/src/element.rs index df88d6af9b0282ea8799b41a8ad1e8729c7522cd..214ce41d2b950dcd1c1585101ed4788c4ff11c86 100644 --- a/crates/gpui3/src/element.rs +++ b/crates/gpui3/src/element.rs @@ -1,4 +1,4 @@ -use super::{Handle, Layout, LayoutId, Pixels, Point, Result, ViewContext, WindowContext}; +use super::{Handle, Layout, LayoutId, Pixels, Point, Result, ViewContext}; pub(crate) use smallvec::SmallVec; use std::{any::Any, cell::RefCell, marker::PhantomData, rc::Rc}; diff --git a/crates/storybook2/src/collab_panel.rs b/crates/storybook2/src/collab_panel.rs index af975cc4e45f79e066f83e82e1d7765727cbf36e..0828abd90395a828fe138509f3b45963cab46150 100644 --- a/crates/storybook2/src/collab_panel.rs +++ b/crates/storybook2/src/collab_panel.rs @@ -4,11 +4,11 @@ use gpui3::{ ScrollState, StyleHelpers, View, ViewContext, WindowContext, }; -struct CollabPanel { +pub struct CollabPanel { scroll_state: ScrollState, } -pub fn collab_panel(cx: &mut WindowContext) -> View { +pub fn collab_panel(cx: &mut WindowContext) -> View { view(cx.entity(|cx| CollabPanel::new(cx)), |panel, cx| { panel.render(cx) }) diff --git a/crates/storybook2/src/storybook2.rs b/crates/storybook2/src/storybook2.rs index 8572286163d27fe22583da1930a579e91b6d4e95..83357905c623ff288aa205d20318928b9d08c235 100644 --- a/crates/storybook2/src/storybook2.rs +++ b/crates/storybook2/src/storybook2.rs @@ -52,7 +52,7 @@ fn main() { } fn storybook(cx: &mut ViewContext) -> impl Element { - workspace().themed(current_theme(cx)) + workspace(cx).themed(current_theme(cx)) } // Nathan: During the transition to gpui2, we will include the base theme on the legacy Theme struct. diff --git a/crates/storybook2/src/workspace.rs b/crates/storybook2/src/workspace.rs index 1e3df3bac512871a776ede236ea11dae225236b0..7661a57454cfcadfa1ba82152f7cd919717f6c9e 100644 --- a/crates/storybook2/src/workspace.rs +++ b/crates/storybook2/src/workspace.rs @@ -1,25 +1,35 @@ -use crate::{collab_panel::collab_panel, theme::theme}; +use crate::{ + collab_panel::{collab_panel, CollabPanel}, + theme::theme, +}; use gpui3::{ - div, img, svg, view, Element, ParentElement, ScrollState, StyleHelpers, View, ViewContext, - WindowAppearance, WindowContext, + div, img, svg, view, Context, Element, ParentElement, RootView, StyleHelpers, View, + ViewContext, WindowContext, }; -#[derive(Default)] -struct Workspace { - left_scroll_state: ScrollState, - right_scroll_state: ScrollState, +pub struct Workspace { + left_panel: View, + right_panel: View, } -pub fn workspace(cx: &mut WindowContext) -> View { - let workspace = cx.entity(|_| Workspace::default()); - view(workspace, |workspace, cx| workspace.render(cx)) +pub fn workspace(cx: &mut WindowContext) -> RootView { + view(cx.entity(|cx| Workspace::new(cx)), |workspace, cx| { + workspace.render(cx) + }) } impl Workspace { - fn render(&mut self, cx: &mut ViewContext) -> impl Element { + fn new(cx: &mut ViewContext) -> Self { + Self { + left_panel: collab_panel(cx), + right_panel: collab_panel(cx), + } + } + + fn render(&mut self, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); - div() + div::() .size_full() .flex() .flex_col() @@ -29,34 +39,40 @@ impl Workspace { .items_start() .text_color(theme.lowest.base.default.foreground) .fill(theme.middle.base.default.background) - .child(titlebar()) + .child(titlebar(cx)) .child( - div() + div::() .flex_1() .w_full() .flex() .flex_row() .overflow_hidden() - .child(collab_panel(self.left_scroll_state.clone())) + .child(self.left_panel.clone()) .child(div().h_full().flex_1()) - .child(collab_panel(self.right_scroll_state.clone())), + .child(self.right_panel.clone()), ) - .child(statusbar()) + .child(statusbar::statusbar(cx)) } } -struct TitleBar; +struct Titlebar; -pub fn titlebar() -> impl Element { - TitleBar +pub fn titlebar(cx: &mut ViewContext) -> impl Element { + let ref mut this = Titlebar; + let theme = theme(cx); + div() + .flex() + .items_center() + .justify_between() + .w_full() + .h_8() + .fill(theme.lowest.base.default.background) + .child(this.left_group(cx)) + .child(this.right_group(cx)) } -impl TitleBar { - fn render( - &mut self, - _: &mut V, - cx: &mut ViewContext, - ) -> impl Element { +impl Titlebar { + fn render(&mut self, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); div() .flex() @@ -276,7 +292,7 @@ mod statusbar { use super::*; - pub fn statusbar(_: &mut V, cx: &mut ViewContext) -> impl Element { + pub fn statusbar(cx: &mut ViewContext) -> impl Element { let theme = theme(cx); div() .flex() @@ -285,8 +301,8 @@ mod statusbar { .w_full() .h_8() .fill(theme.lowest.base.default.background) - .child(left_group(cx)) - .child(right_group(cx)) + // .child(left_group(cx)) + // .child(right_group(cx)) } fn left_group(cx: &mut ViewContext) -> impl Element {