Rename IntoAnyElement trait to Component

This commit is contained in:
Nathan Sobo 2023-10-26 12:46:52 +02:00
parent 8ecfea55cd
commit 0285284ae1
60 changed files with 297 additions and 300 deletions

View file

@ -46,20 +46,20 @@ pub struct GlobalElementId(SmallVec<[ElementId; 32]>);
pub trait ParentElement<V: 'static> { pub trait ParentElement<V: 'static> {
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<V>; 2]>; fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<V>; 2]>;
fn child(mut self, child: impl IntoAnyElement<V>) -> Self fn child(mut self, child: impl Component<V>) -> Self
where where
Self: Sized, Self: Sized,
{ {
self.children_mut().push(child.into_any()); self.children_mut().push(child.render());
self self
} }
fn children(mut self, iter: impl IntoIterator<Item = impl IntoAnyElement<V>>) -> Self fn children(mut self, iter: impl IntoIterator<Item = impl Component<V>>) -> Self
where where
Self: Sized, Self: Sized,
{ {
self.children_mut() self.children_mut()
.extend(iter.into_iter().map(|item| item.into_any())); .extend(iter.into_iter().map(|item| item.render()));
self self
} }
} }
@ -207,8 +207,8 @@ impl<V> AnyElement<V> {
} }
} }
pub trait IntoAnyElement<V> { pub trait Component<V> {
fn into_any(self) -> AnyElement<V>; fn render(self) -> AnyElement<V>;
fn when(mut self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self fn when(mut self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
where where
@ -221,8 +221,8 @@ pub trait IntoAnyElement<V> {
} }
} }
impl<V> IntoAnyElement<V> for AnyElement<V> { impl<V> Component<V> for AnyElement<V> {
fn into_any(self) -> AnyElement<V> { fn render(self) -> AnyElement<V> {
self self
} }
} }
@ -230,7 +230,7 @@ impl<V> IntoAnyElement<V> for AnyElement<V> {
impl<V, E, F> Element<V> for Option<F> impl<V, E, F> Element<V> for Option<F>
where where
V: 'static, V: 'static,
E: 'static + IntoAnyElement<V> + Send + Sync, E: 'static + Component<V> + Send + Sync,
F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + Send + Sync + 'static, F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + Send + Sync + 'static,
{ {
type ElementState = AnyElement<V>; type ElementState = AnyElement<V>;
@ -246,7 +246,7 @@ where
cx: &mut ViewContext<V>, cx: &mut ViewContext<V>,
) -> Self::ElementState { ) -> Self::ElementState {
let render = self.take().unwrap(); let render = self.take().unwrap();
(render)(view_state, cx).into_any() (render)(view_state, cx).render()
} }
fn layout( fn layout(
@ -269,24 +269,24 @@ where
} }
} }
impl<V, E, F> IntoAnyElement<V> for Option<F> impl<V, E, F> Component<V> for Option<F>
where where
V: 'static, V: 'static,
E: 'static + IntoAnyElement<V> + Send + Sync, E: 'static + Component<V> + Send + Sync,
F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + Send + Sync + 'static, F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + Send + Sync + 'static,
{ {
fn into_any(self) -> AnyElement<V> { fn render(self) -> AnyElement<V> {
AnyElement::new(self) AnyElement::new(self)
} }
} }
impl<V, E, F> IntoAnyElement<V> for F impl<V, E, F> Component<V> for F
where where
V: 'static, V: 'static,
E: 'static + IntoAnyElement<V> + Send + Sync, E: 'static + Component<V> + Send + Sync,
F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + Send + Sync + 'static, F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + Send + Sync + 'static,
{ {
fn into_any(self) -> AnyElement<V> { fn render(self) -> AnyElement<V> {
AnyElement::new(Some(self)) AnyElement::new(Some(self))
} }
} }

View file

@ -1,7 +1,7 @@
use crate::{ use crate::{
point, AnyElement, BorrowWindow, Bounds, Element, ElementFocus, ElementId, ElementInteraction, point, AnyElement, BorrowWindow, Bounds, Component, Element, ElementFocus, ElementId,
FocusDisabled, FocusEnabled, FocusHandle, FocusListeners, Focusable, GlobalElementId, ElementInteraction, FocusDisabled, FocusEnabled, FocusHandle, FocusListeners, Focusable,
GroupBounds, InteractiveElementState, IntoAnyElement, LayoutId, Overflow, ParentElement, GlobalElementId, GroupBounds, InteractiveElementState, LayoutId, Overflow, ParentElement,
Pixels, Point, SharedString, StatefulInteraction, StatefulInteractive, StatelessInteraction, Pixels, Point, SharedString, StatefulInteraction, StatefulInteractive, StatelessInteraction,
StatelessInteractive, Style, StyleRefinement, Styled, ViewContext, StatelessInteractive, Style, StyleRefinement, Styled, ViewContext,
}; };
@ -303,13 +303,13 @@ where
} }
} }
impl<V, I, F> IntoAnyElement<V> for Div<V, I, F> impl<V, I, F> Component<V> for Div<V, I, F>
where where
// V: Any + Send + Sync, // V: Any + Send + Sync,
I: ElementInteraction<V>, I: ElementInteraction<V>,
F: ElementFocus<V>, F: ElementFocus<V>,
{ {
fn into_any(self) -> AnyElement<V> { fn render(self) -> AnyElement<V> {
AnyElement::new(self) AnyElement::new(self)
} }
} }

View file

@ -1,6 +1,6 @@
use crate::{ use crate::{
div, AnyElement, BorrowWindow, Bounds, Div, DivState, Element, ElementFocus, ElementId, div, AnyElement, BorrowWindow, Bounds, Component, Div, DivState, Element, ElementFocus,
ElementInteraction, FocusDisabled, FocusEnabled, FocusListeners, Focusable, IntoAnyElement, ElementId, ElementInteraction, FocusDisabled, FocusEnabled, FocusListeners, Focusable,
LayoutId, Pixels, SharedString, StatefulInteraction, StatefulInteractive, StatelessInteraction, LayoutId, Pixels, SharedString, StatefulInteraction, StatefulInteractive, StatelessInteraction,
StatelessInteractive, StyleRefinement, Styled, ViewContext, StatelessInteractive, StyleRefinement, Styled, ViewContext,
}; };
@ -55,12 +55,12 @@ where
} }
} }
impl<V, I, F> IntoAnyElement<V> for Img<V, I, F> impl<V, I, F> Component<V> for Img<V, I, F>
where where
I: ElementInteraction<V>, I: ElementInteraction<V>,
F: ElementFocus<V>, F: ElementFocus<V>,
{ {
fn into_any(self) -> AnyElement<V> { fn render(self) -> AnyElement<V> {
AnyElement::new(self) AnyElement::new(self)
} }
} }

View file

@ -1,6 +1,6 @@
use crate::{ use crate::{
div, AnyElement, Bounds, Div, DivState, Element, ElementFocus, ElementId, ElementInteraction, div, AnyElement, Bounds, Component, Div, DivState, Element, ElementFocus, ElementId,
FocusDisabled, FocusEnabled, FocusListeners, Focusable, IntoAnyElement, LayoutId, Pixels, ElementInteraction, FocusDisabled, FocusEnabled, FocusListeners, Focusable, LayoutId, Pixels,
SharedString, StatefulInteraction, StatefulInteractive, StatelessInteraction, SharedString, StatefulInteraction, StatefulInteractive, StatelessInteraction,
StatelessInteractive, StyleRefinement, Styled, ViewContext, StatelessInteractive, StyleRefinement, Styled, ViewContext,
}; };
@ -45,12 +45,12 @@ where
} }
} }
impl<V, I, F> IntoAnyElement<V> for Svg<V, I, F> impl<V, I, F> Component<V> for Svg<V, I, F>
where where
I: ElementInteraction<V>, I: ElementInteraction<V>,
F: ElementFocus<V>, F: ElementFocus<V>,
{ {
fn into_any(self) -> AnyElement<V> { fn render(self) -> AnyElement<V> {
AnyElement::new(self) AnyElement::new(self)
} }
} }

