Replace derive Element with derive IntoAnyElement everywhere

This commit is contained in:
Nathan Sobo 2023-10-26 12:38:23 +02:00
parent 315744ec20
commit 8ecfea55cd
45 changed files with 185 additions and 292 deletions

View file

@ -209,6 +209,16 @@ impl<V> AnyElement<V> {
pub trait IntoAnyElement<V> {
fn into_any(self) -> AnyElement<V>;
fn when(mut self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
where
Self: Sized,
{
if condition {
self = then(self);
}
self
}
}
impl<V> IntoAnyElement<V> for AnyElement<V> {

View file

@ -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<gpui2::ElementId> {
None
}
fn initialize(
&mut self,
view_state: &mut #state_type,
_: Option<Self::ElementState>,
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<gpui2::Pixels>,
view_state: &mut #state_type,
rendered_element: &mut Self::ElementState,
cx: &mut gpui2::ViewContext<#state_type>,
) {
rendered_element.paint(view_state, cx)
}
}
};
gen.into()
}

View file

@ -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)

View file

@ -14,7 +14,7 @@ impl<V, D> Default for ButtonHandlers<V, D> {
}
}
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct Button<V: 'static, D: 'static> {
handlers: ButtonHandlers<V, D>,
label: Option<ArcCow<'static, str>>,

View file

@ -3,7 +3,6 @@ use gpui2::{
div, px, view, Context, IntoAnyElement, ParentElement, SharedString, Styled, View,
WindowContext,
};
use ui::ElementExt;
pub struct ScrollStory {
text: View<()>,

View file

@ -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<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
}
@ -19,7 +19,7 @@ impl<S: 'static + Send + Sync> ZIndexStory<S> {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
Story::container(cx)
.child(Story::title(cx, "z-index"))
.child(
@ -88,7 +88,7 @@ trait Styles: Styled + Sized {
impl<V: 'static + Send + Sync> Styles for Div<V> {}
#[derive(Element)]
#[derive(IntoAnyElement)]
struct ZIndexExample<V: 'static + Send + Sync> {
view_type: PhantomData<V>,
z_index: u32,
@ -102,7 +102,7 @@ impl<V: 'static + Send + Sync> ZIndexExample<V> {
}
}
fn render(&mut self, _view: &mut V, cx: &mut ViewContext<V>) -> impl IntoAnyElement<V> {
fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl IntoAnyElement<V> {
div()
.relative()
.size_full()

View file

@ -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<S: 'static + Send + Sync> {
id: ElementId,
state_type: PhantomData<S>,
@ -26,7 +26,7 @@ impl<S: 'static + Send + Sync> AssistantPanel<S> {
self
}
fn render(&mut self, view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
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<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
}
@ -96,7 +96,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
Story::container(cx)
.child(Story::title_for::<_, AssistantPanel<S>>(cx))
.child(Story::label(cx, "Default"))

View file

@ -9,7 +9,7 @@ use crate::{h_stack, HighlightedText};
#[derive(Clone)]
pub struct Symbol(pub Vec<HighlightedText>);
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct Breadcrumb<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
path: PathBuf,
@ -31,7 +31,7 @@ impl<S: 'static + Send + Sync> Breadcrumb<S> {
div().child(" ").text_color(theme.text_muted)
}
fn render(&mut self, view_state: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, view_state: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
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<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
}
@ -98,11 +98,7 @@ mod stories {
}
}
fn render(
&mut self,
view_state: &mut S,
cx: &mut ViewContext<S>,
) -> impl IntoAnyElement<S> {
fn render(self, view_state: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
Story::container(cx)

View file

@ -109,7 +109,7 @@ impl BufferRow {
}
}
#[derive(Element, Clone)]
#[derive(IntoAnyElement, Clone)]
pub struct Buffer<S: 'static + Send + Sync + Clone> {
id: ElementId,
state_type: PhantomData<S>,
@ -219,7 +219,7 @@ impl<S: 'static + Send + Sync + Clone> Buffer<S> {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
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<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
}
@ -258,7 +258,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
Story::container(cx)

View file

