From d120d0cf2e703ec9cede3118b6a3e061db86e0b6 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 21 Sep 2023 14:10:53 -0600 Subject: [PATCH] Checkpoint --- 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(-) diff --git a/crates/gpui3/src/app.rs b/crates/gpui3/src/app.rs index b05a34e009..a6ec39244b 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 df88d6af9b..214ce41d2b 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 af975cc4e4..0828abd903 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 8572286163..83357905c6 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 1e3df3bac5..7661a57454 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 {