WIP

Nathan Sobo created

Change summary

crates/gpui3/src/elements.rs              |  3 ++
crates/gpui3/src/platform/mac/platform.rs |  2 
crates/storybook2/src/collab_panel.rs     | 17 ++++++---------
crates/storybook2/src/element_ext.rs      | 13 +++--------
crates/storybook2/src/theme.rs            | 15 ++++++-------
crates/storybook2/src/workspace.rs        | 26 +++++++++++-------------
6 files changed, 34 insertions(+), 42 deletions(-)

Detailed changes

crates/gpui3/src/platform/mac/platform.rs 🔗

@@ -1123,7 +1123,7 @@ mod tests {
     }
 
     fn build_platform() -> MacPlatform {
-        let mut platform = MacPlatform::new();
+        let platform = MacPlatform::new();
         platform.0.borrow_mut().pasteboard = unsafe { NSPasteboard::pasteboardWithUniqueName(nil) };
         platform
     }

crates/storybook2/src/collab_panel.rs 🔗

@@ -1,12 +1,9 @@
 use crate::theme::{theme, Theme};
-use gpui2::{
-    elements::{div, div::ScrollState, img, svg},
-    style::{StyleHelpers, Styleable},
-    ArcCow, Element, IntoElement, ParentElement, ViewContext,
+use gpui3::{
+    div, img, svg, ArcCow, Element, IntoAnyElement, ParentElement, ScrollState, Styled, ViewContext,
 };
 use std::marker::PhantomData;
 
-#[derive(Element)]
 pub struct CollabPanelElement<V: 'static> {
     view_type: PhantomData<V>,
     scroll_state: ScrollState,
@@ -22,7 +19,7 @@ pub fn collab_panel<V: 'static>(scroll_state: ScrollState) -> CollabPanelElement
 }
 
 impl<V: 'static> CollabPanelElement<V> {