@ -5,7 +5,7 @@ use chrono::NaiveDateTime;
use crate::prelude::*;
use crate::{Icon, IconButton, Input, Label, LabelColor};
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct ChatPanel<S: 'static + Send + Sync> {
element_id: ElementId,
messages: Vec<ChatMessage<S>>,
@ -24,7 +24,7 @@ impl<S: 'static + Send + Sync> ChatPanel<S> {
self
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
div()
.id(self.element_id.clone())
.flex()
@ -70,7 +70,7 @@ impl<S: 'static + Send + Sync> ChatPanel<S> {
}
}
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct ChatMessage<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
author: String,
@ -88,7 +88,7 @@ impl<S: 'static + Send + Sync> ChatMessage<S> {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
div()
.flex()
.flex_col()
@ -117,7 +117,7 @@ mod stories {
use super::*;
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct ChatPanelStory<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
}
@ -129,7 +129,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
Story::container(cx)
.child(Story::title_for::<_, ChatPanel<S>>(cx))
.child(Story::label(cx, "Default"))

View file

@ -5,7 +5,7 @@ use crate::{
};
use std::marker::PhantomData;
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct CollabPanel<S: 'static + Send + Sync> {
id: ElementId,
state_type: PhantomData<S>,
@ -19,7 +19,7 @@ impl<S: 'static + Send + Sync> CollabPanel<S> {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
v_stack()
@ -98,7 +98,7 @@ mod stories {
use super::*;
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct CollabPanelStory<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
}
@ -110,7 +110,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
Story::container(cx)
.child(Story::title_for::<_, CollabPanel<S>>(cx))
.child(Story::label(cx, "Default"))

View file

@ -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<S: 'static + Send + Sync> {
id: ElementId,
state_type: PhantomData<S>,
@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync> CommandPalette<S> {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
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<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
}
@ -49,7 +49,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
Story::container(cx)
.child(Story::title_for::<_, CommandPalette<S>>(cx))
.child(Story::label(cx, "Default"))

View file

@ -31,7 +31,7 @@ impl<S: 'static + Send + Sync> ContextMenuItem<S> {
}
}
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct ContextMenu<S: 'static + Send + Sync> {
items: Vec<ContextMenuItem<S>>,
}
@ -42,7 +42,7 @@ impl<S: 'static + Send + Sync> ContextMenu<S> {
items: items.into_iter().collect(),
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
v_stack()
@ -73,7 +73,7 @@ mod stories {
use super::*;
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct ContextMenuStory<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
}
@ -85,7 +85,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
Story::container(cx)
.child(Story::title_for::<_, ContextMenu<S>>(cx))
.child(Story::label(cx, "Default"))

View file

@ -2,7 +2,7 @@ use std::marker::PhantomData;
use crate::{prelude::*, Button, Label, LabelColor, Modal};
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct CopilotModal<S: 'static + Send + Sync + Clone> {
id: ElementId,
state_type: PhantomData<S>,
@ -16,7 +16,7 @@ impl<S: 'static + Send + Sync + Clone> CopilotModal<S> {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
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<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
}
@ -47,7 +47,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
Story::container(cx)
.child(Story::title_for::<_, CopilotModal<S>>(cx))
.child(Story::label(cx, "Default"))

View file

@ -3,7 +3,7 @@ use std::marker::PhantomData;
use crate::prelude::*;
use crate::{Avatar, Player};
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct Facepile<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
players: Vec<Player>,
@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync> Facepile<S> {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
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<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
}
@ -51,7 +51,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let players = static_players();
Story::container(cx)

View file

@ -16,7 +16,7 @@ impl<S: 'static + Send + Sync> Default for IconButtonHandlers<S> {
}
}
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct IconButton<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
id: ElementId,
@ -68,7 +68,7 @@ impl<S: 'static + Send + Sync> IconButton<S> {
self
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
let icon_color = match (self.state, self.color) {

View file

@ -5,7 +5,7 @@ use strum::{EnumIter, IntoEnumIterator};
use crate::prelude::*;
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct Keybinding<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
@ -34,7 +34,7 @@ impl<S: 'static + Send + Sync> Keybinding<S> {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
div()
.flex()
.gap_2()
@ -54,7 +54,7 @@ impl<S: 'static + Send + Sync> Keybinding<S> {
}
}
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct Key<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
key: SharedString,
@ -68,7 +68,7 @@ impl<S: 'static + Send + Sync> Key<S> {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
div()
@ -173,7 +173,7 @@ mod stories {
use super::*;
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct KeybindingStory<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
}
@ -185,7 +185,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let all_modifier_permutations = ModifierKey::iter().permutations(2);
Story::container(cx)

