diff --git a/crates/gpui3_macros/src/derive_element.rs b/crates/gpui3_macros/src/derive_element.rs index 8e73507baf..9dd232b450 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.rs index b2c41afb29..9bdffa991c 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.rs index 89a4d6783b..9f75c4edad 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(cx: &mut WindowContext) -> View { +fn workspace(cx: &mut WindowContext) -> View { view(cx.entity(|cx| Workspace::new()), Workspace::render) } @@ -372,23 +371,16 @@ pub use stories::*; mod stories { use super::*; - // #[derive(Element)] - // pub struct WorkspaceStory { - // state_type: PhantomData, - // } - pub struct WorkspaceStory { workspace: View, } pub fn workspace_story(cx: &mut WindowContext) -> View { - todo!() - // let workspace = workspace::

(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.rs index ac54a7b806..a367664e7a 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 { pub(crate) child: E, } +impl IntoAnyElement for Themed +where + E: Element, +{ + fn into_any(self) -> AnyElement { + AnyElement::new(self) + } +} + impl Element for Themed { type ViewState = E::ViewState; type ElementState = E::ElementState;