Checkpoint

Nathan Sobo created

Change summary

crates/gpui3/src/app.rs               |  4 
crates/gpui3/src/element.rs           |  2 
crates/storybook2/src/collab_panel.rs |  4 
crates/storybook2/src/storybook2.rs   |  2 
crates/storybook2/src/workspace.rs    | 74 +++++++++++++++++-----------
5 files changed, 51 insertions(+), 35 deletions(-)

Detailed changes

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<S: 'static>(
         &mut self,
         options: crate::WindowOptions,
-        build_root_view: impl FnOnce(&mut WindowContext) -> View<S>,
+        build_root_view: impl FnOnce(&mut WindowContext) -> RootView<S>,
     ) -> WindowHandle<S> {
         let id = self.windows.insert(None);
         let handle = WindowHandle::new(id);

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};
 

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<CollabPanel> {
+pub fn collab_panel<S: 'static>(cx: &mut WindowContext) -> View<CollabPanel, S> {
     view(cx.entity(|cx| CollabPanel::new(cx)), |panel, cx| {
         panel.render(cx)
     })

crates/storybook2/src/storybook2.rs 🔗

@@ -52,7 +52,7 @@ fn main() {
 }
 
 fn storybook<V: 'static>(cx: &mut ViewContext<V>) -> 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.

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<CollabPanel, Self>,
+    right_panel: View<CollabPanel, Self>,
 }
 
-pub fn workspace(cx: &mut WindowContext) -> View<Workspace> {
-    let workspace = cx.entity(|_| Workspace::default());
-    view(workspace, |workspace, cx| workspace.render(cx))
+pub fn workspace(cx: &mut WindowContext) -> RootView<Workspace> {
+    view(cx.entity(|cx| Workspace::new(cx)), |workspace, cx| {
+        workspace.render(cx)
+    })
 }
 
 impl Workspace {
-    fn render<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl Element<State = V> {
+    fn new(cx: &mut ViewContext<Self>) -> Self {
+        Self {
+            left_panel: collab_panel(cx),
+            right_panel: collab_panel(cx),
+        }
+    }
+
+    fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element<State = Self> {
         let theme = theme(cx);
 
-        div()
+        div::<Self>()
             .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::<Self>()
                     .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<V: 'static>() -> impl Element<State = V> {
-    TitleBar
+pub fn titlebar<S: 'static>(cx: &mut ViewContext<S>) -> impl Element<State = S> {
+    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<V: 'static>(
-        &mut self,
-        _: &mut V,
-        cx: &mut ViewContext<V>,
-    ) -> impl Element<State = V> {
+impl Titlebar {
+    fn render<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl Element<State = V> {
         let theme = theme(cx);
         div()
             .flex()
@@ -276,7 +292,7 @@ mod statusbar {
 
     use super::*;
 
-    pub fn statusbar<V: 'static>(_: &mut V, cx: &mut ViewContext<V>) -> impl Element<State = V> {
+    pub fn statusbar<S: 'static>(cx: &mut ViewContext<S>) -> impl Element<State = S> {
         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<V: 'static>(cx: &mut ViewContext<V>) -> impl Element<State = V> {