View file

@ -3,7 +3,7 @@ use std::marker::PhantomData;
use crate::prelude::*;
use crate::{OrderMethod, Palette, PaletteItem};
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct LanguageSelector<S: 'static + Send + Sync + Clone> {
id: ElementId,
state_type: PhantomData<S>,
@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync + Clone> LanguageSelector<S> {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
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<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
}
@ -60,7 +60,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
Story::container(cx)
.child(Story::title_for::<_, LanguageSelector<S>>(cx))
.child(Story::label(cx, "Default"))

View file

@ -17,7 +17,7 @@ pub enum ListItemVariant {
Inset,
}
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct ListHeader<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
label: SharedString,
@ -92,7 +92,7 @@ impl<S: 'static + Send + Sync> ListHeader<S> {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
let is_toggleable = self.toggleable != Toggleable::NotToggleable;
@ -134,7 +134,7 @@ impl<S: 'static + Send + Sync> ListHeader<S> {
}
}
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct ListSubHeader<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
label: SharedString,
@ -157,7 +157,7 @@ impl<S: 'static + Send + Sync> ListSubHeader<S> {
self
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
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<S: 'static + Send + Sync> {
Entry(ListEntry<S>),
Details(ListDetailsEntry<S>),
@ -230,7 +230,7 @@ impl<S: 'static + Send + Sync> From<ListSubHeader<S>> for ListItem<S> {
}
impl<S: 'static + Send + Sync> ListItem<S> {
fn render(&mut self, view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
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<S: 'static + Send + Sync> ListItem<S> {
}
}
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct ListEntry<S: 'static + Send + Sync> {
disclosure_control_style: DisclosureControlVisibility,
indent_level: u32,
@ -364,7 +364,7 @@ impl<S: 'static + Send + Sync> ListEntry<S> {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let settings = user_settings(cx);
let theme = theme(cx);
@ -430,7 +430,7 @@ impl<S: 'static + Send + Sync> Default for ListDetailsEntryHandlers<S> {
}
}
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct ListDetailsEntry<S: 'static + Send + Sync> {
label: SharedString,
meta: Option<SharedString>,
@ -474,7 +474,7 @@ impl<S: 'static + Send + Sync> ListDetailsEntry<S> {
self
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
let settings = user_settings(cx);
@ -519,7 +519,7 @@ impl<S: 'static + Send + Sync> ListDetailsEntry<S> {
}
}
#[derive(Clone, Element)]
#[derive(Clone, IntoAnyElement)]
pub struct ListSeparator<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
}
@ -531,14 +531,14 @@ impl<S: 'static + Send + Sync> ListSeparator<S> {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
div().h_px().w_full().bg(theme.border)
}
}
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct List<S: 'static + Send + Sync> {
items: Vec<ListItem<S>>,
empty_message: SharedString,
@ -571,7 +571,7 @@ impl<S: 'static + Send + Sync> List<S> {
self
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let is_toggleable = self.toggleable != Toggleable::NotToggleable;
let is_toggled = Toggleable::is_toggled(&self.toggleable);

View file

@ -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<S: 'static + Send + Sync> {
id: ElementId,
state_type: PhantomData<S>,
@ -42,7 +42,7 @@ impl<S: 'static + Send + Sync> Modal<S> {
self
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
v_stack()

View file

