From 8ecfea55cd53fdc24f54764509945344424b8e9b Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 26 Oct 2023 12:38:23 +0200 Subject: [PATCH] Replace derive Element with derive IntoAnyElement everywhere --- crates/gpui2/src/element.rs | 10 ++ crates/gpui2_macros/src/derive_element.rs | 94 ------------------- crates/gpui2_macros/src/gpui2_macros.rs | 6 -- crates/storybook2/src/components.rs | 2 +- crates/storybook2/src/stories/scroll.rs | 1 - crates/storybook2/src/stories/z_index.rs | 8 +- crates/ui2/src/components/assistant_panel.rs | 8 +- crates/ui2/src/components/breadcrumb.rs | 12 +-- crates/ui2/src/components/buffer.rs | 8 +- crates/ui2/src/components/chat_panel.rs | 12 +-- crates/ui2/src/components/collab_panel.rs | 8 +- crates/ui2/src/components/command_palette.rs | 8 +- crates/ui2/src/components/context_menu.rs | 8 +- crates/ui2/src/components/copilot.rs | 8 +- crates/ui2/src/components/facepile.rs | 8 +- crates/ui2/src/components/icon_button.rs | 4 +- crates/ui2/src/components/keybinding.rs | 12 +-- .../ui2/src/components/language_selector.rs | 8 +- crates/ui2/src/components/list.rs | 28 +++--- crates/ui2/src/components/modal.rs | 4 +- crates/ui2/src/components/multi_buffer.rs | 8 +- .../ui2/src/components/notification_toast.rs | 4 +- .../ui2/src/components/notifications_panel.rs | 8 +- crates/ui2/src/components/palette.rs | 12 +-- crates/ui2/src/components/panel.rs | 8 +- crates/ui2/src/components/panes.rs | 6 +- crates/ui2/src/components/player_stack.rs | 4 +- crates/ui2/src/components/project_panel.rs | 8 +- crates/ui2/src/components/recent_projects.rs | 8 +- crates/ui2/src/components/status_bar.rs | 9 -- crates/ui2/src/components/tab.rs | 8 +- crates/ui2/src/components/tab_bar.rs | 8 +- crates/ui2/src/components/terminal.rs | 8 +- crates/ui2/src/components/theme_selector.rs | 8 +- crates/ui2/src/components/toast.rs | 10 +- crates/ui2/src/components/toolbar.rs | 8 +- crates/ui2/src/components/traffic_lights.rs | 12 +-- crates/ui2/src/element_ext.rs | 21 ++--- crates/ui2/src/elements/avatar.rs | 8 +- crates/ui2/src/elements/button.rs | 14 +-- crates/ui2/src/elements/details.rs | 8 +- crates/ui2/src/elements/icon.rs | 8 +- crates/ui2/src/elements/input.rs | 8 +- crates/ui2/src/elements/label.rs | 12 +-- crates/ui2/src/elements/tool_divider.rs | 4 +- 45 files changed, 185 insertions(+), 292 deletions(-) delete mode 100644 crates/gpui2_macros/src/derive_element.rs diff --git a/crates/gpui2/src/element.rs b/crates/gpui2/src/element.rs index 87e1e5c83669346d860ade4135883d46d62d6218..39b7898d16b4f8cbd250bfc76713a1c97531a907 100644 --- a/crates/gpui2/src/element.rs +++ b/crates/gpui2/src/element.rs @@ -209,6 +209,16 @@ impl AnyElement { pub trait IntoAnyElement { fn into_any(self) -> AnyElement; + + fn when(mut self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self + where + Self: Sized, + { + if condition { + self = then(self); + } + self + } } impl IntoAnyElement for AnyElement { diff --git a/crates/gpui2_macros/src/derive_element.rs b/crates/gpui2_macros/src/derive_element.rs deleted file mode 100644 index a63be0f5da0cac96198d90cfe192de6e8ea6bf66..0000000000000000000000000000000000000000 --- a/crates/gpui2_macros/src/derive_element.rs +++ /dev/null @@ -1,94 +0,0 @@ -use proc_macro::TokenStream; -use quote::quote; -use syn::{parse_macro_input, DeriveInput, GenericParam}; - -pub fn derive_element(input: TokenStream) -> TokenStream { - let ast = parse_macro_input!(input as DeriveInput); - let type_name = ast.ident; - - let mut state_type = quote! { () }; - - for param in &ast.generics.params { - if let GenericParam::Type(type_param) = param { - let type_ident = &type_param.ident; - state_type = quote! {#type_ident}; - break; - } - } - - let attrs = &ast.attrs; - for attr in attrs { - if attr.path.is_ident("element") { - match attr.parse_meta() { - Ok(syn::Meta::List(i)) => { - for nested_meta in i.nested { - if let syn::NestedMeta::Meta(syn::Meta::NameValue(nv)) = nested_meta { - if nv.path.is_ident("view_state") { - if let syn::Lit::Str(lit_str) = nv.lit { - state_type = lit_str.value().parse().unwrap(); - } - } - } - } - } - _ => (), - } - } - } - - let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl(); - - let gen = quote! { - impl #impl_generics gpui2::IntoAnyElement<#state_type> for #type_name #ty_generics - #where_clause - { - fn into_any(self) -> gpui2::AnyElement<#state_type> { - gpui2::AnyElement::new(self) - } - } - - impl #impl_generics gpui2::Element<#state_type> for #type_name #ty_generics - #where_clause - { - type ElementState = gpui2::AnyElement<#state_type>; - - fn id(&self) -> Option { - None - } - - fn initialize( - &mut self, - view_state: &mut #state_type, - _: Option, - cx: &mut gpui2::ViewContext<#state_type> - ) -> Self::ElementState { - use gpui2::IntoAnyElement; - - let mut element = self.render(view_state, cx).into_any(); - element.initialize(view_state, cx); - element - } - - fn layout( - &mut self, - view_state: &mut #state_type, - rendered_element: &mut Self::ElementState, - cx: &mut gpui2::ViewContext<#state_type>, - ) -> gpui2::LayoutId { - rendered_element.layout(view_state, cx) - } - - fn paint( - &mut self, - bounds: gpui2::Bounds, - view_state: &mut #state_type, - rendered_element: &mut Self::ElementState, - cx: &mut gpui2::ViewContext<#state_type>, - ) { - rendered_element.paint(view_state, cx) - } - } - }; - - gen.into() -} diff --git a/crates/gpui2_macros/src/gpui2_macros.rs b/crates/gpui2_macros/src/gpui2_macros.rs index c4a3d5eeac8708869f4a28c286318ca5e84e83b1..3635320d55f3ca7fd9f218ab8b14b66c11402080 100644 --- a/crates/gpui2_macros/src/gpui2_macros.rs +++ b/crates/gpui2_macros/src/gpui2_macros.rs @@ -1,6 +1,5 @@ use proc_macro::TokenStream; -mod derive_element; mod derive_into_any_element; mod style_helpers; mod test; @@ -10,11 +9,6 @@ pub fn style_helpers(args: TokenStream) -> TokenStream { style_helpers::style_helpers(args) } -#[proc_macro_derive(Element, attributes(element))] -pub fn derive_element(input: TokenStream) -> TokenStream { - derive_element::derive_element(input) -} - #[proc_macro_derive(IntoAnyElement, attributes(element))] pub fn derive_into_any_element(input: TokenStream) -> TokenStream { derive_into_any_element::derive_into_any_element(input) diff --git a/crates/storybook2/src/components.rs b/crates/storybook2/src/components.rs index c39ccaa3d9a36504e84c41c950ad296e08a9c04d..5eaa894302a0d29d894b81f9e36a9ca3b3690c22 100644 --- a/crates/storybook2/src/components.rs +++ b/crates/storybook2/src/components.rs @@ -14,7 +14,7 @@ impl Default for ButtonHandlers { } } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct Button { handlers: ButtonHandlers, label: Option>, diff --git a/crates/storybook2/src/stories/scroll.rs b/crates/storybook2/src/stories/scroll.rs index f589ea7cef9cc9f2c70baa3c464a0be742899a76..86a8ca41c8f13f424069f51f04e63be8e54835c4 100644 --- a/crates/storybook2/src/stories/scroll.rs +++ b/crates/storybook2/src/stories/scroll.rs @@ -3,7 +3,6 @@ use gpui2::{ div, px, view, Context, IntoAnyElement, ParentElement, SharedString, Styled, View, WindowContext, }; -use ui::ElementExt; pub struct ScrollStory { text: View<()>, diff --git a/crates/storybook2/src/stories/z_index.rs b/crates/storybook2/src/stories/z_index.rs index 213d7bed4eaf2b504ecbc3baa7f76af699934663..270bd086402927f33328581d0d46b543f7a1d802 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(Element)] +#[derive(IntoAnyElement)] pub struct ZIndexStory { state_type: PhantomData, } @@ -19,7 +19,7 @@ impl ZIndexStory { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title(cx, "z-index")) .child( @@ -88,7 +88,7 @@ trait Styles: Styled + Sized { impl Styles for Div {} -#[derive(Element)] +#[derive(IntoAnyElement)] struct ZIndexExample { view_type: PhantomData, z_index: u32, @@ -102,7 +102,7 @@ impl ZIndexExample { } } - fn render(&mut self, _view: &mut V, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut V, cx: &mut ViewContext) -> impl IntoAnyElement { div() .relative() .size_full() diff --git a/crates/ui2/src/components/assistant_panel.rs b/crates/ui2/src/components/assistant_panel.rs index 1c47bf1a913490d817b48797a1c90b6e1e9bb75a..fa5ac38dc1274e25a578a57006270d6c4313e566 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(Element)] +#[derive(IntoAnyElement)] pub struct AssistantPanel { id: ElementId, state_type: PhantomData, @@ -26,7 +26,7 @@ impl AssistantPanel { self } - fn render(&mut self, view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Panel::new(self.id.clone(), cx) .children(vec![div() .flex() @@ -84,7 +84,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct AssistantPanelStory { state_type: PhantomData, } @@ -96,7 +96,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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 5f4d3cbafe58db2354e2f41262ecc7880481e12d..00a471e7cc46bef195d12e556ddefd26cffce682 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(Element)] +#[derive(IntoAnyElement)] pub struct Breadcrumb { state_type: PhantomData, path: PathBuf, @@ -31,7 +31,7 @@ impl Breadcrumb { div().child(" › ").text_color(theme.text_muted) } - fn render(&mut self, view_state: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, view_state: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let symbols_len = self.symbols.len(); @@ -86,7 +86,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct BreadcrumbStory { state_type: PhantomData, } @@ -98,11 +98,7 @@ mod stories { } } - fn render( - &mut self, - view_state: &mut S, - cx: &mut ViewContext, - ) -> impl IntoAnyElement { + fn render(self, view_state: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); Story::container(cx) diff --git a/crates/ui2/src/components/buffer.rs b/crates/ui2/src/components/buffer.rs index 7b67afc2b40358e481002e3c959b5d4a5d35c785..662ccd5736c264fdf8ea55a1573c1c28ada0d6e4 100644 --- a/crates/ui2/src/components/buffer.rs +++ b/crates/ui2/src/components/buffer.rs @@ -109,7 +109,7 @@ impl BufferRow { } } -#[derive(Element, Clone)] +#[derive(IntoAnyElement, Clone)] pub struct Buffer { id: ElementId, state_type: PhantomData, @@ -219,7 +219,7 @@ impl Buffer { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let rows = self.render_rows(cx); @@ -246,7 +246,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct BufferStory { state_type: PhantomData, } @@ -258,7 +258,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); Story::container(cx) diff --git a/crates/ui2/src/components/chat_panel.rs b/crates/ui2/src/components/chat_panel.rs index afb79cc907646e249c7a308573d33b098cebdb47..db0f573485960f1b7b90e3f939923f5292c40ac7 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(Element)] +#[derive(IntoAnyElement)] 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 IntoAnyElement { div() .id(self.element_id.clone()) .flex() @@ -70,7 +70,7 @@ impl ChatPanel { } } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct ChatMessage { state_type: PhantomData, author: String, @@ -88,7 +88,7 @@ impl ChatMessage { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div() .flex() .flex_col() @@ -117,7 +117,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct ChatPanelStory { state_type: PhantomData, } @@ -129,7 +129,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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 d7dfcdceab465921a0e37c5f8c0090dba95d8b1f..050b7c2b8547553714ca7456f255b3bf943c66e7 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(Element)] +#[derive(IntoAnyElement)] pub struct CollabPanel { id: ElementId, state_type: PhantomData, @@ -19,7 +19,7 @@ impl CollabPanel { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); v_stack() @@ -98,7 +98,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct CollabPanelStory { state_type: PhantomData, } @@ -110,7 +110,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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 b2418813d5f9b4a64a4fe3e6ef3491e178db41f8..f79038b1729aef5596c0f04a1f53e76d950a200c 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(Element)] +#[derive(IntoAnyElement)] pub struct CommandPalette { id: ElementId, state_type: PhantomData, @@ -17,7 +17,7 @@ impl CommandPalette { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div().id(self.id.clone()).child( Palette::new("palette") .items(example_editor_actions()) @@ -37,7 +37,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct CommandPaletteStory { state_type: PhantomData, } @@ -49,7 +49,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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 ea12cdcfc58648409a1e0afa7d92686601ddfc73..5463cb29e70079c265b69cc39540d5ed1bdadee0 100644 --- a/crates/ui2/src/components/context_menu.rs +++ b/crates/ui2/src/components/context_menu.rs @@ -31,7 +31,7 @@ impl ContextMenuItem { } } -#[derive(Element)] +#[derive(IntoAnyElement)] 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 IntoAnyElement { let theme = theme(cx); v_stack() @@ -73,7 +73,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct ContextMenuStory { state_type: PhantomData, } @@ -85,7 +85,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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 b1f41078e8bbd55b5520db3488204d15ce8d0fd5..ca82ea5a0aea92c8cedc736f36275ade1e3031d8 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(Element)] +#[derive(IntoAnyElement)] pub struct CopilotModal { id: ElementId, state_type: PhantomData, @@ -16,7 +16,7 @@ impl CopilotModal { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div().id(self.id.clone()).child( Modal::new("some-id") .title("Connect Copilot to Zed") @@ -35,7 +35,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct CopilotModalStory { state_type: PhantomData, } @@ -47,7 +47,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, CopilotModal>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/facepile.rs b/crates/ui2/src/components/facepile.rs index 0763b34b03f02aba0ec9114a28b050cffa78317a..c87de6a2a28bf928ca8f362e104be51129378ba2 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(Element)] +#[derive(IntoAnyElement)] pub struct Facepile { state_type: PhantomData, players: Vec, @@ -17,7 +17,7 @@ impl Facepile { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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(Element)] + #[derive(IntoAnyElement)] pub struct FacepileStory { state_type: PhantomData, } @@ -51,7 +51,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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 63158421930a1df3effe8a48afa396c423e9e25f..0801c5ac234f854631c64b8c71d5d52133fc653c 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(Element)] +#[derive(IntoAnyElement)] pub struct IconButton { state_type: PhantomData, id: ElementId, @@ -68,7 +68,7 @@ impl IconButton { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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 78d05e4f3039ac52938b812c1efd004637982c40..7a240aa39ce5ed4828913448868a7a6d53af2b1e 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(Element)] +#[derive(IntoAnyElement)] pub struct Keybinding { state_type: PhantomData, @@ -34,7 +34,7 @@ impl Keybinding { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div() .flex() .gap_2() @@ -54,7 +54,7 @@ impl Keybinding { } } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct Key { state_type: PhantomData, key: SharedString, @@ -68,7 +68,7 @@ impl Key { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); div() @@ -173,7 +173,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct KeybindingStory { state_type: PhantomData, } @@ -185,7 +185,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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 0aea61b9a03203692a95f5618d98091d96edf7cf..5dd571ec42e668041d22532394718b878c7f03b7 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(Element)] +#[derive(IntoAnyElement)] pub struct LanguageSelector { id: ElementId, state_type: PhantomData, @@ -17,7 +17,7 @@ impl LanguageSelector { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div().id(self.id.clone()).child( Palette::new("palette") .items(vec![ @@ -48,7 +48,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct LanguageSelectorStory { state_type: PhantomData, } @@ -60,7 +60,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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 b7557b44d4483eafddb0711b0692670e9f6950a1..00684a7eb94b618b7ef9b52f90069b26bac90500 100644 --- a/crates/ui2/src/components/list.rs +++ b/crates/ui2/src/components/list.rs @@ -17,7 +17,7 @@ pub enum ListItemVariant { Inset, } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct ListHeader { state_type: PhantomData, label: SharedString, @@ -92,7 +92,7 @@ impl ListHeader { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let is_toggleable = self.toggleable != Toggleable::NotToggleable; @@ -134,7 +134,7 @@ impl ListHeader { } } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct ListSubHeader { state_type: PhantomData, label: SharedString, @@ -157,7 +157,7 @@ impl ListSubHeader { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { h_stack().flex_1().w_full().relative().py_1().child( div() .h_6() @@ -197,7 +197,7 @@ pub enum ListEntrySize { Medium, } -#[derive(Element)] +#[derive(IntoAnyElement)] pub enum ListItem { Entry(ListEntry), Details(ListDetailsEntry), @@ -230,7 +230,7 @@ impl From> for ListItem { } impl ListItem { - fn render(&mut self, view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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(Element)] +#[derive(IntoAnyElement)] pub struct ListEntry { disclosure_control_style: DisclosureControlVisibility, indent_level: u32, @@ -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 IntoAnyElement { let settings = user_settings(cx); let theme = theme(cx); @@ -430,7 +430,7 @@ impl Default for ListDetailsEntryHandlers { } } -#[derive(Element)] +#[derive(IntoAnyElement)] 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 IntoAnyElement { let theme = theme(cx); let settings = user_settings(cx); @@ -519,7 +519,7 @@ impl ListDetailsEntry { } } -#[derive(Clone, Element)] +#[derive(Clone, IntoAnyElement)] pub struct ListSeparator { state_type: PhantomData, } @@ -531,14 +531,14 @@ impl ListSeparator { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); div().h_px().w_full().bg(theme.border) } } -#[derive(Element)] +#[derive(IntoAnyElement)] 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 IntoAnyElement { 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 63e7bc7c1ad6c8face547ccf70b448081619b4e8..c8fbfc0c6d54ce489aed05980a036e48bbf414f3 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(Element)] +#[derive(IntoAnyElement)] 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 IntoAnyElement { 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 3bd3057d6593c5a8e0c9beb09c832bc5e6cc101a..86e89c896c6dfe0face65cb8e9c9cf9ac620147f 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(Element)] +#[derive(IntoAnyElement)] pub struct MultiBuffer { state_type: PhantomData, buffers: Vec>, @@ -17,7 +17,7 @@ impl MultiBuffer { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); v_stack() @@ -50,7 +50,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct MultiBufferStory { state_type: PhantomData, } @@ -62,7 +62,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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 cf68738a7ea3098a4dbbf41c1a2a251b8876ab4b..6a1011207b18a71f28993d430cfe4c3f93e19bab 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(Element)] +#[derive(IntoAnyElement)] pub struct NotificationToast { state_type: PhantomData, label: SharedString, @@ -28,7 +28,7 @@ impl NotificationToast { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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 1937c8e0609880b1bcf6f73c0ee24eaceea79baa..44af3696c2f43244e3b99a7f518dc2f655da93ff 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(Element)] +#[derive(IntoAnyElement)] pub struct NotificationsPanel { id: ElementId, state_type: PhantomData, @@ -17,7 +17,7 @@ impl NotificationsPanel { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); div() @@ -58,7 +58,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct NotificationsPanelStory { state_type: PhantomData, } @@ -70,7 +70,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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 b7cb7033bc9403eb1ed1347f47792011a70870e2..5b52f41aec929bd38cb36b63dbd09d56098dd4a7 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(Element)] +#[derive(IntoAnyElement)] 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 IntoAnyElement { let theme = theme(cx); v_stack() @@ -101,7 +101,7 @@ impl Palette { } } -#[derive(Element)] +#[derive(IntoAnyElement)] 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 IntoAnyElement { div() .flex() .flex_row() @@ -160,7 +160,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct PaletteStory { state_type: PhantomData, } @@ -172,7 +172,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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 67b00d881bd57331d8543db4e32d5875c17c53d4..e6bca5afa7e38c4a642b4f4ef1e1b5f50feb8d6b 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(Element)] +#[derive(IntoAnyElement)] 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 IntoAnyElement { let theme = theme(cx); let current_size = self.width.unwrap_or(self.initial_width); @@ -136,7 +136,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct PanelStory { state_type: PhantomData, } @@ -148,7 +148,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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 bf135d85b6c81b7bd74314cf68f179295e2c9268..118bb5f1974aadfe0ca5ec98e788ee8abb5eeda9 100644 --- a/crates/ui2/src/components/panes.rs +++ b/crates/ui2/src/components/panes.rs @@ -75,7 +75,7 @@ impl ParentElement for Pane { } } -#[derive(Element)] +#[derive(IntoAnyElement)] 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 IntoAnyElement { let theme = theme(cx); if !self.panes.is_empty() { @@ -129,7 +129,7 @@ impl PaneGroup { .w_full() .h_full() .bg(theme.editor) - .children(self.groups.iter_mut().map(|group| group.render(view, cx))); + .children(self.groups.drain(..).map(|group| group.render(view, cx))); if self.split_direction == SplitDirection::Horizontal { return el; diff --git a/crates/ui2/src/components/player_stack.rs b/crates/ui2/src/components/player_stack.rs index 6ca16d14e621e3e4f01f5581e3f1578a14bf2f0c..88b2833dda0d3242453d0f6051aced35763993bf 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(Element)] +#[derive(IntoAnyElement)] pub struct PlayerStack { state_type: PhantomData, player_with_call_status: PlayerWithCallStatus, @@ -17,7 +17,7 @@ impl PlayerStack { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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 5a4591cadde5e1a8bbe0f8985fb8fc1a10c65d2e..5771f996c500a48becbcac1f717df2714cd72ba8 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(Element)] +#[derive(IntoAnyElement)] pub struct ProjectPanel { id: ElementId, state_type: PhantomData, @@ -19,7 +19,7 @@ impl ProjectPanel { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); div() @@ -67,7 +67,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct ProjectPanelStory { state_type: PhantomData, } @@ -79,7 +79,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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 bab96444a5679052095acd0d5b1ce9dc426e5ad3..d29caa2fd205b334226dd02b62affcdbb05ee85b 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(Element)] +#[derive(IntoAnyElement)] pub struct RecentProjects { id: ElementId, state_type: PhantomData, @@ -17,7 +17,7 @@ impl RecentProjects { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div().id(self.id.clone()).child( Palette::new("palette") .items(vec![ @@ -44,7 +44,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct RecentProjectsStory { state_type: PhantomData, } @@ -56,7 +56,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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 2e4399539cf5ab4e7242d16f3251f59ea38436c6..4ea0fe4eeb9090a5c61d72170a47e1b655c5e41e 100644 --- a/crates/ui2/src/components/status_bar.rs +++ b/crates/ui2/src/components/status_bar.rs @@ -36,15 +36,6 @@ pub struct StatusBar { bottom_tools: Option, } -// impl IntoAnyElement for StatusBar { -// fn into_any(self) -> gpui2::AnyElement { -// (move |workspace: &mut Workspace, cx: &mut ViewContext<'_, '_, Workspace>| { -// self.render(workspace, cx) -// }) -// .into_any() -// } -// } - impl StatusBar { pub fn new() -> Self { Self { diff --git a/crates/ui2/src/components/tab.rs b/crates/ui2/src/components/tab.rs index daff5ea66c6afd69a2bb99c8fa8e3c1777348f67..02a2420580f2c332d1dc024c1fd5764dee4afff7 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(Element, Clone)] +#[derive(IntoAnyElement, Clone)] pub struct Tab { state_type: PhantomData, id: ElementId, @@ -81,7 +81,7 @@ impl Tab { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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(Element)] + #[derive(IntoAnyElement)] pub struct TabStory { state_type: PhantomData, } @@ -188,7 +188,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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 4e49ef289aab289e32beb50da609ea79da2c8309..38dd9edade800d4e8d4f51a0ccdcdaf6d6762a66 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(Element)] +#[derive(IntoAnyElement)] pub struct TabBar { id: ElementId, state_type: PhantomData, @@ -27,7 +27,7 @@ impl TabBar { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let (can_navigate_back, can_navigate_forward) = self.can_navigate; @@ -100,7 +100,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct TabBarStory { state_type: PhantomData, } @@ -112,7 +112,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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 2061d42ad2c75e382675aac7ab6774ea79761698..55ab3e02fc25d7007f28d747a1ec566bc733ef2c 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(Element)] +#[derive(IntoAnyElement)] pub struct Terminal { state_type: PhantomData, } @@ -17,7 +17,7 @@ impl Terminal { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let can_navigate_back = true; @@ -93,7 +93,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct TerminalStory { state_type: PhantomData, } @@ -105,7 +105,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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 0758cf643b97f4387ec630527b2c681198fa7407..1851aea9541736985df6cc9e5648f87a74bbdf5e 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(Element)] +#[derive(IntoAnyElement)] pub struct ThemeSelector { id: ElementId, state_type: PhantomData, @@ -17,7 +17,7 @@ impl ThemeSelector { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div().child( Palette::new(self.id.clone()) .items(vec![ @@ -49,7 +49,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct ThemeSelectorStory { state_type: PhantomData, } @@ -61,7 +61,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, ThemeSelector>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/toast.rs b/crates/ui2/src/components/toast.rs index faf58467a26045f3dbfc0873286f439ba3a92b99..268042144b56da147e02f99dff4c3e7543eeca76 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(Element)] +#[derive(IntoAnyElement)] pub struct Toast { origin: ToastOrigin, children: SmallVec<[AnyElement; 2]>, @@ -36,7 +36,7 @@ impl Toast { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let mut div = div(); @@ -57,7 +57,7 @@ impl Toast { .shadow_md() .overflow_hidden() .bg(theme.elevated_surface) - .children(self.children.drain(..)) + .children(self.children) } } @@ -78,7 +78,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct ToastStory { state_type: PhantomData, } @@ -90,7 +90,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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 74b2c9257811d1a092bc769b4c6e50eee3f4e17d..e18c81314d4375342c1550b4646123532efadea5 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(Element)] +#[derive(IntoAnyElement)] pub struct Toolbar { left_items: SmallVec<[AnyElement; 2]>, right_items: SmallVec<[AnyElement; 2]>, @@ -54,7 +54,7 @@ impl Toolbar { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); div() @@ -80,7 +80,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct ToolbarStory { state_type: PhantomData, } @@ -92,7 +92,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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 8ac76439f8240accb14f32f629fd5524dbbc05f7..cfe589b463587736d8170321e1e123381541f8d3 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(Element)] +#[derive(IntoAnyElement)] struct TrafficLight { state_type: PhantomData, color: TrafficLightColor, @@ -25,7 +25,7 @@ impl TrafficLight { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let fill = match (self.window_has_focus, self.color) { @@ -39,7 +39,7 @@ impl TrafficLight { } } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct TrafficLights { state_type: PhantomData, window_has_focus: bool, @@ -58,7 +58,7 @@ impl TrafficLights { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div() .flex() .items_center() @@ -87,7 +87,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct TrafficLightsStory { state_type: PhantomData, } @@ -99,7 +99,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, TrafficLights>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/element_ext.rs b/crates/ui2/src/element_ext.rs index 813f01dd24c59dc221ba2c25c9fc3425cb843f26..fb31307d12c45d2ca8e9a888e4e67e38f3cf3090 100644 --- a/crates/ui2/src/element_ext.rs +++ b/crates/ui2/src/element_ext.rs @@ -1,18 +1,15 @@ use gpui2::Element; pub trait ElementExt: Element { - /// Applies a given function `then` to the current element if `condition` is true. - /// This function is used to conditionally modify the element based on a given condition. - /// If `condition` is false, it just returns the current element as it is. - fn when(mut self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self - where - Self: Sized, - { - if condition { - self = then(self); - } - self - } + // fn when(mut self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self + // where + // Self: Sized, + // { + // if condition { + // self = then(self); + // } + // self + // } // fn when_some(mut self, option: Option, then: impl FnOnce(Self, T) -> U) -> U // where diff --git a/crates/ui2/src/elements/avatar.rs b/crates/ui2/src/elements/avatar.rs index 555818a87cf50e2039412056b256d8e3b0073760..7d2e91ae8ce112b775448fe503b91fca5471acb9 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(Element)] +#[derive(IntoAnyElement)] pub struct Avatar { state_type: PhantomData, src: SharedString, @@ -25,7 +25,7 @@ impl Avatar { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let mut img = img(); @@ -51,7 +51,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct AvatarStory { state_type: PhantomData, } @@ -63,7 +63,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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 9f399ea331e75a8d8ce6e8549571944aa4b8aae7..843a786aff8d67fbd9f897a87b9ae4a43ca3727a 100644 --- a/crates/ui2/src/elements/button.rs +++ b/crates/ui2/src/elements/button.rs @@ -61,7 +61,7 @@ impl Default for ButtonHandlers { } } -#[derive(Element)] +#[derive(IntoAnyElement)] 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(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + pub fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let icon_color = self.icon_color(); let mut button = h_stack() @@ -193,7 +193,7 @@ impl Button { } } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct ButtonGroup { state_type: PhantomData, buttons: Vec>, @@ -207,10 +207,10 @@ impl ButtonGroup { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let mut el = h_stack().text_size(ui_size(cx, 1.)); - for button in &mut self.buttons { + for button in self.buttons { el = el.child(button.render(_view, cx)); } @@ -230,7 +230,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct ButtonStory { state_type: PhantomData, } @@ -242,7 +242,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let states = InteractionState::iter(); Story::container(cx) diff --git a/crates/ui2/src/elements/details.rs b/crates/ui2/src/elements/details.rs index ea05436401a7feaa5b7c1b8db932edde422c58cb..5f0676f9f4515c1aa63617c1fd71dd25e75af764 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(Element)] +#[derive(IntoAnyElement)] 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 IntoAnyElement { let theme = theme(cx); v_stack() @@ -54,7 +54,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct DetailsStory { state_type: PhantomData, } @@ -66,7 +66,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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 2a0f6b3a0baa10bb6b571e989f01c98b9bd4e80c..18d6050dd1c9a63596903648a7ca8f591d8cd0d5 100644 --- a/crates/ui2/src/elements/icon.rs +++ b/crates/ui2/src/elements/icon.rs @@ -148,7 +148,7 @@ impl Icon { } } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct IconElement { state_type: PhantomData, icon: Icon, @@ -176,7 +176,7 @@ impl IconElement { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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(Element, Default)] + #[derive(IntoAnyElement)] pub struct IconStory { state_type: PhantomData, } @@ -214,7 +214,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let icons = Icon::iter(); Story::container(cx) diff --git a/crates/ui2/src/elements/input.rs b/crates/ui2/src/elements/input.rs index 142acc887097e506d132c2c84366c10f299a8a23..6a70c9cf798d2438a4686d490f32521a87ee5a76 100644 --- a/crates/ui2/src/elements/input.rs +++ b/crates/ui2/src/elements/input.rs @@ -11,7 +11,7 @@ pub enum InputVariant { Filled, } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct Input { state_type: PhantomData, placeholder: SharedString, @@ -60,7 +60,7 @@ impl Input { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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(Element)] + #[derive(IntoAnyElement)] pub struct InputStory { state_type: PhantomData, } @@ -132,7 +132,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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 f8d4a8d1152d8ff22fd78689854a4a93e3165a4e..2d522a27b163b6f05a4a93973ea3f69e8edbd73a 100644 --- a/crates/ui2/src/elements/label.rs +++ b/crates/ui2/src/elements/label.rs @@ -48,7 +48,7 @@ pub enum LineHeightStyle { UILabel, } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct Label { state_type: PhantomData, label: SharedString, @@ -83,7 +83,7 @@ impl Label { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div() .when(self.strikethrough, |this| { this.relative().child( @@ -105,7 +105,7 @@ impl Label { } } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct HighlightedLabel { state_type: PhantomData, label: SharedString, @@ -135,7 +135,7 @@ impl HighlightedLabel { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let highlight_color = theme.text_accent; @@ -211,7 +211,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct LabelStory { state_type: PhantomData, } @@ -223,7 +223,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { 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 f73c8953ee6c033cba1448f6d5c77171ea9354ea..b388894d1a8bc46e384a7144d395826ddba9d316 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(Element)] +#[derive(IntoAnyElement)] pub struct ToolDivider { state_type: PhantomData, } @@ -14,7 +14,7 @@ impl ToolDivider { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); div().w_px().h_3().bg(theme.border)