diff --git a/crates/collab_ui2/src/collab_titlebar_item.rs b/crates/collab_ui2/src/collab_titlebar_item.rs index 94db2f4d9f..b5db5abddd 100644 --- a/crates/collab_ui2/src/collab_titlebar_item.rs +++ b/crates/collab_ui2/src/collab_titlebar_item.rs @@ -31,7 +31,7 @@ use std::sync::Arc; use call::ActiveCall; use client::{Client, UserStore}; use gpui::{ - div, px, rems, AppContext, Div, InteractiveElement, Model, ParentElement, Render, RenderOnce, + div, px, rems, AppContext, Div, InteractiveElement, IntoElement, Model, ParentElement, Render, Stateful, StatefulInteractiveElement, Styled, Subscription, ViewContext, VisualContext, WeakView, WindowBounds, }; diff --git a/crates/diagnostics2/src/diagnostics.rs b/crates/diagnostics2/src/diagnostics.rs index 7ff8cd84db..9e97bff968 100644 --- a/crates/diagnostics2/src/diagnostics.rs +++ b/crates/diagnostics2/src/diagnostics.rs @@ -14,8 +14,8 @@ use editor::{ use futures::future::try_join_all; use gpui::{ actions, div, AnyElement, AnyView, AppContext, Context, Div, EventEmitter, FocusEvent, - FocusHandle, Focusable, FocusableElement, FocusableView, InteractiveElement, Model, - ParentElement, Render, RenderOnce, SharedString, Styled, Subscription, Task, View, ViewContext, + FocusHandle, Focusable, FocusableElement, FocusableView, InteractiveElement, IntoElement, + Model, ParentElement, Render, SharedString, Styled, Subscription, Task, View, ViewContext, VisualContext, WeakView, WindowContext, }; use language::{ @@ -792,14 +792,14 @@ fn diagnostic_header_renderer(diagnostic: Diagnostic) -> RenderBlock { .when_some(diagnostic.code.as_ref(), |stack, code| { stack.child(Label::new(code.clone())) }) - .render_into_any() + .into_any_element() }) } pub(crate) fn render_summary(summary: &DiagnosticSummary) -> AnyElement { if summary.error_count == 0 && summary.warning_count == 0 { let label = Label::new("No problems"); - label.render_into_any() + label.into_any_element() } else { h_stack() .bg(gpui::red()) @@ -807,7 +807,7 @@ pub(crate) fn render_summary(summary: &DiagnosticSummary) -> AnyElement { .child(Label::new(summary.error_count.to_string())) .child(IconElement::new(Icon::ExclamationTriangle)) .child(Label::new(summary.warning_count.to_string())) - .render_into_any() + .into_any_element() } } diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rs index fa5f4dfa42..33b742f9df 100644 --- a/crates/editor2/src/editor.rs +++ b/crates/editor2/src/editor.rs @@ -40,9 +40,9 @@ use fuzzy::{StringMatch, StringMatchCandidate}; use git::diff_hunk_to_display; use gpui::{ actions, div, point, prelude::*, px, relative, rems, size, uniform_list, Action, AnyElement, - AppContext, AsyncWindowContext, BackgroundExecutor, Bounds, ClipboardItem, Component, Context, + AppContext, AsyncWindowContext, BackgroundExecutor, Bounds, ClipboardItem, Context, EventEmitter, FocusHandle, FocusableView, FontFeatures, FontStyle, FontWeight, HighlightStyle, - Hsla, InputHandler, KeyContext, Model, MouseButton, ParentElement, Pixels, Render, + Hsla, InputHandler, KeyContext, Model, MouseButton, ParentElement, Pixels, Render, RenderOnce, SharedString, Styled, Subscription, Task, TextStyle, UniformListScrollHandle, View, ViewContext, VisualContext, WeakView, WhiteSpace, WindowContext, }; @@ -1373,7 +1373,7 @@ impl CompletionsMenu { .track_scroll(self.scroll_handle.clone()) .with_width_from_item(widest_completion_ix); - list.render_into_any() + list.into_any_element() // todo!("multiline documentation") // enum MultiLineDocumentation {} @@ -1596,7 +1596,7 @@ impl CodeActionsMenu { .max_by_key(|(_, action)| action.lsp_action.title.chars().count()) .map(|(ix, _)| ix), ) - .render_into_any(); + .into_any_element(); if self.deployed_from_indicator { *cursor_position.column_mut() = 0; @@ -7796,7 +7796,7 @@ impl Editor { .clone(), }, )) - .render_into_any() + .into_any_element() } }), disposition: BlockDisposition::Below, @@ -10005,7 +10005,7 @@ pub fn diagnostic_block_renderer(diagnostic: Diagnostic, is_valid: bool) -> Rend cx.write_to_clipboard(ClipboardItem::new(message.clone())); })) .tooltip(|cx| Tooltip::text("Copy diagnostic message", cx)) - .render_into_any() + .into_any_element() }) } diff --git a/crates/editor2/src/element.rs b/crates/editor2/src/element.rs index 7f6135087a..5476cd8ab1 100644 --- a/crates/editor2/src/element.rs +++ b/crates/editor2/src/element.rs @@ -19,8 +19,8 @@ use anyhow::Result; use collections::{BTreeMap, HashMap}; use gpui::{ div, point, px, relative, size, transparent_black, Action, AnyElement, AvailableSpace, - BorrowWindow, Bounds, Component, ContentMask, Corners, DispatchPhase, Edges, Element, - ElementId, ElementInputHandler, Entity, EntityId, Hsla, InteractiveElement, LineLayout, + BorrowWindow, Bounds, ContentMask, Corners, DispatchPhase, Edges, Element, ElementId, + ElementInputHandler, Entity, EntityId, Hsla, InteractiveElement, IntoElement, LineLayout, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, ParentElement, Pixels, RenderOnce, ScrollWheelEvent, ShapedLine, SharedString, Size, StatefulInteractiveElement, Style, Styled, TextRun, TextStyle, View, ViewContext, WeakView, WindowContext, WrappedLine, @@ -663,7 +663,7 @@ impl EditorElement { for (ix, fold_indicator) in layout.fold_indicators.drain(..).enumerate() { if let Some(mut fold_indicator) = fold_indicator { - let mut fold_indicator = fold_indicator.render_into_any(); + let mut fold_indicator = fold_indicator.into_any_element(); let available_space = size( AvailableSpace::MinContent, AvailableSpace::Definite(line_height * 0.55), @@ -684,7 +684,7 @@ impl EditorElement { } if let Some(indicator) = layout.code_actions_indicator.take() { - let mut button = indicator.button.render_into_any(); + let mut button = indicator.button.into_any_element(); let available_space = size( AvailableSpace::MinContent, AvailableSpace::Definite(line_height), @@ -2653,14 +2653,14 @@ impl Element for EditorElement { } } -impl RenderOnce for EditorElement { +impl IntoElement for EditorElement { type Element = Self; fn element_id(&self) -> Option { self.editor.element_id() } - fn render_once(self) -> Self::Element { + fn into_element(self) -> Self::Element { self } } diff --git a/crates/file_finder2/src/file_finder.rs b/crates/file_finder2/src/file_finder.rs index 0b9157bb4f..873054a68c 100644 --- a/crates/file_finder2/src/file_finder.rs +++ b/crates/file_finder2/src/file_finder.rs @@ -3,7 +3,7 @@ use editor::{scroll::autoscroll::Autoscroll, Bias, Editor}; use fuzzy::{CharBag, PathMatch, PathMatchCandidate}; use gpui::{ actions, div, AppContext, Div, EventEmitter, FocusHandle, FocusableView, InteractiveElement, - Manager, Model, ParentElement, Render, RenderOnce, Styled, Task, View, ViewContext, + IntoElement, Manager, Model, ParentElement, Render, Styled, Task, View, ViewContext, VisualContext, WeakView, }; use picker::{Picker, PickerDelegate}; diff --git a/crates/gpui2/src/element.rs b/crates/gpui2/src/element.rs index 5cd015503d..5f62629265 100644 --- a/crates/gpui2/src/element.rs +++ b/crates/gpui2/src/element.rs @@ -12,15 +12,15 @@ pub trait Render: 'static + Sized { fn render(&mut self, cx: &mut ViewContext) -> Self::Element; } -pub trait RenderOnce: Sized { +pub trait IntoElement: Sized { type Element: Element + 'static; fn element_id(&self) -> Option; - fn render_once(self) -> Self::Element; + fn into_element(self) -> Self::Element; - fn render_into_any(self) -> AnyElement { - self.render_once().into_any() + fn into_any_element(self) -> AnyElement { + self.into_element().into_any() } fn draw( @@ -33,7 +33,7 @@ pub trait RenderOnce: Sized { where T: Clone + Default + Debug + Into, { - let element = self.render_once(); + let element = self.into_element(); let element_id = element.element_id(); let element = DrawableElement { element: Some(element), @@ -57,7 +57,7 @@ pub trait RenderOnce: Sized { fn map(self, f: impl FnOnce(Self) -> U) -> U where Self: Sized, - U: RenderOnce, + U: IntoElement, { f(self) } @@ -83,7 +83,7 @@ pub trait RenderOnce: Sized { } } -pub trait Element: 'static + RenderOnce { +pub trait Element: 'static + IntoElement { type State: 'static; fn layout( @@ -99,30 +99,30 @@ pub trait Element: 'static + RenderOnce { } } -pub trait Component: 'static { - type Rendered: RenderOnce; +pub trait RenderOnce: 'static { + type Rendered: IntoElement; fn render(self, cx: &mut WindowContext) -> Self::Rendered; } -pub struct CompositeElement { +pub struct Component { component: Option, } -pub struct CompositeElementState { - rendered_element: Option<::Element>, - rendered_element_state: <::Element as Element>::State, +pub struct CompositeElementState { + rendered_element: Option<::Element>, + rendered_element_state: <::Element as Element>::State, } -impl CompositeElement { +impl Component { pub fn new(component: C) -> Self { - CompositeElement { + Component { component: Some(component), } } } -impl Element for CompositeElement { +impl Element for Component { type State = CompositeElementState; fn layout( @@ -130,7 +130,7 @@ impl Element for CompositeElement { state: Option, cx: &mut WindowContext, ) -> (LayoutId, Self::State) { - let mut element = self.component.take().unwrap().render(cx).render_once(); + let mut element = self.component.take().unwrap().render(cx).into_element(); let (layout_id, state) = element.layout(state.map(|s| s.rendered_element_state), cx); let state = CompositeElementState { rendered_element: Some(element), @@ -148,14 +148,14 @@ impl Element for CompositeElement { } } -impl RenderOnce for CompositeElement { +impl IntoElement for Component { type Element = Self; fn element_id(&self) -> Option { None } - fn render_once(self) -> Self::Element { + fn into_element(self) -> Self::Element { self } } @@ -166,23 +166,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 RenderOnce) -> Self + fn child(mut self, child: impl IntoElement) -> Self where Self: Sized, { - self.children_mut().push(child.render_once().into_any()); + self.children_mut().push(child.into_element().into_any()); self } - fn children(mut self, children: impl IntoIterator) -> Self + fn children(mut self, children: impl IntoIterator) -> Self where Self: Sized, { - self.children_mut().extend( - children - .into_iter() - .map(|child| child.render_once().into_any()), - ); + self.children_mut() + .extend(children.into_iter().map(|child| child.into_any_element())); self } } @@ -486,14 +483,14 @@ impl Element for AnyElement { } } -impl RenderOnce for AnyElement { +impl IntoElement for AnyElement { type Element = Self; fn element_id(&self) -> Option { AnyElement::element_id(self) } - fn render_once(self) -> Self::Element { + fn into_element(self) -> Self::Element { self } } diff --git a/crates/gpui2/src/elements/div.rs b/crates/gpui2/src/elements/div.rs index 630b368b95..406f2ea311 100644 --- a/crates/gpui2/src/elements/div.rs +++ b/crates/gpui2/src/elements/div.rs @@ -1,9 +1,9 @@ use crate::{ point, px, Action, AnyDrag, AnyElement, AnyTooltip, AnyView, AppContext, BorrowAppContext, BorrowWindow, Bounds, ClickEvent, DispatchPhase, Element, ElementId, FocusEvent, FocusHandle, - KeyContext, KeyDownEvent, KeyUpEvent, LayoutId, MouseButton, MouseDownEvent, MouseMoveEvent, - MouseUpEvent, ParentElement, Pixels, Point, Render, RenderOnce, ScrollWheelEvent, SharedString, - Size, Style, StyleRefinement, Styled, Task, View, Visibility, WindowContext, + IntoElement, KeyContext, KeyDownEvent, KeyUpEvent, LayoutId, MouseButton, MouseDownEvent, + MouseMoveEvent, MouseUpEvent, ParentElement, Pixels, Point, Render, ScrollWheelEvent, + SharedString, Size, Style, StyleRefinement, Styled, Task, View, Visibility, WindowContext, }; use collections::HashMap; use refineable::Refineable; @@ -666,14 +666,14 @@ impl Element for Div { } } -impl RenderOnce for Div { +impl IntoElement for Div { type Element = Self; fn element_id(&self) -> Option { self.interactivity.element_id.clone() } - fn render_once(self) -> Self::Element { + fn into_element(self) -> Self::Element { self } } @@ -1278,7 +1278,7 @@ where } } -impl RenderOnce for Focusable +impl IntoElement for Focusable where E: Element, { @@ -1288,7 +1288,7 @@ where self.element.element_id() } - fn render_once(self) -> Self::Element { + fn into_element(self) -> Self::Element { self.element } } @@ -1352,7 +1352,7 @@ where } } -impl RenderOnce for Stateful +impl IntoElement for Stateful where E: Element, { @@ -1362,7 +1362,7 @@ where self.element.element_id() } - fn render_once(self) -> Self::Element { + fn into_element(self) -> Self::Element { self } } diff --git a/crates/gpui2/src/elements/img.rs b/crates/gpui2/src/elements/img.rs index 3c0f4c00be..f7dcd7ab82 100644 --- a/crates/gpui2/src/elements/img.rs +++ b/crates/gpui2/src/elements/img.rs @@ -1,6 +1,6 @@ use crate::{ - Bounds, Element, InteractiveElement, InteractiveElementState, Interactivity, LayoutId, Pixels, - RenderOnce, SharedString, StyleRefinement, Styled, WindowContext, + Bounds, Element, InteractiveElement, InteractiveElementState, Interactivity, IntoElement, + LayoutId, Pixels, SharedString, StyleRefinement, Styled, WindowContext, }; use futures::FutureExt; use util::ResultExt; @@ -86,14 +86,14 @@ impl Element for Img { } } -impl RenderOnce for Img { +impl IntoElement for Img { type Element = Self; fn element_id(&self) -> Option { self.interactivity.element_id.clone() } - fn render_once(self) -> Self::Element { + fn into_element(self) -> Self::Element { self } } diff --git a/crates/gpui2/src/elements/overlay.rs b/crates/gpui2/src/elements/overlay.rs index 29ac2f00c4..d8aad4a42f 100644 --- a/crates/gpui2/src/elements/overlay.rs +++ b/crates/gpui2/src/elements/overlay.rs @@ -2,8 +2,8 @@ use smallvec::SmallVec; use taffy::style::{Display, Position}; use crate::{ - point, AnyElement, BorrowWindow, Bounds, Element, LayoutId, ParentElement, Pixels, Point, - RenderOnce, Size, Style, WindowContext, + point, AnyElement, BorrowWindow, Bounds, Element, IntoElement, LayoutId, ParentElement, Pixels, + Point, Size, Style, WindowContext, }; pub struct OverlayState { @@ -151,14 +151,14 @@ impl Element for Overlay { } } -impl RenderOnce for Overlay { +impl IntoElement for Overlay { type Element = Self; fn element_id(&self) -> Option { None } - fn render_once(self) -> Self::Element { + fn into_element(self) -> Self::Element { self } } diff --git a/crates/gpui2/src/elements/svg.rs b/crates/gpui2/src/elements/svg.rs index c24e4d9b8b..aba31686f5 100644 --- a/crates/gpui2/src/elements/svg.rs +++ b/crates/gpui2/src/elements/svg.rs @@ -1,6 +1,6 @@ use crate::{ Bounds, Element, ElementId, InteractiveElement, InteractiveElementState, Interactivity, - LayoutId, Pixels, RenderOnce, SharedString, StyleRefinement, Styled, WindowContext, + IntoElement, LayoutId, Pixels, SharedString, StyleRefinement, Styled, WindowContext, }; use util::ResultExt; @@ -49,14 +49,14 @@ impl Element for Svg { } } -impl RenderOnce for Svg { +impl IntoElement for Svg { type Element = Self; fn element_id(&self) -> Option { self.interactivity.element_id.clone() } - fn render_once(self) -> Self::Element { + fn into_element(self) -> Self::Element { self } } diff --git a/crates/gpui2/src/elements/text.rs b/crates/gpui2/src/elements/text.rs index a34de482d5..74b74d0d05 100644 --- a/crates/gpui2/src/elements/text.rs +++ b/crates/gpui2/src/elements/text.rs @@ -1,5 +1,5 @@ use crate::{ - Bounds, Element, ElementId, LayoutId, Pixels, RenderOnce, SharedString, Size, TextRun, + Bounds, Element, ElementId, IntoElement, LayoutId, Pixels, SharedString, Size, TextRun, WhiteSpace, WindowContext, WrappedLine, }; use anyhow::anyhow; @@ -26,14 +26,14 @@ impl Element for &'static str { } } -impl RenderOnce for &'static str { +impl IntoElement for &'static str { type Element = Self; fn element_id(&self) -> Option { None } - fn render_once(self) -> Self::Element { + fn into_element(self) -> Self::Element { self } } @@ -57,14 +57,14 @@ impl Element for SharedString { } } -impl RenderOnce for SharedString { +impl IntoElement for SharedString { type Element = Self; fn element_id(&self) -> Option { None } - fn render_once(self) -> Self::Element { + fn into_element(self) -> Self::Element { self } } @@ -106,14 +106,14 @@ impl Element for StyledText { } } -impl RenderOnce for StyledText { +impl IntoElement for StyledText { type Element = Self; fn element_id(&self) -> Option { None } - fn render_once(self) -> Self::Element { + fn into_element(self) -> Self::Element { self } } @@ -272,14 +272,14 @@ impl Element for InteractiveText { } } -impl RenderOnce for InteractiveText { +impl IntoElement for InteractiveText { type Element = Self; fn element_id(&self) -> Option { Some(self.element_id.clone()) } - fn render_once(self) -> Self::Element { + fn into_element(self) -> Self::Element { self } } diff --git a/crates/gpui2/src/elements/uniform_list.rs b/crates/gpui2/src/elements/uniform_list.rs index 3c3222c8a0..b3b99ee680 100644 --- a/crates/gpui2/src/elements/uniform_list.rs +++ b/crates/gpui2/src/elements/uniform_list.rs @@ -1,6 +1,6 @@ use crate::{ point, px, size, AnyElement, AvailableSpace, Bounds, Element, ElementId, InteractiveElement, - InteractiveElementState, Interactivity, LayoutId, Pixels, Point, Render, RenderOnce, Size, + InteractiveElementState, Interactivity, IntoElement, LayoutId, Pixels, Point, Render, Size, StyleRefinement, Styled, View, ViewContext, WindowContext, }; use smallvec::SmallVec; @@ -18,7 +18,7 @@ pub fn uniform_list( ) -> UniformList where I: Into, - R: RenderOnce, + R: IntoElement, V: Render, { let id = id.into(); @@ -29,7 +29,7 @@ where view.update(cx, |this, cx| { f(this, range, cx) .into_iter() - .map(|component| component.render_into_any()) + .map(|component| component.into_any_element()) .collect() }) }; @@ -243,14 +243,14 @@ impl Element for UniformList { } } -impl RenderOnce for UniformList { +impl IntoElement for UniformList { type Element = Self; fn element_id(&self) -> Option { Some(self.id.clone()) } - fn render_once(self) -> Self::Element { + fn into_element(self) -> Self::Element { self } } diff --git a/crates/gpui2/src/interactive.rs b/crates/gpui2/src/interactive.rs index 3dfe0c3b43..2d48ec5a11 100644 --- a/crates/gpui2/src/interactive.rs +++ b/crates/gpui2/src/interactive.rs @@ -1,6 +1,6 @@ use crate::{ - div, point, Div, Element, FocusHandle, Keystroke, Modifiers, Pixels, Point, Render, RenderOnce, - ViewContext, + div, point, Div, Element, FocusHandle, IntoElement, Keystroke, Modifiers, Pixels, Point, + Render, ViewContext, }; use smallvec::SmallVec; use std::{any::Any, fmt::Debug, marker::PhantomData, ops::Deref, path::PathBuf}; @@ -64,7 +64,7 @@ pub struct Drag where R: Fn(&mut V, &mut ViewContext) -> E, V: 'static, - E: RenderOnce, + E: IntoElement, { pub state: S, pub render_drag_handle: R, @@ -286,8 +286,8 @@ pub struct FocusEvent { #[cfg(test)] mod test { use crate::{ - self as gpui, div, Div, FocusHandle, InteractiveElement, KeyBinding, Keystroke, - ParentElement, Render, RenderOnce, Stateful, TestAppContext, VisualContext, + self as gpui, div, Div, FocusHandle, InteractiveElement, IntoElement, KeyBinding, + Keystroke, ParentElement, Render, Stateful, TestAppContext, VisualContext, }; struct TestView { @@ -315,7 +315,7 @@ mod test { div() .key_context("nested") .track_focus(&self.focus_handle) - .render_once(), + .into_element(), ), ) } diff --git a/crates/gpui2/src/prelude.rs b/crates/gpui2/src/prelude.rs index 50f48596bc..90d09b3fc5 100644 --- a/crates/gpui2/src/prelude.rs +++ b/crates/gpui2/src/prelude.rs @@ -1,5 +1,5 @@ pub use crate::{ - BorrowAppContext, BorrowWindow, Component, Context, Element, FocusableElement, - InteractiveElement, ParentElement, Refineable, Render, RenderOnce, StatefulInteractiveElement, - Styled, VisualContext, + BorrowAppContext, BorrowWindow, Context, Element, FocusableElement, InteractiveElement, + IntoElement, ParentElement, Refineable, Render, RenderOnce, StatefulInteractiveElement, Styled, + VisualContext, }; diff --git a/crates/gpui2/src/view.rs b/crates/gpui2/src/view.rs index efa40627ac..02696deb8a 100644 --- a/crates/gpui2/src/view.rs +++ b/crates/gpui2/src/view.rs @@ -1,7 +1,7 @@ use crate::{ private::Sealed, AnyElement, AnyModel, AnyWeakModel, AppContext, AvailableSpace, BorrowWindow, - Bounds, Element, ElementId, Entity, EntityId, Flatten, FocusHandle, FocusableView, LayoutId, - Model, Pixels, Point, Render, RenderOnce, Size, ViewContext, VisualContext, WeakModel, + Bounds, Element, ElementId, Entity, EntityId, Flatten, FocusHandle, FocusableView, IntoElement, + LayoutId, Model, Pixels, Point, Render, Size, ViewContext, VisualContext, WeakModel, WindowContext, }; use anyhow::{Context, Result}; @@ -244,26 +244,26 @@ impl Element for AnyView { } } -impl RenderOnce for View { +impl IntoElement for View { type Element = View; fn element_id(&self) -> Option { Some(self.model.entity_id.into()) } - fn render_once(self) -> Self::Element { + fn into_element(self) -> Self::Element { self } } -impl RenderOnce for AnyView { +impl IntoElement for AnyView { type Element = Self; fn element_id(&self) -> Option { Some(self.model.entity_id.into()) } - fn render_once(self) -> Self::Element { + fn into_element(self) -> Self::Element { self } } diff --git a/crates/gpui2_macros/src/derive_component.rs b/crates/gpui2_macros/src/derive_component.rs deleted file mode 100644 index aaf814497a..0000000000 --- a/crates/gpui2_macros/src/derive_component.rs +++ /dev/null @@ -1,66 +0,0 @@ -use proc_macro::TokenStream; -use quote::quote; -use syn::{parse_macro_input, parse_quote, DeriveInput}; - -pub fn derive_component(input: TokenStream) -> TokenStream { - let ast = parse_macro_input!(input as DeriveInput); - let name = &ast.ident; - - let mut trait_generics = ast.generics.clone(); - let view_type = if let Some(view_type) = specified_view_type(&ast) { - quote! { #view_type } - } else { - if let Some(first_type_param) = ast.generics.params.iter().find_map(|param| { - if let syn::GenericParam::Type(type_param) = param { - Some(type_param.ident.clone()) - } else { - None - } - }) { - quote! { #first_type_param } - } else { - trait_generics.params.push(parse_quote! { V: 'static }); - quote! { V } - } - }; - - let (impl_generics, _, where_clause) = trait_generics.split_for_impl(); - let (_, ty_generics, _) = ast.generics.split_for_impl(); - - let expanded = quote! { - impl #impl_generics gpui::Component<#view_type> for #name #ty_generics #where_clause { - fn render(self) -> gpui::AnyElement<#view_type> { - (move |view_state: &mut #view_type, cx: &mut gpui::ViewContext<'_, #view_type>| self.render(view_state, cx)) - .render() - } - } - }; - - TokenStream::from(expanded) -} - -fn specified_view_type(ast: &DeriveInput) -> Option { - let component_attr = ast - .attrs - .iter() - .find(|attr| attr.path.is_ident("component"))?; - - if let Ok(syn::Meta::List(meta_list)) = component_attr.parse_meta() { - meta_list.nested.iter().find_map(|nested| { - if let syn::NestedMeta::Meta(syn::Meta::NameValue(nv)) = nested { - if nv.path.is_ident("view_type") { - if let syn::Lit::Str(lit_str) = &nv.lit { - return Some( - lit_str - .parse::() - .expect("Failed to parse view_type"), - ); - } - } - } - None - }) - } else { - None - } -} diff --git a/crates/gpui2_macros/src/derive_render_once.rs b/crates/gpui2_macros/src/derive_into_element.rs similarity index 60% rename from crates/gpui2_macros/src/derive_render_once.rs rename to crates/gpui2_macros/src/derive_into_element.rs index efe6aab0bb..12c6975e07 100644 --- a/crates/gpui2_macros/src/derive_render_once.rs +++ b/crates/gpui2_macros/src/derive_into_element.rs @@ -2,23 +2,23 @@ use proc_macro::TokenStream; use quote::quote; use syn::{parse_macro_input, DeriveInput}; -pub fn derive_render_once(input: TokenStream) -> TokenStream { +pub fn derive_into_element(input: TokenStream) -> TokenStream { let ast = parse_macro_input!(input as DeriveInput); let type_name = &ast.ident; let (impl_generics, type_generics, where_clause) = ast.generics.split_for_impl(); let gen = quote! { - impl #impl_generics gpui::RenderOnce for #type_name #type_generics + impl #impl_generics gpui::IntoElement for #type_name #type_generics #where_clause { - type Element = gpui::CompositeElement; + type Element = gpui::Component; fn element_id(&self) -> Option { None } - fn render_once(self) -> Self::Element { - gpui::CompositeElement::new(self) + fn into_element(self) -> Self::Element { + gpui::Component::new(self) } } }; diff --git a/crates/gpui2_macros/src/gpui2_macros.rs b/crates/gpui2_macros/src/gpui2_macros.rs index 6dd817e280..a7fb363d36 100644 --- a/crates/gpui2_macros/src/gpui2_macros.rs +++ b/crates/gpui2_macros/src/gpui2_macros.rs @@ -1,6 +1,5 @@ mod action; -mod derive_component; -mod derive_render_once; +mod derive_into_element; mod register_action; mod style_helpers; mod test; @@ -17,14 +16,9 @@ pub fn register_action(attr: TokenStream, item: TokenStream) -> TokenStream { register_action::register_action_macro(attr, item) } -#[proc_macro_derive(Component, attributes(component))] -pub fn derive_component(input: TokenStream) -> TokenStream { - derive_component::derive_component(input) -} - -#[proc_macro_derive(RenderOnce, attributes(view))] -pub fn derive_render_once(input: TokenStream) -> TokenStream { - derive_render_once::derive_render_once(input) +#[proc_macro_derive(IntoElement)] +pub fn derive_into_element(input: TokenStream) -> TokenStream { + derive_into_element::derive_into_element(input) } #[proc_macro] diff --git a/crates/picker2/src/picker2.rs b/crates/picker2/src/picker2.rs index e58b7782ef..70a8df21e1 100644 --- a/crates/picker2/src/picker2.rs +++ b/crates/picker2/src/picker2.rs @@ -15,7 +15,7 @@ pub struct Picker { } pub trait PickerDelegate: Sized + 'static { - type ListItem: RenderOnce; + type ListItem: IntoElement; fn match_count(&self) -> usize; fn selected_index(&self) -> usize; diff --git a/crates/project_panel2/src/project_panel.rs b/crates/project_panel2/src/project_panel.rs index 4d1a6ee8f7..160c48f721 100644 --- a/crates/project_panel2/src/project_panel.rs +++ b/crates/project_panel2/src/project_panel.rs @@ -10,8 +10,8 @@ use anyhow::{anyhow, Result}; use gpui::{ actions, div, px, uniform_list, Action, AppContext, AssetSource, AsyncWindowContext, ClipboardItem, Div, EventEmitter, FocusHandle, Focusable, FocusableView, InteractiveElement, - Model, MouseButton, MouseDownEvent, ParentElement, Pixels, Point, PromptLevel, Render, - RenderOnce, Stateful, StatefulInteractiveElement, Styled, Task, UniformListScrollHandle, View, + IntoElement, Model, MouseButton, MouseDownEvent, ParentElement, Pixels, Point, PromptLevel, + Render, Stateful, StatefulInteractiveElement, Styled, Task, UniformListScrollHandle, View, ViewContext, VisualContext as _, WeakView, WindowContext, }; use menu::{Confirm, SelectNext, SelectPrev}; diff --git a/crates/search2/src/buffer_search.rs b/crates/search2/src/buffer_search.rs index 3674baf356..ad549256f9 100644 --- a/crates/search2/src/buffer_search.rs +++ b/crates/search2/src/buffer_search.rs @@ -10,9 +10,9 @@ use collections::HashMap; use editor::Editor; use futures::channel::oneshot; use gpui::{ - actions, div, red, Action, AppContext, Div, EventEmitter, InteractiveElement as _, - ParentElement as _, Render, RenderOnce, Styled, Subscription, Task, View, ViewContext, - VisualContext as _, WindowContext, + actions, div, red, Action, AppContext, Div, EventEmitter, InteractiveElement as _, IntoElement, + ParentElement as _, Render, Styled, Subscription, Task, View, ViewContext, VisualContext as _, + WindowContext, }; use project::search::SearchQuery; use serde::Deserialize; @@ -538,7 +538,7 @@ impl BufferSearchBar { self.update_matches(cx) } - fn render_action_button(&self) -> impl RenderOnce { + fn render_action_button(&self) -> impl IntoElement { // let tooltip_style = theme.tooltip.clone(); // let style = theme.search.action_button.clone(); diff --git a/crates/search2/src/search.rs b/crates/search2/src/search.rs index 12152701bc..118d9054e6 100644 --- a/crates/search2/src/search.rs +++ b/crates/search2/src/search.rs @@ -1,6 +1,6 @@ use bitflags::bitflags; pub use buffer_search::BufferSearchBar; -use gpui::{actions, Action, AppContext, RenderOnce}; +use gpui::{actions, Action, AppContext, IntoElement}; pub use mode::SearchMode; use project::search::SearchQuery; use ui::ButtonVariant; @@ -82,7 +82,7 @@ impl SearchOptions { options } - pub fn as_button(&self, active: bool) -> impl RenderOnce { + pub fn as_button(&self, active: bool) -> impl IntoElement { ui::IconButton::new(0, self.icon()) .on_click({ let action = self.to_toggle_action(); @@ -95,7 +95,7 @@ impl SearchOptions { } } -fn toggle_replace_button(active: bool) -> impl RenderOnce { +fn toggle_replace_button(active: bool) -> impl IntoElement { // todo: add toggle_replace button ui::IconButton::new(0, ui::Icon::Replace) .on_click(|_, cx| { @@ -109,7 +109,7 @@ fn toggle_replace_button(active: bool) -> impl RenderOnce { fn render_replace_button( action: impl Action + 'static + Send + Sync, icon: ui::Icon, -) -> impl RenderOnce { +) -> impl IntoElement { // todo: add tooltip ui::IconButton::new(0, icon).on_click(move |_, cx| { cx.dispatch_action(action.boxed_clone()); diff --git a/crates/search2/src/search_bar.rs b/crates/search2/src/search_bar.rs index da097b43a6..1a7456f41c 100644 --- a/crates/search2/src/search_bar.rs +++ b/crates/search2/src/search_bar.rs @@ -1,4 +1,4 @@ -use gpui::{MouseDownEvent, RenderOnce, WindowContext}; +use gpui::{IntoElement, MouseDownEvent, WindowContext}; use ui::{Button, ButtonVariant, IconButton}; use crate::mode::SearchMode; @@ -7,7 +7,7 @@ pub(super) fn render_nav_button( icon: ui::Icon, _active: bool, on_click: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static, -) -> impl RenderOnce { +) -> impl IntoElement { // let tooltip_style = cx.theme().tooltip.clone(); // let cursor_style = if active { // CursorStyle::PointingHand diff --git a/crates/storybook2/src/stories/z_index.rs b/crates/storybook2/src/stories/z_index.rs index 4f551c8ea0..9d04d3d81f 100644 --- a/crates/storybook2/src/stories/z_index.rs +++ b/crates/storybook2/src/stories/z_index.rs @@ -1,4 +1,4 @@ -use gpui::{px, rgb, Div, Hsla, Render, RenderOnce}; +use gpui::{px, rgb, Div, Hsla, IntoElement, Render, RenderOnce}; use story::Story; use ui::prelude::*; @@ -76,12 +76,12 @@ trait Styles: Styled + Sized { impl Styles for Div {} -#[derive(RenderOnce)] +#[derive(IntoElement)] struct ZIndexExample { z_index: u32, } -impl Component for ZIndexExample { +impl RenderOnce for ZIndexExample { type Rendered = Div; fn render(self, cx: &mut WindowContext) -> Self::Rendered { diff --git a/crates/ui2/src/components/avatar.rs b/crates/ui2/src/components/avatar.rs index 364a145494..976243365c 100644 --- a/crates/ui2/src/components/avatar.rs +++ b/crates/ui2/src/components/avatar.rs @@ -1,5 +1,5 @@ use crate::prelude::*; -use gpui::{img, Img, RenderOnce}; +use gpui::{img, Img, IntoElement}; #[derive(Debug, Default, PartialEq, Clone)] pub enum Shape { @@ -8,13 +8,13 @@ pub enum Shape { RoundedRectangle, } -#[derive(RenderOnce)] +#[derive(IntoElement)] pub struct Avatar { src: SharedString, shape: Shape, } -impl Component for Avatar { +impl RenderOnce for Avatar { type Rendered = Img; fn render(self, _: &mut WindowContext) -> Self::Rendered { diff --git a/crates/ui2/src/components/button.rs b/crates/ui2/src/components/button.rs index a5176be52e..02902a4b64 100644 --- a/crates/ui2/src/components/button.rs +++ b/crates/ui2/src/components/button.rs @@ -1,8 +1,8 @@ use std::rc::Rc; use gpui::{ - DefiniteLength, Div, Hsla, MouseButton, MouseDownEvent, RenderOnce, StatefulInteractiveElement, - WindowContext, + DefiniteLength, Div, Hsla, IntoElement, MouseButton, MouseDownEvent, + StatefulInteractiveElement, WindowContext, }; use crate::prelude::*; @@ -64,7 +64,7 @@ impl ButtonVariant { } } -#[derive(RenderOnce)] +#[derive(IntoElement)] pub struct Button { disabled: bool, click_handler: Option>, @@ -76,7 +76,7 @@ pub struct Button { color: Option, } -impl Component for Button { +impl RenderOnce for Button { type Rendered = gpui::Stateful
; fn render(self, cx: &mut WindowContext) -> Self::Rendered { @@ -207,12 +207,12 @@ impl Button { } } -#[derive(RenderOnce)] +#[derive(IntoElement)] pub struct ButtonGroup { buttons: Vec