-    fn render(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
+    fn render(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl Element {
         let theme = theme(cx);
 
         // Panel
@@ -117,10 +114,10 @@ impl<V: 'static> CollabPanelElement<V> {
 
     fn list_section_header(
         &self,
-        label: impl IntoElement<V>,
+        label: impl IntoAnyElement<V>,
         expanded: bool,
         theme: &Theme,
-    ) -> impl Element<V> {
+    ) -> impl Element {
         div()
             .h_7()
             .px_2()
@@ -146,9 +143,9 @@ impl<V: 'static> CollabPanelElement<V> {
     fn list_item(
         &self,
         avatar_uri: impl Into<ArcCow<'static, str>>,
-        label: impl IntoElement<V>,
+        label: impl IntoAnyElement<V>,
         theme: &Theme,
-    ) -> impl Element<V> {
+    ) -> impl Element {
         div()
             .h_7()
             .px_2()

crates/storybook2/src/element_ext.rs 🔗

@@ -1,22 +1,17 @@
 use crate::theme::{Theme, Themed};
 use gpui3::Element;
-use std::marker::PhantomData;
 
 pub trait ElementExt: Element {
-    fn themed(self, theme: Theme) -> Themed<V, Self>
+    fn themed(self, theme: Theme) -> Themed<Self>
     where
         Self: Sized;
 }
 
-impl<V: 'static, E: Element> ElementExt for E {
-    fn themed(self, theme: Theme) -> Themed<V, Self>
+impl<E: Element> ElementExt for E {
+    fn themed(self, theme: Theme) -> Themed<Self>
     where
         Self: Sized,
     {
-        Themed {
-            child: self,
-            theme,
-            view_type: PhantomData,
-        }
+        Themed { child: self, theme }
     }
 }

crates/storybook2/src/theme.rs 🔗

@@ -1,5 +1,5 @@
 use gpui3::{
-    serde_json, AppContext, Element, Hsla, IntoAnyElement, Layout, Vector2F, ViewContext,
+    serde_json, AppContext, Element, Hsla, IntoAnyElement, Layout, LayoutId, Vector2F, ViewContext,
     WindowContext,
 };
 use serde::{de::Visitor, Deserialize, Deserializer};
@@ -131,25 +131,24 @@ where
     deserializer.deserialize_map(SyntaxVisitor)
 }
 
-pub struct Themed<V: 'static, E: Element<V>> {
+pub struct Themed<E> {
     pub(crate) theme: Theme,
     pub(crate) child: E,
-    pub(crate) view_type: PhantomData<V>,
 }
 
-impl<V: 'static, E: Element<V>> Element<V> for Themed<V, E> {
+impl<E: Element> Element for Themed<E> {
     type FrameState = E::FrameState;
 
     fn layout(
         &mut self,
-        view: &mut V,
-        cx: &mut ViewContext<V>,
-    ) -> anyhow::Result<(gpui2::LayoutId, Self::FrameState)>
+        state: &mut E::State,
+        cx: &mut ViewContext<E::State>,
+    ) -> anyhow::Result<(LayoutId, Self::FrameState)>
     where
         Self: Sized,
     {
         cx.push_theme(self.theme.clone());
-        let result = self.child.layout(view, cx);
+        let result = self.child.layout(state, cx);
         cx.pop_theme();
         result
     }

crates/storybook2/src/workspace.rs 🔗

@@ -1,18 +1,18 @@
 use crate::{collab_panel::collab_panel, theme::theme};
-use gpui3::{div, Element, IntoAnyElement, ParentElement, ScrollState, Styled, ViewContext};
+use gpui3::{div, img, svg, Element, ParentElement, ScrollState, Styled, ViewContext};
 
-#[derive(Element, Default)]
+#[derive(Default)]
 struct WorkspaceElement {
     left_scroll_state: ScrollState,
     right_scroll_state: ScrollState,
 }
 
-pub fn workspace<V: 'static>() -> impl Element<V> {
+pub fn workspace<V: 'static>() -> impl Element {
     WorkspaceElement::default()
 }
 
 impl WorkspaceElement {
-    fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
+    fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl Element {
         let theme = theme(cx);
 
         div()
@@ -41,15 +41,14 @@ impl WorkspaceElement {
     }
 }
 
-#[derive(Element)]
 struct TitleBar;
 
-pub fn titlebar<V: 'static>() -> impl Element<V> {
+pub fn titlebar<V: 'static>() -> impl Element {
     TitleBar
 }
 
 impl TitleBar {
-    fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
+    fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl Element {
         let theme = theme(cx);
         div()
             .flex()
@@ -62,7 +61,7 @@ impl TitleBar {
             .child(self.right_group(cx))
     }
 
-    fn left_group<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
+    fn left_group<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl Element {
         let theme = theme(cx);
         div()
             .flex()
@@ -136,7 +135,7 @@ impl TitleBar {
             )
     }
 
-    fn right_group<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
+    fn right_group<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl Element {
         let theme = theme(cx);
         div()
             .flex()
@@ -264,15 +263,14 @@ impl TitleBar {
 
 // ================================================================================ //
 
-#[derive(Element)]
 struct StatusBar;
 
-pub fn statusbar<V: 'static>() -> impl Element<V> {
+pub fn statusbar<V: 'static>() -> impl Element {
     StatusBar
 }
 
 impl StatusBar {
-    fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
+    fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl Element {
         let theme = theme(cx);
         div()
             .flex()
@@ -285,7 +283,7 @@ impl StatusBar {
             .child(self.right_group(cx))
     }
 
-    fn left_group<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
+    fn left_group<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl Element {
         let theme = theme(cx);
         div()
             .flex()
@@ -382,7 +380,7 @@ impl StatusBar {
             )
     }
 
-    fn right_group<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
+    fn right_group<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl Element {
         let theme = theme(cx);
         div()
             .flex()