View file

@ -1,41 +1,41 @@
use crate::{ use crate::{
AnyElement, BorrowWindow, Bounds, Element, IntoAnyElement, LayoutId, Line, Pixels, AnyElement, BorrowWindow, Bounds, Component, Element, LayoutId, Line, Pixels, SharedString,
SharedString, Size, ViewContext, Size, ViewContext,
}; };
use parking_lot::Mutex; use parking_lot::Mutex;
use smallvec::SmallVec; use smallvec::SmallVec;
use std::{marker::PhantomData, sync::Arc}; use std::{marker::PhantomData, sync::Arc};
use util::ResultExt; use util::ResultExt;
impl<V: 'static> IntoAnyElement<V> for SharedString { impl<V: 'static> Component<V> for SharedString {
fn into_any(self) -> AnyElement<V> { fn render(self) -> AnyElement<V> {
Text { Text {
text: self, text: self,
state_type: PhantomData, state_type: PhantomData,
} }
.into_any() .render()
} }
} }
impl<V: 'static> IntoAnyElement<V> for &'static str { impl<V: 'static> Component<V> for &'static str {
fn into_any(self) -> AnyElement<V> { fn render(self) -> AnyElement<V> {
Text { Text {
text: self.into(), text: self.into(),
state_type: PhantomData, state_type: PhantomData,
} }
.into_any() .render()
} }
} }
// TODO: Figure out how to pass `String` to `child` without this. // TODO: Figure out how to pass `String` to `child` without this.
// This impl doesn't exist in the `gpui2` crate. // This impl doesn't exist in the `gpui2` crate.
impl<V: 'static> IntoAnyElement<V> for String { impl<V: 'static> Component<V> for String {
fn into_any(self) -> AnyElement<V> { fn render(self) -> AnyElement<V> {
Text { Text {
text: self.into(), text: self.into(),
state_type: PhantomData, state_type: PhantomData,
} }
.into_any() .render()
} }
} }
@ -47,8 +47,8 @@ pub struct Text<V> {
unsafe impl<V> Send for Text<V> {} unsafe impl<V> Send for Text<V> {}
unsafe impl<V> Sync for Text<V> {} unsafe impl<V> Sync for Text<V> {}
impl<V: 'static> IntoAnyElement<V> for Text<V> { impl<V: 'static> Component<V> for Text<V> {
fn into_any(self) -> AnyElement<V> { fn render(self) -> AnyElement<V> {
AnyElement::new(self) AnyElement::new(self)
} }
} }

View file

