Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
WIP
Antonio Scandurra2044ccdc0b47
diff --git a/crates/gpui3_macros/src/derive_element.rs b/crates/gpui3_macros/src/derive_element.rsindex 8e73507baf5..9dd232b450a 100644--- a/crates/gpui3_macros/src/derive_element.rs+++ b/crates/gpui3_macros/src/derive_element.rs@@ -41,6 +41,14 @@ pub fn derive_element(input: TokenStream) -> TokenStream {let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl();let gen = quote! {+ impl #impl_generics gpui3::IntoAnyElement<#state_type> for #type_name #ty_generics+ #where_clause+ {+ fn into_any(self) -> gpui3::AnyElement<#state_type> {+ gpui3::AnyElement::new(self)+ }+ }+impl #impl_generics gpui3::Element for #type_name #ty_generics#where_clause{diff --git a/crates/ui2/src/components/list.rs b/crates/ui2/src/components/list.rsindex b2c41afb29d..9bdffa991c4 100644--- a/crates/ui2/src/components/list.rs+++ b/crates/ui2/src/components/list.rs@@ -1,6 +1,6 @@use std::marker::PhantomData;-use gpui3::{div, Div, Hsla, WindowContext};+use gpui3::{div, Div};use crate::prelude::*;use crate::theme::theme;diff --git a/crates/ui2/src/components/workspace.rs b/crates/ui2/src/components/workspace.rsindex 89a4d6783b8..9f75c4edad4 100644--- a/crates/ui2/src/components/workspace.rs+++ b/crates/ui2/src/components/workspace.rs@@ -1,4 +1,3 @@-use std::marker::PhantomData;use std::sync::atomic::{AtomicBool, Ordering};use std::sync::{Arc, OnceLock};@@ -116,7 +115,7 @@ pub struct Workspace {bottom_panel_scroll_state: ScrollState,}-fn workspace<P: 'static>(cx: &mut WindowContext) -> View<Workspace> {+fn workspace(cx: &mut WindowContext) -> View<Workspace> {view(cx.entity(|cx| Workspace::new()), Workspace::render)}@@ -372,23 +371,16 @@ pub use stories::*;mod stories {use super::*;- // #[derive(Element)]- // pub struct WorkspaceStory<S: 'static + Send + Sync + Clone> {- // state_type: PhantomData<S>,- // }-pub struct WorkspaceStory {workspace: View<Workspace>,}pub fn workspace_story(cx: &mut WindowContext) -> View<WorkspaceStory> {- todo!()- // let workspace = workspace::<P>(cx);- // view(- // cx.entity(|cx| WorkspaceStory {- // workspace,- // }),- // |view, cx| view.workspace.clone(),- // )+ view(+ cx.entity(|cx| WorkspaceStory {+ workspace: workspace(cx),+ }),+ |view, cx| view.workspace.clone(),+ )}}diff --git a/crates/ui2/src/theme.rs b/crates/ui2/src/theme.rsindex ac54a7b8065..a367664e7af 100644--- a/crates/ui2/src/theme.rs+++ b/crates/ui2/src/theme.rs@@ -3,7 +3,8 @@ use std::fmt;use std::sync::Arc;use gpui3::{- BorrowAppContext, Bounds, Element, Hsla, LayoutId, Pixels, Result, ViewContext, WindowContext,+ AnyElement, BorrowAppContext, Bounds, Element, Hsla, IntoAnyElement, LayoutId, Pixels, Result,+ ViewContext, WindowContext,};use serde::{de::Visitor, Deserialize, Deserializer};@@ -146,6 +147,15 @@ pub struct Themed<E> {pub(crate) child: E,}+impl<E> IntoAnyElement<E::ViewState> for Themed<E>+where+ E: Element,+{+ fn into_any(self) -> AnyElement<E::ViewState> {+ AnyElement::new(self)+ }+}+impl<E: Element> Element for Themed<E> {type ViewState = E::ViewState;type ElementState = E::ElementState;