diff --git a/crates/gpui2/src/element.rs b/crates/gpui2/src/element.rs index 39b7898d16..762c887342 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 fbef75ab1c..6fe10d94a3 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 d64536a7ed..747e573ea5 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 409094d740..7db4c5cf6d 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 e054da87a6..3aff568c4c 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 f51516dbe5..9ec6c38dfe 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 b1b287c4ab..a27faed07d 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 9f339f1b44..45f4b44c85 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 3635320d55..2e0c0547f7 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 5eaa894302..a3dca51adc 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 fbb4f5099c..ec89238ac4 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 86a8ca41c8..a1e3c6700e 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 270bd08640..d68b4916c2 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 8cd3f9e329..5f60ad14ea 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 4db1fd434b..29ff5eaa98 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 fa5ac38dc1..c07723cedb 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 00a471e7cc..289c071021 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 662ccd5736..ffef5c4039 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 e3e92aa073..b5e74a4810 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 db0f573485..2800207b34 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 050b7c2b85..8f30b33da0 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 f79038b172..d00b9b7743 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 5463cb29e7..b52051daa3 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 ca82ea5a0a..9e5454ee8a 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 3fc41d7db6..fb26dad791 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 c87de6a2a2..565396e733 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 0801c5ac23..fe41de15a0 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 7a240aa39c..d77798ad6c 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 5dd571ec42..ebb8f152f8 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 00684a7eb9..b1b3f506ea 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 c8fbfc0c6d..0d57013e5d 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 86e89c896c..30fcb935bb 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 6a1011207b..6460c2f693 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 44af3696c2..39ec9ea73f 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 5b52f41aec..56928d4192 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 e6bca5afa7..63c694a7a3 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 118bb5f197..fafa2dd2a1 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 88b2833dda..f1a8df8218 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 5771f996c5..e0791ab323 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 d29caa2fd2..94d4c467f8 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 4ea0fe4eeb..e2fcfe9e02 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 02a2420580..63cdd55b76 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 38dd9edade..344baaab4b 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 55ab3e02fc..1f00a50685 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 1851aea954..e0865c3bcb 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 a20c7877b2..2d080ac649 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 268042144b..78bb467aa6 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 e18c81314d..3f629f93ad 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 cfe589b463..25b6d535c5 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 34158c9918..e979de6d7c 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 7d2e91ae8c..53f3dab58a 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 843a786aff..7c4290bd54 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 5f0676f9f4..84af82500b 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 18d6050dd1..a29202aca0 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 6a70c9cf79..d65dc62d65 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 2d522a27b1..0910a59b55 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 b388894d1a..1c80bca05e 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 141c20c505..8098d3e40b 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 c4bf9c3caa..c35ddff0a9 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 b585140cf7..d8d924dbb0 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) } }