@ -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<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
buffers: Vec<Buffer<S>>,
@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync + Clone> MultiBuffer<S> {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
v_stack()
@ -50,7 +50,7 @@ mod stories {
use super::*;
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct MultiBufferStory<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
}
@ -62,7 +62,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
Story::container(cx)

View file

@ -4,7 +4,7 @@ use gpui2::rems;
use crate::{h_stack, prelude::*, Icon};
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct NotificationToast<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
label: SharedString,
@ -28,7 +28,7 @@ impl<S: 'static + Send + Sync + Clone> NotificationToast<S> {
self
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
h_stack()

View file

@ -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<S: 'static + Send + Sync> {
id: ElementId,
state_type: PhantomData<S>,
@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync> NotificationsPanel<S> {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
div()
@ -58,7 +58,7 @@ mod stories {
use super::*;
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct NotificationsPanelStory<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
}
@ -70,7 +70,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
Story::container(cx)
.child(Story::title_for::<_, NotificationsPanel<S>>(cx))
.child(Story::label(cx, "Default"))

View file

@ -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<S: 'static + Send + Sync> {
id: ElementId,
state_type: PhantomData<S>,
@ -46,7 +46,7 @@ impl<S: 'static + Send + Sync> Palette<S> {
self
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
v_stack()
@ -101,7 +101,7 @@ impl<S: 'static + Send + Sync> Palette<S> {
}
}
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct PaletteItem<S: 'static + Send + Sync> {
pub label: SharedString,
pub sublabel: Option<SharedString>,
@ -135,7 +135,7 @@ impl<S: 'static + Send + Sync> PaletteItem<S> {
self
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
div()
.flex()
.flex_row()
@ -160,7 +160,7 @@ mod stories {
use super::*;
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct PaletteStory<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
}
@ -172,7 +172,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
Story::container(cx)
.child(Story::title_for::<_, Palette<S>>(cx))
.child(Story::label(cx, "Default"))

View file

@ -40,7 +40,7 @@ pub enum PanelSide {
use std::collections::HashSet;
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct Panel<S: 'static + Send + Sync> {
id: ElementId,
state_type: PhantomData<S>,
@ -96,7 +96,7 @@ impl<S: 'static + Send + Sync> Panel<S> {
self
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
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<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
}
@ -148,7 +148,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
Story::container(cx)
.child(Story::title_for::<_, Panel<S>>(cx))
.child(Story::label(cx, "Default"))

View file

