diff --git a/crates/gpui2/src/element.rs b/crates/gpui2/src/element.rs index 39b7898d16b4f8cbd250bfc76713a1c97531a907..762c8873424a7c2a6d2b99d69c7e499d696e4fb6 100644 --- a/crates/gpui2/src/element.rs +++ b/crates/gpui2/src/element.rs @@ -46,20 +46,20 @@ pub struct GlobalElementId(SmallVec<[ElementId; 32]>); pub trait ParentElement { fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]>; - fn child(mut self, child: impl IntoAnyElement) -> Self + fn child(mut self, child: impl Component) -> Self where Self: Sized, { - self.children_mut().push(child.into_any()); + self.children_mut().push(child.render()); self } - fn children(mut self, iter: impl IntoIterator>) -> Self + fn children(mut self, iter: impl IntoIterator>) -> Self where Self: Sized, { self.children_mut() - .extend(iter.into_iter().map(|item| item.into_any())); + .extend(iter.into_iter().map(|item| item.render())); self } } @@ -207,8 +207,8 @@ impl AnyElement { } } -pub trait IntoAnyElement { - fn into_any(self) -> AnyElement; +pub trait Component { + fn render(self) -> AnyElement; fn when(mut self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self where @@ -221,8 +221,8 @@ pub trait IntoAnyElement { } } -impl IntoAnyElement for AnyElement { - fn into_any(self) -> AnyElement { +impl Component for AnyElement { + fn render(self) -> AnyElement { self } } @@ -230,7 +230,7 @@ impl IntoAnyElement for AnyElement { impl Element for Option where V: 'static, - E: 'static + IntoAnyElement + Send + Sync, + E: 'static + Component + Send + Sync, F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + Send + Sync + 'static, { type ElementState = AnyElement; @@ -246,7 +246,7 @@ where cx: &mut ViewContext, ) -> Self::ElementState { let render = self.take().unwrap(); - (render)(view_state, cx).into_any() + (render)(view_state, cx).render() } fn layout( @@ -269,24 +269,24 @@ where } } -impl IntoAnyElement for Option +impl Component for Option where V: 'static, - E: 'static + IntoAnyElement + Send + Sync, + E: 'static + Component + Send + Sync, F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + Send + Sync + 'static, { - fn into_any(self) -> AnyElement { + fn render(self) -> AnyElement { AnyElement::new(self) } } -impl IntoAnyElement for F +impl Component for F where V: 'static, - E: 'static + IntoAnyElement + Send + Sync, + E: 'static + Component + Send + Sync, F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + Send + Sync + 'static, { - fn into_any(self) -> AnyElement { + fn render(self) -> AnyElement { AnyElement::new(Some(self)) } } diff --git a/crates/gpui2/src/elements/div.rs b/crates/gpui2/src/elements/div.rs index fbef75ab1c02f765eed5c5148bf6fc751d16c5ef..6fe10d94a31324984df8431c13a0747d704110b4 100644 --- a/crates/gpui2/src/elements/div.rs +++ b/crates/gpui2/src/elements/div.rs @@ -1,7 +1,7 @@ use crate::{ - point, AnyElement, BorrowWindow, Bounds, Element, ElementFocus, ElementId, ElementInteraction, - FocusDisabled, FocusEnabled, FocusHandle, FocusListeners, Focusable, GlobalElementId, - GroupBounds, InteractiveElementState, IntoAnyElement, LayoutId, Overflow, ParentElement, + point, AnyElement, BorrowWindow, Bounds, Component, Element, ElementFocus, ElementId, + ElementInteraction, FocusDisabled, FocusEnabled, FocusHandle, FocusListeners, Focusable, + GlobalElementId, GroupBounds, InteractiveElementState, LayoutId, Overflow, ParentElement, Pixels, Point, SharedString, StatefulInteraction, StatefulInteractive, StatelessInteraction, StatelessInteractive, Style, StyleRefinement, Styled, ViewContext, }; @@ -303,13 +303,13 @@ where } } -impl IntoAnyElement for Div +impl Component for Div where // V: Any + Send + Sync, I: ElementInteraction, F: ElementFocus, { - fn into_any(self) -> AnyElement { + fn render(self) -> AnyElement { AnyElement::new(self) } } diff --git a/crates/gpui2/src/elements/img.rs b/crates/gpui2/src/elements/img.rs index d64536a7ed74a967bd2ca770255d6dcf6a694600..747e573ea566ec882aa965c3efa0cc01cf6fbf70 100644 --- a/crates/gpui2/src/elements/img.rs +++ b/crates/gpui2/src/elements/img.rs @@ -1,6 +1,6 @@ use crate::{ - div, AnyElement, BorrowWindow, Bounds, Div, DivState, Element, ElementFocus, ElementId, - ElementInteraction, FocusDisabled, FocusEnabled, FocusListeners, Focusable, IntoAnyElement, + div, AnyElement, BorrowWindow, Bounds, Component, Div, DivState, Element, ElementFocus, + ElementId, ElementInteraction, FocusDisabled, FocusEnabled, FocusListeners, Focusable, LayoutId, Pixels, SharedString, StatefulInteraction, StatefulInteractive, StatelessInteraction, StatelessInteractive, StyleRefinement, Styled, ViewContext, }; @@ -55,12 +55,12 @@ where } } -impl IntoAnyElement for Img +impl Component for Img where I: ElementInteraction, F: ElementFocus, { - fn into_any(self) -> AnyElement { + fn render(self) -> AnyElement { AnyElement::new(self) } } diff --git a/crates/gpui2/src/elements/svg.rs b/crates/gpui2/src/elements/svg.rs index 409094d740ef2bc3a523d14f07430b9c41af685d..7db4c5cf6db86d96bf154c9a4f243c630b0a3fe5 100644 --- a/crates/gpui2/src/elements/svg.rs +++ b/crates/gpui2/src/elements/svg.rs @@ -1,6 +1,6 @@ use crate::{ - div, AnyElement, Bounds, Div, DivState, Element, ElementFocus, ElementId, ElementInteraction, - FocusDisabled, FocusEnabled, FocusListeners, Focusable, IntoAnyElement, LayoutId, Pixels, + div, AnyElement, Bounds, Component, Div, DivState, Element, ElementFocus, ElementId, + ElementInteraction, FocusDisabled, FocusEnabled, FocusListeners, Focusable, LayoutId, Pixels, SharedString, StatefulInteraction, StatefulInteractive, StatelessInteraction, StatelessInteractive, StyleRefinement, Styled, ViewContext, }; @@ -45,12 +45,12 @@ where } } -impl IntoAnyElement for Svg +impl Component for Svg where I: ElementInteraction, F: ElementFocus, { - fn into_any(self) -> AnyElement { + fn render(self) -> AnyElement { AnyElement::new(self) } } diff --git a/crates/gpui2/src/elements/text.rs b/crates/gpui2/src/elements/text.rs index e054da87a68bb3266142d90785c45b476631553c..3aff568c4c2f71ed4002006b3a7c9ae306db3b99 100644 --- a/crates/gpui2/src/elements/text.rs +++ b/crates/gpui2/src/elements/text.rs @@ -1,41 +1,41 @@ use crate::{ - AnyElement, BorrowWindow, Bounds, Element, IntoAnyElement, LayoutId, Line, Pixels, - SharedString, Size, ViewContext, + AnyElement, BorrowWindow, Bounds, Component, Element, LayoutId, Line, Pixels, SharedString, + Size, ViewContext, }; use parking_lot::Mutex; use smallvec::SmallVec; use std::{marker::PhantomData, sync::Arc}; use util::ResultExt; -impl IntoAnyElement for SharedString { - fn into_any(self) -> AnyElement { +impl Component for SharedString { + fn render(self) -> AnyElement { Text { text: self, state_type: PhantomData, } - .into_any() + .render() } } -impl IntoAnyElement for &'static str { - fn into_any(self) -> AnyElement { +impl Component for &'static str { + fn render(self) -> AnyElement { Text { text: self.into(), state_type: PhantomData, } - .into_any() + .render() } } // TODO: Figure out how to pass `String` to `child` without this. // This impl doesn't exist in the `gpui2` crate. -impl IntoAnyElement for String { - fn into_any(self) -> AnyElement { +impl Component for String { + fn render(self) -> AnyElement { Text { text: self.into(), state_type: PhantomData, } - .into_any() + .render() } } @@ -47,8 +47,8 @@ pub struct Text { unsafe impl Send for Text {} unsafe impl Sync for Text {} -impl IntoAnyElement for Text { - fn into_any(self) -> AnyElement { +impl Component for Text { + fn render(self) -> AnyElement { AnyElement::new(self) } } diff --git a/crates/gpui2/src/interactive.rs b/crates/gpui2/src/interactive.rs index f51516dbe52927f884bab119c67ae025b43ae90b..9ec6c38dfe967e03423b6071b32f8737d310d44a 100644 --- a/crates/gpui2/src/interactive.rs +++ b/crates/gpui2/src/interactive.rs @@ -1,7 +1,7 @@ use crate::{ - point, px, view, Action, AnyBox, AnyDrag, AppContext, BorrowWindow, Bounds, DispatchContext, - DispatchPhase, Element, ElementId, FocusHandle, IntoAnyElement, KeyMatch, Keystroke, Modifiers, - Overflow, Pixels, Point, SharedString, Size, Style, StyleRefinement, ViewContext, + point, px, view, Action, AnyBox, AnyDrag, AppContext, BorrowWindow, Bounds, Component, + DispatchContext, DispatchPhase, Element, ElementId, FocusHandle, KeyMatch, Keystroke, + Modifiers, Overflow, Pixels, Point, SharedString, Size, Style, StyleRefinement, ViewContext, }; use collections::HashMap; use derive_more::{Deref, DerefMut}; @@ -327,7 +327,7 @@ pub trait StatefulInteractive: StatelessInteractive { S: Any + Send + Sync, R: Fn(&mut V, &mut ViewContext) -> E, R: 'static + Send + Sync, - E: IntoAnyElement, + E: Component, { debug_assert!( self.stateful_interaction().drag_listener.is_none(), @@ -871,7 +871,7 @@ pub struct Drag where R: Fn(&mut V, &mut ViewContext) -> E, V: 'static, - E: IntoAnyElement, + E: Component, { pub state: S, pub render_drag_handle: R, @@ -882,7 +882,7 @@ impl Drag where R: Fn(&mut V, &mut ViewContext) -> E, V: 'static, - E: IntoAnyElement, + E: Component, { pub fn new(state: S, render_drag_handle: R) -> Self { Drag { diff --git a/crates/gpui2/src/view.rs b/crates/gpui2/src/view.rs index b1b287c4ab20e186351783b5591d0e45f6be9c59..a27faed07de617a613f4d4469afdde76e9210542 100644 --- a/crates/gpui2/src/view.rs +++ b/crates/gpui2/src/view.rs @@ -1,7 +1,7 @@ use parking_lot::Mutex; use crate::{ - AnyBox, AnyElement, BorrowWindow, Bounds, Element, ElementId, EntityId, Handle, IntoAnyElement, + AnyBox, AnyElement, BorrowWindow, Bounds, Component, Element, ElementId, EntityId, Handle, LayoutId, Pixels, ViewContext, WindowContext, }; use std::{marker::PhantomData, sync::Arc}; @@ -33,16 +33,16 @@ pub fn view( render: impl Fn(&mut V, &mut ViewContext) -> E + Send + Sync + 'static, ) -> View where - E: IntoAnyElement, + E: Component, { View { state, - render: Arc::new(move |state, cx| render(state, cx).into_any()), + render: Arc::new(move |state, cx| render(state, cx).render()), } } -impl IntoAnyElement for View { - fn into_any(self) -> AnyElement { +impl Component for View { + fn render(self) -> AnyElement { AnyElement::new(EraseViewState { view: self, parent_view_state_type: PhantomData, @@ -98,8 +98,8 @@ struct EraseViewState { unsafe impl Send for EraseViewState {} unsafe impl Sync for EraseViewState {} -impl IntoAnyElement for EraseViewState { - fn into_any(self) -> AnyElement { +impl Component for EraseViewState { + fn render(self) -> AnyElement { AnyElement::new(self) } } @@ -185,8 +185,8 @@ pub struct AnyView { view: Arc>, } -impl IntoAnyElement for AnyView { - fn into_any(self) -> AnyElement { +impl Component for AnyView { + fn render(self) -> AnyElement { AnyElement::new(EraseAnyViewState { view: self, parent_view_state_type: PhantomData, @@ -238,8 +238,8 @@ struct EraseAnyViewState { unsafe impl Send for EraseAnyViewState {} unsafe impl Sync for EraseAnyViewState {} -impl IntoAnyElement for EraseAnyViewState { - fn into_any(self) -> AnyElement { +impl Component for EraseAnyViewState { + fn render(self) -> AnyElement { AnyElement::new(self) } } diff --git a/crates/gpui2_macros/src/derive_into_any_element.rs b/crates/gpui2_macros/src/derive_component.rs similarity index 84% rename from crates/gpui2_macros/src/derive_into_any_element.rs rename to crates/gpui2_macros/src/derive_component.rs index 9f339f1b44b5c34e821c1245131a01818cf012dc..45f4b44c858223cae28ec53427e307dba5ef5b90 100644 --- a/crates/gpui2_macros/src/derive_into_any_element.rs +++ b/crates/gpui2_macros/src/derive_component.rs @@ -2,7 +2,7 @@ use proc_macro::TokenStream; use quote::quote; use syn::{parse_macro_input, DeriveInput}; -pub fn derive_into_any_element(input: TokenStream) -> TokenStream { +pub fn derive_component(input: TokenStream) -> TokenStream { let ast = parse_macro_input!(input as DeriveInput); let name = &ast.ident; let generics = &ast.generics; @@ -11,7 +11,7 @@ pub fn derive_into_any_element(input: TokenStream) -> TokenStream { let specified_view_type = ast .attrs .iter() - .find(|attr| attr.path.is_ident("element")) + .find(|attr| attr.path.is_ident("component")) .and_then(|attr| { if let Ok(syn::Meta::List(meta_list)) = attr.parse_meta() { meta_list.nested.iter().find_map(|nested| { @@ -42,10 +42,10 @@ pub fn derive_into_any_element(input: TokenStream) -> TokenStream { }); let expanded = quote! { - impl #impl_generics gpui2::IntoAnyElement<#view_type> for #name #ty_generics #where_clause { - fn into_any(self) -> gpui2::AnyElement<#view_type> { + impl #impl_generics gpui2::Component<#view_type> for #name #ty_generics #where_clause { + fn render(self) -> gpui2::AnyElement<#view_type> { (move |view_state: &mut #view_type, cx: &mut gpui2::ViewContext<'_, '_, #view_type>| self.render(view_state, cx)) - .into_any() + .render() } } }; diff --git a/crates/gpui2_macros/src/gpui2_macros.rs b/crates/gpui2_macros/src/gpui2_macros.rs index 3635320d55f3ca7fd9f218ab8b14b66c11402080..2e0c0547f79e29f1e3bcc5bfcc43cfed516f7df9 100644 --- a/crates/gpui2_macros/src/gpui2_macros.rs +++ b/crates/gpui2_macros/src/gpui2_macros.rs @@ -1,6 +1,6 @@ use proc_macro::TokenStream; -mod derive_into_any_element; +mod derive_component; mod style_helpers; mod test; @@ -9,9 +9,9 @@ pub fn style_helpers(args: TokenStream) -> TokenStream { style_helpers::style_helpers(args) } -#[proc_macro_derive(IntoAnyElement, attributes(element))] -pub fn derive_into_any_element(input: TokenStream) -> TokenStream { - derive_into_any_element::derive_into_any_element(input) +#[proc_macro_derive(Component, attributes(component))] +pub fn derive_component(input: TokenStream) -> TokenStream { + derive_component::derive_component(input) } #[proc_macro_attribute] diff --git a/crates/storybook2/src/components.rs b/crates/storybook2/src/components.rs index 5eaa894302a0d29d894b81f9e36a9ca3b3690c22..a3dca51adc44050e31473a3e3e526d7f2a4b381e 100644 --- a/crates/storybook2/src/components.rs +++ b/crates/storybook2/src/components.rs @@ -14,7 +14,7 @@ impl Default for ButtonHandlers { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Button { handlers: ButtonHandlers, label: Option>, diff --git a/crates/storybook2/src/stories/kitchen_sink.rs b/crates/storybook2/src/stories/kitchen_sink.rs index fbb4f5099c6937e7eec1c53b17cc179089a139e4..ec89238ac45ef68a51e9e3a69545248112a8f697 100644 --- a/crates/storybook2/src/stories/kitchen_sink.rs +++ b/crates/storybook2/src/stories/kitchen_sink.rs @@ -16,7 +16,7 @@ impl KitchenSinkStory { view(cx.entity(|cx| Self::new()), Self::render) } - fn render(&mut self, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(&mut self, cx: &mut ViewContext) -> impl Component { let element_stories = ElementStory::iter() .map(|selector| selector.story(cx)) .collect::>(); diff --git a/crates/storybook2/src/stories/scroll.rs b/crates/storybook2/src/stories/scroll.rs index 86a8ca41c8f13f424069f51f04e63be8e54835c4..a1e3c6700e4ac47646467d0e9ffb8cf495a5a90f 100644 --- a/crates/storybook2/src/stories/scroll.rs +++ b/crates/storybook2/src/stories/scroll.rs @@ -1,7 +1,6 @@ use crate::themes::rose_pine; use gpui2::{ - div, px, view, Context, IntoAnyElement, ParentElement, SharedString, Styled, View, - WindowContext, + div, px, view, Component, Context, ParentElement, SharedString, Styled, View, WindowContext, }; pub struct ScrollStory { @@ -16,7 +15,7 @@ impl ScrollStory { } } -fn checkerboard(depth: usize) -> impl IntoAnyElement +fn checkerboard(depth: usize) -> impl Component where S: 'static + Send + Sync, { diff --git a/crates/storybook2/src/stories/z_index.rs b/crates/storybook2/src/stories/z_index.rs index 270bd086402927f33328581d0d46b543f7a1d802..d68b4916c247e6aabd012dac936a899b6dba6a8e 100644 --- a/crates/storybook2/src/stories/z_index.rs +++ b/crates/storybook2/src/stories/z_index.rs @@ -7,7 +7,7 @@ use crate::story::Story; /// A reimplementation of the MDN `z-index` example, found here: /// [https://developer.mozilla.org/en-US/docs/Web/CSS/z-index](https://developer.mozilla.org/en-US/docs/Web/CSS/z-index). -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct ZIndexStory { state_type: PhantomData, } @@ -19,7 +19,7 @@ impl ZIndexStory { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title(cx, "z-index")) .child( @@ -88,7 +88,7 @@ trait Styles: Styled + Sized { impl Styles for Div {} -#[derive(IntoAnyElement)] +#[derive(Component)] struct ZIndexExample { view_type: PhantomData, z_index: u32, @@ -102,7 +102,7 @@ impl ZIndexExample { } } - fn render(self, _view: &mut V, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut V, cx: &mut ViewContext) -> impl Component { div() .relative() .size_full() diff --git a/crates/storybook2/src/story_selector.rs b/crates/storybook2/src/story_selector.rs index 8cd3f9e3294d6c555af686e3038936af56eb8d3d..5f60ad14eaddf51323f92ecb9c509951df7b8eb3 100644 --- a/crates/storybook2/src/story_selector.rs +++ b/crates/storybook2/src/story_selector.rs @@ -28,29 +28,29 @@ impl ElementStory { pub fn story(&self, cx: &mut WindowContext) -> AnyView { match self { Self::Avatar => { - view(cx.entity(|cx| ()), |_, _| ui::AvatarStory::new().into_any()).into_any() + view(cx.entity(|cx| ()), |_, _| ui::AvatarStory::new().render()).into_any() } Self::Button => { - view(cx.entity(|cx| ()), |_, _| ui::ButtonStory::new().into_any()).into_any() + view(cx.entity(|cx| ()), |_, _| ui::ButtonStory::new().render()).into_any() } Self::Details => view(cx.entity(|cx| ()), |_, _| { - ui::DetailsStory::new().into_any() + ui::DetailsStory::new().render() }) .into_any(), Self::Focus => FocusStory::view(cx).into_any(), Self::Icon => { - view(cx.entity(|cx| ()), |_, _| ui::IconStory::new().into_any()).into_any() + view(cx.entity(|cx| ()), |_, _| ui::IconStory::new().render()).into_any() } Self::Input => { - view(cx.entity(|cx| ()), |_, _| ui::InputStory::new().into_any()).into_any() + view(cx.entity(|cx| ()), |_, _| ui::InputStory::new().render()).into_any() } Self::Label => { - view(cx.entity(|cx| ()), |_, _| ui::LabelStory::new().into_any()).into_any() + view(cx.entity(|cx| ()), |_, _| ui::LabelStory::new().render()).into_any() } Self::Scroll => ScrollStory::view(cx).into_any(), Self::Text => TextStory::view(cx).into_any(), Self::ZIndex => { - view(cx.entity(|cx| ()), |_, _| ZIndexStory::new().into_any()).into_any() + view(cx.entity(|cx| ()), |_, _| ZIndexStory::new().render()).into_any() } } } @@ -91,93 +91,93 @@ impl ComponentStory { pub fn story(&self, cx: &mut WindowContext) -> AnyView { match self { Self::AssistantPanel => view(cx.entity(|cx| ()), |_, _| { - ui::AssistantPanelStory::new().into_any() + ui::AssistantPanelStory::new().render() }) .into_any(), Self::Buffer => { - view(cx.entity(|cx| ()), |_, _| ui::BufferStory::new().into_any()).into_any() + view(cx.entity(|cx| ()), |_, _| ui::BufferStory::new().render()).into_any() } Self::Breadcrumb => view(cx.entity(|cx| ()), |_, _| { - ui::BreadcrumbStory::new().into_any() + ui::BreadcrumbStory::new().render() }) .into_any(), Self::ChatPanel => view(cx.entity(|cx| ()), |_, _| { - ui::ChatPanelStory::new().into_any() + ui::ChatPanelStory::new().render() }) .into_any(), Self::CollabPanel => view(cx.entity(|cx| ()), |_, _| { - ui::CollabPanelStory::new().into_any() + ui::CollabPanelStory::new().render() }) .into_any(), Self::CommandPalette => view(cx.entity(|cx| ()), |_, _| { - ui::CommandPaletteStory::new().into_any() + ui::CommandPaletteStory::new().render() }) .into_any(), Self::ContextMenu => view(cx.entity(|cx| ()), |_, _| { - ui::ContextMenuStory::new().into_any() + ui::ContextMenuStory::new().render() }) .into_any(), Self::Facepile => view(cx.entity(|cx| ()), |_, _| { - ui::FacepileStory::new().into_any() + ui::FacepileStory::new().render() }) .into_any(), Self::Keybinding => view(cx.entity(|cx| ()), |_, _| { - ui::KeybindingStory::new().into_any() + ui::KeybindingStory::new().render() }) .into_any(), Self::LanguageSelector => view(cx.entity(|cx| ()), |_, _| { - ui::LanguageSelectorStory::new().into_any() + ui::LanguageSelectorStory::new().render() }) .into_any(), Self::MultiBuffer => view(cx.entity(|cx| ()), |_, _| { - ui::MultiBufferStory::new().into_any() + ui::MultiBufferStory::new().render() }) .into_any(), Self::NotificationsPanel => view(cx.entity(|cx| ()), |_, _| { - ui::NotificationsPanelStory::new().into_any() + ui::NotificationsPanelStory::new().render() }) .into_any(), Self::Palette => view(cx.entity(|cx| ()), |_, _| { - ui::PaletteStory::new().into_any() + ui::PaletteStory::new().render() }) .into_any(), Self::Panel => { - view(cx.entity(|cx| ()), |_, _| ui::PanelStory::new().into_any()).into_any() + view(cx.entity(|cx| ()), |_, _| ui::PanelStory::new().render()).into_any() } Self::ProjectPanel => view(cx.entity(|cx| ()), |_, _| { - ui::ProjectPanelStory::new().into_any() + ui::ProjectPanelStory::new().render() }) .into_any(), Self::RecentProjects => view(cx.entity(|cx| ()), |_, _| { - ui::RecentProjectsStory::new().into_any() + ui::RecentProjectsStory::new().render() }) .into_any(), - Self::Tab => view(cx.entity(|cx| ()), |_, _| ui::TabStory::new().into_any()).into_any(), + Self::Tab => view(cx.entity(|cx| ()), |_, _| ui::TabStory::new().render()).into_any(), Self::TabBar => { - view(cx.entity(|cx| ()), |_, _| ui::TabBarStory::new().into_any()).into_any() + view(cx.entity(|cx| ()), |_, _| ui::TabBarStory::new().render()).into_any() } Self::Terminal => view(cx.entity(|cx| ()), |_, _| { - ui::TerminalStory::new().into_any() + ui::TerminalStory::new().render() }) .into_any(), Self::ThemeSelector => view(cx.entity(|cx| ()), |_, _| { - ui::ThemeSelectorStory::new().into_any() + ui::ThemeSelectorStory::new().render() }) .into_any(), Self::TitleBar => ui::TitleBarStory::view(cx).into_any(), Self::Toast => { - view(cx.entity(|cx| ()), |_, _| ui::ToastStory::new().into_any()).into_any() + view(cx.entity(|cx| ()), |_, _| ui::ToastStory::new().render()).into_any() } Self::Toolbar => view(cx.entity(|cx| ()), |_, _| { - ui::ToolbarStory::new().into_any() + ui::ToolbarStory::new().render() }) .into_any(), Self::TrafficLights => view(cx.entity(|cx| ()), |_, _| { - ui::TrafficLightsStory::new().into_any() + ui::TrafficLightsStory::new().render() }) .into_any(), Self::Copilot => view(cx.entity(|cx| ()), |_, _| { - ui::CopilotModalStory::new().into_any() + ui::CopilotModalStory::new().render() }) .into_any(), Self::Workspace => ui::WorkspaceStory::view(cx).into_any(), diff --git a/crates/storybook2/src/storybook2.rs b/crates/storybook2/src/storybook2.rs index 4db1fd434babf2963a774757136aa07dc9a26233..29ff5eaa9801e98f776f17550b851bba4a4b518b 100644 --- a/crates/storybook2/src/storybook2.rs +++ b/crates/storybook2/src/storybook2.rs @@ -107,7 +107,7 @@ impl StoryWrapper { Self { story, theme } } - fn render(&mut self, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(&mut self, cx: &mut ViewContext) -> impl Component { themed(self.theme.clone(), cx, |cx| { div() .flex() diff --git a/crates/ui2/src/components/assistant_panel.rs b/crates/ui2/src/components/assistant_panel.rs index fa5ac38dc1274e25a578a57006270d6c4313e566..c07723cedbc4acb2b7144974ef8bd8f629de08a2 100644 --- a/crates/ui2/src/components/assistant_panel.rs +++ b/crates/ui2/src/components/assistant_panel.rs @@ -5,7 +5,7 @@ use gpui2::{rems, AbsoluteLength}; use crate::prelude::*; use crate::{Icon, IconButton, Label, Panel, PanelSide}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct AssistantPanel { id: ElementId, state_type: PhantomData, @@ -26,7 +26,7 @@ impl AssistantPanel { self } - fn render(self, view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, view: &mut S, cx: &mut ViewContext) -> impl Component { Panel::new(self.id.clone(), cx) .children(vec![div() .flex() @@ -69,7 +69,7 @@ impl AssistantPanel { .overflow_y_scroll() .child(Label::new("Is this thing on?")), ) - .into_any()]) + .render()]) .side(self.current_side) .width(AbsoluteLength::Rems(rems(32.))) } @@ -84,7 +84,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct AssistantPanelStory { state_type: PhantomData, } @@ -96,7 +96,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, AssistantPanel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/breadcrumb.rs b/crates/ui2/src/components/breadcrumb.rs index 00a471e7cc46bef195d12e556ddefd26cffce682..289c0710212fc5aaf2e2703985f26ebc832b6fda 100644 --- a/crates/ui2/src/components/breadcrumb.rs +++ b/crates/ui2/src/components/breadcrumb.rs @@ -9,7 +9,7 @@ use crate::{h_stack, HighlightedText}; #[derive(Clone)] pub struct Symbol(pub Vec); -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Breadcrumb { state_type: PhantomData, path: PathBuf, @@ -31,7 +31,7 @@ impl Breadcrumb { div().child(" › ").text_color(theme.text_muted) } - fn render(self, view_state: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, view_state: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let symbols_len = self.symbols.len(); @@ -86,7 +86,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct BreadcrumbStory { state_type: PhantomData, } @@ -98,7 +98,7 @@ mod stories { } } - fn render(self, view_state: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, view_state: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); Story::container(cx) diff --git a/crates/ui2/src/components/buffer.rs b/crates/ui2/src/components/buffer.rs index 662ccd5736c264fdf8ea55a1573c1c28ada0d6e4..ffef5c4039e6f391ef423ab8f0014728682563ed 100644 --- a/crates/ui2/src/components/buffer.rs +++ b/crates/ui2/src/components/buffer.rs @@ -109,7 +109,7 @@ impl BufferRow { } } -#[derive(IntoAnyElement, Clone)] +#[derive(Component, Clone)] pub struct Buffer { id: ElementId, state_type: PhantomData, @@ -158,7 +158,7 @@ impl Buffer { self } - fn render_row(row: BufferRow, cx: &WindowContext) -> impl IntoAnyElement { + fn render_row(row: BufferRow, cx: &WindowContext) -> impl Component { let theme = theme(cx); let line_background = if row.current { @@ -208,7 +208,7 @@ impl Buffer { })) } - fn render_rows(&self, cx: &WindowContext) -> Vec> { + fn render_rows(&self, cx: &WindowContext) -> Vec> { match &self.rows { Some(rows) => rows .rows @@ -219,7 +219,7 @@ impl Buffer { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let rows = self.render_rows(cx); @@ -246,7 +246,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct BufferStory { state_type: PhantomData, } @@ -258,7 +258,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); Story::container(cx) diff --git a/crates/ui2/src/components/buffer_search.rs b/crates/ui2/src/components/buffer_search.rs index e3e92aa073fdedcfee755025a03e7f13a18b00e3..b5e74a481004b9373710ecafd90b51df7654760d 100644 --- a/crates/ui2/src/components/buffer_search.rs +++ b/crates/ui2/src/components/buffer_search.rs @@ -25,7 +25,7 @@ impl BufferSearch { view(cx.entity(|cx| Self::new()), Self::render) } - fn render(&mut self, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(&mut self, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); h_stack().bg(theme.toolbar).p_2().child( diff --git a/crates/ui2/src/components/chat_panel.rs b/crates/ui2/src/components/chat_panel.rs index db0f573485960f1b7b90e3f939923f5292c40ac7..2800207b3423088c449f7e54d055fc6a78bb0c3c 100644 --- a/crates/ui2/src/components/chat_panel.rs +++ b/crates/ui2/src/components/chat_panel.rs @@ -5,7 +5,7 @@ use chrono::NaiveDateTime; use crate::prelude::*; use crate::{Icon, IconButton, Input, Label, LabelColor}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct ChatPanel { element_id: ElementId, messages: Vec>, @@ -24,7 +24,7 @@ impl ChatPanel { self } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div() .id(self.element_id.clone()) .flex() @@ -70,7 +70,7 @@ impl ChatPanel { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct ChatMessage { state_type: PhantomData, author: String, @@ -88,7 +88,7 @@ impl ChatMessage { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div() .flex() .flex_col() @@ -117,7 +117,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct ChatPanelStory { state_type: PhantomData, } @@ -129,7 +129,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, ChatPanel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/collab_panel.rs b/crates/ui2/src/components/collab_panel.rs index 050b7c2b8547553714ca7456f255b3bf943c66e7..8f30b33da0f1707fb581c7f58e048170b490d091 100644 --- a/crates/ui2/src/components/collab_panel.rs +++ b/crates/ui2/src/components/collab_panel.rs @@ -5,7 +5,7 @@ use crate::{ }; use std::marker::PhantomData; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct CollabPanel { id: ElementId, state_type: PhantomData, @@ -19,7 +19,7 @@ impl CollabPanel { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); v_stack() @@ -98,7 +98,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct CollabPanelStory { state_type: PhantomData, } @@ -110,7 +110,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, CollabPanel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/command_palette.rs b/crates/ui2/src/components/command_palette.rs index f79038b1729aef5596c0f04a1f53e76d950a200c..d00b9b77437ed8c8ca7e68f18540a1148d1fd817 100644 --- a/crates/ui2/src/components/command_palette.rs +++ b/crates/ui2/src/components/command_palette.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{example_editor_actions, OrderMethod, Palette}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct CommandPalette { id: ElementId, state_type: PhantomData, @@ -17,7 +17,7 @@ impl CommandPalette { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div().id(self.id.clone()).child( Palette::new("palette") .items(example_editor_actions()) @@ -37,7 +37,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct CommandPaletteStory { state_type: PhantomData, } @@ -49,7 +49,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, CommandPalette>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/context_menu.rs b/crates/ui2/src/components/context_menu.rs index 5463cb29e70079c265b69cc39540d5ed1bdadee0..b52051daa3eed70497d3246698937343488b5cc6 100644 --- a/crates/ui2/src/components/context_menu.rs +++ b/crates/ui2/src/components/context_menu.rs @@ -31,7 +31,7 @@ impl ContextMenuItem { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct ContextMenu { items: Vec>, } @@ -42,7 +42,7 @@ impl ContextMenu { items: items.into_iter().collect(), } } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); v_stack() @@ -73,7 +73,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct ContextMenuStory { state_type: PhantomData, } @@ -85,7 +85,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, ContextMenu>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/copilot.rs b/crates/ui2/src/components/copilot.rs index ca82ea5a0aea92c8cedc736f36275ade1e3031d8..9e5454ee8aa39dad8a18616b64c65417886b7176 100644 --- a/crates/ui2/src/components/copilot.rs +++ b/crates/ui2/src/components/copilot.rs @@ -2,7 +2,7 @@ use std::marker::PhantomData; use crate::{prelude::*, Button, Label, LabelColor, Modal}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct CopilotModal { id: ElementId, state_type: PhantomData, @@ -16,7 +16,7 @@ impl CopilotModal { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div().id(self.id.clone()).child( Modal::new("some-id") .title("Connect Copilot to Zed") @@ -35,7 +35,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct CopilotModalStory { state_type: PhantomData, } @@ -47,7 +47,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, CopilotModal>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/editor_pane.rs b/crates/ui2/src/components/editor_pane.rs index 3fc41d7db6c168df9c4ad34e2f6bca3e150a7b21..fb26dad7918cb167eade1dc742987a8b1de8357f 100644 --- a/crates/ui2/src/components/editor_pane.rs +++ b/crates/ui2/src/components/editor_pane.rs @@ -49,7 +49,7 @@ impl EditorPane { ) } - fn render(&mut self, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(&mut self, cx: &mut ViewContext) -> impl Component { v_stack() .w_full() .h_full() diff --git a/crates/ui2/src/components/facepile.rs b/crates/ui2/src/components/facepile.rs index c87de6a2a28bf928ca8f362e104be51129378ba2..565396e7335900f6418c52c18c4b0552b77b04e2 100644 --- a/crates/ui2/src/components/facepile.rs +++ b/crates/ui2/src/components/facepile.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{Avatar, Player}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Facepile { state_type: PhantomData, players: Vec, @@ -17,7 +17,7 @@ impl Facepile { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let player_count = self.players.len(); let player_list = self.players.iter().enumerate().map(|(ix, player)| { let isnt_last = ix < player_count - 1; @@ -39,7 +39,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct FacepileStory { state_type: PhantomData, } @@ -51,7 +51,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let players = static_players(); Story::container(cx) diff --git a/crates/ui2/src/components/icon_button.rs b/crates/ui2/src/components/icon_button.rs index 0801c5ac234f854631c64b8c71d5d52133fc653c..fe41de15a0e085837202122a828c752561a2d62a 100644 --- a/crates/ui2/src/components/icon_button.rs +++ b/crates/ui2/src/components/icon_button.rs @@ -16,7 +16,7 @@ impl Default for IconButtonHandlers { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct IconButton { state_type: PhantomData, id: ElementId, @@ -68,7 +68,7 @@ impl IconButton { self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let icon_color = match (self.state, self.color) { diff --git a/crates/ui2/src/components/keybinding.rs b/crates/ui2/src/components/keybinding.rs index 7a240aa39ce5ed4828913448868a7a6d53af2b1e..d77798ad6c76e6eee84cc21d6ee20d435cc08d0f 100644 --- a/crates/ui2/src/components/keybinding.rs +++ b/crates/ui2/src/components/keybinding.rs @@ -5,7 +5,7 @@ use strum::{EnumIter, IntoEnumIterator}; use crate::prelude::*; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Keybinding { state_type: PhantomData, @@ -34,7 +34,7 @@ impl Keybinding { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div() .flex() .gap_2() @@ -54,7 +54,7 @@ impl Keybinding { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Key { state_type: PhantomData, key: SharedString, @@ -68,7 +68,7 @@ impl Key { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); div() @@ -173,7 +173,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct KeybindingStory { state_type: PhantomData, } @@ -185,7 +185,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let all_modifier_permutations = ModifierKey::iter().permutations(2); Story::container(cx) diff --git a/crates/ui2/src/components/language_selector.rs b/crates/ui2/src/components/language_selector.rs index 5dd571ec42e668041d22532394718b878c7f03b7..ebb8f152f820562bea936070a36d8ad8cb46a1d3 100644 --- a/crates/ui2/src/components/language_selector.rs +++ b/crates/ui2/src/components/language_selector.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{OrderMethod, Palette, PaletteItem}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct LanguageSelector { id: ElementId, state_type: PhantomData, @@ -17,7 +17,7 @@ impl LanguageSelector { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div().id(self.id.clone()).child( Palette::new("palette") .items(vec![ @@ -48,7 +48,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct LanguageSelectorStory { state_type: PhantomData, } @@ -60,7 +60,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, LanguageSelector>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/list.rs b/crates/ui2/src/components/list.rs index 00684a7eb94b618b7ef9b52f90069b26bac90500..b1b3f506eab67aa94ac9a7adfa0db8df03bf2ef3 100644 --- a/crates/ui2/src/components/list.rs +++ b/crates/ui2/src/components/list.rs @@ -17,7 +17,7 @@ pub enum ListItemVariant { Inset, } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct ListHeader { state_type: PhantomData, label: SharedString, @@ -92,7 +92,7 @@ impl ListHeader { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let is_toggleable = self.toggleable != Toggleable::NotToggleable; @@ -134,7 +134,7 @@ impl ListHeader { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct ListSubHeader { state_type: PhantomData, label: SharedString, @@ -157,7 +157,7 @@ impl ListSubHeader { self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { h_stack().flex_1().w_full().relative().py_1().child( div() .h_6() @@ -197,7 +197,7 @@ pub enum ListEntrySize { Medium, } -#[derive(IntoAnyElement)] +#[derive(Component)] pub enum ListItem { Entry(ListEntry), Details(ListDetailsEntry), @@ -230,7 +230,7 @@ impl From> for ListItem { } impl ListItem { - fn render(self, view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, view: &mut S, cx: &mut ViewContext) -> impl Component { match self { ListItem::Entry(entry) => div().child(entry.render(view, cx)), ListItem::Separator(separator) => div().child(separator.render(view, cx)), @@ -252,7 +252,7 @@ impl ListItem { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct ListEntry { disclosure_control_style: DisclosureControlVisibility, indent_level: u32, @@ -344,7 +344,7 @@ impl ListEntry { } } - fn disclosure_control(&mut self, cx: &mut ViewContext) -> Option> { + fn disclosure_control(&mut self, cx: &mut ViewContext) -> Option> { let disclosure_control_icon = if let Some(ToggleState::Toggled) = self.toggle { IconElement::new(Icon::ChevronDown) } else { @@ -364,7 +364,7 @@ impl ListEntry { } } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let settings = user_settings(cx); let theme = theme(cx); @@ -430,7 +430,7 @@ impl Default for ListDetailsEntryHandlers { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct ListDetailsEntry { label: SharedString, meta: Option, @@ -474,7 +474,7 @@ impl ListDetailsEntry { self } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let settings = user_settings(cx); @@ -519,7 +519,7 @@ impl ListDetailsEntry { } } -#[derive(Clone, IntoAnyElement)] +#[derive(Clone, Component)] pub struct ListSeparator { state_type: PhantomData, } @@ -531,14 +531,14 @@ impl ListSeparator { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); div().h_px().w_full().bg(theme.border) } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct List { items: Vec>, empty_message: SharedString, @@ -571,7 +571,7 @@ impl List { self } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let is_toggleable = self.toggleable != Toggleable::NotToggleable; let is_toggled = Toggleable::is_toggled(&self.toggleable); diff --git a/crates/ui2/src/components/modal.rs b/crates/ui2/src/components/modal.rs index c8fbfc0c6d54ce489aed05980a036e48bbf414f3..0d57013e5d53e301528fca44dc8712ffb90e85c5 100644 --- a/crates/ui2/src/components/modal.rs +++ b/crates/ui2/src/components/modal.rs @@ -5,7 +5,7 @@ use smallvec::SmallVec; use crate::{h_stack, prelude::*, v_stack, Button, Icon, IconButton, Label}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Modal { id: ElementId, state_type: PhantomData, @@ -42,7 +42,7 @@ impl Modal { self } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); v_stack() diff --git a/crates/ui2/src/components/multi_buffer.rs b/crates/ui2/src/components/multi_buffer.rs index 86e89c896c6dfe0face65cb8e9c9cf9ac620147f..30fcb935bbd5c4107c674317a14d62ce748dca43 100644 --- a/crates/ui2/src/components/multi_buffer.rs +++ b/crates/ui2/src/components/multi_buffer.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{v_stack, Buffer, Icon, IconButton, Label}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct MultiBuffer { state_type: PhantomData, buffers: Vec>, @@ -17,7 +17,7 @@ impl MultiBuffer { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); v_stack() @@ -50,7 +50,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct MultiBufferStory { state_type: PhantomData, } @@ -62,7 +62,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); Story::container(cx) diff --git a/crates/ui2/src/components/notification_toast.rs b/crates/ui2/src/components/notification_toast.rs index 6a1011207b18a71f28993d430cfe4c3f93e19bab..6460c2f693db871807206506cfe5ec630125f79d 100644 --- a/crates/ui2/src/components/notification_toast.rs +++ b/crates/ui2/src/components/notification_toast.rs @@ -4,7 +4,7 @@ use gpui2::rems; use crate::{h_stack, prelude::*, Icon}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct NotificationToast { state_type: PhantomData, label: SharedString, @@ -28,7 +28,7 @@ impl NotificationToast { self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); h_stack() diff --git a/crates/ui2/src/components/notifications_panel.rs b/crates/ui2/src/components/notifications_panel.rs index 44af3696c2f43244e3b99a7f518dc2f655da93ff..39ec9ea73f41ea63d3f5c0e093ca3681cd256c20 100644 --- a/crates/ui2/src/components/notifications_panel.rs +++ b/crates/ui2/src/components/notifications_panel.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::{prelude::*, static_new_notification_items, static_read_notification_items}; use crate::{List, ListHeader}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct NotificationsPanel { id: ElementId, state_type: PhantomData, @@ -17,7 +17,7 @@ impl NotificationsPanel { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); div() @@ -58,7 +58,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct NotificationsPanelStory { state_type: PhantomData, } @@ -70,7 +70,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, NotificationsPanel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/palette.rs b/crates/ui2/src/components/palette.rs index 5b52f41aec929bd38cb36b63dbd09d56098dd4a7..56928d4192574e4769972396a834680919ea87bd 100644 --- a/crates/ui2/src/components/palette.rs +++ b/crates/ui2/src/components/palette.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{h_stack, v_stack, Keybinding, Label, LabelColor}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Palette { id: ElementId, state_type: PhantomData, @@ -46,7 +46,7 @@ impl Palette { self } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); v_stack() @@ -101,7 +101,7 @@ impl Palette { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct PaletteItem { pub label: SharedString, pub sublabel: Option, @@ -135,7 +135,7 @@ impl PaletteItem { self } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div() .flex() .flex_row() @@ -160,7 +160,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct PaletteStory { state_type: PhantomData, } @@ -172,7 +172,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, Palette>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/panel.rs b/crates/ui2/src/components/panel.rs index e6bca5afa7e38c4a642b4f4ef1e1b5f50feb8d6b..63c694a7a3c602167984dc18faaef1c220558616 100644 --- a/crates/ui2/src/components/panel.rs +++ b/crates/ui2/src/components/panel.rs @@ -40,7 +40,7 @@ pub enum PanelSide { use std::collections::HashSet; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Panel { id: ElementId, state_type: PhantomData, @@ -96,7 +96,7 @@ impl Panel { self } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let current_size = self.width.unwrap_or(self.initial_width); @@ -136,7 +136,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct PanelStory { state_type: PhantomData, } @@ -148,7 +148,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, Panel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/panes.rs b/crates/ui2/src/components/panes.rs index 118bb5f1974aadfe0ca5ec98e788ee8abb5eeda9..fafa2dd2a1be6649a1abce026a1fa06674f26a59 100644 --- a/crates/ui2/src/components/panes.rs +++ b/crates/ui2/src/components/panes.rs @@ -12,7 +12,7 @@ pub enum SplitDirection { Vertical, } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Pane { id: ElementId, size: Size, @@ -44,7 +44,7 @@ impl Pane { self } - fn render(self, view: &mut V, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, view: &mut V, cx: &mut ViewContext) -> impl Component { div() .id(self.id.clone()) .flex() @@ -75,7 +75,7 @@ impl ParentElement for Pane { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct PaneGroup { state_type: PhantomData, groups: Vec>, @@ -102,7 +102,7 @@ impl PaneGroup { } } - fn render(mut self, view: &mut V, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, view: &mut V, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); if !self.panes.is_empty() { diff --git a/crates/ui2/src/components/player_stack.rs b/crates/ui2/src/components/player_stack.rs index 88b2833dda0d3242453d0f6051aced35763993bf..f1a8df821885cd26ff70e7e5255b31be331c257d 100644 --- a/crates/ui2/src/components/player_stack.rs +++ b/crates/ui2/src/components/player_stack.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{Avatar, Facepile, PlayerWithCallStatus}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct PlayerStack { state_type: PhantomData, player_with_call_status: PlayerWithCallStatus, @@ -17,7 +17,7 @@ impl PlayerStack { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let player = self.player_with_call_status.get_player(); self.player_with_call_status.get_call_status(); diff --git a/crates/ui2/src/components/project_panel.rs b/crates/ui2/src/components/project_panel.rs index 5771f996c500a48becbcac1f717df2714cd72ba8..e0791ab323d134653f06fbb7fab55b4af49345cc 100644 --- a/crates/ui2/src/components/project_panel.rs +++ b/crates/ui2/src/components/project_panel.rs @@ -5,7 +5,7 @@ use crate::{ static_project_panel_project_items, static_project_panel_single_items, Input, List, ListHeader, }; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct ProjectPanel { id: ElementId, state_type: PhantomData, @@ -19,7 +19,7 @@ impl ProjectPanel { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); div() @@ -67,7 +67,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct ProjectPanelStory { state_type: PhantomData, } @@ -79,7 +79,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, ProjectPanel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/recent_projects.rs b/crates/ui2/src/components/recent_projects.rs index d29caa2fd205b334226dd02b62affcdbb05ee85b..94d4c467f8e35d6f287222d29fd7a0de0320d0b1 100644 --- a/crates/ui2/src/components/recent_projects.rs +++ b/crates/ui2/src/components/recent_projects.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{OrderMethod, Palette, PaletteItem}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct RecentProjects { id: ElementId, state_type: PhantomData, @@ -17,7 +17,7 @@ impl RecentProjects { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div().id(self.id.clone()).child( Palette::new("palette") .items(vec![ @@ -44,7 +44,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct RecentProjectsStory { state_type: PhantomData, } @@ -56,7 +56,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, RecentProjects>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/status_bar.rs b/crates/ui2/src/components/status_bar.rs index 4ea0fe4eeb9090a5c61d72170a47e1b655c5e41e..e2fcfe9e0240c8f6665cc71468332f50457034d4 100644 --- a/crates/ui2/src/components/status_bar.rs +++ b/crates/ui2/src/components/status_bar.rs @@ -28,8 +28,8 @@ impl Default for ToolGroup { } } -#[derive(IntoAnyElement)] -#[element(view_type = "Workspace")] +#[derive(Component)] +#[component(view_type = "Workspace")] pub struct StatusBar { left_tools: Option, right_tools: Option, @@ -86,7 +86,7 @@ impl StatusBar { self, view: &mut Workspace, cx: &mut ViewContext, - ) -> impl IntoAnyElement { + ) -> impl Component { let theme = theme(cx); div() @@ -105,7 +105,7 @@ impl StatusBar { &self, workspace: &mut Workspace, cx: &WindowContext, - ) -> impl IntoAnyElement { + ) -> impl Component { div() .flex() .items_center() @@ -136,7 +136,7 @@ impl StatusBar { &self, workspace: &mut Workspace, cx: &WindowContext, - ) -> impl IntoAnyElement { + ) -> impl Component { div() .flex() .items_center() diff --git a/crates/ui2/src/components/tab.rs b/crates/ui2/src/components/tab.rs index 02a2420580f2c332d1dc024c1fd5764dee4afff7..63cdd55b76842d930e50f32df55af458493cc0cc 100644 --- a/crates/ui2/src/components/tab.rs +++ b/crates/ui2/src/components/tab.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{Icon, IconColor, IconElement, Label, LabelColor}; -#[derive(IntoAnyElement, Clone)] +#[derive(Component, Clone)] pub struct Tab { state_type: PhantomData, id: ElementId, @@ -81,7 +81,7 @@ impl Tab { self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let has_fs_conflict = self.fs_status == FileSystemStatus::Conflict; let is_deleted = self.fs_status == FileSystemStatus::Deleted; @@ -176,7 +176,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct TabStory { state_type: PhantomData, } @@ -188,7 +188,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let git_statuses = GitStatus::iter(); let fs_statuses = FileSystemStatus::iter(); diff --git a/crates/ui2/src/components/tab_bar.rs b/crates/ui2/src/components/tab_bar.rs index 38dd9edade800d4e8d4f51a0ccdcdaf6d6762a66..344baaab4b405587e45c3c4588ca2abafff5374a 100644 --- a/crates/ui2/src/components/tab_bar.rs +++ b/crates/ui2/src/components/tab_bar.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{Icon, IconButton, Tab}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct TabBar { id: ElementId, state_type: PhantomData, @@ -27,7 +27,7 @@ impl TabBar { self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let (can_navigate_back, can_navigate_forward) = self.can_navigate; @@ -100,7 +100,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct TabBarStory { state_type: PhantomData, } @@ -112,7 +112,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, TabBar>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/terminal.rs b/crates/ui2/src/components/terminal.rs index 55ab3e02fc25d7007f28d747a1ec566bc733ef2c..1f00a506857db86d7cdb3fb854fa4d98fb9fbbc2 100644 --- a/crates/ui2/src/components/terminal.rs +++ b/crates/ui2/src/components/terminal.rs @@ -5,7 +5,7 @@ use gpui2::{relative, rems, Size}; use crate::prelude::*; use crate::{Icon, IconButton, Pane, Tab}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Terminal { state_type: PhantomData, } @@ -17,7 +17,7 @@ impl Terminal { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let can_navigate_back = true; @@ -93,7 +93,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct TerminalStory { state_type: PhantomData, } @@ -105,7 +105,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, Terminal>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/theme_selector.rs b/crates/ui2/src/components/theme_selector.rs index 1851aea9541736985df6cc9e5648f87a74bbdf5e..e0865c3bcb691b69be644749454ad9d5087c940d 100644 --- a/crates/ui2/src/components/theme_selector.rs +++ b/crates/ui2/src/components/theme_selector.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{OrderMethod, Palette, PaletteItem}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct ThemeSelector { id: ElementId, state_type: PhantomData, @@ -17,7 +17,7 @@ impl ThemeSelector { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div().child( Palette::new(self.id.clone()) .items(vec![ @@ -49,7 +49,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct ThemeSelectorStory { state_type: PhantomData, } @@ -61,7 +61,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, ThemeSelector>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/title_bar.rs b/crates/ui2/src/components/title_bar.rs index a20c7877b2a91dc7f54d0c7d813bdad80e170f13..2d080ac649dafa3dcc908be9e86d7c3ffc4ae6c8 100644 --- a/crates/ui2/src/components/title_bar.rs +++ b/crates/ui2/src/components/title_bar.rs @@ -87,7 +87,7 @@ impl TitleBar { ) } - fn render(&mut self, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(&mut self, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let settings = user_settings(cx); @@ -204,7 +204,7 @@ mod stories { ) } - fn render(&mut self, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(&mut self, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, TitleBar>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/toast.rs b/crates/ui2/src/components/toast.rs index 268042144b56da147e02f99dff4c3e7543eeca76..78bb467aa60c2c5aab1822a67ebb4bc0207e8452 100644 --- a/crates/ui2/src/components/toast.rs +++ b/crates/ui2/src/components/toast.rs @@ -22,7 +22,7 @@ pub enum ToastOrigin { /// they are actively showing the a process in progress. /// /// Only one toast may be visible at a time. -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Toast { origin: ToastOrigin, children: SmallVec<[AnyElement; 2]>, @@ -36,7 +36,7 @@ impl Toast { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let mut div = div(); @@ -78,7 +78,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct ToastStory { state_type: PhantomData, } @@ -90,7 +90,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, Toast>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/toolbar.rs b/crates/ui2/src/components/toolbar.rs index e18c81314d4375342c1550b4646123532efadea5..3f629f93adb4e80d94706cd37521876615166ad6 100644 --- a/crates/ui2/src/components/toolbar.rs +++ b/crates/ui2/src/components/toolbar.rs @@ -6,7 +6,7 @@ use crate::prelude::*; #[derive(Clone)] pub struct ToolbarItem {} -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Toolbar { left_items: SmallVec<[AnyElement; 2]>, right_items: SmallVec<[AnyElement; 2]>, @@ -20,41 +20,41 @@ impl Toolbar { } } - pub fn left_item(mut self, child: impl IntoAnyElement) -> Self + pub fn left_item(mut self, child: impl Component) -> Self where Self: Sized, { - self.left_items.push(child.into_any()); + self.left_items.push(child.render()); self } - pub fn left_items(mut self, iter: impl IntoIterator>) -> Self + pub fn left_items(mut self, iter: impl IntoIterator>) -> Self where Self: Sized, { self.left_items - .extend(iter.into_iter().map(|item| item.into_any())); + .extend(iter.into_iter().map(|item| item.render())); self } - pub fn right_item(mut self, child: impl IntoAnyElement) -> Self + pub fn right_item(mut self, child: impl Component) -> Self where Self: Sized, { - self.right_items.push(child.into_any()); + self.right_items.push(child.render()); self } - pub fn right_items(mut self, iter: impl IntoIterator>) -> Self + pub fn right_items(mut self, iter: impl IntoIterator>) -> Self where Self: Sized, { self.right_items - .extend(iter.into_iter().map(|item| item.into_any())); + .extend(iter.into_iter().map(|item| item.render())); self } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); div() @@ -80,7 +80,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct ToolbarStory { state_type: PhantomData, } @@ -92,7 +92,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); Story::container(cx) diff --git a/crates/ui2/src/components/traffic_lights.rs b/crates/ui2/src/components/traffic_lights.rs index cfe589b463587736d8170321e1e123381541f8d3..25b6d535c5ff9b414083fb936d6ce7c23946e8c8 100644 --- a/crates/ui2/src/components/traffic_lights.rs +++ b/crates/ui2/src/components/traffic_lights.rs @@ -9,7 +9,7 @@ enum TrafficLightColor { Green, } -#[derive(IntoAnyElement)] +#[derive(Component)] struct TrafficLight { state_type: PhantomData, color: TrafficLightColor, @@ -25,7 +25,7 @@ impl TrafficLight { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let fill = match (self.window_has_focus, self.color) { @@ -39,7 +39,7 @@ impl TrafficLight { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct TrafficLights { state_type: PhantomData, window_has_focus: bool, @@ -58,7 +58,7 @@ impl TrafficLights { self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div() .flex() .items_center() @@ -87,7 +87,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct TrafficLightsStory { state_type: PhantomData, } @@ -99,7 +99,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, TrafficLights>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/workspace.rs b/crates/ui2/src/components/workspace.rs index 34158c99185ebf6945577de39c58911dfc07f7b7..e979de6d7c9db94f5938a4e340890f83d2524fe4 100644 --- a/crates/ui2/src/components/workspace.rs +++ b/crates/ui2/src/components/workspace.rs @@ -174,7 +174,7 @@ impl Workspace { view(cx.entity(|cx| Self::new(cx)), Self::render) } - pub fn render(&mut self, cx: &mut ViewContext) -> impl IntoAnyElement { + pub fn render(&mut self, cx: &mut ViewContext) -> impl Component { let theme = old_theme(cx).clone(); // HACK: This should happen inside of `debug_toggle_user_settings`, but diff --git a/crates/ui2/src/elements/avatar.rs b/crates/ui2/src/elements/avatar.rs index 7d2e91ae8ce112b775448fe503b91fca5471acb9..53f3dab58a4021dd495bbd921f127124fdfea59c 100644 --- a/crates/ui2/src/elements/avatar.rs +++ b/crates/ui2/src/elements/avatar.rs @@ -4,7 +4,7 @@ use gpui2::img; use crate::prelude::*; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Avatar { state_type: PhantomData, src: SharedString, @@ -25,7 +25,7 @@ impl Avatar { self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let mut img = img(); @@ -51,7 +51,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct AvatarStory { state_type: PhantomData, } @@ -63,7 +63,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, Avatar>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/elements/button.rs b/crates/ui2/src/elements/button.rs index 843a786aff8d67fbd9f897a87b9ae4a43ca3727a..7c4290bd54efb9520fcffc78e088011de0bccea0 100644 --- a/crates/ui2/src/elements/button.rs +++ b/crates/ui2/src/elements/button.rs @@ -61,7 +61,7 @@ impl Default for ButtonHandlers { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Button { state_type: PhantomData, disabled: bool, @@ -150,7 +150,7 @@ impl Button { self.icon.map(|i| IconElement::new(i).color(icon_color)) } - pub fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + pub fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let icon_color = self.icon_color(); let mut button = h_stack() @@ -193,7 +193,7 @@ impl Button { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct ButtonGroup { state_type: PhantomData, buttons: Vec>, @@ -207,7 +207,7 @@ impl ButtonGroup { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let mut el = h_stack().text_size(ui_size(cx, 1.)); for button in self.buttons { @@ -230,7 +230,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct ButtonStory { state_type: PhantomData, } @@ -242,7 +242,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let states = InteractionState::iter(); Story::container(cx) diff --git a/crates/ui2/src/elements/details.rs b/crates/ui2/src/elements/details.rs index 5f0676f9f4515c1aa63617c1fd71dd25e75af764..84af82500b8c9a89f713ee82f6f6e5968d8f2cec 100644 --- a/crates/ui2/src/elements/details.rs +++ b/crates/ui2/src/elements/details.rs @@ -2,7 +2,7 @@ use std::marker::PhantomData; use crate::{prelude::*, v_stack, ButtonGroup}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Details { state_type: PhantomData, text: &'static str, @@ -30,7 +30,7 @@ impl Details { self } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); v_stack() @@ -54,7 +54,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct DetailsStory { state_type: PhantomData, } @@ -66,7 +66,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, Details>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/elements/icon.rs b/crates/ui2/src/elements/icon.rs index 18d6050dd1c9a63596903648a7ca8f591d8cd0d5..a29202aca0663349d544bfb5d4fa54c8c528e80c 100644 --- a/crates/ui2/src/elements/icon.rs +++ b/crates/ui2/src/elements/icon.rs @@ -148,7 +148,7 @@ impl Icon { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct IconElement { state_type: PhantomData, icon: Icon, @@ -176,7 +176,7 @@ impl IconElement { self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let fill = self.color.color(cx); let svg_size = match self.size { IconSize::Small => ui_size(cx, 12. / 14.), @@ -202,7 +202,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct IconStory { state_type: PhantomData, } @@ -214,7 +214,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let icons = Icon::iter(); Story::container(cx) diff --git a/crates/ui2/src/elements/input.rs b/crates/ui2/src/elements/input.rs index 6a70c9cf798d2438a4686d490f32521a87ee5a76..d65dc62d654e43fd680599d104d909713578ed9f 100644 --- a/crates/ui2/src/elements/input.rs +++ b/crates/ui2/src/elements/input.rs @@ -11,7 +11,7 @@ pub enum InputVariant { Filled, } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Input { state_type: PhantomData, placeholder: SharedString, @@ -60,7 +60,7 @@ impl Input { self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let (input_bg, input_hover_bg, input_active_bg) = match self.variant { @@ -120,7 +120,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct InputStory { state_type: PhantomData, } @@ -132,7 +132,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, Input>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/elements/label.rs b/crates/ui2/src/elements/label.rs index 2d522a27b163b6f05a4a93973ea3f69e8edbd73a..0910a59b5544f428015dd9ad9a202a7e1c7dff5b 100644 --- a/crates/ui2/src/elements/label.rs +++ b/crates/ui2/src/elements/label.rs @@ -48,7 +48,7 @@ pub enum LineHeightStyle { UILabel, } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Label { state_type: PhantomData, label: SharedString, @@ -83,7 +83,7 @@ impl Label { self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div() .when(self.strikethrough, |this| { this.relative().child( @@ -105,7 +105,7 @@ impl Label { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct HighlightedLabel { state_type: PhantomData, label: SharedString, @@ -135,7 +135,7 @@ impl HighlightedLabel { self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let highlight_color = theme.text_accent; @@ -211,7 +211,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct LabelStory { state_type: PhantomData, } @@ -223,7 +223,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, Label>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/elements/tool_divider.rs b/crates/ui2/src/elements/tool_divider.rs index b388894d1a8bc46e384a7144d395826ddba9d316..1c80bca05eca022555d286734e1e81067b1ef943 100644 --- a/crates/ui2/src/elements/tool_divider.rs +++ b/crates/ui2/src/elements/tool_divider.rs @@ -2,7 +2,7 @@ use std::marker::PhantomData; use crate::prelude::*; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct ToolDivider { state_type: PhantomData, } @@ -14,7 +14,7 @@ impl ToolDivider { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); div().w_px().h_3().bg(theme.border) diff --git a/crates/ui2/src/prelude.rs b/crates/ui2/src/prelude.rs index 141c20c5055fec9c4d6353fffeb482af4c92a46e..8098d3e40b34a7e869a6c148b03dba8531ca6ae4 100644 --- a/crates/ui2/src/prelude.rs +++ b/crates/ui2/src/prelude.rs @@ -1,5 +1,5 @@ pub use gpui2::{ - div, Element, ElementId, IntoAnyElement, ParentElement, SharedString, StatefulInteractive, + div, Element, ElementId, Component, ParentElement, SharedString, StatefulInteractive, StatelessInteractive, Styled, ViewContext, WindowContext, }; diff --git a/crates/ui2/src/story.rs b/crates/ui2/src/story.rs index c4bf9c3caadac25c10d1b5f61a59b8316648a67b..c35ddff0a9254c042efb1c9cb826f5180dc75514 100644 --- a/crates/ui2/src/story.rs +++ b/crates/ui2/src/story.rs @@ -21,7 +21,7 @@ impl Story { pub fn title( cx: &mut ViewContext, title: &str, - ) -> impl IntoAnyElement { + ) -> impl Component { let theme = theme(cx); div() @@ -30,16 +30,14 @@ impl Story { .child(title.to_owned()) } - pub fn title_for( - cx: &mut ViewContext, - ) -> impl IntoAnyElement { + pub fn title_for(cx: &mut ViewContext) -> impl Component { Self::title(cx, std::any::type_name::()) } pub fn label( cx: &mut ViewContext, label: &str, - ) -> impl IntoAnyElement { + ) -> impl Component { let theme = theme(cx); div() diff --git a/crates/ui2/src/theme.rs b/crates/ui2/src/theme.rs index b585140cf73ee5cd2b39cc887f4a96908d60d475..d8d924dbb095ff5a4c9d485019bc718240390e19 100644 --- a/crates/ui2/src/theme.rs +++ b/crates/ui2/src/theme.rs @@ -1,5 +1,5 @@ use gpui2::{ - AnyElement, Bounds, Element, Hsla, IntoAnyElement, LayoutId, Pixels, Result, ViewContext, + AnyElement, Bounds, Component, Element, Hsla, LayoutId, Pixels, Result, ViewContext, WindowContext, }; use serde::{de::Visitor, Deserialize, Deserializer}; @@ -149,13 +149,13 @@ pub struct Themed { pub(crate) child: E, } -impl IntoAnyElement for Themed +impl Component for Themed where V: 'static, E: 'static + Element + Send + Sync, E::ElementState: Send + Sync, { - fn into_any(self) -> AnyElement { + fn render(self) -> AnyElement { AnyElement::new(self) } }