@ -1,7 +1,7 @@
use crate::{ use crate::{
point, px, view, Action, AnyBox, AnyDrag, AppContext, BorrowWindow, Bounds, DispatchContext, point, px, view, Action, AnyBox, AnyDrag, AppContext, BorrowWindow, Bounds, Component,
DispatchPhase, Element, ElementId, FocusHandle, IntoAnyElement, KeyMatch, Keystroke, Modifiers, DispatchContext, DispatchPhase, Element, ElementId, FocusHandle, KeyMatch, Keystroke,
Overflow, Pixels, Point, SharedString, Size, Style, StyleRefinement, ViewContext, Modifiers, Overflow, Pixels, Point, SharedString, Size, Style, StyleRefinement, ViewContext,
}; };
use collections::HashMap; use collections::HashMap;
use derive_more::{Deref, DerefMut}; use derive_more::{Deref, DerefMut};
@ -327,7 +327,7 @@ pub trait StatefulInteractive<V: 'static>: StatelessInteractive<V> {
S: Any + Send + Sync, S: Any + Send + Sync,
R: Fn(&mut V, &mut ViewContext<V>) -> E, R: Fn(&mut V, &mut ViewContext<V>) -> E,
R: 'static + Send + Sync, R: 'static + Send + Sync,
E: IntoAnyElement<V>, E: Component<V>,
{ {
debug_assert!( debug_assert!(
self.stateful_interaction().drag_listener.is_none(), self.stateful_interaction().drag_listener.is_none(),
@ -871,7 +871,7 @@ pub struct Drag<S, R, V, E>
where where
R: Fn(&mut V, &mut ViewContext<V>) -> E, R: Fn(&mut V, &mut ViewContext<V>) -> E,
V: 'static, V: 'static,
E: IntoAnyElement<V>, E: Component<V>,
{ {
pub state: S, pub state: S,
pub render_drag_handle: R, pub render_drag_handle: R,
@ -882,7 +882,7 @@ impl<S, R, V, E> Drag<S, R, V, E>
where where
R: Fn(&mut V, &mut ViewContext<V>) -> E, R: Fn(&mut V, &mut ViewContext<V>) -> E,
V: 'static, V: 'static,
E: IntoAnyElement<V>, E: Component<V>,
{ {
pub fn new(state: S, render_drag_handle: R) -> Self { pub fn new(state: S, render_drag_handle: R) -> Self {
Drag { Drag {

View file

@ -1,7 +1,7 @@
use parking_lot::Mutex; use parking_lot::Mutex;
use crate::{ use crate::{
AnyBox, AnyElement, BorrowWindow, Bounds, Element, ElementId, EntityId, Handle, IntoAnyElement, AnyBox, AnyElement, BorrowWindow, Bounds, Component, Element, ElementId, EntityId, Handle,
LayoutId, Pixels, ViewContext, WindowContext, LayoutId, Pixels, ViewContext, WindowContext,
}; };
use std::{marker::PhantomData, sync::Arc}; use std::{marker::PhantomData, sync::Arc};
@ -33,16 +33,16 @@ pub fn view<V, E>(
render: impl Fn(&mut V, &mut ViewContext<V>) -> E + Send + Sync + 'static, render: impl Fn(&mut V, &mut ViewContext<V>) -> E + Send + Sync + 'static,
) -> View<V> ) -> View<V>
where where
E: IntoAnyElement<V>, E: Component<V>,
{ {
View { View {
state, state,
render: Arc::new(move |state, cx| render(state, cx).into_any()), render: Arc::new(move |state, cx| render(state, cx).render()),
} }
} }
impl<V: 'static, ParentViewState: 'static> IntoAnyElement<ParentViewState> for View<V> { impl<V: 'static, ParentViewState: 'static> Component<ParentViewState> for View<V> {
fn into_any(self) -> AnyElement<ParentViewState> { fn render(self) -> AnyElement<ParentViewState> {
AnyElement::new(EraseViewState { AnyElement::new(EraseViewState {
view: self, view: self,
parent_view_state_type: PhantomData, parent_view_state_type: PhantomData,
@ -98,8 +98,8 @@ struct EraseViewState<V, ParentV> {
unsafe impl<V, ParentV> Send for EraseViewState<V, ParentV> {} unsafe impl<V, ParentV> Send for EraseViewState<V, ParentV> {}
unsafe impl<V, ParentV> Sync for EraseViewState<V, ParentV> {} unsafe impl<V, ParentV> Sync for EraseViewState<V, ParentV> {}
impl<V: 'static, ParentV: 'static> IntoAnyElement<ParentV> for EraseViewState<V, ParentV> { impl<V: 'static, ParentV: 'static> Component<ParentV> for EraseViewState<V, ParentV> {
fn into_any(self) -> AnyElement<ParentV> { fn render(self) -> AnyElement<ParentV> {
AnyElement::new(self) AnyElement::new(self)
} }
} }
@ -185,8 +185,8 @@ pub struct AnyView {
view: Arc<Mutex<dyn ViewObject>>, view: Arc<Mutex<dyn ViewObject>>,
} }
impl<ParentV: 'static> IntoAnyElement<ParentV> for AnyView { impl<ParentV: 'static> Component<ParentV> for AnyView {
fn into_any(self) -> AnyElement<ParentV> { fn render(self) -> AnyElement<ParentV> {
AnyElement::new(EraseAnyViewState { AnyElement::new(EraseAnyViewState {
view: self, view: self,
parent_view_state_type: PhantomData, parent_view_state_type: PhantomData,
@ -238,8 +238,8 @@ struct EraseAnyViewState<ParentViewState> {
unsafe impl<ParentV> Send for EraseAnyViewState<ParentV> {} unsafe impl<ParentV> Send for EraseAnyViewState<ParentV> {}
unsafe impl<ParentV> Sync for EraseAnyViewState<ParentV> {} unsafe impl<ParentV> Sync for EraseAnyViewState<ParentV> {}
impl<ParentV: 'static> IntoAnyElement<ParentV> for EraseAnyViewState<ParentV> { impl<ParentV: 'static> Component<ParentV> for EraseAnyViewState<ParentV> {
fn into_any(self) -> AnyElement<ParentV> { fn render(self) -> AnyElement<ParentV> {
AnyElement::new(self) AnyElement::new(self)
} }
} }

View file

@ -2,7 +2,7 @@ use proc_macro::TokenStream;
use quote::quote; use quote::quote;
use syn::{parse_macro_input, DeriveInput}; use syn::{parse_macro_input, DeriveInput};
pub fn derive_into_any_element(input: TokenStream) -> TokenStream { pub fn derive_component(input: TokenStream) -> TokenStream {
let ast = parse_macro_input!(input as DeriveInput); let ast = parse_macro_input!(input as DeriveInput);
let name = &ast.ident; let name = &ast.ident;
let generics = &ast.generics; let generics = &ast.generics;
@ -11,7 +11,7 @@ pub fn derive_into_any_element(input: TokenStream) -> TokenStream {
let specified_view_type = ast let specified_view_type = ast
.attrs .attrs
.iter() .iter()
.find(|attr| attr.path.is_ident("element")) .find(|attr| attr.path.is_ident("component"))
.and_then(|attr| { .and_then(|attr| {
if let Ok(syn::Meta::List(meta_list)) = attr.parse_meta() { if let Ok(syn::Meta::List(meta_list)) = attr.parse_meta() {
meta_list.nested.iter().find_map(|nested| { meta_list.nested.iter().find_map(|nested| {
@ -42,10 +42,10 @@ pub fn derive_into_any_element(input: TokenStream) -> TokenStream {
}); });
let expanded = quote! { let expanded = quote! {
impl #impl_generics gpui2::IntoAnyElement<#view_type> for #name #ty_generics #where_clause { impl #impl_generics gpui2::Component<#view_type> for #name #ty_generics #where_clause {
fn into_any(self) -> gpui2::AnyElement<#view_type> { fn render(self) -> gpui2::AnyElement<#view_type> {
(move |view_state: &mut #view_type, cx: &mut gpui2::ViewContext<'_, '_, #view_type>| self.render(view_state, cx)) (move |view_state: &mut #view_type, cx: &mut gpui2::ViewContext<'_, '_, #view_type>| self.render(view_state, cx))
.into_any() .render()
} }
} }
}; };

View file

@ -1,6 +1,6 @@
use proc_macro::TokenStream; use proc_macro::TokenStream;
mod derive_into_any_element; mod derive_component;
mod style_helpers; mod style_helpers;
mod test; mod test;
@ -9,9 +9,9 @@ pub fn style_helpers(args: TokenStream) -> TokenStream {
style_helpers::style_helpers(args) style_helpers::style_helpers(args)
} }
#[proc_macro_derive(IntoAnyElement, attributes(element))] #[proc_macro_derive(Component, attributes(component))]
pub fn derive_into_any_element(input: TokenStream) -> TokenStream { pub fn derive_component(input: TokenStream) -> TokenStream {
derive_into_any_element::derive_into_any_element(input) derive_component::derive_component(input)
} }
#[proc_macro_attribute] #[proc_macro_attribute]

View file

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

View file

@ -16,7 +16,7 @@ impl KitchenSinkStory {
view(cx.entity(|cx| Self::new()), Self::render) view(cx.entity(|cx| Self::new()), Self::render)
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoAnyElement<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Component<Self> {
let element_stories = ElementStory::iter() let element_stories = ElementStory::iter()
.map(|selector| selector.story(cx)) .map(|selector| selector.story(cx))
.collect::<Vec<_>>(); .collect::<Vec<_>>();

View file

@ -1,7 +1,6 @@
use crate::themes::rose_pine; use crate::themes::rose_pine;
use gpui2::{ use gpui2::{
div, px, view, Context, IntoAnyElement, ParentElement, SharedString, Styled, View, div, px, view, Component, Context, ParentElement, SharedString, Styled, View, WindowContext,
WindowContext,
}; };
pub struct ScrollStory { pub struct ScrollStory {
@ -16,7 +15,7 @@ impl ScrollStory {
} }
} }
fn checkerboard<S>(depth: usize) -> impl IntoAnyElement<S> fn checkerboard<S>(depth: usize) -> impl Component<S>
where where
S: 'static + Send + Sync, S: 'static + Send + Sync,
{ {

View file

@ -7,7 +7,7 @@ use crate::story::Story;
/// A reimplementation of the MDN `z-index` example, found here: /// 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). /// [https://developer.mozilla.org/en-US/docs/Web/CSS/z-index](https://developer.mozilla.org/en-US/docs/Web/CSS/z-index).
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct ZIndexStory<S: 'static + Send + Sync> { pub struct ZIndexStory<S: 'static + Send + Sync> {
state_type: PhantomData<S>, state_type: PhantomData<S>,
} }
@ -19,7 +19,7 @@ impl<S: 'static + Send + Sync> ZIndexStory<S> {
} }
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
Story::container(cx) Story::container(cx)
.child(Story::title(cx, "z-index")) .child(Story::title(cx, "z-index"))
.child( .child(
@ -88,7 +88,7 @@ trait Styles: Styled + Sized {
impl<V: 'static + Send + Sync> Styles for Div<V> {} impl<V: 'static + Send + Sync> Styles for Div<V> {}
#[derive(IntoAnyElement)] #[derive(Component)]
struct ZIndexExample<V: 'static + Send + Sync> { struct ZIndexExample<V: 'static + Send + Sync> {
view_type: PhantomData<V>, view_type: PhantomData<V>,
z_index: u32, z_index: u32,
@ -102,7 +102,7 @@ impl<V: 'static + Send + Sync> ZIndexExample<V> {
} }
} }
fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl IntoAnyElement<V> { fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
div() div()
.relative() .relative()
.size_full() .size_full()

View file

@ -28,29 +28,29 @@ impl ElementStory {
pub fn story(&self, cx: &mut WindowContext) -> AnyView { pub fn story(&self, cx: &mut WindowContext) -> AnyView {
match self { match self {
Self::Avatar => { Self::Avatar => {
view(cx.entity(|cx| ()), |_, _| ui::AvatarStory::new().into_any()).into_any() view(cx.entity(|cx| ()), |_, _| ui::AvatarStory::new().render()).into_any()
} }
Self::Button => { Self::Button => {
view(cx.entity(|cx| ()), |_, _| ui::ButtonStory::new().into_any()).into_any() view(cx.entity(|cx| ()), |_, _| ui::ButtonStory::new().render()).into_any()
} }
Self::Details => view(cx.entity(|cx| ()), |_, _| { Self::Details => view(cx.entity(|cx| ()), |_, _| {
ui::DetailsStory::new().into_any() ui::DetailsStory::new().render()
}) })
.into_any(), .into_any(),
Self::Focus => FocusStory::view(cx).into_any(), Self::Focus => FocusStory::view(cx).into_any(),
Self::Icon => { Self::Icon => {
view(cx.entity(|cx| ()), |_, _| ui::IconStory::new().into_any()).into_any() view(cx.entity(|cx| ()), |_, _| ui::IconStory::new().render()).into_any()
} }
Self::Input => { Self::Input => {
view(cx.entity(|cx| ()), |_, _| ui::InputStory::new().into_any()).into_any() view(cx.entity(|cx| ()), |_, _| ui::InputStory::new().render()).into_any()
} }
Self::Label => { Self::Label => {
view(cx.entity(|cx| ()), |_, _| ui::LabelStory::new().into_any()).into_any() view(cx.entity(|cx| ()), |_, _| ui::LabelStory::new().render()).into_any()
} }
Self::Scroll => ScrollStory::view(cx).into_any(), Self::Scroll => ScrollStory::view(cx).into_any(),
Self::Text => TextStory::view(cx).into_any(), Self::Text => TextStory::view(cx).into_any(),
Self::ZIndex => { Self::ZIndex => {
view(cx.entity(|cx| ()), |_, _| ZIndexStory::new().into_any()).into_any() view(cx.entity(|cx| ()), |_, _| ZIndexStory::new().render()).into_any()
} }
} }
} }
@ -91,93 +91,93 @@ impl ComponentStory {
pub fn story(&self, cx: &mut WindowContext) -> AnyView { pub fn story(&self, cx: &mut WindowContext) -> AnyView {
match self { match self {
Self::AssistantPanel => view(cx.entity(|cx| ()), |_, _| { Self::AssistantPanel => view(cx.entity(|cx| ()), |_, _| {
ui::AssistantPanelStory::new().into_any() ui::AssistantPanelStory::new().render()
}) })
.into_any(), .into_any(),
Self::Buffer => { Self::Buffer => {
view(cx.entity(|cx| ()), |_, _| ui::BufferStory::new().into_any()).into_any() view(cx.entity(|cx| ()), |_, _| ui::BufferStory::new().render()).into_any()
} }
Self::Breadcrumb => view(cx.entity(|cx| ()), |_, _| { Self::Breadcrumb => view(cx.entity(|cx| ()), |_, _| {
ui::BreadcrumbStory::new().into_any() ui::BreadcrumbStory::new().render()
}) })
.into_any(), .into_any(),
Self::ChatPanel => view(cx.entity(|cx| ()), |_, _| { Self::ChatPanel => view(cx.entity(|cx| ()), |_, _| {
ui::ChatPanelStory::new().into_any() ui::ChatPanelStory::new().render()
}) })
.into_any(), .into_any(),
Self::CollabPanel => view(cx.entity(|cx| ()), |_, _| { Self::CollabPanel => view(cx.entity(|cx| ()), |_, _| {
ui::CollabPanelStory::new().into_any() ui::CollabPanelStory::new().render()
}) })
.into_any(), .into_any(),
Self::CommandPalette => view(cx.entity(|cx| ()), |_, _| { Self::CommandPalette => view(cx.entity(|cx| ()), |_, _| {
ui::CommandPaletteStory::new().into_any() ui::CommandPaletteStory::new().render()
}) })
.into_any(), .into_any(),
Self::ContextMenu => view(cx.entity(|cx| ()), |_, _| { Self::ContextMenu => view(cx.entity(|cx| ()), |_, _| {
ui::ContextMenuStory::new().into_any() ui::ContextMenuStory::new().render()
}) })
.into_any(), .into_any(),
Self::Facepile => view(cx.entity(|cx| ()), |_, _| { Self::Facepile => view(cx.entity(|cx| ()), |_, _| {
ui::FacepileStory::new().into_any() ui::FacepileStory::new().render()
}) })
.into_any(), .into_any(),
Self::Keybinding => view(cx.entity(|cx| ()), |_, _| { Self::Keybinding => view(cx.entity(|cx| ()), |_, _| {
ui::KeybindingStory::new().into_any() ui::KeybindingStory::new().render()
}) })
.into_any(), .into_any(),
Self::LanguageSelector => view(cx.entity(|cx| ()), |_, _| { Self::LanguageSelector => view(cx.entity(|cx| ()), |_, _| {
ui::LanguageSelectorStory::new().into_any() ui::LanguageSelectorStory::new().render()
}) })
.into_any(), .into_any(),
Self::MultiBuffer => view(cx.entity(|cx| ()), |_, _| { Self::MultiBuffer => view(cx.entity(|cx| ()), |_, _| {
ui::MultiBufferStory::new().into_any() ui::MultiBufferStory::new().render()
}) })
.into_any(), .into_any(),
Self::NotificationsPanel => view(cx.entity(|cx| ()), |_, _| { Self::NotificationsPanel => view(cx.entity(|cx| ()), |_, _| {
ui::NotificationsPanelStory::new().into_any() ui::NotificationsPanelStory::new().render()
}) })
.into_any(), .into_any(),
Self::Palette => view(cx.entity(|cx| ()), |_, _| { Self::Palette => view(cx.entity(|cx| ()), |_, _| {
ui::PaletteStory::new().into_any() ui::PaletteStory::new().render()
}) })
.into_any(), .into_any(),
Self::Panel => { Self::Panel => {
view(cx.entity(|cx| ()), |_, _| ui::PanelStory::new().into_any()).into_any() view(cx.entity(|cx| ()), |_, _| ui::PanelStory::new().render()).into_any()
} }
Self::ProjectPanel => view(cx.entity(|cx| ()), |_, _| { Self::ProjectPanel => view(cx.entity(|cx| ()), |_, _| {
ui::ProjectPanelStory::new().into_any() ui::ProjectPanelStory::new().render()
}) })
.into_any(), .into_any(),
Self::RecentProjects => view(cx.entity(|cx| ()), |_, _| { Self::RecentProjects => view(cx.entity(|cx| ()), |_, _| {
ui::RecentProjectsStory::new().into_any() ui::RecentProjectsStory::new().render()
}) })
.into_any(), .into_any(),
Self::Tab => view(cx.entity(|cx| ()), |_, _| ui::TabStory::new().into_any()).into_any(), Self::Tab => view(cx.entity(|cx| ()), |_, _| ui::TabStory::new().render()).into_any(),
Self::TabBar => { Self::TabBar => {
view(cx.entity(|cx| ()), |_, _| ui::TabBarStory::new().into_any()).into_any() view(cx.entity(|cx| ()), |_, _| ui::TabBarStory::new().render()).into_any()
} }
Self::Terminal => view(cx.entity(|cx| ()), |_, _| { Self::Terminal => view(cx.entity(|cx| ()), |_, _| {
ui::TerminalStory::new().into_any() ui::TerminalStory::new().render()
}) })
.into_any(), .into_any(),
Self::ThemeSelector => view(cx.entity(|cx| ()), |_, _| { Self::ThemeSelector => view(cx.entity(|cx| ()), |_, _| {
ui::ThemeSelectorStory::new().into_any() ui::ThemeSelectorStory::new().render()
}) })
.into_any(), .into_any(),
Self::TitleBar => ui::TitleBarStory::view(cx).into_any(), Self::TitleBar => ui::TitleBarStory::view(cx).into_any(),
Self::Toast => { Self::Toast => {
view(cx.entity(|cx| ()), |_, _| ui::ToastStory::new().into_any()).into_any() view(cx.entity(|cx| ()), |_, _| ui::ToastStory::new().render()).into_any()
} }
Self::Toolbar => view(cx.entity(|cx| ()), |_, _| { Self::Toolbar => view(cx.entity(|cx| ()), |_, _| {
ui::ToolbarStory::new().into_any() ui::ToolbarStory::new().render()
}) })
.into_any(), .into_any(),
Self::TrafficLights => view(cx.entity(|cx| ()), |_, _| { Self::TrafficLights => view(cx.entity(|cx| ()), |_, _| {
ui::TrafficLightsStory::new().into_any() ui::TrafficLightsStory::new().render()
}) })
.into_any(), .into_any(),
Self::Copilot => view(cx.entity(|cx| ()), |_, _| { Self::Copilot => view(cx.entity(|cx| ()), |_, _| {
ui::CopilotModalStory::new().into_any() ui::CopilotModalStory::new().render()
}) })
.into_any(), .into_any(),
Self::Workspace => ui::WorkspaceStory::view(cx).into_any(), Self::Workspace => ui::WorkspaceStory::view(cx).into_any(),

View file

@ -107,7 +107,7 @@ impl StoryWrapper {
Self { story, theme } Self { story, theme }
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoAnyElement<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Component<Self> {
themed(self.theme.clone(), cx, |cx| { themed(self.theme.clone(), cx, |cx| {
div() div()
.flex() .flex()

View file

@ -5,7 +5,7 @@ use gpui2::{rems, AbsoluteLength};
use crate::prelude::*; use crate::prelude::*;
use crate::{Icon, IconButton, Label, Panel, PanelSide}; use crate::{Icon, IconButton, Label, Panel, PanelSide};
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct AssistantPanel<S: 'static + Send + Sync> { pub struct AssistantPanel<S: 'static + Send + Sync> {
id: ElementId, id: ElementId,
state_type: PhantomData<S>, state_type: PhantomData<S>,
@ -26,7 +26,7 @@ impl<S: 'static + Send + Sync> AssistantPanel<S> {
self self
} }
fn render(self, view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
Panel::new(self.id.clone(), cx) Panel::new(self.id.clone(), cx)
.children(vec![div() .children(vec![div()
.flex() .flex()
@ -69,7 +69,7 @@ impl<S: 'static + Send + Sync> AssistantPanel<S> {
.overflow_y_scroll() .overflow_y_scroll()
.child(Label::new("Is this thing on?")), .child(Label::new("Is this thing on?")),
) )
.into_any()]) .render()])
.side(self.current_side) .side(self.current_side)
.width(AbsoluteLength::Rems(rems(32.))) .width(AbsoluteLength::Rems(rems(32.)))
} }
@ -84,7 +84,7 @@ mod stories {
use super::*; use super::*;
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct AssistantPanelStory<S: 'static + Send + Sync> { pub struct AssistantPanelStory<S: 'static + Send + Sync> {
state_type: PhantomData<S>, state_type: PhantomData<S>,
} }
@ -96,7 +96,7 @@ mod stories {
} }
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, AssistantPanel<S>>(cx)) .child(Story::title_for::<_, AssistantPanel<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

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

View file

@ -109,7 +109,7 @@ impl BufferRow {
} }
} }
#[derive(IntoAnyElement, Clone)] #[derive(Component, Clone)]
pub struct Buffer<S: 'static + Send + Sync + Clone> { pub struct Buffer<S: 'static + Send + Sync + Clone> {
id: ElementId, id: ElementId,
state_type: PhantomData<S>, state_type: PhantomData<S>,
@ -158,7 +158,7 @@ impl<S: 'static + Send + Sync + Clone> Buffer<S> {
self self
} }
fn render_row(row: BufferRow, cx: &WindowContext) -> impl IntoAnyElement<S> { fn render_row(row: BufferRow, cx: &WindowContext) -> impl Component<S> {
let theme = theme(cx); let theme = theme(cx);
let line_background = if row.current { let line_background = if row.current {
@ -208,7 +208,7 @@ impl<S: 'static + Send + Sync + Clone> Buffer<S> {
})) }))
} }
fn render_rows(&self, cx: &WindowContext) -> Vec<impl IntoAnyElement<S>> { fn render_rows(&self, cx: &WindowContext) -> Vec<impl Component<S>> {
match &self.rows { match &self.rows {
Some(rows) => rows Some(rows) => rows
.rows .rows
@ -219,7 +219,7 @@ impl<S: 'static + Send + Sync + Clone> Buffer<S> {
} }
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
let theme = theme(cx); let theme = theme(cx);
let rows = self.render_rows(cx); let rows = self.render_rows(cx);
@ -246,7 +246,7 @@ mod stories {
use super::*; use super::*;
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct BufferStory<S: 'static + Send + Sync + Clone> { pub struct BufferStory<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>, state_type: PhantomData<S>,
} }
@ -258,7 +258,7 @@ mod stories {
} }
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
let theme = theme(cx); let theme = theme(cx);
Story::container(cx) Story::container(cx)

View file

@ -25,7 +25,7 @@ impl BufferSearch {
view(cx.entity(|cx| Self::new()), Self::render) view(cx.entity(|cx| Self::new()), Self::render)
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoAnyElement<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Component<Self> {
let theme = theme(cx); let theme = theme(cx);
h_stack().bg(theme.toolbar).p_2().child( h_stack().bg(theme.toolbar).p_2().child(

View file

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

View file

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

View file

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

View file

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

View file

@ -2,7 +2,7 @@ use std::marker::PhantomData;
use crate::{prelude::*, Button, Label, LabelColor, Modal}; use crate::{prelude::*, Button, Label, LabelColor, Modal};
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct CopilotModal<S: 'static + Send + Sync + Clone> { pub struct CopilotModal<S: 'static + Send + Sync + Clone> {
id: ElementId, id: ElementId,
state_type: PhantomData<S>, state_type: PhantomData<S>,
@ -16,7 +16,7 @@ impl<S: 'static + Send + Sync + Clone> CopilotModal<S> {
} }
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
div().id(self.id.clone()).child( div().id(self.id.clone()).child(
Modal::new("some-id") Modal::new("some-id")
.title("Connect Copilot to Zed") .title("Connect Copilot to Zed")
@ -35,7 +35,7 @@ mod stories {
use super::*; use super::*;
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct CopilotModalStory<S: 'static + Send + Sync + Clone> { pub struct CopilotModalStory<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>, state_type: PhantomData<S>,
} }
@ -47,7 +47,7 @@ mod stories {
} }
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, CopilotModal<S>>(cx)) .child(Story::title_for::<_, CopilotModal<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -49,7 +49,7 @@ impl EditorPane {
) )
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoAnyElement<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Component<Self> {
v_stack() v_stack()
.w_full() .w_full()
.h_full() .h_full()

View file

@ -3,7 +3,7 @@ use std::marker::PhantomData;
use crate::prelude::*; use crate::prelude::*;
use crate::{Avatar, Player}; use crate::{Avatar, Player};
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct Facepile<S: 'static + Send + Sync> { pub struct Facepile<S: 'static + Send + Sync> {
state_type: PhantomData<S>, state_type: PhantomData<S>,
players: Vec<Player>, players: Vec<Player>,
@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync> Facepile<S> {
} }
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
let player_count = self.players.len(); let player_count = self.players.len();
let player_list = self.players.iter().enumerate().map(|(ix, player)| { let player_list = self.players.iter().enumerate().map(|(ix, player)| {
let isnt_last = ix < player_count - 1; let isnt_last = ix < player_count - 1;
@ -39,7 +39,7 @@ mod stories {
use super::*; use super::*;
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct FacepileStory<S: 'static + Send + Sync> { pub struct FacepileStory<S: 'static + Send + Sync> {
state_type: PhantomData<S>, state_type: PhantomData<S>,
} }
@ -51,7 +51,7 @@ mod stories {
} }
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
let players = static_players(); let players = static_players();
Story::container(cx) Story::container(cx)

View file

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

View file

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

View file

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

View file

@ -17,7 +17,7 @@ pub enum ListItemVariant {
Inset, Inset,
} }
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct ListHeader<S: 'static + Send + Sync> { pub struct ListHeader<S: 'static + Send + Sync> {
state_type: PhantomData<S>, state_type: PhantomData<S>,
label: SharedString, label: SharedString,
@ -92,7 +92,7 @@ impl<S: 'static + Send + Sync> ListHeader<S> {
} }
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
let theme = theme(cx); let theme = theme(cx);
let is_toggleable = self.toggleable != Toggleable::NotToggleable; let is_toggleable = self.toggleable != Toggleable::NotToggleable;
@ -134,7 +134,7 @@ impl<S: 'static + Send + Sync> ListHeader<S> {
} }
} }
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct ListSubHeader<S: 'static + Send + Sync> { pub struct ListSubHeader<S: 'static + Send + Sync> {
state_type: PhantomData<S>, state_type: PhantomData<S>,
label: SharedString, label: SharedString,
@ -157,7 +157,7 @@ impl<S: 'static + Send + Sync> ListSubHeader<S> {
self self
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
h_stack().flex_1().w_full().relative().py_1().child( h_stack().flex_1().w_full().relative().py_1().child(
div() div()
.h_6() .h_6()
@ -197,7 +197,7 @@ pub enum ListEntrySize {
Medium, Medium,
} }
#[derive(IntoAnyElement)] #[derive(Component)]
pub enum ListItem<S: 'static + Send + Sync> { pub enum ListItem<S: 'static + Send + Sync> {
Entry(ListEntry<S>), Entry(ListEntry<S>),
Details(ListDetailsEntry<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> { impl<S: 'static + Send + Sync> ListItem<S> {
fn render(self, view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
match self { match self {
ListItem::Entry(entry) => div().child(entry.render(view, cx)), ListItem::Entry(entry) => div().child(entry.render(view, cx)),
ListItem::Separator(separator) => div().child(separator.render(view, cx)), ListItem::Separator(separator) => div().child(separator.render(view, cx)),
@ -252,7 +252,7 @@ impl<S: 'static + Send + Sync> ListItem<S> {
} }
} }
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct ListEntry<S: 'static + Send + Sync> { pub struct ListEntry<S: 'static + Send + Sync> {
disclosure_control_style: DisclosureControlVisibility, disclosure_control_style: DisclosureControlVisibility,
indent_level: u32, indent_level: u32,
@ -344,7 +344,7 @@ impl<S: 'static + Send + Sync> ListEntry<S> {
} }
} }
fn disclosure_control(&mut self, cx: &mut ViewContext<S>) -> Option<impl IntoAnyElement<S>> { fn disclosure_control(&mut self, cx: &mut ViewContext<S>) -> Option<impl Component<S>> {
let disclosure_control_icon = if let Some(ToggleState::Toggled) = self.toggle { let disclosure_control_icon = if let Some(ToggleState::Toggled) = self.toggle {
IconElement::new(Icon::ChevronDown) IconElement::new(Icon::ChevronDown)
} else { } else {
@ -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 Component<S> {
let settings = user_settings(cx); let settings = user_settings(cx);
let theme = theme(cx); let theme = theme(cx);
@ -430,7 +430,7 @@ impl<S: 'static + Send + Sync> Default for ListDetailsEntryHandlers<S> {
} }
} }
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct ListDetailsEntry<S: 'static + Send + Sync> { pub struct ListDetailsEntry<S: 'static + Send + Sync> {
label: SharedString, label: SharedString,
meta: Option<SharedString>, meta: Option<SharedString>,
@ -474,7 +474,7 @@ impl<S: 'static + Send + Sync> ListDetailsEntry<S> {
self 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 Component<S> {
let theme = theme(cx); let theme = theme(cx);
let settings = user_settings(cx); let settings = user_settings(cx);
@ -519,7 +519,7 @@ impl<S: 'static + Send + Sync> ListDetailsEntry<S> {
} }
} }
#[derive(Clone, IntoAnyElement)] #[derive(Clone, Component)]
pub struct ListSeparator<S: 'static + Send + Sync> { pub struct ListSeparator<S: 'static + Send + Sync> {
state_type: PhantomData<S>, state_type: PhantomData<S>,
} }
@ -531,14 +531,14 @@ impl<S: 'static + Send + Sync> ListSeparator<S> {
} }
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
let theme = theme(cx); let theme = theme(cx);
div().h_px().w_full().bg(theme.border) div().h_px().w_full().bg(theme.border)
} }
} }
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct List<S: 'static + Send + Sync> { pub struct List<S: 'static + Send + Sync> {
items: Vec<ListItem<S>>, items: Vec<ListItem<S>>,
empty_message: SharedString, empty_message: SharedString,
@ -571,7 +571,7 @@ impl<S: 'static + Send + Sync> List<S> {
self 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 Component<S> {
let is_toggleable = self.toggleable != Toggleable::NotToggleable; let is_toggleable = self.toggleable != Toggleable::NotToggleable;
let is_toggled = Toggleable::is_toggled(&self.toggleable); 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}; use crate::{h_stack, prelude::*, v_stack, Button, Icon, IconButton, Label};
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct Modal<S: 'static + Send + Sync> { pub struct Modal<S: 'static + Send + Sync> {
id: ElementId, id: ElementId,
state_type: PhantomData<S>, state_type: PhantomData<S>,
@ -42,7 +42,7 @@ impl<S: 'static + Send + Sync> Modal<S> {
self 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 Component<S> {
let theme = theme(cx); let theme = theme(cx);
v_stack() v_stack()

View file

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

View file

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

View file

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

View file

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

View file

@ -12,7 +12,7 @@ pub enum SplitDirection {
Vertical, Vertical,
} }
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct Pane<V: 'static> { pub struct Pane<V: 'static> {
id: ElementId, id: ElementId,
size: Size<Length>, size: Size<Length>,
@ -44,7 +44,7 @@ impl<V: 'static> Pane<V> {
self self
} }
fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> impl IntoAnyElement<V> { fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
div() div()
.id(self.id.clone()) .id(self.id.clone())
.flex() .flex()
@ -75,7 +75,7 @@ impl<V: 'static> ParentElement<V> for Pane<V> {
} }
} }
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct PaneGroup<V: 'static + Send + Sync> { pub struct PaneGroup<V: 'static + Send + Sync> {
state_type: PhantomData<V>, state_type: PhantomData<V>,
groups: Vec<PaneGroup<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 Component<V> {
let theme = theme(cx); let theme = theme(cx);
if !self.panes.is_empty() { if !self.panes.is_empty() {

View file

@ -3,7 +3,7 @@ use std::marker::PhantomData;
use crate::prelude::*; use crate::prelude::*;
use crate::{Avatar, Facepile, PlayerWithCallStatus}; use crate::{Avatar, Facepile, PlayerWithCallStatus};
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct PlayerStack<S: 'static + Send + Sync> { pub struct PlayerStack<S: 'static + Send + Sync> {
state_type: PhantomData<S>, state_type: PhantomData<S>,
player_with_call_status: PlayerWithCallStatus, player_with_call_status: PlayerWithCallStatus,
@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync> PlayerStack<S> {
} }
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
let theme = theme(cx); let theme = theme(cx);
let player = self.player_with_call_status.get_player(); let player = self.player_with_call_status.get_player();
self.player_with_call_status.get_call_status(); 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, static_project_panel_project_items, static_project_panel_single_items, Input, List, ListHeader,
}; };
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct ProjectPanel<S: 'static + Send + Sync> { pub struct ProjectPanel<S: 'static + Send + Sync> {
id: ElementId, id: ElementId,
state_type: PhantomData<S>, state_type: PhantomData<S>,
@ -19,7 +19,7 @@ impl<S: 'static + Send + Sync> ProjectPanel<S> {
} }
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
let theme = theme(cx); let theme = theme(cx);
div() div()
@ -67,7 +67,7 @@ mod stories {
use super::*; use super::*;
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct ProjectPanelStory<S: 'static + Send + Sync + Clone> { pub struct ProjectPanelStory<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>, state_type: PhantomData<S>,
} }
@ -79,7 +79,7 @@ mod stories {
} }
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, ProjectPanel<S>>(cx)) .child(Story::title_for::<_, ProjectPanel<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

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

View file

@ -28,8 +28,8 @@ impl Default for ToolGroup {
} }
} }
#[derive(IntoAnyElement)] #[derive(Component)]
#[element(view_type = "Workspace")] #[component(view_type = "Workspace")]
pub struct StatusBar { pub struct StatusBar {
left_tools: Option<ToolGroup>, left_tools: Option<ToolGroup>,
right_tools: Option<ToolGroup>, right_tools: Option<ToolGroup>,
@ -86,7 +86,7 @@ impl StatusBar {
self, self,
view: &mut Workspace, view: &mut Workspace,
cx: &mut ViewContext<Workspace>, cx: &mut ViewContext<Workspace>,
) -> impl IntoAnyElement<Workspace> { ) -> impl Component<Workspace> {
let theme = theme(cx); let theme = theme(cx);
div() div()
@ -105,7 +105,7 @@ impl StatusBar {
&self, &self,
workspace: &mut Workspace, workspace: &mut Workspace,
cx: &WindowContext, cx: &WindowContext,
) -> impl IntoAnyElement<Workspace> { ) -> impl Component<Workspace> {
div() div()
.flex() .flex()
.items_center() .items_center()
@ -136,7 +136,7 @@ impl StatusBar {
&self, &self,
workspace: &mut Workspace, workspace: &mut Workspace,
cx: &WindowContext, cx: &WindowContext,
) -> impl IntoAnyElement<Workspace> { ) -> impl Component<Workspace> {
div() div()
.flex() .flex()
.items_center() .items_center()

View file

@ -3,7 +3,7 @@ use std::marker::PhantomData;
use crate::prelude::*; use crate::prelude::*;
use crate::{Icon, IconColor, IconElement, Label, LabelColor}; use crate::{Icon, IconColor, IconElement, Label, LabelColor};
#[derive(IntoAnyElement, Clone)] #[derive(Component, Clone)]
pub struct Tab<S: 'static + Send + Sync + Clone> { pub struct Tab<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>, state_type: PhantomData<S>,
id: ElementId, id: ElementId,
@ -81,7 +81,7 @@ impl<S: 'static + Send + Sync + Clone> Tab<S> {
self self
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
let theme = theme(cx); let theme = theme(cx);
let has_fs_conflict = self.fs_status == FileSystemStatus::Conflict; let has_fs_conflict = self.fs_status == FileSystemStatus::Conflict;
let is_deleted = self.fs_status == FileSystemStatus::Deleted; let is_deleted = self.fs_status == FileSystemStatus::Deleted;
@ -176,7 +176,7 @@ mod stories {
use super::*; use super::*;
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct TabStory<S: 'static + Send + Sync + Clone> { pub struct TabStory<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>, state_type: PhantomData<S>,
} }
@ -188,7 +188,7 @@ mod stories {
} }
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
let git_statuses = GitStatus::iter(); let git_statuses = GitStatus::iter();
let fs_statuses = FileSystemStatus::iter(); let fs_statuses = FileSystemStatus::iter();

View file

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

View file

@ -5,7 +5,7 @@ use gpui2::{relative, rems, Size};
use crate::prelude::*; use crate::prelude::*;
use crate::{Icon, IconButton, Pane, Tab}; use crate::{Icon, IconButton, Pane, Tab};
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct Terminal<S: 'static + Send + Sync + Clone> { pub struct Terminal<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>, state_type: PhantomData<S>,
} }
@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync + Clone> Terminal<S> {
} }
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
let theme = theme(cx); let theme = theme(cx);
let can_navigate_back = true; let can_navigate_back = true;
@ -93,7 +93,7 @@ mod stories {
use super::*; use super::*;
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct TerminalStory<S: 'static + Send + Sync + Clone> { pub struct TerminalStory<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>, state_type: PhantomData<S>,
} }
@ -105,7 +105,7 @@ mod stories {
} }
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, Terminal<S>>(cx)) .child(Story::title_for::<_, Terminal<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

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

View file

@ -87,7 +87,7 @@ impl TitleBar {
) )
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoAnyElement<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Component<Self> {
let theme = theme(cx); let theme = theme(cx);
let settings = user_settings(cx); let settings = user_settings(cx);
@ -204,7 +204,7 @@ mod stories {
) )
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoAnyElement<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Component<Self> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, TitleBar>(cx)) .child(Story::title_for::<_, TitleBar>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -22,7 +22,7 @@ pub enum ToastOrigin {
/// they are actively showing the a process in progress. /// they are actively showing the a process in progress.
/// ///
/// Only one toast may be visible at a time. /// Only one toast may be visible at a time.
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct Toast<S: 'static + Send + Sync> { pub struct Toast<S: 'static + Send + Sync> {
origin: ToastOrigin, origin: ToastOrigin,
children: SmallVec<[AnyElement<S>; 2]>, children: SmallVec<[AnyElement<S>; 2]>,
@ -36,7 +36,7 @@ impl<S: 'static + Send + Sync> Toast<S> {
} }
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
let theme = theme(cx); let theme = theme(cx);
let mut div = div(); let mut div = div();
@ -78,7 +78,7 @@ mod stories {
use super::*; use super::*;
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct ToastStory<S: 'static + Send + Sync> { pub struct ToastStory<S: 'static + Send + Sync> {
state_type: PhantomData<S>, state_type: PhantomData<S>,
} }
@ -90,7 +90,7 @@ mod stories {
} }
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, Toast<S>>(cx)) .child(Story::title_for::<_, Toast<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -6,7 +6,7 @@ use crate::prelude::*;
#[derive(Clone)] #[derive(Clone)]
pub struct ToolbarItem {} pub struct ToolbarItem {}
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct Toolbar<S: 'static + Send + Sync> { pub struct Toolbar<S: 'static + Send + Sync> {
left_items: SmallVec<[AnyElement<S>; 2]>, left_items: SmallVec<[AnyElement<S>; 2]>,
right_items: SmallVec<[AnyElement<S>; 2]>, right_items: SmallVec<[AnyElement<S>; 2]>,
@ -20,41 +20,41 @@ impl<S: 'static + Send + Sync> Toolbar<S> {
} }
} }
pub fn left_item(mut self, child: impl IntoAnyElement<S>) -> Self pub fn left_item(mut self, child: impl Component<S>) -> Self
where where
Self: Sized, Self: Sized,
{ {
self.left_items.push(child.into_any()); self.left_items.push(child.render());
self self
} }
pub fn left_items(mut self, iter: impl IntoIterator<Item = impl IntoAnyElement<S>>) -> Self pub fn left_items(mut self, iter: impl IntoIterator<Item = impl Component<S>>) -> Self
where where
Self: Sized, Self: Sized,
{ {
self.left_items self.left_items
.extend(iter.into_iter().map(|item| item.into_any())); .extend(iter.into_iter().map(|item| item.render()));
self self
} }
pub fn right_item(mut self, child: impl IntoAnyElement<S>) -> Self pub fn right_item(mut self, child: impl Component<S>) -> Self
where where
Self: Sized, Self: Sized,
{ {
self.right_items.push(child.into_any()); self.right_items.push(child.render());
self self
} }
pub fn right_items(mut self, iter: impl IntoIterator<Item = impl IntoAnyElement<S>>) -> Self pub fn right_items(mut self, iter: impl IntoIterator<Item = impl Component<S>>) -> Self
where where
Self: Sized, Self: Sized,
{ {
self.right_items self.right_items
.extend(iter.into_iter().map(|item| item.into_any())); .extend(iter.into_iter().map(|item| item.render()));
self 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 Component<S> {
let theme = theme(cx); let theme = theme(cx);
div() div()
@ -80,7 +80,7 @@ mod stories {
use super::*; use super::*;
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct ToolbarStory<S: 'static + Send + Sync + Clone> { pub struct ToolbarStory<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>, state_type: PhantomData<S>,
} }
@ -92,7 +92,7 @@ mod stories {
} }
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
let theme = theme(cx); let theme = theme(cx);
Story::container(cx) Story::container(cx)

View file

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

View file

@ -174,7 +174,7 @@ impl Workspace {
view(cx.entity(|cx| Self::new(cx)), Self::render) view(cx.entity(|cx| Self::new(cx)), Self::render)
} }
pub fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoAnyElement<Self> { pub fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Component<Self> {
let theme = old_theme(cx).clone(); let theme = old_theme(cx).clone();
// HACK: This should happen inside of `debug_toggle_user_settings`, but // HACK: This should happen inside of `debug_toggle_user_settings`, but

View file

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

View file

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

View file

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

View file

@ -148,7 +148,7 @@ impl Icon {
} }
} }
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct IconElement<S: 'static + Send + Sync> { pub struct IconElement<S: 'static + Send + Sync> {
state_type: PhantomData<S>, state_type: PhantomData<S>,
icon: Icon, icon: Icon,
@ -176,7 +176,7 @@ impl<S: 'static + Send + Sync> IconElement<S> {
self self
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
let fill = self.color.color(cx); let fill = self.color.color(cx);
let svg_size = match self.size { let svg_size = match self.size {
IconSize::Small => ui_size(cx, 12. / 14.), IconSize::Small => ui_size(cx, 12. / 14.),
@ -202,7 +202,7 @@ mod stories {
use super::*; use super::*;
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct IconStory<S: 'static + Send + Sync> { pub struct IconStory<S: 'static + Send + Sync> {
state_type: PhantomData<S>, state_type: PhantomData<S>,
} }
@ -214,7 +214,7 @@ mod stories {
} }
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
let icons = Icon::iter(); let icons = Icon::iter();
Story::container(cx) Story::container(cx)

View file

@ -11,7 +11,7 @@ pub enum InputVariant {
Filled, Filled,
} }
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct Input<S: 'static + Send + Sync> { pub struct Input<S: 'static + Send + Sync> {
state_type: PhantomData<S>, state_type: PhantomData<S>,
placeholder: SharedString, placeholder: SharedString,
@ -60,7 +60,7 @@ impl<S: 'static + Send + Sync> Input<S> {
self self
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
let theme = theme(cx); let theme = theme(cx);
let (input_bg, input_hover_bg, input_active_bg) = match self.variant { let (input_bg, input_hover_bg, input_active_bg) = match self.variant {
@ -120,7 +120,7 @@ mod stories {
use super::*; use super::*;
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct InputStory<S: 'static + Send + Sync> { pub struct InputStory<S: 'static + Send + Sync> {
state_type: PhantomData<S>, state_type: PhantomData<S>,
} }
@ -132,7 +132,7 @@ mod stories {
} }
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, Input<S>>(cx)) .child(Story::title_for::<_, Input<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -48,7 +48,7 @@ pub enum LineHeightStyle {
UILabel, UILabel,
} }
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct Label<S: 'static + Send + Sync> { pub struct Label<S: 'static + Send + Sync> {
state_type: PhantomData<S>, state_type: PhantomData<S>,
label: SharedString, label: SharedString,
@ -83,7 +83,7 @@ impl<S: 'static + Send + Sync> Label<S> {
self self
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
div() div()
.when(self.strikethrough, |this| { .when(self.strikethrough, |this| {
this.relative().child( this.relative().child(
@ -105,7 +105,7 @@ impl<S: 'static + Send + Sync> Label<S> {
} }
} }
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct HighlightedLabel<S: 'static + Send + Sync> { pub struct HighlightedLabel<S: 'static + Send + Sync> {
state_type: PhantomData<S>, state_type: PhantomData<S>,
label: SharedString, label: SharedString,
@ -135,7 +135,7 @@ impl<S: 'static + Send + Sync> HighlightedLabel<S> {
self self
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
let theme = theme(cx); let theme = theme(cx);
let highlight_color = theme.text_accent; let highlight_color = theme.text_accent;
@ -211,7 +211,7 @@ mod stories {
use super::*; use super::*;
#[derive(IntoAnyElement)] #[derive(Component)]
pub struct LabelStory<S: 'static + Send + Sync> { pub struct LabelStory<S: 'static + Send + Sync> {
state_type: PhantomData<S>, state_type: PhantomData<S>,
} }
@ -223,7 +223,7 @@ mod stories {
} }
} }
fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl IntoAnyElement<S> { fn render(self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Component<S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, Label<S>>(cx)) .child(Story::title_for::<_, Label<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

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

View file

@ -1,5 +1,5 @@
pub use gpui2::{ pub use gpui2::{
div, Element, ElementId, IntoAnyElement, ParentElement, SharedString, StatefulInteractive, div, Element, ElementId, Component, ParentElement, SharedString, StatefulInteractive,
StatelessInteractive, Styled, ViewContext, WindowContext, StatelessInteractive, Styled, ViewContext, WindowContext,
}; };

View file

@ -21,7 +21,7 @@ impl Story {
pub fn title<S: 'static + Send + Sync>( pub fn title<S: 'static + Send + Sync>(
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
title: &str, title: &str,
) -> impl IntoAnyElement<S> { ) -> impl Component<S> {
let theme = theme(cx); let theme = theme(cx);
div() div()
@ -30,16 +30,14 @@ impl Story {
.child(title.to_owned()) .child(title.to_owned())
} }
pub fn title_for<S: 'static + Send + Sync, T>( pub fn title_for<S: 'static + Send + Sync, T>(cx: &mut ViewContext<S>) -> impl Component<S> {
cx: &mut ViewContext<S>,
) -> impl IntoAnyElement<S> {
Self::title(cx, std::any::type_name::<T>()) Self::title(cx, std::any::type_name::<T>())
} }
pub fn label<S: 'static + Send + Sync>( pub fn label<S: 'static + Send + Sync>(
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
label: &str, label: &str,
) -> impl IntoAnyElement<S> { ) -> impl Component<S> {
let theme = theme(cx); let theme = theme(cx);
div() div()

View file

@ -1,5 +1,5 @@
use gpui2::{ use gpui2::{
AnyElement, Bounds, Element, Hsla, IntoAnyElement, LayoutId, Pixels, Result, ViewContext, AnyElement, Bounds, Component, Element, Hsla, LayoutId, Pixels, Result, ViewContext,
WindowContext, WindowContext,
}; };
use serde::{de::Visitor, Deserialize, Deserializer}; use serde::{de::Visitor, Deserialize, Deserializer};
@ -149,13 +149,13 @@ pub struct Themed<E> {
pub(crate) child: E, pub(crate) child: E,
} }
impl<V, E> IntoAnyElement<V> for Themed<E> impl<V, E> Component<V> for Themed<E>
where where
V: 'static, V: 'static,
E: 'static + Element<V> + Send + Sync, E: 'static + Element<V> + Send + Sync,
E::ElementState: Send + Sync, E::ElementState: Send + Sync,
{ {
fn into_any(self) -> AnyElement<V> { fn render(self) -> AnyElement<V> {
AnyElement::new(self) AnyElement::new(self)
} }
} }