@ -75,7 +75,7 @@ impl<V: 'static> ParentElement<V> for Pane<V> {
}
}
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct PaneGroup<V: 'static + Send + Sync> {
state_type: PhantomData<V>,
groups: Vec<PaneGroup<V>>,
@ -102,7 +102,7 @@ impl<V: 'static + Send + Sync> PaneGroup<V> {
}
}
fn render(&mut self, view: &mut V, cx: &mut ViewContext<V>) -> impl IntoAnyElement<V> {
fn render(mut self, view: &mut V, cx: &mut ViewContext<V>) -> impl IntoAnyElement<V> {
let theme = theme(cx);
if !self.panes.is_empty() {
@ -129,7 +129,7 @@ impl<V: 'static + Send + Sync> PaneGroup<V> {
.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;

View file

@ -3,7 +3,7 @@ use std::marker::PhantomData;
use crate::prelude::*;
use crate::{Avatar, Facepile, PlayerWithCallStatus};
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct PlayerStack<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
player_with_call_status: PlayerWithCallStatus,
@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync> PlayerStack<S> {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
let player = self.player_with_call_status.get_player();
self.player_with_call_status.get_call_status();

View file

@ -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<S: 'static + Send + Sync> {
id: ElementId,
state_type: PhantomData<S>,
@ -19,7 +19,7 @@ impl<S: 'static + Send + Sync> ProjectPanel<S> {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
div()
@ -67,7 +67,7 @@ mod stories {
use super::*;
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct ProjectPanelStory<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
}
@ -79,7 +79,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
Story::container(cx)
.child(Story::title_for::<_, ProjectPanel<S>>(cx))
.child(Story::label(cx, "Default"))

View file

@ -3,7 +3,7 @@ use std::marker::PhantomData;
use crate::prelude::*;
use crate::{OrderMethod, Palette, PaletteItem};
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct RecentProjects<S: 'static + Send + Sync + Clone> {
id: ElementId,
state_type: PhantomData<S>,
@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync + Clone> RecentProjects<S> {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
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<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
}
@ -56,7 +56,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
Story::container(cx)
.child(Story::title_for::<_, RecentProjects<S>>(cx))
.child(Story::label(cx, "Default"))

View file

@ -36,15 +36,6 @@ pub struct StatusBar {
bottom_tools: Option<ToolGroup>,
}
// impl IntoAnyElement<Workspace> for StatusBar {
// fn into_any(self) -> gpui2::AnyElement<Workspace> {
// (move |workspace: &mut Workspace, cx: &mut ViewContext<'_, '_, Workspace>| {
// self.render(workspace, cx)
// })
// .into_any()
// }
// }
impl StatusBar {
pub fn new() -> Self {
Self {

View file

@ -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<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
id: ElementId,
@ -81,7 +81,7 @@ impl<S: 'static + Send + Sync + Clone> Tab<S> {
self
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
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<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
}
@ -188,7 +188,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let git_statuses = GitStatus::iter();
let fs_statuses = FileSystemStatus::iter();

View file

@ -3,7 +3,7 @@ use std::marker::PhantomData;
use crate::prelude::*;
use crate::{Icon, IconButton, Tab};
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct TabBar<S: 'static + Send + Sync + Clone> {
id: ElementId,
state_type: PhantomData<S>,
@ -27,7 +27,7 @@ impl<S: 'static + Send + Sync + Clone> TabBar<S> {
self
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
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<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
}
@ -112,7 +112,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
Story::container(cx)
.child(Story::title_for::<_, TabBar<S>>(cx))
.child(Story::label(cx, "Default"))

View file

@ -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<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
}
@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync + Clone> Terminal<S> {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
let can_navigate_back = true;
@ -93,7 +93,7 @@ mod stories {
use super::*;
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct TerminalStory<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
}
@ -105,7 +105,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
Story::container(cx)
.child(Story::title_for::<_, Terminal<S>>(cx))
.child(Story::label(cx, "Default"))

View file

@ -3,7 +3,7 @@ use std::marker::PhantomData;
use crate::prelude::*;
use crate::{OrderMethod, Palette, PaletteItem};
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct ThemeSelector<S: 'static + Send + Sync> {
id: ElementId,
state_type: PhantomData<S>,
@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync> ThemeSelector<S> {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
div().child(
Palette::new(self.id.clone())
.items(vec![
@ -49,7 +49,7 @@ mod stories {
use super::*;
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct ThemeSelectorStory<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
}
@ -61,7 +61,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
Story::container(cx)
.child(Story::title_for::<_, ThemeSelector<S>>(cx))
.child(Story::label(cx, "Default"))

View file

@ -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<S: 'static + Send + Sync> {
origin: ToastOrigin,
children: SmallVec<[AnyElement<S>; 2]>,
@ -36,7 +36,7 @@ impl<S: 'static + Send + Sync> Toast<S> {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
let mut div = div();
@ -57,7 +57,7 @@ impl<S: 'static + Send + Sync> Toast<S> {
.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<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
}
@ -90,7 +90,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
Story::container(cx)
.child(Story::title_for::<_, Toast<S>>(cx))
.child(Story::label(cx, "Default"))

View file

@ -6,7 +6,7 @@ use crate::prelude::*;
#[derive(Clone)]
pub struct ToolbarItem {}
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct Toolbar<S: 'static + Send + Sync> {
left_items: SmallVec<[AnyElement<S>; 2]>,
right_items: SmallVec<[AnyElement<S>; 2]>,
@ -54,7 +54,7 @@ impl<S: 'static + Send + Sync> Toolbar<S> {
self
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
div()
@ -80,7 +80,7 @@ mod stories {
use super::*;
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct ToolbarStory<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
}
@ -92,7 +92,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
Story::container(cx)

View file

@ -9,7 +9,7 @@ enum TrafficLightColor {
Green,
}
#[derive(Element)]
#[derive(IntoAnyElement)]
struct TrafficLight<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
color: TrafficLightColor,
@ -25,7 +25,7 @@ impl<S: 'static + Send + Sync> TrafficLight<S> {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
let fill = match (self.window_has_focus, self.color) {
@ -39,7 +39,7 @@ impl<S: 'static + Send + Sync> TrafficLight<S> {
}
}
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct TrafficLights<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
window_has_focus: bool,
@ -58,7 +58,7 @@ impl<S: 'static + Send + Sync> TrafficLights<S> {
self
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
div()
.flex()
.items_center()
@ -87,7 +87,7 @@ mod stories {
use super::*;
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct TrafficLightsStory<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
}
@ -99,7 +99,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
Story::container(cx)
.child(Story::title_for::<_, TrafficLights<S>>(cx))
.child(Story::label(cx, "Default"))

View file

@ -1,18 +1,15 @@
use gpui2::Element;
pub trait ElementExt<S: 'static + Send + Sync>: Element<S> {
/// 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<T, U>(mut self, option: Option<T>, then: impl FnOnce(Self, T) -> U) -> U
// where

View file

@ -4,7 +4,7 @@ use gpui2::img;
use crate::prelude::*;
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct Avatar<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
src: SharedString,
@ -25,7 +25,7 @@ impl<S: 'static + Send + Sync> Avatar<S> {
self
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
let mut img = img();
@ -51,7 +51,7 @@ mod stories {
use super::*;
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct AvatarStory<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
}
@ -63,7 +63,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
Story::container(cx)
.child(Story::title_for::<_, Avatar<S>>(cx))
.child(Story::label(cx, "Default"))

View file

@ -61,7 +61,7 @@ impl<S: 'static + Send + Sync> Default for ButtonHandlers<S> {
}
}
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct Button<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
disabled: bool,
@ -150,7 +150,7 @@ impl<S: 'static + Send + Sync> Button<S> {
self.icon.map(|i| IconElement::new(i).color(icon_color))
}
pub fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
pub fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let icon_color = self.icon_color();
let mut button = h_stack()
@ -193,7 +193,7 @@ impl<S: 'static + Send + Sync> Button<S> {
}
}
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct ButtonGroup<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
buttons: Vec<Button<S>>,
@ -207,10 +207,10 @@ impl<S: 'static + Send + Sync> ButtonGroup<S> {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
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<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
}
@ -242,7 +242,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let states = InteractionState::iter();
Story::container(cx)

View file

@ -2,7 +2,7 @@ use std::marker::PhantomData;
use crate::{prelude::*, v_stack, ButtonGroup};
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct Details<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
text: &'static str,
@ -30,7 +30,7 @@ impl<S: 'static + Send + Sync> Details<S> {
self
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
v_stack()
@ -54,7 +54,7 @@ mod stories {
use super::*;
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct DetailsStory<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
}
@ -66,7 +66,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
Story::container(cx)
.child(Story::title_for::<_, Details<S>>(cx))
.child(Story::label(cx, "Default"))

View file

@ -148,7 +148,7 @@ impl Icon {
}
}
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct IconElement<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
icon: Icon,
@ -176,7 +176,7 @@ impl<S: 'static + Send + Sync> IconElement<S> {
self
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
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<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
}
@ -214,7 +214,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let icons = Icon::iter();
Story::container(cx)

View file

@ -11,7 +11,7 @@ pub enum InputVariant {
Filled,
}
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct Input<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
placeholder: SharedString,
@ -60,7 +60,7 @@ impl<S: 'static + Send + Sync> Input<S> {
self
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
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<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
}
@ -132,7 +132,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
Story::container(cx)
.child(Story::title_for::<_, Input<S>>(cx))
.child(Story::label(cx, "Default"))

View file

@ -48,7 +48,7 @@ pub enum LineHeightStyle {
UILabel,
}
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct Label<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
label: SharedString,
@ -83,7 +83,7 @@ impl<S: 'static + Send + Sync> Label<S> {
self
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
div()
.when(self.strikethrough, |this| {
this.relative().child(
@ -105,7 +105,7 @@ impl<S: 'static + Send + Sync> Label<S> {
}
}
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct HighlightedLabel<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
label: SharedString,
@ -135,7 +135,7 @@ impl<S: 'static + Send + Sync> HighlightedLabel<S> {
self
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
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<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
}
@ -223,7 +223,7 @@ mod stories {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
Story::container(cx)
.child(Story::title_for::<_, Label<S>>(cx))
.child(Story::label(cx, "Default"))

View file

@ -2,7 +2,7 @@ use std::marker::PhantomData;
use crate::prelude::*;
#[derive(Element)]
#[derive(IntoAnyElement)]
pub struct ToolDivider<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
}
@ -14,7 +14,7 @@ impl<S: 'static + Send + Sync> ToolDivider<S> {
}
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> {
let theme = theme(cx);
div().w_px().h_3().bg(theme.border)