From 06bff418183ced84e9b6315874e4d68e25fa8207 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Wed, 25 Oct 2023 21:08:34 +0200 Subject: [PATCH 01/17] WIP: ElementRenderer --- crates/ui2/src/components/panes.rs | 80 +++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/crates/ui2/src/components/panes.rs b/crates/ui2/src/components/panes.rs index 77b6817d89..e44056138b 100644 --- a/crates/ui2/src/components/panes.rs +++ b/crates/ui2/src/components/panes.rs @@ -12,7 +12,7 @@ pub enum SplitDirection { Vertical, } -#[derive(Element)] +// #[derive(Element)] pub struct Pane { id: ElementId, state_type: PhantomData, @@ -21,6 +21,84 @@ pub struct Pane { children: SmallVec<[AnyElement; 2]>, } +impl IntoAnyElement for Pane { + fn into_any(self) -> AnyElement { + ElementRenderer { + id: Some(self.id), + render: Some(move |view_state, cx| self.render(view_state, cx)), + view_type: PhantomData, + element_type: PhantomData, + } + } +} + +struct ElementRenderer +where + E: IntoAnyElement, + F: FnOnce(&mut V, &mut ViewContext) -> E, +{ + id: Option, + render: Option, + view_type: PhantomData, + element_type: PhantomData, +} + +impl Element for ElementRenderer +where + V: 'static, + E: IntoAnyElement, + F: FnOnce(&mut V, &mut ViewContext) -> E, +{ + type ViewState = V; + type ElementState = AnyElement; + + fn id(&self) -> Option { + self.id + } + + fn initialize( + &mut self, + view_state: &mut Self::ViewState, + rendered_element: Option, + cx: &mut ViewContext, + ) -> Self::ElementState { + rendered_element.unwrap_or_else(|| { + let render = self.render.take().unwrap(); + (render)(view_state, cx) + }) + } + + fn layout( + &mut self, + view_state: &mut Self::ViewState, + rendered_element: &mut Self::ElementState, + cx: &mut ViewContext, + ) -> gpui2::LayoutId { + rendered_element.layout(view_state, cx) + } + + fn paint( + &mut self, + bounds: gpui2::Bounds, + view_state: &mut Self::ViewState, + rendered_element: &mut Self::ElementState, + cx: &mut ViewContext, + ) { + rendered_element.paint(view_state, cx) + } +} + +impl IntoAnyElement for ElementRenderer +where + V: 'static, + E: IntoAnyElement, + F: FnOnce(&mut V, &mut ViewContext) -> E, +{ + fn into_any(self) -> AnyElement { + self + } +} + impl Pane { pub fn new(id: impl Into, size: Size) -> Self { // Fill is only here for debugging purposes, remove before release From 965bfd8439f0c665e1e95a962f4ee0450a840585 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Thu, 26 Oct 2023 09:45:26 +0200 Subject: [PATCH 02/17] WIP: Pass in `V` to `Element` --- crates/gpui2/src/element.rs | 46 +++++++++---------- crates/gpui2/src/elements/div.rs | 25 +++++----- crates/gpui2/src/elements/img.rs | 13 +++--- crates/gpui2/src/elements/svg.rs | 15 +++--- crates/gpui2/src/focusable.rs | 19 ++------ crates/gpui2/src/interactive.rs | 79 +++++++++----------------------- crates/gpui2/src/view.rs | 33 ++++++------- 7 files changed, 87 insertions(+), 143 deletions(-) diff --git a/crates/gpui2/src/element.rs b/crates/gpui2/src/element.rs index a6efbe52eb..e20d26b3d7 100644 --- a/crates/gpui2/src/element.rs +++ b/crates/gpui2/src/element.rs @@ -3,36 +3,35 @@ use derive_more::{Deref, DerefMut}; pub(crate) use smallvec::SmallVec; use std::{any::Any, mem}; -pub trait Element: IntoAnyElement { - type ViewState: 'static; +pub trait Element: IntoAnyElement { type ElementState: 'static; fn id(&self) -> Option; fn initialize( &mut self, - view_state: &mut Self::ViewState, + view_state: &mut V, element_state: Option, - cx: &mut ViewContext, + cx: &mut ViewContext, ) -> Self::ElementState; // where - // Self::ViewState: Any + Send + Sync; + // V: Any + Send + Sync; fn layout( &mut self, - view_state: &mut Self::ViewState, + view_state: &mut V, element_state: &mut Self::ElementState, - cx: &mut ViewContext, + cx: &mut ViewContext, ) -> LayoutId; // where - // Self::ViewState: Any + Send + Sync; + // V: Any + Send + Sync; fn paint( &mut self, bounds: Bounds, - view_state: &mut Self::ViewState, + view_state: &mut V, element_state: &mut Self::ElementState, - cx: &mut ViewContext, + cx: &mut ViewContext, ); // where @@ -42,10 +41,10 @@ pub trait Element: IntoAnyElement { #[derive(Deref, DerefMut, Default, Clone, Debug, Eq, PartialEq, Hash)] pub struct GlobalElementId(SmallVec<[ElementId; 32]>); -pub trait ParentElement: Element { - fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]>; +pub trait ParentElement: Element { + fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]>; - fn child(mut self, child: impl IntoAnyElement) -> Self + fn child(mut self, child: impl IntoAnyElement) -> Self where Self: Sized, { @@ -53,10 +52,7 @@ pub trait ParentElement: Element { self } - fn children( - mut self, - iter: impl IntoIterator>, - ) -> Self + fn children(mut self, iter: impl IntoIterator>) -> Self where Self: Sized, { @@ -72,7 +68,7 @@ trait ElementObject { fn paint(&mut self, view_state: &mut V, cx: &mut ViewContext); } -struct RenderedElement { +struct RenderedElement> { element: E, phase: ElementRenderPhase, } @@ -94,7 +90,7 @@ enum ElementRenderPhase { /// Internal struct that wraps an element to store Layout and ElementState after the element is rendered. /// It's allocated as a trait object to erase the element type and wrapped in AnyElement for /// improved usability. -impl RenderedElement { +impl> RenderedElement { fn new(element: E) -> Self { RenderedElement { element, @@ -103,13 +99,13 @@ impl RenderedElement { } } -impl ElementObject for RenderedElement +impl ElementObject for RenderedElement where - E: Element, + E: Element, // E::ViewState: Any + Send + Sync, E::ElementState: Any + Send + Sync, { - fn initialize(&mut self, view_state: &mut E::ViewState, cx: &mut ViewContext) { + fn initialize(&mut self, view_state: &mut V, cx: &mut ViewContext) { let frame_state = if let Some(id) = self.element.id() { cx.with_element_state(id, |element_state, cx| { let element_state = self.element.initialize(view_state, element_state, cx); @@ -124,7 +120,7 @@ where self.phase = ElementRenderPhase::Initialized { frame_state }; } - fn layout(&mut self, state: &mut E::ViewState, cx: &mut ViewContext) -> LayoutId { + fn layout(&mut self, state: &mut V, cx: &mut ViewContext) -> LayoutId { let layout_id; let mut frame_state; match mem::take(&mut self.phase) { @@ -154,7 +150,7 @@ where layout_id } - fn paint(&mut self, view_state: &mut E::ViewState, cx: &mut ViewContext) { + fn paint(&mut self, view_state: &mut V, cx: &mut ViewContext) { self.phase = match mem::take(&mut self.phase) { ElementRenderPhase::LayoutRequested { layout_id, @@ -186,7 +182,7 @@ impl AnyElement { pub fn new(element: E) -> Self where E: 'static + Send + Sync, - E: Element, + E: Element, E::ElementState: Any + Send + Sync, { AnyElement(Box::new(RenderedElement::new(element))) diff --git a/crates/gpui2/src/elements/div.rs b/crates/gpui2/src/elements/div.rs index 71196eadca..9e1414e91a 100644 --- a/crates/gpui2/src/elements/div.rs +++ b/crates/gpui2/src/elements/div.rs @@ -189,12 +189,11 @@ pub struct DivState { child_layout_ids: SmallVec<[LayoutId; 4]>, } -impl Element for Div +impl Element for Div where I: ElementInteraction, F: ElementFocus, { - type ViewState = V; type ElementState = DivState; fn id(&self) -> Option { @@ -205,9 +204,9 @@ where fn initialize( &mut self, - view_state: &mut Self::ViewState, + view_state: &mut V, element_state: Option, - cx: &mut ViewContext, + cx: &mut ViewContext, ) -> Self::ElementState { let mut element_state = element_state.unwrap_or_default(); self.focus @@ -224,9 +223,9 @@ where fn layout( &mut self, - view_state: &mut Self::ViewState, + view_state: &mut V, element_state: &mut Self::ElementState, - cx: &mut ViewContext, + cx: &mut ViewContext, ) -> LayoutId { let style = self.compute_style(Bounds::default(), element_state, cx); style.apply_text_style(cx, |cx| { @@ -245,9 +244,9 @@ where fn paint( &mut self, bounds: Bounds, - view_state: &mut Self::ViewState, + view_state: &mut V, element_state: &mut Self::ElementState, - cx: &mut ViewContext, + cx: &mut ViewContext, ) { self.with_element_id(cx, |this, _global_id, cx| { if let Some(group) = this.group.clone() { @@ -315,12 +314,12 @@ where } } -impl ParentElement for Div +impl ParentElement for Div where I: ElementInteraction, F: ElementFocus, { - fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> { + fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> { &mut self.children } } @@ -335,7 +334,7 @@ where } } -impl StatelessInteractive for Div +impl StatelessInteractive for Div where I: ElementInteraction, F: ElementFocus, @@ -345,11 +344,11 @@ where } } -impl StatefulInteractive for Div, F> +impl StatefulInteractive for Div, F> where F: ElementFocus, { - fn stateful_interaction(&mut self) -> &mut StatefulInteraction { + fn stateful_interaction(&mut self) -> &mut StatefulInteraction { &mut self.interaction } } diff --git a/crates/gpui2/src/elements/img.rs b/crates/gpui2/src/elements/img.rs index adce6aea6b..e52b1ca332 100644 --- a/crates/gpui2/src/elements/img.rs +++ b/crates/gpui2/src/elements/img.rs @@ -65,12 +65,11 @@ where } } -impl Element for Img +impl Element for Img where I: ElementInteraction, F: ElementFocus, { - type ViewState = V; type ElementState = DivState; fn id(&self) -> Option { @@ -90,7 +89,7 @@ where &mut self, view_state: &mut V, element_state: &mut Self::ElementState, - cx: &mut ViewContext, + cx: &mut ViewContext, ) -> LayoutId { self.base.layout(view_state, element_state, cx) } @@ -143,7 +142,7 @@ where } } -impl StatelessInteractive for Img +impl StatelessInteractive for Img where I: ElementInteraction, F: ElementFocus, @@ -153,11 +152,11 @@ where } } -impl StatefulInteractive for Img, F> +impl StatefulInteractive for Img, F> where F: ElementFocus, { - fn stateful_interaction(&mut self) -> &mut StatefulInteraction { + fn stateful_interaction(&mut self) -> &mut StatefulInteraction { self.base.stateful_interaction() } } @@ -167,7 +166,7 @@ where V: 'static, I: ElementInteraction, { - fn focus_listeners(&mut self) -> &mut FocusListeners { + fn focus_listeners(&mut self) -> &mut FocusListeners { self.base.focus_listeners() } diff --git a/crates/gpui2/src/elements/svg.rs b/crates/gpui2/src/elements/svg.rs index 7e9017264f..ae388efb3f 100644 --- a/crates/gpui2/src/elements/svg.rs +++ b/crates/gpui2/src/elements/svg.rs @@ -55,12 +55,11 @@ where } } -impl Element for Svg +impl Element for Svg where I: ElementInteraction, F: ElementFocus, { - type ViewState = V; type ElementState = DivState; fn id(&self) -> Option { @@ -80,7 +79,7 @@ where &mut self, view_state: &mut V, element_state: &mut Self::ElementState, - cx: &mut ViewContext, + cx: &mut ViewContext, ) -> LayoutId { self.base.layout(view_state, element_state, cx) } @@ -88,7 +87,7 @@ where fn paint( &mut self, bounds: Bounds, - view: &mut Self::ViewState, + view: &mut V, element_state: &mut Self::ElementState, cx: &mut ViewContext, ) where @@ -116,7 +115,7 @@ where } } -impl StatelessInteractive for Svg +impl StatelessInteractive for Svg where I: ElementInteraction, F: ElementFocus, @@ -126,12 +125,12 @@ where } } -impl StatefulInteractive for Svg, F> +impl StatefulInteractive for Svg, F> where V: 'static, F: ElementFocus, { - fn stateful_interaction(&mut self) -> &mut StatefulInteraction { + fn stateful_interaction(&mut self) -> &mut StatefulInteraction { self.base.stateful_interaction() } } @@ -140,7 +139,7 @@ impl Focusable for Svg> where I: ElementInteraction, { - fn focus_listeners(&mut self) -> &mut FocusListeners { + fn focus_listeners(&mut self) -> &mut FocusListeners { self.base.focus_listeners() } diff --git a/crates/gpui2/src/focusable.rs b/crates/gpui2/src/focusable.rs index 3345b4c6c6..0d2e09ec49 100644 --- a/crates/gpui2/src/focusable.rs +++ b/crates/gpui2/src/focusable.rs @@ -11,8 +11,8 @@ pub type FocusListeners = SmallVec<[FocusListener; 2]>; pub type FocusListener = Arc) + Send + Sync + 'static>; -pub trait Focusable: Element { - fn focus_listeners(&mut self) -> &mut FocusListeners; +pub trait Focusable: Element { + fn focus_listeners(&mut self) -> &mut FocusListeners; fn set_focus_style(&mut self, style: StyleRefinement); fn set_focus_in_style(&mut self, style: StyleRefinement); fn set_in_focus_style(&mut self, style: StyleRefinement); @@ -62,10 +62,7 @@ pub trait Focusable: Element { fn on_blur( mut self, - listener: impl Fn(&mut Self::ViewState, &FocusEvent, &mut ViewContext) - + Send - + Sync - + 'static, + listener: impl Fn(&mut V, &FocusEvent, &mut ViewContext) + Send + Sync + 'static, ) -> Self where Self: Sized, @@ -81,10 +78,7 @@ pub trait Focusable: Element { fn on_focus_in( mut self, - listener: impl Fn(&mut Self::ViewState, &FocusEvent, &mut ViewContext) - + Send - + Sync - + 'static, + listener: impl Fn(&mut V, &FocusEvent, &mut ViewContext) + Send + Sync + 'static, ) -> Self where Self: Sized, @@ -109,10 +103,7 @@ pub trait Focusable: Element { fn on_focus_out( mut self, - listener: impl Fn(&mut Self::ViewState, &FocusEvent, &mut ViewContext) - + Send - + Sync - + 'static, + listener: impl Fn(&mut V, &FocusEvent, &mut ViewContext) + Send + Sync + 'static, ) -> Self where Self: Sized, diff --git a/crates/gpui2/src/interactive.rs b/crates/gpui2/src/interactive.rs index fd603eda46..7cc014e723 100644 --- a/crates/gpui2/src/interactive.rs +++ b/crates/gpui2/src/interactive.rs @@ -19,8 +19,8 @@ use std::{ const DRAG_THRESHOLD: f64 = 2.; -pub trait StatelessInteractive: Element { - fn stateless_interaction(&mut self) -> &mut StatelessInteraction; +pub trait StatelessInteractive: Element { + fn stateless_interaction(&mut self) -> &mut StatelessInteraction; fn hover(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self where @@ -48,10 +48,7 @@ pub trait StatelessInteractive: Element { fn on_mouse_down( mut self, button: MouseButton, - handler: impl Fn(&mut Self::ViewState, &MouseDownEvent, &mut ViewContext) - + Send - + Sync - + 'static, + handler: impl Fn(&mut V, &MouseDownEvent, &mut ViewContext) + Send + Sync + 'static, ) -> Self where Self: Sized, @@ -72,10 +69,7 @@ pub trait StatelessInteractive: Element { fn on_mouse_up( mut self, button: MouseButton, - handler: impl Fn(&mut Self::ViewState, &MouseUpEvent, &mut ViewContext) - + Send - + Sync - + 'static, + handler: impl Fn(&mut V, &MouseUpEvent, &mut ViewContext) + Send + Sync + 'static, ) -> Self where Self: Sized, @@ -96,10 +90,7 @@ pub trait StatelessInteractive: Element { fn on_mouse_down_out( mut self, button: MouseButton, - handler: impl Fn(&mut Self::ViewState, &MouseDownEvent, &mut ViewContext) - + Send - + Sync - + 'static, + handler: impl Fn(&mut V, &MouseDownEvent, &mut ViewContext) + Send + Sync + 'static, ) -> Self where Self: Sized, @@ -120,10 +111,7 @@ pub trait StatelessInteractive: Element { fn on_mouse_up_out( mut self, button: MouseButton, - handler: impl Fn(&mut Self::ViewState, &MouseUpEvent, &mut ViewContext) - + Send - + Sync - + 'static, + handler: impl Fn(&mut V, &MouseUpEvent, &mut ViewContext) + Send + Sync + 'static, ) -> Self where Self: Sized, @@ -143,10 +131,7 @@ pub trait StatelessInteractive: Element { fn on_mouse_move( mut self, - handler: impl Fn(&mut Self::ViewState, &MouseMoveEvent, &mut ViewContext) - + Send - + Sync - + 'static, + handler: impl Fn(&mut V, &MouseMoveEvent, &mut ViewContext) + Send + Sync + 'static, ) -> Self where Self: Sized, @@ -163,10 +148,7 @@ pub trait StatelessInteractive: Element { fn on_scroll_wheel( mut self, - handler: impl Fn(&mut Self::ViewState, &ScrollWheelEvent, &mut ViewContext) - + Send - + Sync - + 'static, + handler: impl Fn(&mut V, &ScrollWheelEvent, &mut ViewContext) + Send + Sync + 'static, ) -> Self where Self: Sized, @@ -194,10 +176,7 @@ pub trait StatelessInteractive: Element { fn on_action( mut self, - listener: impl Fn(&mut Self::ViewState, &A, DispatchPhase, &mut ViewContext) - + Send - + Sync - + 'static, + listener: impl Fn(&mut V, &A, DispatchPhase, &mut ViewContext) + Send + Sync + 'static, ) -> Self where Self: Sized, @@ -215,12 +194,8 @@ pub trait StatelessInteractive: Element { fn on_key_down( mut self, - listener: impl Fn( - &mut Self::ViewState, - &KeyDownEvent, - DispatchPhase, - &mut ViewContext, - ) + Send + listener: impl Fn(&mut V, &KeyDownEvent, DispatchPhase, &mut ViewContext) + + Send + Sync + 'static, ) -> Self @@ -240,7 +215,7 @@ pub trait StatelessInteractive: Element { fn on_key_up( mut self, - listener: impl Fn(&mut Self::ViewState, &KeyUpEvent, DispatchPhase, &mut ViewContext) + listener: impl Fn(&mut V, &KeyUpEvent, DispatchPhase, &mut ViewContext) + Send + Sync + 'static, @@ -289,10 +264,7 @@ pub trait StatelessInteractive: Element { fn on_drop( mut self, - listener: impl Fn(&mut Self::ViewState, S, &mut ViewContext) - + Send - + Sync - + 'static, + listener: impl Fn(&mut V, S, &mut ViewContext) + Send + Sync + 'static, ) -> Self where Self: Sized, @@ -307,8 +279,8 @@ pub trait StatelessInteractive: Element { } } -pub trait StatefulInteractive: StatelessInteractive { - fn stateful_interaction(&mut self) -> &mut StatefulInteraction; +pub trait StatefulInteractive: StatelessInteractive { + fn stateful_interaction(&mut self) -> &mut StatefulInteraction; fn active(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self where @@ -335,10 +307,7 @@ pub trait StatefulInteractive: StatelessInteractive { fn on_click( mut self, - listener: impl Fn(&mut Self::ViewState, &ClickEvent, &mut ViewContext) - + Send - + Sync - + 'static, + listener: impl Fn(&mut V, &ClickEvent, &mut ViewContext) + Send + Sync + 'static, ) -> Self where Self: Sized, @@ -351,20 +320,14 @@ pub trait StatefulInteractive: StatelessInteractive { fn on_drag( mut self, - listener: impl Fn( - &mut Self::ViewState, - &mut ViewContext, - ) -> Drag - + Send - + Sync - + 'static, + listener: impl Fn(&mut V, &mut ViewContext) -> Drag + Send + Sync + 'static, ) -> Self where Self: Sized, S: Any + Send + Sync, - R: Fn(&mut Self::ViewState, &mut ViewContext) -> E, + R: Fn(&mut V, &mut ViewContext) -> E, R: 'static + Send + Sync, - E: Element, + E: Element, { debug_assert!( self.stateful_interaction().drag_listener.is_none(), @@ -907,7 +870,7 @@ pub struct ClickEvent { pub struct Drag where R: Fn(&mut V, &mut ViewContext) -> E, - E: Element, + E: Element, { pub state: S, pub render_drag_handle: R, @@ -917,7 +880,7 @@ where impl Drag where R: Fn(&mut V, &mut ViewContext) -> E, - E: Element, + E: Element, { pub fn new(state: S, render_drag_handle: R) -> Self { Drag { diff --git a/crates/gpui2/src/view.rs b/crates/gpui2/src/view.rs index ed633e8966..13f29e641d 100644 --- a/crates/gpui2/src/view.rs +++ b/crates/gpui2/src/view.rs @@ -50,8 +50,7 @@ impl IntoAnyElement for V } } -impl Element for View { - type ViewState = (); +impl Element<()> for View { type ElementState = AnyElement; fn id(&self) -> Option { @@ -105,8 +104,7 @@ impl IntoAnyElement for EraseViewState Element for EraseViewState { - type ViewState = ParentV; +impl Element for EraseViewState { type ElementState = AnyBox; fn id(&self) -> Option { @@ -115,18 +113,18 @@ impl Element for EraseViewState { fn initialize( &mut self, - _: &mut Self::ViewState, + _: &mut ParentV, _: Option, - cx: &mut ViewContext, + cx: &mut ViewContext, ) -> Self::ElementState { ViewObject::initialize(&mut self.view, cx) } fn layout( &mut self, - _: &mut Self::ViewState, + _: &mut ParentV, element: &mut Self::ElementState, - cx: &mut ViewContext, + cx: &mut ViewContext, ) -> LayoutId { ViewObject::layout(&mut self.view, element, cx) } @@ -134,9 +132,9 @@ impl Element for EraseViewState { fn paint( &mut self, bounds: Bounds, - _: &mut Self::ViewState, + _: &mut ParentV, element: &mut Self::ElementState, - cx: &mut ViewContext, + cx: &mut ViewContext, ) { ViewObject::paint(&mut self.view, bounds, element, cx) } @@ -247,8 +245,7 @@ impl IntoAnyElement for EraseAnyViewState { } } -impl Element for EraseAnyViewState { - type ViewState = ParentV; +impl Element for EraseAnyViewState { type ElementState = AnyBox; fn id(&self) -> Option { @@ -257,18 +254,18 @@ impl Element for EraseAnyViewState { fn initialize( &mut self, - _: &mut Self::ViewState, + _: &mut ParentV, _: Option, - cx: &mut ViewContext, + cx: &mut ViewContext, ) -> Self::ElementState { self.view.view.lock().initialize(cx) } fn layout( &mut self, - _: &mut Self::ViewState, + _: &mut ParentV, element: &mut Self::ElementState, - cx: &mut ViewContext, + cx: &mut ViewContext, ) -> LayoutId { self.view.view.lock().layout(element, cx) } @@ -276,9 +273,9 @@ impl Element for EraseAnyViewState { fn paint( &mut self, bounds: Bounds, - _: &mut Self::ViewState, + _: &mut ParentV, element: &mut Self::ElementState, - cx: &mut ViewContext, + cx: &mut ViewContext, ) { self.view.view.lock().paint(bounds, element, cx) } From 8b972f6d8ebbbf73955f26a3e77764a0a7be8c23 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Thu, 26 Oct 2023 09:51:33 +0200 Subject: [PATCH 03/17] WIP: Fix compilation of `gpui2` --- crates/gpui2/src/element.rs | 5 +++-- crates/gpui2/src/elements/div.rs | 2 +- crates/gpui2/src/elements/img.rs | 2 +- crates/gpui2/src/elements/svg.rs | 2 +- crates/gpui2/src/elements/text.rs | 3 +-- crates/gpui2/src/focusable.rs | 7 ++----- crates/gpui2/src/interactive.rs | 6 ++++-- crates/gpui2/src/view.rs | 13 ++++++------- 8 files changed, 19 insertions(+), 21 deletions(-) diff --git a/crates/gpui2/src/element.rs b/crates/gpui2/src/element.rs index e20d26b3d7..c6707049a6 100644 --- a/crates/gpui2/src/element.rs +++ b/crates/gpui2/src/element.rs @@ -41,7 +41,7 @@ pub trait Element: IntoAnyElement { #[derive(Deref, DerefMut, Default, Clone, Debug, Eq, PartialEq, Hash)] pub struct GlobalElementId(SmallVec<[ElementId; 32]>); -pub trait ParentElement: Element { +pub trait ParentElement: Element { fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]>; fn child(mut self, child: impl IntoAnyElement) -> Self @@ -68,7 +68,7 @@ trait ElementObject { fn paint(&mut self, view_state: &mut V, cx: &mut ViewContext); } -struct RenderedElement> { +struct RenderedElement> { element: E, phase: ElementRenderPhase, } @@ -181,6 +181,7 @@ pub struct AnyElement(Box + Send + Sync>); impl AnyElement { pub fn new(element: E) -> Self where + V: 'static, E: 'static + Send + Sync, E: Element, E::ElementState: Any + Send + Sync, diff --git a/crates/gpui2/src/elements/div.rs b/crates/gpui2/src/elements/div.rs index 9e1414e91a..fbef75ab1c 100644 --- a/crates/gpui2/src/elements/div.rs +++ b/crates/gpui2/src/elements/div.rs @@ -160,7 +160,7 @@ impl Div, FocusDisabled> { } } -impl Focusable for Div> +impl Focusable for Div> where V: 'static, I: ElementInteraction, diff --git a/crates/gpui2/src/elements/img.rs b/crates/gpui2/src/elements/img.rs index e52b1ca332..d64536a7ed 100644 --- a/crates/gpui2/src/elements/img.rs +++ b/crates/gpui2/src/elements/img.rs @@ -161,7 +161,7 @@ where } } -impl Focusable for Img> +impl Focusable for Img> where V: 'static, I: ElementInteraction, diff --git a/crates/gpui2/src/elements/svg.rs b/crates/gpui2/src/elements/svg.rs index ae388efb3f..409094d740 100644 --- a/crates/gpui2/src/elements/svg.rs +++ b/crates/gpui2/src/elements/svg.rs @@ -135,7 +135,7 @@ where } } -impl Focusable for Svg> +impl Focusable for Svg> where I: ElementInteraction, { diff --git a/crates/gpui2/src/elements/text.rs b/crates/gpui2/src/elements/text.rs index 7b0052826c..e054da87a6 100644 --- a/crates/gpui2/src/elements/text.rs +++ b/crates/gpui2/src/elements/text.rs @@ -53,8 +53,7 @@ impl IntoAnyElement for Text { } } -impl Element for Text { - type ViewState = V; +impl Element for Text { type ElementState = Arc>>; fn id(&self) -> Option { diff --git a/crates/gpui2/src/focusable.rs b/crates/gpui2/src/focusable.rs index 0d2e09ec49..c283998ca2 100644 --- a/crates/gpui2/src/focusable.rs +++ b/crates/gpui2/src/focusable.rs @@ -11,7 +11,7 @@ pub type FocusListeners = SmallVec<[FocusListener; 2]>; pub type FocusListener = Arc) + Send + Sync + 'static>; -pub trait Focusable: Element { +pub trait Focusable: Element { fn focus_listeners(&mut self) -> &mut FocusListeners; fn set_focus_style(&mut self, style: StyleRefinement); fn set_focus_in_style(&mut self, style: StyleRefinement); @@ -43,10 +43,7 @@ pub trait Focusable: Element { fn on_focus( mut self, - listener: impl Fn(&mut Self::ViewState, &FocusEvent, &mut ViewContext) - + Send - + Sync - + 'static, + listener: impl Fn(&mut V, &FocusEvent, &mut ViewContext) + Send + Sync + 'static, ) -> Self where Self: Sized, diff --git a/crates/gpui2/src/interactive.rs b/crates/gpui2/src/interactive.rs index 7cc014e723..f00e24b472 100644 --- a/crates/gpui2/src/interactive.rs +++ b/crates/gpui2/src/interactive.rs @@ -19,7 +19,7 @@ use std::{ const DRAG_THRESHOLD: f64 = 2.; -pub trait StatelessInteractive: Element { +pub trait StatelessInteractive: Element { fn stateless_interaction(&mut self) -> &mut StatelessInteraction; fn hover(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self @@ -279,7 +279,7 @@ pub trait StatelessInteractive: Element { } } -pub trait StatefulInteractive: StatelessInteractive { +pub trait StatefulInteractive: StatelessInteractive { fn stateful_interaction(&mut self) -> &mut StatefulInteraction; fn active(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self @@ -870,6 +870,7 @@ pub struct ClickEvent { pub struct Drag where R: Fn(&mut V, &mut ViewContext) -> E, + V: 'static, E: Element, { pub state: S, @@ -880,6 +881,7 @@ where impl Drag where R: Fn(&mut V, &mut ViewContext) -> E, + V: 'static, E: Element, { pub fn new(state: S, render_drag_handle: R) -> Self { diff --git a/crates/gpui2/src/view.rs b/crates/gpui2/src/view.rs index 13f29e641d..b1b287c4ab 100644 --- a/crates/gpui2/src/view.rs +++ b/crates/gpui2/src/view.rs @@ -194,8 +194,7 @@ impl IntoAnyElement for AnyView { } } -impl Element for AnyView { - type ViewState = (); +impl Element<()> for AnyView { type ElementState = AnyBox; fn id(&self) -> Option { @@ -204,18 +203,18 @@ impl Element for AnyView { fn initialize( &mut self, - _: &mut Self::ViewState, + _: &mut (), _: Option, - cx: &mut ViewContext, + cx: &mut ViewContext<()>, ) -> Self::ElementState { self.view.lock().initialize(cx) } fn layout( &mut self, - _: &mut Self::ViewState, + _: &mut (), element: &mut Self::ElementState, - cx: &mut ViewContext, + cx: &mut ViewContext<()>, ) -> LayoutId { self.view.lock().layout(element, cx) } @@ -225,7 +224,7 @@ impl Element for AnyView { bounds: Bounds, _: &mut (), element: &mut AnyBox, - cx: &mut ViewContext, + cx: &mut ViewContext<()>, ) { self.view.lock().paint(bounds, element, cx) } From 9fb9885931091380d542f83b36d5c86ed69093c6 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Thu, 26 Oct 2023 10:08:39 +0200 Subject: [PATCH 04/17] Checkpoint: Compiling --- crates/gpui2_macros/src/derive_element.rs | 15 +++++----- crates/storybook2/src/stories/kitchen_sink.rs | 2 +- crates/storybook2/src/stories/scroll.rs | 2 +- crates/storybook2/src/stories/z_index.rs | 14 ++++----- crates/storybook2/src/storybook2.rs | 2 +- crates/ui2/src/components/assistant_panel.rs | 4 +-- crates/ui2/src/components/breadcrumb.rs | 4 +-- crates/ui2/src/components/buffer.rs | 8 ++--- crates/ui2/src/components/buffer_search.rs | 2 +- crates/ui2/src/components/chat_panel.rs | 6 ++-- crates/ui2/src/components/collab_panel.rs | 4 +-- crates/ui2/src/components/command_palette.rs | 4 +-- crates/ui2/src/components/context_menu.rs | 4 +-- crates/ui2/src/components/copilot.rs | 4 +-- crates/ui2/src/components/editor_pane.rs | 2 +- crates/ui2/src/components/facepile.rs | 4 +-- crates/ui2/src/components/icon_button.rs | 2 +- crates/ui2/src/components/keybinding.rs | 6 ++-- .../ui2/src/components/language_selector.rs | 4 +-- crates/ui2/src/components/list.rs | 16 +++++----- crates/ui2/src/components/modal.rs | 6 ++-- crates/ui2/src/components/multi_buffer.rs | 4 +-- .../ui2/src/components/notification_toast.rs | 2 +- .../ui2/src/components/notifications_panel.rs | 4 +-- crates/ui2/src/components/palette.rs | 6 ++-- crates/ui2/src/components/panel.rs | 8 ++--- crates/ui2/src/components/panes.rs | 8 ++--- crates/ui2/src/components/player_stack.rs | 2 +- crates/ui2/src/components/project_panel.rs | 4 +-- crates/ui2/src/components/recent_projects.rs | 4 +-- crates/ui2/src/components/status_bar.rs | 10 ++----- crates/ui2/src/components/tab.rs | 4 +-- crates/ui2/src/components/tab_bar.rs | 4 +-- crates/ui2/src/components/terminal.rs | 4 +-- crates/ui2/src/components/theme_selector.rs | 4 +-- crates/ui2/src/components/title_bar.rs | 4 +-- crates/ui2/src/components/toast.rs | 12 +++----- crates/ui2/src/components/toolbar.rs | 4 +-- crates/ui2/src/components/traffic_lights.rs | 6 ++-- crates/ui2/src/components/workspace.rs | 6 ++-- crates/ui2/src/element_ext.rs | 4 +-- crates/ui2/src/elements/avatar.rs | 4 +-- crates/ui2/src/elements/button.rs | 6 ++-- crates/ui2/src/elements/details.rs | 4 +-- crates/ui2/src/elements/icon.rs | 4 +-- crates/ui2/src/elements/input.rs | 4 +-- crates/ui2/src/elements/label.rs | 6 ++-- crates/ui2/src/elements/tool_divider.rs | 2 +- crates/ui2/src/story.rs | 6 ++-- crates/ui2/src/theme.rs | 30 ++++++++++--------- 50 files changed, 139 insertions(+), 146 deletions(-) diff --git a/crates/gpui2_macros/src/derive_element.rs b/crates/gpui2_macros/src/derive_element.rs index 3f6b053aa0..a63be0f5da 100644 --- a/crates/gpui2_macros/src/derive_element.rs +++ b/crates/gpui2_macros/src/derive_element.rs @@ -47,10 +47,9 @@ pub fn derive_element(input: TokenStream) -> TokenStream { } } - impl #impl_generics gpui2::Element for #type_name #ty_generics + impl #impl_generics gpui2::Element<#state_type> for #type_name #ty_generics #where_clause { - type ViewState = #state_type; type ElementState = gpui2::AnyElement<#state_type>; fn id(&self) -> Option { @@ -59,9 +58,9 @@ pub fn derive_element(input: TokenStream) -> TokenStream { fn initialize( &mut self, - view_state: &mut Self::ViewState, + view_state: &mut #state_type, _: Option, - cx: &mut gpui2::ViewContext + cx: &mut gpui2::ViewContext<#state_type> ) -> Self::ElementState { use gpui2::IntoAnyElement; @@ -72,9 +71,9 @@ pub fn derive_element(input: TokenStream) -> TokenStream { fn layout( &mut self, - view_state: &mut Self::ViewState, + view_state: &mut #state_type, rendered_element: &mut Self::ElementState, - cx: &mut gpui2::ViewContext, + cx: &mut gpui2::ViewContext<#state_type>, ) -> gpui2::LayoutId { rendered_element.layout(view_state, cx) } @@ -82,9 +81,9 @@ pub fn derive_element(input: TokenStream) -> TokenStream { fn paint( &mut self, bounds: gpui2::Bounds, - view_state: &mut Self::ViewState, + view_state: &mut #state_type, rendered_element: &mut Self::ElementState, - cx: &mut gpui2::ViewContext, + cx: &mut gpui2::ViewContext<#state_type>, ) { rendered_element.paint(view_state, cx) } diff --git a/crates/storybook2/src/stories/kitchen_sink.rs b/crates/storybook2/src/stories/kitchen_sink.rs index e7c4e752f6..63cb1d0f51 100644 --- a/crates/storybook2/src/stories/kitchen_sink.rs +++ b/crates/storybook2/src/stories/kitchen_sink.rs @@ -16,7 +16,7 @@ impl KitchenSinkStory { view(cx.entity(|cx| Self::new()), Self::render) } - fn render(&mut self, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, cx: &mut ViewContext) -> impl Element { let element_stories = ElementStory::iter() .map(|selector| selector.story(cx)) .collect::>(); diff --git a/crates/storybook2/src/stories/scroll.rs b/crates/storybook2/src/stories/scroll.rs index c5df3bd3d3..67200b52bc 100644 --- a/crates/storybook2/src/stories/scroll.rs +++ b/crates/storybook2/src/stories/scroll.rs @@ -16,7 +16,7 @@ impl ScrollStory { } } -fn checkerboard(depth: usize) -> impl Element +fn checkerboard(depth: usize) -> impl Element where S: 'static + Send + Sync, { diff --git a/crates/storybook2/src/stories/z_index.rs b/crates/storybook2/src/stories/z_index.rs index 9dd74b6884..39ac6fd6e4 100644 --- a/crates/storybook2/src/stories/z_index.rs +++ b/crates/storybook2/src/stories/z_index.rs @@ -19,7 +19,7 @@ impl ZIndexStory { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { Story::container(cx) .child(Story::title(cx, "z-index")) .child( @@ -86,23 +86,23 @@ trait Styles: Styled + Sized { } } -impl Styles for Div {} +impl Styles for Div {} #[derive(Element)] -struct ZIndexExample { - state_type: PhantomData, +struct ZIndexExample { + view_type: PhantomData, z_index: u32, } -impl ZIndexExample { +impl ZIndexExample { pub fn new(z_index: u32) -> Self { Self { - state_type: PhantomData, + view_type: PhantomData, z_index, } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut V, cx: &mut ViewContext) -> impl Element { div() .relative() .size_full() diff --git a/crates/storybook2/src/storybook2.rs b/crates/storybook2/src/storybook2.rs index c6d71f079d..107d737ef9 100644 --- a/crates/storybook2/src/storybook2.rs +++ b/crates/storybook2/src/storybook2.rs @@ -107,7 +107,7 @@ impl StoryWrapper { Self { story, theme } } - fn render(&mut self, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, cx: &mut ViewContext) -> impl Element { themed(self.theme.clone(), cx, |cx| { div() .flex() diff --git a/crates/ui2/src/components/assistant_panel.rs b/crates/ui2/src/components/assistant_panel.rs index 31f299de91..77d29f44f7 100644 --- a/crates/ui2/src/components/assistant_panel.rs +++ b/crates/ui2/src/components/assistant_panel.rs @@ -26,7 +26,7 @@ impl AssistantPanel { self } - fn render(&mut self, view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, view: &mut S, cx: &mut ViewContext) -> impl Element { Panel::new(self.id.clone(), cx) .children(vec![div() .flex() @@ -100,7 +100,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { Story::container(cx) .child(Story::title_for::<_, AssistantPanel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/breadcrumb.rs b/crates/ui2/src/components/breadcrumb.rs index e67ceb1751..4bd5283db3 100644 --- a/crates/ui2/src/components/breadcrumb.rs +++ b/crates/ui2/src/components/breadcrumb.rs @@ -35,7 +35,7 @@ impl Breadcrumb { &mut self, view_state: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { let theme = theme(cx); let symbols_len = self.symbols.len(); @@ -106,7 +106,7 @@ mod stories { &mut self, view_state: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { let theme = theme(cx); Story::container(cx) diff --git a/crates/ui2/src/components/buffer.rs b/crates/ui2/src/components/buffer.rs index 2e0e07e16c..51f5ea9196 100644 --- a/crates/ui2/src/components/buffer.rs +++ b/crates/ui2/src/components/buffer.rs @@ -158,7 +158,7 @@ impl Buffer { self } - fn render_row(row: BufferRow, cx: &WindowContext) -> impl Element { + fn render_row(row: BufferRow, cx: &WindowContext) -> impl Element { let theme = theme(cx); let line_background = if row.current { @@ -208,7 +208,7 @@ impl Buffer { })) } - fn render_rows(&self, cx: &WindowContext) -> Vec> { + fn render_rows(&self, cx: &WindowContext) -> Vec> { match &self.rows { Some(rows) => rows .rows @@ -219,7 +219,7 @@ impl Buffer { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); let rows = self.render_rows(cx); @@ -262,7 +262,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { let theme = theme(cx); Story::container(cx) diff --git a/crates/ui2/src/components/buffer_search.rs b/crates/ui2/src/components/buffer_search.rs index 1edbd58c87..3294aec780 100644 --- a/crates/ui2/src/components/buffer_search.rs +++ b/crates/ui2/src/components/buffer_search.rs @@ -25,7 +25,7 @@ impl BufferSearch { view(cx.entity(|cx| Self::new()), Self::render) } - fn render(&mut self, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); h_stack().bg(theme.toolbar).p_2().child( diff --git a/crates/ui2/src/components/chat_panel.rs b/crates/ui2/src/components/chat_panel.rs index 7afccd6d9d..b66868138f 100644 --- a/crates/ui2/src/components/chat_panel.rs +++ b/crates/ui2/src/components/chat_panel.rs @@ -24,7 +24,7 @@ impl ChatPanel { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { div() .id(self.element_id.clone()) .flex() @@ -88,7 +88,7 @@ impl ChatMessage { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { div() .flex() .flex_col() @@ -133,7 +133,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { Story::container(cx) .child(Story::title_for::<_, ChatPanel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/collab_panel.rs b/crates/ui2/src/components/collab_panel.rs index 6414e0e5ff..40276f20b3 100644 --- a/crates/ui2/src/components/collab_panel.rs +++ b/crates/ui2/src/components/collab_panel.rs @@ -19,7 +19,7 @@ impl CollabPanel { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); v_stack() @@ -114,7 +114,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { Story::container(cx) .child(Story::title_for::<_, CollabPanel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/command_palette.rs b/crates/ui2/src/components/command_palette.rs index 45194e843c..036a41e0b9 100644 --- a/crates/ui2/src/components/command_palette.rs +++ b/crates/ui2/src/components/command_palette.rs @@ -17,7 +17,7 @@ impl CommandPalette { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { div().id(self.id.clone()).child( Palette::new("palette") .items(example_editor_actions()) @@ -53,7 +53,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { Story::container(cx) .child(Story::title_for::<_, CommandPalette>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/context_menu.rs b/crates/ui2/src/components/context_menu.rs index 73813ed613..fb076dc9fe 100644 --- a/crates/ui2/src/components/context_menu.rs +++ b/crates/ui2/src/components/context_menu.rs @@ -42,7 +42,7 @@ impl ContextMenu { items: items.into_iter().collect(), } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); v_stack() @@ -89,7 +89,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { Story::container(cx) .child(Story::title_for::<_, ContextMenu>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/copilot.rs b/crates/ui2/src/components/copilot.rs index b0f20cfa0d..8c51b1f4eb 100644 --- a/crates/ui2/src/components/copilot.rs +++ b/crates/ui2/src/components/copilot.rs @@ -16,7 +16,7 @@ impl CopilotModal { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { div().id(self.id.clone()).child( Modal::new("some-id") .title("Connect Copilot to Zed") @@ -51,7 +51,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { Story::container(cx) .child(Story::title_for::<_, CopilotModal>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/editor_pane.rs b/crates/ui2/src/components/editor_pane.rs index 7489b3e47d..b641c86f7e 100644 --- a/crates/ui2/src/components/editor_pane.rs +++ b/crates/ui2/src/components/editor_pane.rs @@ -49,7 +49,7 @@ impl EditorPane { ) } - fn render(&mut self, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, cx: &mut ViewContext) -> impl Element { v_stack() .w_full() .h_full() diff --git a/crates/ui2/src/components/facepile.rs b/crates/ui2/src/components/facepile.rs index 9a96d80010..b75ef328f3 100644 --- a/crates/ui2/src/components/facepile.rs +++ b/crates/ui2/src/components/facepile.rs @@ -17,7 +17,7 @@ impl Facepile { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let player_count = self.players.len(); let player_list = self.players.iter().enumerate().map(|(ix, player)| { let isnt_last = ix < player_count - 1; @@ -55,7 +55,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { let players = static_players(); Story::container(cx) diff --git a/crates/ui2/src/components/icon_button.rs b/crates/ui2/src/components/icon_button.rs index b74165720d..77d248e9ee 100644 --- a/crates/ui2/src/components/icon_button.rs +++ b/crates/ui2/src/components/icon_button.rs @@ -68,7 +68,7 @@ impl IconButton { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); let icon_color = match (self.state, self.color) { diff --git a/crates/ui2/src/components/keybinding.rs b/crates/ui2/src/components/keybinding.rs index 2fb40adac6..25de760cab 100644 --- a/crates/ui2/src/components/keybinding.rs +++ b/crates/ui2/src/components/keybinding.rs @@ -34,7 +34,7 @@ impl Keybinding { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { div() .flex() .gap_2() @@ -68,7 +68,7 @@ impl Key { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); div() @@ -189,7 +189,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { let all_modifier_permutations = ModifierKey::iter().permutations(2); Story::container(cx) diff --git a/crates/ui2/src/components/language_selector.rs b/crates/ui2/src/components/language_selector.rs index 224db69754..dbead8467e 100644 --- a/crates/ui2/src/components/language_selector.rs +++ b/crates/ui2/src/components/language_selector.rs @@ -17,7 +17,7 @@ impl LanguageSelector { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { div().id(self.id.clone()).child( Palette::new("palette") .items(vec![ @@ -64,7 +64,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { Story::container(cx) .child(Story::title_for::<_, LanguageSelector>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/list.rs b/crates/ui2/src/components/list.rs index 99282fa06d..0c41671247 100644 --- a/crates/ui2/src/components/list.rs +++ b/crates/ui2/src/components/list.rs @@ -92,7 +92,7 @@ impl ListHeader { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); let is_toggleable = self.toggleable != Toggleable::NotToggleable; @@ -157,7 +157,7 @@ impl ListSubHeader { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { h_stack().flex_1().w_full().relative().py_1().child( div() .h_6() @@ -230,7 +230,7 @@ impl From> for ListItem { } impl ListItem { - fn render(&mut self, view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, view: &mut S, cx: &mut ViewContext) -> impl Element { match self { ListItem::Entry(entry) => div().child(entry.render(view, cx)), ListItem::Separator(separator) => div().child(separator.render(view, cx)), @@ -347,7 +347,7 @@ impl ListEntry { fn disclosure_control( &mut self, cx: &mut ViewContext, - ) -> Option> { + ) -> Option> { let disclosure_control_icon = if let Some(ToggleState::Toggled) = self.toggle { IconElement::new(Icon::ChevronDown) } else { @@ -367,7 +367,7 @@ impl ListEntry { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let settings = user_settings(cx); let theme = theme(cx); @@ -477,7 +477,7 @@ impl ListDetailsEntry { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); let settings = user_settings(cx); @@ -534,7 +534,7 @@ impl ListSeparator { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); div().h_px().w_full().bg(theme.border) @@ -574,7 +574,7 @@ impl List { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let is_toggleable = self.toggleable != Toggleable::NotToggleable; let is_toggled = Toggleable::is_toggled(&self.toggleable); diff --git a/crates/ui2/src/components/modal.rs b/crates/ui2/src/components/modal.rs index 792f8e1268..154df4e862 100644 --- a/crates/ui2/src/components/modal.rs +++ b/crates/ui2/src/components/modal.rs @@ -42,7 +42,7 @@ impl Modal { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); v_stack() @@ -80,8 +80,8 @@ impl Modal { } } -impl ParentElement for Modal { - fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> { +impl ParentElement for Modal { + fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> { &mut self.children } } diff --git a/crates/ui2/src/components/multi_buffer.rs b/crates/ui2/src/components/multi_buffer.rs index b53ea13ef2..568302b559 100644 --- a/crates/ui2/src/components/multi_buffer.rs +++ b/crates/ui2/src/components/multi_buffer.rs @@ -17,7 +17,7 @@ impl MultiBuffer { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); v_stack() @@ -66,7 +66,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { let theme = theme(cx); Story::container(cx) diff --git a/crates/ui2/src/components/notification_toast.rs b/crates/ui2/src/components/notification_toast.rs index b7709e1a58..afcef8fb20 100644 --- a/crates/ui2/src/components/notification_toast.rs +++ b/crates/ui2/src/components/notification_toast.rs @@ -28,7 +28,7 @@ impl NotificationToast { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); h_stack() diff --git a/crates/ui2/src/components/notifications_panel.rs b/crates/ui2/src/components/notifications_panel.rs index eaf64eb484..fd0445d007 100644 --- a/crates/ui2/src/components/notifications_panel.rs +++ b/crates/ui2/src/components/notifications_panel.rs @@ -17,7 +17,7 @@ impl NotificationsPanel { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); div() @@ -74,7 +74,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { Story::container(cx) .child(Story::title_for::<_, NotificationsPanel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/palette.rs b/crates/ui2/src/components/palette.rs index 87eb88c764..9787086cd6 100644 --- a/crates/ui2/src/components/palette.rs +++ b/crates/ui2/src/components/palette.rs @@ -46,7 +46,7 @@ impl Palette { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); v_stack() @@ -135,7 +135,7 @@ impl PaletteItem { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { div() .flex() .flex_row() @@ -176,7 +176,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { Story::container(cx) .child(Story::title_for::<_, Palette>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/panel.rs b/crates/ui2/src/components/panel.rs index 90dbcf3959..0c52a7a12a 100644 --- a/crates/ui2/src/components/panel.rs +++ b/crates/ui2/src/components/panel.rs @@ -96,7 +96,7 @@ impl Panel { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); let current_size = self.width.unwrap_or(self.initial_width); @@ -121,8 +121,8 @@ impl Panel { } } -impl ParentElement for Panel { - fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> { +impl ParentElement for Panel { + fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> { &mut self.children } } @@ -152,7 +152,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { Story::container(cx) .child(Story::title_for::<_, Panel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/panes.rs b/crates/ui2/src/components/panes.rs index 77b6817d89..fd95853201 100644 --- a/crates/ui2/src/components/panes.rs +++ b/crates/ui2/src/components/panes.rs @@ -40,7 +40,7 @@ impl Pane { self } - fn render(&mut self, view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, view: &mut S, cx: &mut ViewContext) -> impl Element { div() .id(self.id.clone()) .flex() @@ -70,8 +70,8 @@ impl Pane { } } -impl ParentElement for Pane { - fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> { +impl ParentElement for Pane { + fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> { &mut self.children } } @@ -103,7 +103,7 @@ impl PaneGroup { } } - fn render(&mut self, view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); if !self.panes.is_empty() { diff --git a/crates/ui2/src/components/player_stack.rs b/crates/ui2/src/components/player_stack.rs index 0240af8f47..0ada98aa3f 100644 --- a/crates/ui2/src/components/player_stack.rs +++ b/crates/ui2/src/components/player_stack.rs @@ -17,7 +17,7 @@ impl PlayerStack { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); let player = self.player_with_call_status.get_player(); self.player_with_call_status.get_call_status(); diff --git a/crates/ui2/src/components/project_panel.rs b/crates/ui2/src/components/project_panel.rs index 9328b21d43..8b52a1b89a 100644 --- a/crates/ui2/src/components/project_panel.rs +++ b/crates/ui2/src/components/project_panel.rs @@ -19,7 +19,7 @@ impl ProjectPanel { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); div() @@ -83,7 +83,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { Story::container(cx) .child(Story::title_for::<_, ProjectPanel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/recent_projects.rs b/crates/ui2/src/components/recent_projects.rs index 6a5f570562..16c019be53 100644 --- a/crates/ui2/src/components/recent_projects.rs +++ b/crates/ui2/src/components/recent_projects.rs @@ -17,7 +17,7 @@ impl RecentProjects { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { div().id(self.id.clone()).child( Palette::new("palette") .items(vec![ @@ -60,7 +60,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { Story::container(cx) .child(Story::title_for::<_, RecentProjects>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/status_bar.rs b/crates/ui2/src/components/status_bar.rs index db28ac5070..5eeeb841ef 100644 --- a/crates/ui2/src/components/status_bar.rs +++ b/crates/ui2/src/components/status_bar.rs @@ -86,7 +86,7 @@ impl StatusBar { &mut self, view: &mut Workspace, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { let theme = theme(cx); div() @@ -101,11 +101,7 @@ impl StatusBar { .child(self.right_tools(view, cx)) } - fn left_tools( - &self, - workspace: &mut Workspace, - cx: &WindowContext, - ) -> impl Element { + fn left_tools(&self, workspace: &mut Workspace, cx: &WindowContext) -> impl Element { div() .flex() .items_center() @@ -136,7 +132,7 @@ impl StatusBar { &self, workspace: &mut Workspace, cx: &WindowContext, - ) -> impl Element { + ) -> impl Element { div() .flex() .items_center() diff --git a/crates/ui2/src/components/tab.rs b/crates/ui2/src/components/tab.rs index 451dba9aa4..4bfd21248f 100644 --- a/crates/ui2/src/components/tab.rs +++ b/crates/ui2/src/components/tab.rs @@ -81,7 +81,7 @@ impl Tab { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); let has_fs_conflict = self.fs_status == FileSystemStatus::Conflict; let is_deleted = self.fs_status == FileSystemStatus::Deleted; @@ -192,7 +192,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { let git_statuses = GitStatus::iter(); let fs_statuses = FileSystemStatus::iter(); diff --git a/crates/ui2/src/components/tab_bar.rs b/crates/ui2/src/components/tab_bar.rs index ef67088287..0cc9409c04 100644 --- a/crates/ui2/src/components/tab_bar.rs +++ b/crates/ui2/src/components/tab_bar.rs @@ -27,7 +27,7 @@ impl TabBar { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); let (can_navigate_back, can_navigate_forward) = self.can_navigate; @@ -116,7 +116,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { Story::container(cx) .child(Story::title_for::<_, TabBar>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/terminal.rs b/crates/ui2/src/components/terminal.rs index 236a8961bb..480c1a5da6 100644 --- a/crates/ui2/src/components/terminal.rs +++ b/crates/ui2/src/components/terminal.rs @@ -17,7 +17,7 @@ impl Terminal { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); let can_navigate_back = true; @@ -109,7 +109,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { Story::container(cx) .child(Story::title_for::<_, Terminal>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/theme_selector.rs b/crates/ui2/src/components/theme_selector.rs index 3186e814bd..cb1b491d87 100644 --- a/crates/ui2/src/components/theme_selector.rs +++ b/crates/ui2/src/components/theme_selector.rs @@ -17,7 +17,7 @@ impl ThemeSelector { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { div().child( Palette::new(self.id.clone()) .items(vec![ @@ -65,7 +65,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { Story::container(cx) .child(Story::title_for::<_, ThemeSelector>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/title_bar.rs b/crates/ui2/src/components/title_bar.rs index 4cfb092169..68661d0ea2 100644 --- a/crates/ui2/src/components/title_bar.rs +++ b/crates/ui2/src/components/title_bar.rs @@ -87,7 +87,7 @@ impl TitleBar { ) } - fn render(&mut self, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); let settings = user_settings(cx); @@ -204,7 +204,7 @@ mod stories { ) } - fn render(&mut self, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, cx: &mut ViewContext) -> impl Element { Story::container(cx) .child(Story::title_for::<_, TitleBar>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/toast.rs b/crates/ui2/src/components/toast.rs index f75f921841..9318b12eec 100644 --- a/crates/ui2/src/components/toast.rs +++ b/crates/ui2/src/components/toast.rs @@ -36,7 +36,7 @@ impl Toast { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); let mut div = div(); @@ -61,8 +61,8 @@ impl Toast { } } -impl ParentElement for Toast { - fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> { +impl ParentElement for Toast { + fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> { &mut self.children } } @@ -90,11 +90,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { Story::container(cx) .child(Story::title_for::<_, Toast>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/toolbar.rs b/crates/ui2/src/components/toolbar.rs index 2dc5dbff2f..51ec6ee497 100644 --- a/crates/ui2/src/components/toolbar.rs +++ b/crates/ui2/src/components/toolbar.rs @@ -54,7 +54,7 @@ impl Toolbar { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); div() @@ -96,7 +96,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { let theme = theme(cx); Story::container(cx) diff --git a/crates/ui2/src/components/traffic_lights.rs b/crates/ui2/src/components/traffic_lights.rs index 254855bc3f..e875075942 100644 --- a/crates/ui2/src/components/traffic_lights.rs +++ b/crates/ui2/src/components/traffic_lights.rs @@ -25,7 +25,7 @@ impl TrafficLight { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); let fill = match (self.window_has_focus, self.color) { @@ -58,7 +58,7 @@ impl TrafficLights { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { div() .flex() .items_center() @@ -103,7 +103,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { Story::container(cx) .child(Story::title_for::<_, TrafficLights>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/workspace.rs b/crates/ui2/src/components/workspace.rs index ee913cb693..92ea93ef02 100644 --- a/crates/ui2/src/components/workspace.rs +++ b/crates/ui2/src/components/workspace.rs @@ -3,13 +3,13 @@ use std::sync::Arc; use chrono::DateTime; use gpui2::{px, relative, rems, view, Context, Size, View}; -use crate::{prelude::*, NotificationsPanel}; use crate::{ - static_livestream, old_theme, user_settings_mut, v_stack, AssistantPanel, Button, ChatMessage, + old_theme, static_livestream, user_settings_mut, v_stack, AssistantPanel, Button, ChatMessage, ChatPanel, CollabPanel, EditorPane, FakeSettings, Label, LanguageSelector, Pane, PaneGroup, Panel, PanelAllowedSides, PanelSide, ProjectPanel, SettingValue, SplitDirection, StatusBar, Terminal, TitleBar, Toast, ToastOrigin, }; +use crate::{prelude::*, NotificationsPanel}; #[derive(Clone)] pub struct Gpui2UiDebug { @@ -174,7 +174,7 @@ impl Workspace { view(cx.entity(|cx| Self::new(cx)), Self::render) } - pub fn render(&mut self, cx: &mut ViewContext) -> impl Element { + pub fn render(&mut self, cx: &mut ViewContext) -> impl Element { let theme = old_theme(cx).clone(); // HACK: This should happen inside of `debug_toggle_user_settings`, but diff --git a/crates/ui2/src/element_ext.rs b/crates/ui2/src/element_ext.rs index a6ad48e629..813f01dd24 100644 --- a/crates/ui2/src/element_ext.rs +++ b/crates/ui2/src/element_ext.rs @@ -1,6 +1,6 @@ use gpui2::Element; -pub trait ElementExt: Element { +pub trait ElementExt: Element { /// Applies a given function `then` to the current element if `condition` is true. /// This function is used to conditionally modify the element based on a given condition. /// If `condition` is false, it just returns the current element as it is. @@ -25,4 +25,4 @@ pub trait ElementExt: Element { // } } -impl> ElementExt for E {} +impl> ElementExt for E {} diff --git a/crates/ui2/src/elements/avatar.rs b/crates/ui2/src/elements/avatar.rs index 416a55a4f7..0bc1ccad22 100644 --- a/crates/ui2/src/elements/avatar.rs +++ b/crates/ui2/src/elements/avatar.rs @@ -25,7 +25,7 @@ impl Avatar { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); let mut img = img(); @@ -67,7 +67,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { Story::container(cx) .child(Story::title_for::<_, Avatar>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/elements/button.rs b/crates/ui2/src/elements/button.rs index 9948c91999..363f70ddb4 100644 --- a/crates/ui2/src/elements/button.rs +++ b/crates/ui2/src/elements/button.rs @@ -154,7 +154,7 @@ impl Button { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { let icon_color = self.icon_color(); let mut button = h_stack() @@ -211,7 +211,7 @@ impl ButtonGroup { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let mut el = h_stack().text_size(ui_size(cx, 1.)); for button in &mut self.buttons { @@ -250,7 +250,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { let states = InteractionState::iter(); Story::container(cx) diff --git a/crates/ui2/src/elements/details.rs b/crates/ui2/src/elements/details.rs index 9a37fb0935..e7df25f6a3 100644 --- a/crates/ui2/src/elements/details.rs +++ b/crates/ui2/src/elements/details.rs @@ -30,7 +30,7 @@ impl Details { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); v_stack() @@ -70,7 +70,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { Story::container(cx) .child(Story::title_for::<_, Details>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/elements/icon.rs b/crates/ui2/src/elements/icon.rs index ebeed25ea8..d20f262fbc 100644 --- a/crates/ui2/src/elements/icon.rs +++ b/crates/ui2/src/elements/icon.rs @@ -176,7 +176,7 @@ impl IconElement { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let fill = self.color.color(cx); let svg_size = match self.size { IconSize::Small => ui_size(cx, 12. / 14.), @@ -218,7 +218,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { let icons = Icon::iter(); Story::container(cx) diff --git a/crates/ui2/src/elements/input.rs b/crates/ui2/src/elements/input.rs index af0e73c9eb..56d81a0831 100644 --- a/crates/ui2/src/elements/input.rs +++ b/crates/ui2/src/elements/input.rs @@ -60,7 +60,7 @@ impl Input { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); let (input_bg, input_hover_bg, input_active_bg) = match self.variant { @@ -136,7 +136,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { Story::container(cx) .child(Story::title_for::<_, Input>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/elements/label.rs b/crates/ui2/src/elements/label.rs index 81219206a9..d29ab8a5ee 100644 --- a/crates/ui2/src/elements/label.rs +++ b/crates/ui2/src/elements/label.rs @@ -83,7 +83,7 @@ impl Label { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { div() .when(self.strikethrough, |this| { this.relative().child( @@ -135,7 +135,7 @@ impl HighlightedLabel { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); let highlight_color = theme.text_accent; @@ -227,7 +227,7 @@ mod stories { &mut self, _view: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { Story::container(cx) .child(Story::title_for::<_, Label>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/elements/tool_divider.rs b/crates/ui2/src/elements/tool_divider.rs index 68b97ccb03..46b790e6bb 100644 --- a/crates/ui2/src/elements/tool_divider.rs +++ b/crates/ui2/src/elements/tool_divider.rs @@ -14,7 +14,7 @@ impl ToolDivider { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); div().w_px().h_3().bg(theme.border) diff --git a/crates/ui2/src/story.rs b/crates/ui2/src/story.rs index 7a5358dfed..9fc6a11f19 100644 --- a/crates/ui2/src/story.rs +++ b/crates/ui2/src/story.rs @@ -21,7 +21,7 @@ impl Story { pub fn title( cx: &mut ViewContext, title: &str, - ) -> impl Element { + ) -> impl Element { let theme = theme(cx); div() @@ -32,14 +32,14 @@ impl Story { pub fn title_for( cx: &mut ViewContext, - ) -> impl Element { + ) -> impl Element { Self::title(cx, std::any::type_name::()) } pub fn label( cx: &mut ViewContext, label: &str, - ) -> impl Element { + ) -> impl Element { let theme = theme(cx); div() diff --git a/crates/ui2/src/theme.rs b/crates/ui2/src/theme.rs index 00f20f5967..b585140cf7 100644 --- a/crates/ui2/src/theme.rs +++ b/crates/ui2/src/theme.rs @@ -132,10 +132,11 @@ where deserializer.deserialize_map(SyntaxVisitor) } -pub fn themed(theme: Theme, cx: &mut ViewContext, build_child: F) -> Themed +pub fn themed(theme: Theme, cx: &mut ViewContext, build_child: F) -> Themed where - E: Element, - F: FnOnce(&mut ViewContext) -> E, + V: 'static, + E: Element, + F: FnOnce(&mut ViewContext) -> E, { cx.default_global::().0.push(theme.clone()); let child = build_child(cx); @@ -148,12 +149,13 @@ pub struct Themed { pub(crate) child: E, } -impl IntoAnyElement for Themed +impl IntoAnyElement for Themed where - E: 'static + Element + Send + Sync, + V: 'static, + E: 'static + Element + Send + Sync, E::ElementState: Send + Sync, { - fn into_any(self) -> AnyElement { + fn into_any(self) -> AnyElement { AnyElement::new(self) } } @@ -161,11 +163,11 @@ where #[derive(Default)] struct ThemeStack(Vec); -impl Element for Themed +impl + Send + Sync> Element for Themed where + V: 'static, E::ElementState: Send + Sync, { - type ViewState = E::ViewState; type ElementState = E::ElementState; fn id(&self) -> Option { @@ -174,9 +176,9 @@ where fn initialize( &mut self, - view_state: &mut Self::ViewState, + view_state: &mut V, element_state: Option, - cx: &mut ViewContext, + cx: &mut ViewContext, ) -> Self::ElementState { cx.default_global::().0.push(self.theme.clone()); let element_state = self.child.initialize(view_state, element_state, cx); @@ -186,9 +188,9 @@ where fn layout( &mut self, - view_state: &mut E::ViewState, + view_state: &mut V, element_state: &mut Self::ElementState, - cx: &mut ViewContext, + cx: &mut ViewContext, ) -> LayoutId where Self: Sized, @@ -202,9 +204,9 @@ where fn paint( &mut self, bounds: Bounds, - view_state: &mut Self::ViewState, + view_state: &mut V, frame_state: &mut Self::ElementState, - cx: &mut ViewContext, + cx: &mut ViewContext, ) where Self: Sized, { From 4266ead9589b644133560b2003cc6a2ebdbb304a Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Thu, 26 Oct 2023 10:46:02 +0200 Subject: [PATCH 05/17] WIP: Trait bounds --- crates/gpui2/src/element.rs | 4 +- crates/ui2/src/components/panes.rs | 77 ++++++++++++++---------------- 2 files changed, 38 insertions(+), 43 deletions(-) diff --git a/crates/gpui2/src/element.rs b/crates/gpui2/src/element.rs index c6707049a6..3b53884e35 100644 --- a/crates/gpui2/src/element.rs +++ b/crates/gpui2/src/element.rs @@ -8,6 +8,8 @@ pub trait Element: IntoAnyElement { fn id(&self) -> Option; + /// Called to initialize this element for the current frame. If this + /// element had state in a previous frame, it will be passed in for the 3rd argument. fn initialize( &mut self, view_state: &mut V, @@ -41,7 +43,7 @@ pub trait Element: IntoAnyElement { #[derive(Deref, DerefMut, Default, Clone, Debug, Eq, PartialEq, Hash)] pub struct GlobalElementId(SmallVec<[ElementId; 32]>); -pub trait ParentElement: Element { +pub trait ParentElement { fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]>; fn child(mut self, child: impl IntoAnyElement) -> Self diff --git a/crates/ui2/src/components/panes.rs b/crates/ui2/src/components/panes.rs index 0c2714916b..789898cb9d 100644 --- a/crates/ui2/src/components/panes.rs +++ b/crates/ui2/src/components/panes.rs @@ -23,56 +23,54 @@ pub struct Pane { impl IntoAnyElement for Pane { fn into_any(self) -> AnyElement { - ElementRenderer { - id: Some(self.id), - render: Some(move |view_state, cx| self.render(view_state, cx)), + let render = move |view_state, cx| self.render(view_state, cx); + + AnyElement::new(ElementRenderer { + render: Some(render), view_type: PhantomData, element_type: PhantomData, - } + }) } } struct ElementRenderer where - E: IntoAnyElement, - F: FnOnce(&mut V, &mut ViewContext) -> E, + V: 'static + Send + Sync, + E: 'static + IntoAnyElement + Send + Sync, + F: FnOnce(&mut V, &mut ViewContext) -> E + 'static + Send + Sync, { - id: Option, render: Option, view_type: PhantomData, element_type: PhantomData, } -impl Element for ElementRenderer +impl Element for ElementRenderer where - V: 'static, - E: IntoAnyElement, - F: FnOnce(&mut V, &mut ViewContext) -> E, + V: 'static + Send + Sync, + E: 'static + IntoAnyElement + Send + Sync, + F: FnOnce(&mut V, &mut ViewContext) -> E + 'static + Send + Sync, { - type ViewState = V; type ElementState = AnyElement; fn id(&self) -> Option { - self.id + None } fn initialize( &mut self, - view_state: &mut Self::ViewState, - rendered_element: Option, - cx: &mut ViewContext, + view_state: &mut V, + _element_state: Option, + cx: &mut ViewContext, ) -> Self::ElementState { - rendered_element.unwrap_or_else(|| { - let render = self.render.take().unwrap(); - (render)(view_state, cx) - }) + let render = self.render.take().unwrap(); + (render)(view_state, cx).into_any() } fn layout( &mut self, - view_state: &mut Self::ViewState, + view_state: &mut V, rendered_element: &mut Self::ElementState, - cx: &mut ViewContext, + cx: &mut ViewContext, ) -> gpui2::LayoutId { rendered_element.layout(view_state, cx) } @@ -80,9 +78,9 @@ where fn paint( &mut self, bounds: gpui2::Bounds, - view_state: &mut Self::ViewState, + view_state: &mut V, rendered_element: &mut Self::ElementState, - cx: &mut ViewContext, + cx: &mut ViewContext, ) { rendered_element.paint(view_state, cx) } @@ -90,16 +88,16 @@ where impl IntoAnyElement for ElementRenderer where - V: 'static, - E: IntoAnyElement, - F: FnOnce(&mut V, &mut ViewContext) -> E, + V: 'static + Send + Sync, + E: 'static + IntoAnyElement + Send + Sync, + F: FnOnce(&mut V, &mut ViewContext) -> E + 'static + Send + Sync, { fn into_any(self) -> AnyElement { - self + AnyElement::new(self) } } -impl Pane { +impl Pane { pub fn new(id: impl Into, size: Size) -> Self { // Fill is only here for debugging purposes, remove before release @@ -118,7 +116,7 @@ impl Pane { self } - fn render(&mut self, view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(self, view: &mut V, cx: &mut ViewContext) -> Div> IntoAnyElement { div() .id(self.id.clone()) .flex() @@ -127,12 +125,7 @@ impl Pane { .w(self.size.width) .h(self.size.height) .relative() - .child( - div() - .z_index(0) - .size_full() - .children(self.children.drain(..)), - ) + .child(div().z_index(0).size_full().children(self.children)) .child( // TODO kb! Figure out why we can't we see the red background when we drag a file over this div. div() @@ -162,8 +155,8 @@ pub struct PaneGroup { split_direction: SplitDirection, } -impl PaneGroup { - pub fn new_groups(groups: Vec>, split_direction: SplitDirection) -> Self { +impl PaneGroup { + pub fn new_groups(groups: Vec>, split_direction: SplitDirection) -> Self { Self { state_type: PhantomData, groups, @@ -172,7 +165,7 @@ impl PaneGroup { } } - pub fn new_panes(panes: Vec>, split_direction: SplitDirection) -> Self { + pub fn new_panes(panes: Vec>, split_direction: SplitDirection) -> Self { Self { state_type: PhantomData, groups: Vec::new(), @@ -181,7 +174,7 @@ impl PaneGroup { } } - fn render(&mut self, view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, view: &mut V, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); if !self.panes.is_empty() { @@ -191,7 +184,7 @@ impl PaneGroup { .gap_px() .w_full() .h_full() - .children(self.panes.iter_mut().map(|pane| pane.render(view, cx))); + .children(self.panes.drain(..).map(|pane| pane.render(view, cx))); if self.split_direction == SplitDirection::Horizontal { return el; @@ -208,7 +201,7 @@ impl PaneGroup { .w_full() .h_full() .bg(theme.editor) - .children(self.groups.iter_mut().map(|group| group.render(view, cx))); + .children(self.groups.iter_mut().map(| group| group.render(view, cx))); if self.split_direction == SplitDirection::Horizontal { return el; From db7d12f6282bce538aa33a5b7d00bc24fe52f041 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 26 Oct 2023 10:59:27 +0200 Subject: [PATCH 06/17] WIP --- crates/ui2/src/components/panes.rs | 53 ++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/crates/ui2/src/components/panes.rs b/crates/ui2/src/components/panes.rs index 789898cb9d..8ad1d4091d 100644 --- a/crates/ui2/src/components/panes.rs +++ b/crates/ui2/src/components/panes.rs @@ -13,17 +13,18 @@ pub enum SplitDirection { } // #[derive(Element)] -pub struct Pane { +pub struct Pane { id: ElementId, - state_type: PhantomData, + state_type: PhantomData, size: Size, fill: Hsla, - children: SmallVec<[AnyElement; 2]>, + children: SmallVec<[AnyElement; 2]>, } impl IntoAnyElement for Pane { fn into_any(self) -> AnyElement { - let render = move |view_state, cx| self.render(view_state, cx); + let render = + move |view_state: &mut V, cx: &mut ViewContext<'_, '_, V>| self.render(view_state, cx); AnyElement::new(ElementRenderer { render: Some(render), @@ -35,20 +36,36 @@ impl IntoAnyElement for Pane { struct ElementRenderer where - V: 'static + Send + Sync, + V: 'static, E: 'static + IntoAnyElement + Send + Sync, - F: FnOnce(&mut V, &mut ViewContext) -> E + 'static + Send + Sync, + F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + 'static + Send + Sync, { render: Option, view_type: PhantomData, element_type: PhantomData, } +unsafe impl Send for ElementRenderer +where + V: 'static, + E: 'static + IntoAnyElement + Send + Sync, + F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + 'static + Send + Sync, +{ +} + +unsafe impl Sync for ElementRenderer +where + V: 'static, + E: 'static + IntoAnyElement + Send + Sync, + F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + 'static + Send + Sync, +{ +} + impl Element for ElementRenderer where - V: 'static + Send + Sync, + V: 'static, E: 'static + IntoAnyElement + Send + Sync, - F: FnOnce(&mut V, &mut ViewContext) -> E + 'static + Send + Sync, + F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + 'static + Send + Sync, { type ElementState = AnyElement; @@ -88,7 +105,7 @@ where impl IntoAnyElement for ElementRenderer where - V: 'static + Send + Sync, + V: 'static, E: 'static + IntoAnyElement + Send + Sync, F: FnOnce(&mut V, &mut ViewContext) -> E + 'static + Send + Sync, { @@ -97,7 +114,7 @@ where } } -impl Pane { +impl Pane { pub fn new(id: impl Into, size: Size) -> Self { // Fill is only here for debugging purposes, remove before release @@ -116,7 +133,7 @@ impl Pane { self } - fn render(self, view: &mut V, cx: &mut ViewContext) -> Div> IntoAnyElement { + fn render(self, view: &mut V, cx: &mut ViewContext) -> impl IntoAnyElement { div() .id(self.id.clone()) .flex() @@ -141,17 +158,17 @@ impl Pane { } } -impl ParentElement for Pane { - fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> { +impl ParentElement for Pane { + fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> { &mut self.children } } #[derive(Element)] -pub struct PaneGroup { - state_type: PhantomData, - groups: Vec>, - panes: Vec>, +pub struct PaneGroup { + state_type: PhantomData, + groups: Vec>, + panes: Vec>, split_direction: SplitDirection, } @@ -201,7 +218,7 @@ impl PaneGroup { .w_full() .h_full() .bg(theme.editor) - .children(self.groups.iter_mut().map(| group| group.render(view, cx))); + .children(self.groups.iter_mut().map(|group| group.render(view, cx))); if self.split_direction == SplitDirection::Horizontal { return el; From 45a8aea0f0a62b0cfd8c1f0e9787202222d4a499 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 26 Oct 2023 11:21:42 +0200 Subject: [PATCH 07/17] Make FnOnces that render elements IntoAnyElement --- crates/gpui2/src/element.rs | 67 +++++++++++++++++++++ crates/ui2/src/components/panes.rs | 96 +----------------------------- 2 files changed, 70 insertions(+), 93 deletions(-) diff --git a/crates/gpui2/src/element.rs b/crates/gpui2/src/element.rs index 3b53884e35..4b5e61be4a 100644 --- a/crates/gpui2/src/element.rs +++ b/crates/gpui2/src/element.rs @@ -180,6 +180,9 @@ where pub struct AnyElement(Box + Send + Sync>); +unsafe impl Send for AnyElement {} +unsafe impl Sync for AnyElement {} + impl AnyElement { pub fn new(element: E) -> Self where @@ -213,3 +216,67 @@ impl IntoAnyElement for AnyElement { self } } + +impl Element for Option +where + V: 'static, + E: 'static + IntoAnyElement + Send + Sync, + F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + Send + Sync + 'static, +{ + type ElementState = AnyElement; + + fn id(&self) -> Option { + None + } + + fn initialize( + &mut self, + view_state: &mut V, + _rendered_element: Option, + cx: &mut ViewContext, + ) -> Self::ElementState { + let render = self.take().unwrap(); + (render)(view_state, cx).into_any() + } + + fn layout( + &mut self, + view_state: &mut V, + rendered_element: &mut Self::ElementState, + cx: &mut ViewContext, + ) -> LayoutId { + rendered_element.layout(view_state, cx) + } + + fn paint( + &mut self, + _bounds: Bounds, + view_state: &mut V, + rendered_element: &mut Self::ElementState, + cx: &mut ViewContext, + ) { + rendered_element.paint(view_state, cx) + } +} + +impl IntoAnyElement for Option +where + V: 'static, + E: 'static + IntoAnyElement + Send + Sync, + F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + Send + Sync + 'static, +{ + fn into_any(self) -> AnyElement { + AnyElement::new(self) + } +} + +impl IntoAnyElement for F +where + V: 'static, + E: 'static + IntoAnyElement + Send + Sync, + F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + Send + Sync + 'static, +{ + fn into_any(self) -> AnyElement { + AnyElement::new(Some(self)) + } +} diff --git a/crates/ui2/src/components/panes.rs b/crates/ui2/src/components/panes.rs index 8ad1d4091d..229de3caa4 100644 --- a/crates/ui2/src/components/panes.rs +++ b/crates/ui2/src/components/panes.rs @@ -12,105 +12,17 @@ pub enum SplitDirection { Vertical, } -// #[derive(Element)] pub struct Pane { id: ElementId, - state_type: PhantomData, size: Size, fill: Hsla, children: SmallVec<[AnyElement; 2]>, } -impl IntoAnyElement for Pane { +impl IntoAnyElement for Pane { fn into_any(self) -> AnyElement { - let render = - move |view_state: &mut V, cx: &mut ViewContext<'_, '_, V>| self.render(view_state, cx); - - AnyElement::new(ElementRenderer { - render: Some(render), - view_type: PhantomData, - element_type: PhantomData, - }) - } -} - -struct ElementRenderer -where - V: 'static, - E: 'static + IntoAnyElement + Send + Sync, - F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + 'static + Send + Sync, -{ - render: Option, - view_type: PhantomData, - element_type: PhantomData, -} - -unsafe impl Send for ElementRenderer -where - V: 'static, - E: 'static + IntoAnyElement + Send + Sync, - F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + 'static + Send + Sync, -{ -} - -unsafe impl Sync for ElementRenderer -where - V: 'static, - E: 'static + IntoAnyElement + Send + Sync, - F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + 'static + Send + Sync, -{ -} - -impl Element for ElementRenderer -where - V: 'static, - E: 'static + IntoAnyElement + Send + Sync, - F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + 'static + Send + Sync, -{ - type ElementState = AnyElement; - - fn id(&self) -> Option { - None - } - - fn initialize( - &mut self, - view_state: &mut V, - _element_state: Option, - cx: &mut ViewContext, - ) -> Self::ElementState { - let render = self.render.take().unwrap(); - (render)(view_state, cx).into_any() - } - - fn layout( - &mut self, - view_state: &mut V, - rendered_element: &mut Self::ElementState, - cx: &mut ViewContext, - ) -> gpui2::LayoutId { - rendered_element.layout(view_state, cx) - } - - fn paint( - &mut self, - bounds: gpui2::Bounds, - view_state: &mut V, - rendered_element: &mut Self::ElementState, - cx: &mut ViewContext, - ) { - rendered_element.paint(view_state, cx) - } -} - -impl IntoAnyElement for ElementRenderer -where - V: 'static, - E: 'static + IntoAnyElement + Send + Sync, - F: FnOnce(&mut V, &mut ViewContext) -> E + 'static + Send + Sync, -{ - fn into_any(self) -> AnyElement { - AnyElement::new(self) + (move |view_state: &mut V, cx: &mut ViewContext<'_, '_, V>| self.render(view_state, cx)) + .into_any() } } @@ -120,10 +32,8 @@ impl Pane { Self { id: id.into(), - state_type: PhantomData, size, fill: hsla(0.3, 0.3, 0.3, 1.), - // fill: system_color.transparent, children: SmallVec::new(), } } From db15db45ce5114571112f617d13ca11b754c6adf Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 26 Oct 2023 11:31:47 +0200 Subject: [PATCH 08/17] WIP --- crates/gpui2/src/element.rs | 2 +- crates/gpui2/src/interactive.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/gpui2/src/element.rs b/crates/gpui2/src/element.rs index 4b5e61be4a..87e1e5c836 100644 --- a/crates/gpui2/src/element.rs +++ b/crates/gpui2/src/element.rs @@ -3,7 +3,7 @@ use derive_more::{Deref, DerefMut}; pub(crate) use smallvec::SmallVec; use std::{any::Any, mem}; -pub trait Element: IntoAnyElement { +pub trait Element { type ElementState: 'static; fn id(&self) -> Option; diff --git a/crates/gpui2/src/interactive.rs b/crates/gpui2/src/interactive.rs index f00e24b472..f51516dbe5 100644 --- a/crates/gpui2/src/interactive.rs +++ b/crates/gpui2/src/interactive.rs @@ -1,7 +1,7 @@ use crate::{ point, px, view, Action, AnyBox, AnyDrag, AppContext, BorrowWindow, Bounds, DispatchContext, - DispatchPhase, Element, ElementId, FocusHandle, KeyMatch, Keystroke, Modifiers, Overflow, - Pixels, Point, SharedString, Size, Style, StyleRefinement, ViewContext, + DispatchPhase, Element, ElementId, FocusHandle, IntoAnyElement, KeyMatch, Keystroke, Modifiers, + Overflow, Pixels, Point, SharedString, Size, Style, StyleRefinement, ViewContext, }; use collections::HashMap; use derive_more::{Deref, DerefMut}; @@ -327,7 +327,7 @@ pub trait StatefulInteractive: StatelessInteractive { S: Any + Send + Sync, R: Fn(&mut V, &mut ViewContext) -> E, R: 'static + Send + Sync, - E: Element, + E: IntoAnyElement, { debug_assert!( self.stateful_interaction().drag_listener.is_none(), @@ -871,7 +871,7 @@ pub struct Drag where R: Fn(&mut V, &mut ViewContext) -> E, V: 'static, - E: Element, + E: IntoAnyElement, { pub state: S, pub render_drag_handle: R, @@ -882,7 +882,7 @@ impl Drag where R: Fn(&mut V, &mut ViewContext) -> E, V: 'static, - E: Element, + E: IntoAnyElement, { pub fn new(state: S, render_drag_handle: R) -> Self { Drag { From 927278e20d149d9c0c5024e435d10a0bb8d4a9d8 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 26 Oct 2023 11:49:36 +0200 Subject: [PATCH 09/17] Remove IntoAnyElement bound from Element trait --- crates/copilot2/src/sign_in.rs | 2 +- crates/storybook2/src/stories/kitchen_sink.rs | 2 +- crates/storybook2/src/stories/scroll.rs | 5 +++-- crates/storybook2/src/stories/z_index.rs | 4 ++-- crates/storybook2/src/storybook2.rs | 4 ++-- crates/ui2/src/components/assistant_panel.rs | 8 ++------ crates/ui2/src/components/breadcrumb.rs | 8 ++------ crates/ui2/src/components/buffer.rs | 12 ++++-------- crates/ui2/src/components/buffer_search.rs | 2 +- crates/ui2/src/components/chat_panel.rs | 10 +++------- crates/ui2/src/components/collab_panel.rs | 8 ++------ crates/ui2/src/components/command_palette.rs | 8 ++------ crates/ui2/src/components/context_menu.rs | 8 ++------ crates/ui2/src/components/copilot.rs | 8 ++------ crates/ui2/src/components/editor_pane.rs | 2 +- crates/ui2/src/components/facepile.rs | 8 ++------ crates/ui2/src/components/icon_button.rs | 2 +- crates/ui2/src/components/keybinding.rs | 10 +++------- .../ui2/src/components/language_selector.rs | 8 ++------ crates/ui2/src/components/list.rs | 19 ++++++++----------- crates/ui2/src/components/modal.rs | 2 +- crates/ui2/src/components/multi_buffer.rs | 8 ++------ .../ui2/src/components/notification_toast.rs | 2 +- .../ui2/src/components/notifications_panel.rs | 8 ++------ crates/ui2/src/components/palette.rs | 10 +++------- crates/ui2/src/components/panel.rs | 8 ++------ crates/ui2/src/components/panes.rs | 2 +- crates/ui2/src/components/player_stack.rs | 2 +- crates/ui2/src/components/project_panel.rs | 8 ++------ crates/ui2/src/components/recent_projects.rs | 8 ++------ crates/ui2/src/components/status_bar.rs | 10 +++++++--- crates/ui2/src/components/tab.rs | 8 ++------ crates/ui2/src/components/tab_bar.rs | 8 ++------ crates/ui2/src/components/terminal.rs | 8 ++------ crates/ui2/src/components/theme_selector.rs | 8 ++------ crates/ui2/src/components/title_bar.rs | 4 ++-- crates/ui2/src/components/toast.rs | 4 ++-- crates/ui2/src/components/toolbar.rs | 8 ++------ crates/ui2/src/components/traffic_lights.rs | 10 +++------- crates/ui2/src/components/workspace.rs | 2 +- crates/ui2/src/elements/avatar.rs | 8 ++------ crates/ui2/src/elements/button.rs | 14 +++----------- crates/ui2/src/elements/details.rs | 8 ++------ crates/ui2/src/elements/icon.rs | 8 ++------ crates/ui2/src/elements/input.rs | 8 ++------ crates/ui2/src/elements/label.rs | 10 +++------- crates/ui2/src/elements/tool_divider.rs | 2 +- crates/ui2/src/story.rs | 6 +++--- 48 files changed, 106 insertions(+), 224 deletions(-) diff --git a/crates/copilot2/src/sign_in.rs b/crates/copilot2/src/sign_in.rs index ab326a8819..57f248aa52 100644 --- a/crates/copilot2/src/sign_in.rs +++ b/crates/copilot2/src/sign_in.rs @@ -106,7 +106,7 @@ // data: &PromptUserDeviceFlow, // style: &theme::Copilot, // cx: &mut ViewContext, -// ) -> impl Element { +// ) -> impl IntoAnyElement { // let copied = cx // .read_from_clipboard() // .map(|item| item.text() == &data.user_code) diff --git a/crates/storybook2/src/stories/kitchen_sink.rs b/crates/storybook2/src/stories/kitchen_sink.rs index 63cb1d0f51..fbb4f5099c 100644 --- a/crates/storybook2/src/stories/kitchen_sink.rs +++ b/crates/storybook2/src/stories/kitchen_sink.rs @@ -16,7 +16,7 @@ impl KitchenSinkStory { view(cx.entity(|cx| Self::new()), Self::render) } - fn render(&mut self, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, cx: &mut ViewContext) -> impl IntoAnyElement { let element_stories = ElementStory::iter() .map(|selector| selector.story(cx)) .collect::>(); diff --git a/crates/storybook2/src/stories/scroll.rs b/crates/storybook2/src/stories/scroll.rs index 67200b52bc..f589ea7cef 100644 --- a/crates/storybook2/src/stories/scroll.rs +++ b/crates/storybook2/src/stories/scroll.rs @@ -1,6 +1,7 @@ use crate::themes::rose_pine; use gpui2::{ - div, px, view, Context, Element, ParentElement, SharedString, Styled, View, WindowContext, + div, px, view, Context, IntoAnyElement, ParentElement, SharedString, Styled, View, + WindowContext, }; use ui::ElementExt; @@ -16,7 +17,7 @@ impl ScrollStory { } } -fn checkerboard(depth: usize) -> impl Element +fn checkerboard(depth: usize) -> impl IntoAnyElement where S: 'static + Send + Sync, { diff --git a/crates/storybook2/src/stories/z_index.rs b/crates/storybook2/src/stories/z_index.rs index 39ac6fd6e4..213d7bed4e 100644 --- a/crates/storybook2/src/stories/z_index.rs +++ b/crates/storybook2/src/stories/z_index.rs @@ -19,7 +19,7 @@ impl ZIndexStory { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title(cx, "z-index")) .child( @@ -102,7 +102,7 @@ impl ZIndexExample { } } - fn render(&mut self, _view: &mut V, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut V, cx: &mut ViewContext) -> impl IntoAnyElement { div() .relative() .size_full() diff --git a/crates/storybook2/src/storybook2.rs b/crates/storybook2/src/storybook2.rs index 107d737ef9..4db1fd434b 100644 --- a/crates/storybook2/src/storybook2.rs +++ b/crates/storybook2/src/storybook2.rs @@ -10,7 +10,7 @@ use std::sync::Arc; use clap::Parser; use gpui2::{ - div, px, size, view, AnyView, AppContext, Bounds, Context, Element, ViewContext, WindowBounds, + div, px, size, view, AnyView, AppContext, Bounds, Context, ViewContext, WindowBounds, WindowOptions, }; use log::LevelFilter; @@ -107,7 +107,7 @@ impl StoryWrapper { Self { story, theme } } - fn render(&mut self, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, cx: &mut ViewContext) -> impl IntoAnyElement { themed(self.theme.clone(), cx, |cx| { div() .flex() diff --git a/crates/ui2/src/components/assistant_panel.rs b/crates/ui2/src/components/assistant_panel.rs index 77d29f44f7..1c47bf1a91 100644 --- a/crates/ui2/src/components/assistant_panel.rs +++ b/crates/ui2/src/components/assistant_panel.rs @@ -26,7 +26,7 @@ impl AssistantPanel { self } - fn render(&mut self, view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Panel::new(self.id.clone(), cx) .children(vec![div() .flex() @@ -96,11 +96,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, AssistantPanel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/breadcrumb.rs b/crates/ui2/src/components/breadcrumb.rs index 4bd5283db3..5f4d3cbafe 100644 --- a/crates/ui2/src/components/breadcrumb.rs +++ b/crates/ui2/src/components/breadcrumb.rs @@ -31,11 +31,7 @@ impl Breadcrumb { div().child(" › ").text_color(theme.text_muted) } - fn render( - &mut self, - view_state: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, view_state: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let symbols_len = self.symbols.len(); @@ -106,7 +102,7 @@ mod stories { &mut self, view_state: &mut S, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl IntoAnyElement { let theme = theme(cx); Story::container(cx) diff --git a/crates/ui2/src/components/buffer.rs b/crates/ui2/src/components/buffer.rs index 51f5ea9196..7b67afc2b4 100644 --- a/crates/ui2/src/components/buffer.rs +++ b/crates/ui2/src/components/buffer.rs @@ -158,7 +158,7 @@ impl Buffer { self } - fn render_row(row: BufferRow, cx: &WindowContext) -> impl Element { + fn render_row(row: BufferRow, cx: &WindowContext) -> impl IntoAnyElement { let theme = theme(cx); let line_background = if row.current { @@ -208,7 +208,7 @@ impl Buffer { })) } - fn render_rows(&self, cx: &WindowContext) -> Vec> { + fn render_rows(&self, cx: &WindowContext) -> Vec> { match &self.rows { Some(rows) => rows .rows @@ -219,7 +219,7 @@ impl Buffer { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let rows = self.render_rows(cx); @@ -258,11 +258,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); Story::container(cx) diff --git a/crates/ui2/src/components/buffer_search.rs b/crates/ui2/src/components/buffer_search.rs index 3294aec780..e3e92aa073 100644 --- a/crates/ui2/src/components/buffer_search.rs +++ b/crates/ui2/src/components/buffer_search.rs @@ -25,7 +25,7 @@ impl BufferSearch { view(cx.entity(|cx| Self::new()), Self::render) } - fn render(&mut self, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); h_stack().bg(theme.toolbar).p_2().child( diff --git a/crates/ui2/src/components/chat_panel.rs b/crates/ui2/src/components/chat_panel.rs index b66868138f..afb79cc907 100644 --- a/crates/ui2/src/components/chat_panel.rs +++ b/crates/ui2/src/components/chat_panel.rs @@ -24,7 +24,7 @@ impl ChatPanel { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div() .id(self.element_id.clone()) .flex() @@ -88,7 +88,7 @@ impl ChatMessage { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div() .flex() .flex_col() @@ -129,11 +129,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, ChatPanel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/collab_panel.rs b/crates/ui2/src/components/collab_panel.rs index 40276f20b3..d7dfcdceab 100644 --- a/crates/ui2/src/components/collab_panel.rs +++ b/crates/ui2/src/components/collab_panel.rs @@ -19,7 +19,7 @@ impl CollabPanel { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); v_stack() @@ -110,11 +110,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, CollabPanel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/command_palette.rs b/crates/ui2/src/components/command_palette.rs index 036a41e0b9..b2418813d5 100644 --- a/crates/ui2/src/components/command_palette.rs +++ b/crates/ui2/src/components/command_palette.rs @@ -17,7 +17,7 @@ impl CommandPalette { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div().id(self.id.clone()).child( Palette::new("palette") .items(example_editor_actions()) @@ -49,11 +49,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, CommandPalette>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/context_menu.rs b/crates/ui2/src/components/context_menu.rs index fb076dc9fe..ea12cdcfc5 100644 --- a/crates/ui2/src/components/context_menu.rs +++ b/crates/ui2/src/components/context_menu.rs @@ -42,7 +42,7 @@ impl ContextMenu { items: items.into_iter().collect(), } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); v_stack() @@ -85,11 +85,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, ContextMenu>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/copilot.rs b/crates/ui2/src/components/copilot.rs index 8c51b1f4eb..b1f41078e8 100644 --- a/crates/ui2/src/components/copilot.rs +++ b/crates/ui2/src/components/copilot.rs @@ -16,7 +16,7 @@ impl CopilotModal { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div().id(self.id.clone()).child( Modal::new("some-id") .title("Connect Copilot to Zed") @@ -47,11 +47,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, CopilotModal>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/editor_pane.rs b/crates/ui2/src/components/editor_pane.rs index b641c86f7e..3fc41d7db6 100644 --- a/crates/ui2/src/components/editor_pane.rs +++ b/crates/ui2/src/components/editor_pane.rs @@ -49,7 +49,7 @@ impl EditorPane { ) } - fn render(&mut self, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, cx: &mut ViewContext) -> impl IntoAnyElement { v_stack() .w_full() .h_full() diff --git a/crates/ui2/src/components/facepile.rs b/crates/ui2/src/components/facepile.rs index b75ef328f3..0763b34b03 100644 --- a/crates/ui2/src/components/facepile.rs +++ b/crates/ui2/src/components/facepile.rs @@ -17,7 +17,7 @@ impl Facepile { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let player_count = self.players.len(); let player_list = self.players.iter().enumerate().map(|(ix, player)| { let isnt_last = ix < player_count - 1; @@ -51,11 +51,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let players = static_players(); Story::container(cx) diff --git a/crates/ui2/src/components/icon_button.rs b/crates/ui2/src/components/icon_button.rs index 77d248e9ee..6315842193 100644 --- a/crates/ui2/src/components/icon_button.rs +++ b/crates/ui2/src/components/icon_button.rs @@ -68,7 +68,7 @@ impl IconButton { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let icon_color = match (self.state, self.color) { diff --git a/crates/ui2/src/components/keybinding.rs b/crates/ui2/src/components/keybinding.rs index 25de760cab..78d05e4f30 100644 --- a/crates/ui2/src/components/keybinding.rs +++ b/crates/ui2/src/components/keybinding.rs @@ -34,7 +34,7 @@ impl Keybinding { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div() .flex() .gap_2() @@ -68,7 +68,7 @@ impl Key { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); div() @@ -185,11 +185,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let all_modifier_permutations = ModifierKey::iter().permutations(2); Story::container(cx) diff --git a/crates/ui2/src/components/language_selector.rs b/crates/ui2/src/components/language_selector.rs index dbead8467e..0aea61b9a0 100644 --- a/crates/ui2/src/components/language_selector.rs +++ b/crates/ui2/src/components/language_selector.rs @@ -17,7 +17,7 @@ impl LanguageSelector { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div().id(self.id.clone()).child( Palette::new("palette") .items(vec![ @@ -60,11 +60,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, LanguageSelector>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/list.rs b/crates/ui2/src/components/list.rs index 0c41671247..b7557b44d4 100644 --- a/crates/ui2/src/components/list.rs +++ b/crates/ui2/src/components/list.rs @@ -92,7 +92,7 @@ impl ListHeader { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let is_toggleable = self.toggleable != Toggleable::NotToggleable; @@ -157,7 +157,7 @@ impl ListSubHeader { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { h_stack().flex_1().w_full().relative().py_1().child( div() .h_6() @@ -230,7 +230,7 @@ impl From> for ListItem { } impl ListItem { - fn render(&mut self, view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { match self { ListItem::Entry(entry) => div().child(entry.render(view, cx)), ListItem::Separator(separator) => div().child(separator.render(view, cx)), @@ -344,10 +344,7 @@ impl ListEntry { } } - fn disclosure_control( - &mut self, - cx: &mut ViewContext, - ) -> Option> { + fn disclosure_control(&mut self, cx: &mut ViewContext) -> Option> { let disclosure_control_icon = if let Some(ToggleState::Toggled) = self.toggle { IconElement::new(Icon::ChevronDown) } else { @@ -367,7 +364,7 @@ impl ListEntry { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let settings = user_settings(cx); let theme = theme(cx); @@ -477,7 +474,7 @@ impl ListDetailsEntry { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let settings = user_settings(cx); @@ -534,7 +531,7 @@ impl ListSeparator { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); div().h_px().w_full().bg(theme.border) @@ -574,7 +571,7 @@ impl List { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let is_toggleable = self.toggleable != Toggleable::NotToggleable; let is_toggled = Toggleable::is_toggled(&self.toggleable); diff --git a/crates/ui2/src/components/modal.rs b/crates/ui2/src/components/modal.rs index 154df4e862..63e7bc7c1a 100644 --- a/crates/ui2/src/components/modal.rs +++ b/crates/ui2/src/components/modal.rs @@ -42,7 +42,7 @@ impl Modal { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); v_stack() diff --git a/crates/ui2/src/components/multi_buffer.rs b/crates/ui2/src/components/multi_buffer.rs index 568302b559..3bd3057d65 100644 --- a/crates/ui2/src/components/multi_buffer.rs +++ b/crates/ui2/src/components/multi_buffer.rs @@ -17,7 +17,7 @@ impl MultiBuffer { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); v_stack() @@ -62,11 +62,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); Story::container(cx) diff --git a/crates/ui2/src/components/notification_toast.rs b/crates/ui2/src/components/notification_toast.rs index afcef8fb20..cf68738a7e 100644 --- a/crates/ui2/src/components/notification_toast.rs +++ b/crates/ui2/src/components/notification_toast.rs @@ -28,7 +28,7 @@ impl NotificationToast { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); h_stack() diff --git a/crates/ui2/src/components/notifications_panel.rs b/crates/ui2/src/components/notifications_panel.rs index fd0445d007..1937c8e060 100644 --- a/crates/ui2/src/components/notifications_panel.rs +++ b/crates/ui2/src/components/notifications_panel.rs @@ -17,7 +17,7 @@ impl NotificationsPanel { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); div() @@ -70,11 +70,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, NotificationsPanel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/palette.rs b/crates/ui2/src/components/palette.rs index 9787086cd6..b7cb7033bc 100644 --- a/crates/ui2/src/components/palette.rs +++ b/crates/ui2/src/components/palette.rs @@ -46,7 +46,7 @@ impl Palette { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); v_stack() @@ -135,7 +135,7 @@ impl PaletteItem { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div() .flex() .flex_row() @@ -172,11 +172,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, Palette>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/panel.rs b/crates/ui2/src/components/panel.rs index 0c52a7a12a..67b00d881b 100644 --- a/crates/ui2/src/components/panel.rs +++ b/crates/ui2/src/components/panel.rs @@ -96,7 +96,7 @@ impl Panel { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let current_size = self.width.unwrap_or(self.initial_width); @@ -148,11 +148,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, Panel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/panes.rs b/crates/ui2/src/components/panes.rs index 229de3caa4..f100723f91 100644 --- a/crates/ui2/src/components/panes.rs +++ b/crates/ui2/src/components/panes.rs @@ -101,7 +101,7 @@ impl PaneGroup { } } - fn render(&mut self, view: &mut V, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, view: &mut V, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); if !self.panes.is_empty() { diff --git a/crates/ui2/src/components/player_stack.rs b/crates/ui2/src/components/player_stack.rs index 0ada98aa3f..6ca16d14e6 100644 --- a/crates/ui2/src/components/player_stack.rs +++ b/crates/ui2/src/components/player_stack.rs @@ -17,7 +17,7 @@ impl PlayerStack { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let player = self.player_with_call_status.get_player(); self.player_with_call_status.get_call_status(); diff --git a/crates/ui2/src/components/project_panel.rs b/crates/ui2/src/components/project_panel.rs index 8b52a1b89a..5a4591cadd 100644 --- a/crates/ui2/src/components/project_panel.rs +++ b/crates/ui2/src/components/project_panel.rs @@ -19,7 +19,7 @@ impl ProjectPanel { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); div() @@ -79,11 +79,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, ProjectPanel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/recent_projects.rs b/crates/ui2/src/components/recent_projects.rs index 16c019be53..bab96444a5 100644 --- a/crates/ui2/src/components/recent_projects.rs +++ b/crates/ui2/src/components/recent_projects.rs @@ -17,7 +17,7 @@ impl RecentProjects { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div().id(self.id.clone()).child( Palette::new("palette") .items(vec![ @@ -56,11 +56,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, RecentProjects>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/status_bar.rs b/crates/ui2/src/components/status_bar.rs index 5eeeb841ef..786b3670a0 100644 --- a/crates/ui2/src/components/status_bar.rs +++ b/crates/ui2/src/components/status_bar.rs @@ -86,7 +86,7 @@ impl StatusBar { &mut self, view: &mut Workspace, cx: &mut ViewContext, - ) -> impl Element { + ) -> impl IntoAnyElement { let theme = theme(cx); div() @@ -101,7 +101,11 @@ impl StatusBar { .child(self.right_tools(view, cx)) } - fn left_tools(&self, workspace: &mut Workspace, cx: &WindowContext) -> impl Element { + fn left_tools( + &self, + workspace: &mut Workspace, + cx: &WindowContext, + ) -> impl IntoAnyElement { div() .flex() .items_center() @@ -132,7 +136,7 @@ impl StatusBar { &self, workspace: &mut Workspace, cx: &WindowContext, - ) -> impl Element { + ) -> impl IntoAnyElement { div() .flex() .items_center() diff --git a/crates/ui2/src/components/tab.rs b/crates/ui2/src/components/tab.rs index 4bfd21248f..daff5ea66c 100644 --- a/crates/ui2/src/components/tab.rs +++ b/crates/ui2/src/components/tab.rs @@ -81,7 +81,7 @@ impl Tab { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let has_fs_conflict = self.fs_status == FileSystemStatus::Conflict; let is_deleted = self.fs_status == FileSystemStatus::Deleted; @@ -188,11 +188,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let git_statuses = GitStatus::iter(); let fs_statuses = FileSystemStatus::iter(); diff --git a/crates/ui2/src/components/tab_bar.rs b/crates/ui2/src/components/tab_bar.rs index 0cc9409c04..4e49ef289a 100644 --- a/crates/ui2/src/components/tab_bar.rs +++ b/crates/ui2/src/components/tab_bar.rs @@ -27,7 +27,7 @@ impl TabBar { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let (can_navigate_back, can_navigate_forward) = self.can_navigate; @@ -112,11 +112,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, TabBar>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/terminal.rs b/crates/ui2/src/components/terminal.rs index 480c1a5da6..2061d42ad2 100644 --- a/crates/ui2/src/components/terminal.rs +++ b/crates/ui2/src/components/terminal.rs @@ -17,7 +17,7 @@ impl Terminal { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let can_navigate_back = true; @@ -105,11 +105,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, Terminal>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/theme_selector.rs b/crates/ui2/src/components/theme_selector.rs index cb1b491d87..0758cf643b 100644 --- a/crates/ui2/src/components/theme_selector.rs +++ b/crates/ui2/src/components/theme_selector.rs @@ -17,7 +17,7 @@ impl ThemeSelector { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div().child( Palette::new(self.id.clone()) .items(vec![ @@ -61,11 +61,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, ThemeSelector>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/title_bar.rs b/crates/ui2/src/components/title_bar.rs index 68661d0ea2..a20c7877b2 100644 --- a/crates/ui2/src/components/title_bar.rs +++ b/crates/ui2/src/components/title_bar.rs @@ -87,7 +87,7 @@ impl TitleBar { ) } - fn render(&mut self, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let settings = user_settings(cx); @@ -204,7 +204,7 @@ mod stories { ) } - fn render(&mut self, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, TitleBar>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/toast.rs b/crates/ui2/src/components/toast.rs index 9318b12eec..faf58467a2 100644 --- a/crates/ui2/src/components/toast.rs +++ b/crates/ui2/src/components/toast.rs @@ -36,7 +36,7 @@ impl Toast { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let mut div = div(); @@ -90,7 +90,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, Toast>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/toolbar.rs b/crates/ui2/src/components/toolbar.rs index 51ec6ee497..74b2c92578 100644 --- a/crates/ui2/src/components/toolbar.rs +++ b/crates/ui2/src/components/toolbar.rs @@ -54,7 +54,7 @@ impl Toolbar { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); div() @@ -92,11 +92,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); Story::container(cx) diff --git a/crates/ui2/src/components/traffic_lights.rs b/crates/ui2/src/components/traffic_lights.rs index e875075942..8ac76439f8 100644 --- a/crates/ui2/src/components/traffic_lights.rs +++ b/crates/ui2/src/components/traffic_lights.rs @@ -25,7 +25,7 @@ impl TrafficLight { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let fill = match (self.window_has_focus, self.color) { @@ -58,7 +58,7 @@ impl TrafficLights { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div() .flex() .items_center() @@ -99,11 +99,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, TrafficLights>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/workspace.rs b/crates/ui2/src/components/workspace.rs index 92ea93ef02..34158c9918 100644 --- a/crates/ui2/src/components/workspace.rs +++ b/crates/ui2/src/components/workspace.rs @@ -174,7 +174,7 @@ impl Workspace { view(cx.entity(|cx| Self::new(cx)), Self::render) } - pub fn render(&mut self, cx: &mut ViewContext) -> impl Element { + pub fn render(&mut self, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = old_theme(cx).clone(); // HACK: This should happen inside of `debug_toggle_user_settings`, but diff --git a/crates/ui2/src/elements/avatar.rs b/crates/ui2/src/elements/avatar.rs index 0bc1ccad22..555818a87c 100644 --- a/crates/ui2/src/elements/avatar.rs +++ b/crates/ui2/src/elements/avatar.rs @@ -25,7 +25,7 @@ impl Avatar { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let mut img = img(); @@ -63,11 +63,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, Avatar>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/elements/button.rs b/crates/ui2/src/elements/button.rs index 363f70ddb4..9f399ea331 100644 --- a/crates/ui2/src/elements/button.rs +++ b/crates/ui2/src/elements/button.rs @@ -150,11 +150,7 @@ impl Button { self.icon.map(|i| IconElement::new(i).color(icon_color)) } - pub fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + pub fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let icon_color = self.icon_color(); let mut button = h_stack() @@ -211,7 +207,7 @@ impl ButtonGroup { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let mut el = h_stack().text_size(ui_size(cx, 1.)); for button in &mut self.buttons { @@ -246,11 +242,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let states = InteractionState::iter(); Story::container(cx) diff --git a/crates/ui2/src/elements/details.rs b/crates/ui2/src/elements/details.rs index e7df25f6a3..ea05436401 100644 --- a/crates/ui2/src/elements/details.rs +++ b/crates/ui2/src/elements/details.rs @@ -30,7 +30,7 @@ impl Details { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); v_stack() @@ -66,11 +66,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, Details>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/elements/icon.rs b/crates/ui2/src/elements/icon.rs index d20f262fbc..2a0f6b3a0b 100644 --- a/crates/ui2/src/elements/icon.rs +++ b/crates/ui2/src/elements/icon.rs @@ -176,7 +176,7 @@ impl IconElement { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let fill = self.color.color(cx); let svg_size = match self.size { IconSize::Small => ui_size(cx, 12. / 14.), @@ -214,11 +214,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let icons = Icon::iter(); Story::container(cx) diff --git a/crates/ui2/src/elements/input.rs b/crates/ui2/src/elements/input.rs index 56d81a0831..142acc8870 100644 --- a/crates/ui2/src/elements/input.rs +++ b/crates/ui2/src/elements/input.rs @@ -60,7 +60,7 @@ impl Input { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let (input_bg, input_hover_bg, input_active_bg) = match self.variant { @@ -132,11 +132,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, Input>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/elements/label.rs b/crates/ui2/src/elements/label.rs index d29ab8a5ee..f8d4a8d115 100644 --- a/crates/ui2/src/elements/label.rs +++ b/crates/ui2/src/elements/label.rs @@ -83,7 +83,7 @@ impl Label { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div() .when(self.strikethrough, |this| { this.relative().child( @@ -135,7 +135,7 @@ impl HighlightedLabel { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let highlight_color = theme.text_accent; @@ -223,11 +223,7 @@ mod stories { } } - fn render( - &mut self, - _view: &mut S, - cx: &mut ViewContext, - ) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, Label>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/elements/tool_divider.rs b/crates/ui2/src/elements/tool_divider.rs index 46b790e6bb..f73c8953ee 100644 --- a/crates/ui2/src/elements/tool_divider.rs +++ b/crates/ui2/src/elements/tool_divider.rs @@ -14,7 +14,7 @@ impl ToolDivider { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); div().w_px().h_3().bg(theme.border) diff --git a/crates/ui2/src/story.rs b/crates/ui2/src/story.rs index 9fc6a11f19..c4bf9c3caa 100644 --- a/crates/ui2/src/story.rs +++ b/crates/ui2/src/story.rs @@ -21,7 +21,7 @@ impl Story { pub fn title( cx: &mut ViewContext, title: &str, - ) -> impl Element { + ) -> impl IntoAnyElement { let theme = theme(cx); div() @@ -32,14 +32,14 @@ impl Story { pub fn title_for( cx: &mut ViewContext, - ) -> impl Element { + ) -> impl IntoAnyElement { Self::title(cx, std::any::type_name::()) } pub fn label( cx: &mut ViewContext, label: &str, - ) -> impl Element { + ) -> impl IntoAnyElement { let theme = theme(cx); div() From 315744ec20d8587219a7b052c2143d7495153e6b Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 26 Oct 2023 12:20:46 +0200 Subject: [PATCH 10/17] Add derive macro for IntoAnyElement --- .../src/derive_into_any_element.rs | 54 +++++++++++++++++++ crates/gpui2_macros/src/gpui2_macros.rs | 6 +++ crates/ui2/src/components/panes.rs | 13 ++--- crates/ui2/src/components/status_bar.rs | 15 ++++-- 4 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 crates/gpui2_macros/src/derive_into_any_element.rs diff --git a/crates/gpui2_macros/src/derive_into_any_element.rs b/crates/gpui2_macros/src/derive_into_any_element.rs new file mode 100644 index 0000000000..9f339f1b44 --- /dev/null +++ b/crates/gpui2_macros/src/derive_into_any_element.rs @@ -0,0 +1,54 @@ +use proc_macro::TokenStream; +use quote::quote; +use syn::{parse_macro_input, DeriveInput}; + +pub fn derive_into_any_element(input: TokenStream) -> TokenStream { + let ast = parse_macro_input!(input as DeriveInput); + let name = &ast.ident; + let generics = &ast.generics; + let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); + + let specified_view_type = ast + .attrs + .iter() + .find(|attr| attr.path.is_ident("element")) + .and_then(|attr| { + if let Ok(syn::Meta::List(meta_list)) = attr.parse_meta() { + meta_list.nested.iter().find_map(|nested| { + if let syn::NestedMeta::Meta(syn::Meta::NameValue(nv)) = nested { + if nv.path.is_ident("view_type") { + if let syn::Lit::Str(lit_str) = &nv.lit { + return Some( + lit_str + .parse::() + .expect("Failed to parse view_type"), + ); + } + } + } + None + }) + } else { + None + } + }); + + let view_type = specified_view_type.unwrap_or_else(|| { + if let Some(syn::GenericParam::Type(type_param)) = generics.params.first() { + type_param.ident.clone() + } else { + panic!("Expected first type parameter"); + } + }); + + let expanded = quote! { + impl #impl_generics gpui2::IntoAnyElement<#view_type> for #name #ty_generics #where_clause { + fn into_any(self) -> gpui2::AnyElement<#view_type> { + (move |view_state: &mut #view_type, cx: &mut gpui2::ViewContext<'_, '_, #view_type>| self.render(view_state, cx)) + .into_any() + } + } + }; + + TokenStream::from(expanded) +} diff --git a/crates/gpui2_macros/src/gpui2_macros.rs b/crates/gpui2_macros/src/gpui2_macros.rs index 59fd046c83..c4a3d5eeac 100644 --- a/crates/gpui2_macros/src/gpui2_macros.rs +++ b/crates/gpui2_macros/src/gpui2_macros.rs @@ -1,6 +1,7 @@ use proc_macro::TokenStream; mod derive_element; +mod derive_into_any_element; mod style_helpers; mod test; @@ -14,6 +15,11 @@ pub fn derive_element(input: TokenStream) -> TokenStream { derive_element::derive_element(input) } +#[proc_macro_derive(IntoAnyElement, attributes(element))] +pub fn derive_into_any_element(input: TokenStream) -> TokenStream { + derive_into_any_element::derive_into_any_element(input) +} + #[proc_macro_attribute] pub fn test(args: TokenStream, function: TokenStream) -> TokenStream { test::test(args, function) diff --git a/crates/ui2/src/components/panes.rs b/crates/ui2/src/components/panes.rs index f100723f91..bf135d85b6 100644 --- a/crates/ui2/src/components/panes.rs +++ b/crates/ui2/src/components/panes.rs @@ -12,6 +12,7 @@ pub enum SplitDirection { Vertical, } +#[derive(IntoAnyElement)] pub struct Pane { id: ElementId, size: Size, @@ -19,12 +20,12 @@ pub struct Pane { children: SmallVec<[AnyElement; 2]>, } -impl IntoAnyElement for Pane { - fn into_any(self) -> AnyElement { - (move |view_state: &mut V, cx: &mut ViewContext<'_, '_, V>| self.render(view_state, cx)) - .into_any() - } -} +// impl IntoAnyElement for Pane { +// fn into_any(self) -> AnyElement { +// (move |view_state: &mut V, cx: &mut ViewContext<'_, '_, V>| self.render(view_state, cx)) +// .into_any() +// } +// } impl Pane { pub fn new(id: impl Into, size: Size) -> Self { diff --git a/crates/ui2/src/components/status_bar.rs b/crates/ui2/src/components/status_bar.rs index 786b3670a0..2e4399539c 100644 --- a/crates/ui2/src/components/status_bar.rs +++ b/crates/ui2/src/components/status_bar.rs @@ -28,14 +28,23 @@ impl Default for ToolGroup { } } -#[derive(Element)] -#[element(view_state = "Workspace")] +#[derive(IntoAnyElement)] +#[element(view_type = "Workspace")] pub struct StatusBar { left_tools: Option, right_tools: Option, bottom_tools: Option, } +// impl IntoAnyElement for StatusBar { +// fn into_any(self) -> gpui2::AnyElement { +// (move |workspace: &mut Workspace, cx: &mut ViewContext<'_, '_, Workspace>| { +// self.render(workspace, cx) +// }) +// .into_any() +// } +// } + impl StatusBar { pub fn new() -> Self { Self { @@ -83,7 +92,7 @@ impl StatusBar { } fn render( - &mut self, + self, view: &mut Workspace, cx: &mut ViewContext, ) -> impl IntoAnyElement { From 8ecfea55cd53fdc24f54764509945344424b8e9b Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 26 Oct 2023 12:38:23 +0200 Subject: [PATCH 11/17] Replace derive Element with derive IntoAnyElement everywhere --- crates/gpui2/src/element.rs | 10 ++ crates/gpui2_macros/src/derive_element.rs | 94 ------------------- crates/gpui2_macros/src/gpui2_macros.rs | 6 -- crates/storybook2/src/components.rs | 2 +- crates/storybook2/src/stories/scroll.rs | 1 - crates/storybook2/src/stories/z_index.rs | 8 +- crates/ui2/src/components/assistant_panel.rs | 8 +- crates/ui2/src/components/breadcrumb.rs | 12 +-- crates/ui2/src/components/buffer.rs | 8 +- crates/ui2/src/components/chat_panel.rs | 12 +-- crates/ui2/src/components/collab_panel.rs | 8 +- crates/ui2/src/components/command_palette.rs | 8 +- crates/ui2/src/components/context_menu.rs | 8 +- crates/ui2/src/components/copilot.rs | 8 +- crates/ui2/src/components/facepile.rs | 8 +- crates/ui2/src/components/icon_button.rs | 4 +- crates/ui2/src/components/keybinding.rs | 12 +-- .../ui2/src/components/language_selector.rs | 8 +- crates/ui2/src/components/list.rs | 28 +++--- crates/ui2/src/components/modal.rs | 4 +- crates/ui2/src/components/multi_buffer.rs | 8 +- .../ui2/src/components/notification_toast.rs | 4 +- .../ui2/src/components/notifications_panel.rs | 8 +- crates/ui2/src/components/palette.rs | 12 +-- crates/ui2/src/components/panel.rs | 8 +- crates/ui2/src/components/panes.rs | 6 +- crates/ui2/src/components/player_stack.rs | 4 +- crates/ui2/src/components/project_panel.rs | 8 +- crates/ui2/src/components/recent_projects.rs | 8 +- crates/ui2/src/components/status_bar.rs | 9 -- crates/ui2/src/components/tab.rs | 8 +- crates/ui2/src/components/tab_bar.rs | 8 +- crates/ui2/src/components/terminal.rs | 8 +- crates/ui2/src/components/theme_selector.rs | 8 +- crates/ui2/src/components/toast.rs | 10 +- crates/ui2/src/components/toolbar.rs | 8 +- crates/ui2/src/components/traffic_lights.rs | 12 +-- crates/ui2/src/element_ext.rs | 21 ++--- crates/ui2/src/elements/avatar.rs | 8 +- crates/ui2/src/elements/button.rs | 14 +-- crates/ui2/src/elements/details.rs | 8 +- crates/ui2/src/elements/icon.rs | 8 +- crates/ui2/src/elements/input.rs | 8 +- crates/ui2/src/elements/label.rs | 12 +-- crates/ui2/src/elements/tool_divider.rs | 4 +- 45 files changed, 185 insertions(+), 292 deletions(-) delete mode 100644 crates/gpui2_macros/src/derive_element.rs diff --git a/crates/gpui2/src/element.rs b/crates/gpui2/src/element.rs index 87e1e5c836..39b7898d16 100644 --- a/crates/gpui2/src/element.rs +++ b/crates/gpui2/src/element.rs @@ -209,6 +209,16 @@ impl AnyElement { pub trait IntoAnyElement { fn into_any(self) -> AnyElement; + + fn when(mut self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self + where + Self: Sized, + { + if condition { + self = then(self); + } + self + } } impl IntoAnyElement for AnyElement { diff --git a/crates/gpui2_macros/src/derive_element.rs b/crates/gpui2_macros/src/derive_element.rs deleted file mode 100644 index a63be0f5da..0000000000 --- a/crates/gpui2_macros/src/derive_element.rs +++ /dev/null @@ -1,94 +0,0 @@ -use proc_macro::TokenStream; -use quote::quote; -use syn::{parse_macro_input, DeriveInput, GenericParam}; - -pub fn derive_element(input: TokenStream) -> TokenStream { - let ast = parse_macro_input!(input as DeriveInput); - let type_name = ast.ident; - - let mut state_type = quote! { () }; - - for param in &ast.generics.params { - if let GenericParam::Type(type_param) = param { - let type_ident = &type_param.ident; - state_type = quote! {#type_ident}; - break; - } - } - - let attrs = &ast.attrs; - for attr in attrs { - if attr.path.is_ident("element") { - match attr.parse_meta() { - Ok(syn::Meta::List(i)) => { - for nested_meta in i.nested { - if let syn::NestedMeta::Meta(syn::Meta::NameValue(nv)) = nested_meta { - if nv.path.is_ident("view_state") { - if let syn::Lit::Str(lit_str) = nv.lit { - state_type = lit_str.value().parse().unwrap(); - } - } - } - } - } - _ => (), - } - } - } - - let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl(); - - let gen = quote! { - impl #impl_generics gpui2::IntoAnyElement<#state_type> for #type_name #ty_generics - #where_clause - { - fn into_any(self) -> gpui2::AnyElement<#state_type> { - gpui2::AnyElement::new(self) - } - } - - impl #impl_generics gpui2::Element<#state_type> for #type_name #ty_generics - #where_clause - { - type ElementState = gpui2::AnyElement<#state_type>; - - fn id(&self) -> Option { - None - } - - fn initialize( - &mut self, - view_state: &mut #state_type, - _: Option, - cx: &mut gpui2::ViewContext<#state_type> - ) -> Self::ElementState { - use gpui2::IntoAnyElement; - - let mut element = self.render(view_state, cx).into_any(); - element.initialize(view_state, cx); - element - } - - fn layout( - &mut self, - view_state: &mut #state_type, - rendered_element: &mut Self::ElementState, - cx: &mut gpui2::ViewContext<#state_type>, - ) -> gpui2::LayoutId { - rendered_element.layout(view_state, cx) - } - - fn paint( - &mut self, - bounds: gpui2::Bounds, - view_state: &mut #state_type, - rendered_element: &mut Self::ElementState, - cx: &mut gpui2::ViewContext<#state_type>, - ) { - rendered_element.paint(view_state, cx) - } - } - }; - - gen.into() -} diff --git a/crates/gpui2_macros/src/gpui2_macros.rs b/crates/gpui2_macros/src/gpui2_macros.rs index c4a3d5eeac..3635320d55 100644 --- a/crates/gpui2_macros/src/gpui2_macros.rs +++ b/crates/gpui2_macros/src/gpui2_macros.rs @@ -1,6 +1,5 @@ use proc_macro::TokenStream; -mod derive_element; mod derive_into_any_element; mod style_helpers; mod test; @@ -10,11 +9,6 @@ pub fn style_helpers(args: TokenStream) -> TokenStream { style_helpers::style_helpers(args) } -#[proc_macro_derive(Element, attributes(element))] -pub fn derive_element(input: TokenStream) -> TokenStream { - derive_element::derive_element(input) -} - #[proc_macro_derive(IntoAnyElement, attributes(element))] pub fn derive_into_any_element(input: TokenStream) -> TokenStream { derive_into_any_element::derive_into_any_element(input) diff --git a/crates/storybook2/src/components.rs b/crates/storybook2/src/components.rs index c39ccaa3d9..5eaa894302 100644 --- a/crates/storybook2/src/components.rs +++ b/crates/storybook2/src/components.rs @@ -14,7 +14,7 @@ impl Default for ButtonHandlers { } } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct Button { handlers: ButtonHandlers, label: Option>, diff --git a/crates/storybook2/src/stories/scroll.rs b/crates/storybook2/src/stories/scroll.rs index f589ea7cef..86a8ca41c8 100644 --- a/crates/storybook2/src/stories/scroll.rs +++ b/crates/storybook2/src/stories/scroll.rs @@ -3,7 +3,6 @@ use gpui2::{ div, px, view, Context, IntoAnyElement, ParentElement, SharedString, Styled, View, WindowContext, }; -use ui::ElementExt; pub struct ScrollStory { text: View<()>, diff --git a/crates/storybook2/src/stories/z_index.rs b/crates/storybook2/src/stories/z_index.rs index 213d7bed4e..270bd08640 100644 --- a/crates/storybook2/src/stories/z_index.rs +++ b/crates/storybook2/src/stories/z_index.rs @@ -7,7 +7,7 @@ use crate::story::Story; /// A reimplementation of the MDN `z-index` example, found here: /// [https://developer.mozilla.org/en-US/docs/Web/CSS/z-index](https://developer.mozilla.org/en-US/docs/Web/CSS/z-index). -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct ZIndexStory { state_type: PhantomData, } @@ -19,7 +19,7 @@ impl ZIndexStory { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title(cx, "z-index")) .child( @@ -88,7 +88,7 @@ trait Styles: Styled + Sized { impl Styles for Div {} -#[derive(Element)] +#[derive(IntoAnyElement)] struct ZIndexExample { view_type: PhantomData, z_index: u32, @@ -102,7 +102,7 @@ impl ZIndexExample { } } - fn render(&mut self, _view: &mut V, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut V, cx: &mut ViewContext) -> impl IntoAnyElement { div() .relative() .size_full() diff --git a/crates/ui2/src/components/assistant_panel.rs b/crates/ui2/src/components/assistant_panel.rs index 1c47bf1a91..fa5ac38dc1 100644 --- a/crates/ui2/src/components/assistant_panel.rs +++ b/crates/ui2/src/components/assistant_panel.rs @@ -5,7 +5,7 @@ use gpui2::{rems, AbsoluteLength}; use crate::prelude::*; use crate::{Icon, IconButton, Label, Panel, PanelSide}; -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct AssistantPanel { id: ElementId, state_type: PhantomData, @@ -26,7 +26,7 @@ impl AssistantPanel { self } - fn render(&mut self, view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Panel::new(self.id.clone(), cx) .children(vec![div() .flex() @@ -84,7 +84,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct AssistantPanelStory { state_type: PhantomData, } @@ -96,7 +96,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, AssistantPanel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/breadcrumb.rs b/crates/ui2/src/components/breadcrumb.rs index 5f4d3cbafe..00a471e7cc 100644 --- a/crates/ui2/src/components/breadcrumb.rs +++ b/crates/ui2/src/components/breadcrumb.rs @@ -9,7 +9,7 @@ use crate::{h_stack, HighlightedText}; #[derive(Clone)] pub struct Symbol(pub Vec); -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct Breadcrumb { state_type: PhantomData, path: PathBuf, @@ -31,7 +31,7 @@ impl Breadcrumb { div().child(" › ").text_color(theme.text_muted) } - fn render(&mut self, view_state: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, view_state: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let symbols_len = self.symbols.len(); @@ -86,7 +86,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct BreadcrumbStory { state_type: PhantomData, } @@ -98,11 +98,7 @@ mod stories { } } - fn render( - &mut self, - view_state: &mut S, - cx: &mut ViewContext, - ) -> impl IntoAnyElement { + fn render(self, view_state: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); Story::container(cx) diff --git a/crates/ui2/src/components/buffer.rs b/crates/ui2/src/components/buffer.rs index 7b67afc2b4..662ccd5736 100644 --- a/crates/ui2/src/components/buffer.rs +++ b/crates/ui2/src/components/buffer.rs @@ -109,7 +109,7 @@ impl BufferRow { } } -#[derive(Element, Clone)] +#[derive(IntoAnyElement, Clone)] pub struct Buffer { id: ElementId, state_type: PhantomData, @@ -219,7 +219,7 @@ impl Buffer { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let rows = self.render_rows(cx); @@ -246,7 +246,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct BufferStory { state_type: PhantomData, } @@ -258,7 +258,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); Story::container(cx) diff --git a/crates/ui2/src/components/chat_panel.rs b/crates/ui2/src/components/chat_panel.rs index afb79cc907..db0f573485 100644 --- a/crates/ui2/src/components/chat_panel.rs +++ b/crates/ui2/src/components/chat_panel.rs @@ -5,7 +5,7 @@ use chrono::NaiveDateTime; use crate::prelude::*; use crate::{Icon, IconButton, Input, Label, LabelColor}; -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct ChatPanel { element_id: ElementId, messages: Vec>, @@ -24,7 +24,7 @@ impl ChatPanel { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div() .id(self.element_id.clone()) .flex() @@ -70,7 +70,7 @@ impl ChatPanel { } } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct ChatMessage { state_type: PhantomData, author: String, @@ -88,7 +88,7 @@ impl ChatMessage { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div() .flex() .flex_col() @@ -117,7 +117,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct ChatPanelStory { state_type: PhantomData, } @@ -129,7 +129,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, ChatPanel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/collab_panel.rs b/crates/ui2/src/components/collab_panel.rs index d7dfcdceab..050b7c2b85 100644 --- a/crates/ui2/src/components/collab_panel.rs +++ b/crates/ui2/src/components/collab_panel.rs @@ -5,7 +5,7 @@ use crate::{ }; use std::marker::PhantomData; -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct CollabPanel { id: ElementId, state_type: PhantomData, @@ -19,7 +19,7 @@ impl CollabPanel { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); v_stack() @@ -98,7 +98,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct CollabPanelStory { state_type: PhantomData, } @@ -110,7 +110,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, CollabPanel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/command_palette.rs b/crates/ui2/src/components/command_palette.rs index b2418813d5..f79038b172 100644 --- a/crates/ui2/src/components/command_palette.rs +++ b/crates/ui2/src/components/command_palette.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{example_editor_actions, OrderMethod, Palette}; -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct CommandPalette { id: ElementId, state_type: PhantomData, @@ -17,7 +17,7 @@ impl CommandPalette { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div().id(self.id.clone()).child( Palette::new("palette") .items(example_editor_actions()) @@ -37,7 +37,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct CommandPaletteStory { state_type: PhantomData, } @@ -49,7 +49,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, CommandPalette>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/context_menu.rs b/crates/ui2/src/components/context_menu.rs index ea12cdcfc5..5463cb29e7 100644 --- a/crates/ui2/src/components/context_menu.rs +++ b/crates/ui2/src/components/context_menu.rs @@ -31,7 +31,7 @@ impl ContextMenuItem { } } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct ContextMenu { items: Vec>, } @@ -42,7 +42,7 @@ impl ContextMenu { items: items.into_iter().collect(), } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); v_stack() @@ -73,7 +73,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct ContextMenuStory { state_type: PhantomData, } @@ -85,7 +85,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, ContextMenu>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/copilot.rs b/crates/ui2/src/components/copilot.rs index b1f41078e8..ca82ea5a0a 100644 --- a/crates/ui2/src/components/copilot.rs +++ b/crates/ui2/src/components/copilot.rs @@ -2,7 +2,7 @@ use std::marker::PhantomData; use crate::{prelude::*, Button, Label, LabelColor, Modal}; -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct CopilotModal { id: ElementId, state_type: PhantomData, @@ -16,7 +16,7 @@ impl CopilotModal { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div().id(self.id.clone()).child( Modal::new("some-id") .title("Connect Copilot to Zed") @@ -35,7 +35,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct CopilotModalStory { state_type: PhantomData, } @@ -47,7 +47,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, CopilotModal>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/facepile.rs b/crates/ui2/src/components/facepile.rs index 0763b34b03..c87de6a2a2 100644 --- a/crates/ui2/src/components/facepile.rs +++ b/crates/ui2/src/components/facepile.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{Avatar, Player}; -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct Facepile { state_type: PhantomData, players: Vec, @@ -17,7 +17,7 @@ impl Facepile { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let player_count = self.players.len(); let player_list = self.players.iter().enumerate().map(|(ix, player)| { let isnt_last = ix < player_count - 1; @@ -39,7 +39,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct FacepileStory { state_type: PhantomData, } @@ -51,7 +51,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let players = static_players(); Story::container(cx) diff --git a/crates/ui2/src/components/icon_button.rs b/crates/ui2/src/components/icon_button.rs index 6315842193..0801c5ac23 100644 --- a/crates/ui2/src/components/icon_button.rs +++ b/crates/ui2/src/components/icon_button.rs @@ -16,7 +16,7 @@ impl Default for IconButtonHandlers { } } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct IconButton { state_type: PhantomData, id: ElementId, @@ -68,7 +68,7 @@ impl IconButton { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let icon_color = match (self.state, self.color) { diff --git a/crates/ui2/src/components/keybinding.rs b/crates/ui2/src/components/keybinding.rs index 78d05e4f30..7a240aa39c 100644 --- a/crates/ui2/src/components/keybinding.rs +++ b/crates/ui2/src/components/keybinding.rs @@ -5,7 +5,7 @@ use strum::{EnumIter, IntoEnumIterator}; use crate::prelude::*; -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct Keybinding { state_type: PhantomData, @@ -34,7 +34,7 @@ impl Keybinding { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div() .flex() .gap_2() @@ -54,7 +54,7 @@ impl Keybinding { } } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct Key { state_type: PhantomData, key: SharedString, @@ -68,7 +68,7 @@ impl Key { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); div() @@ -173,7 +173,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct KeybindingStory { state_type: PhantomData, } @@ -185,7 +185,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let all_modifier_permutations = ModifierKey::iter().permutations(2); Story::container(cx) diff --git a/crates/ui2/src/components/language_selector.rs b/crates/ui2/src/components/language_selector.rs index 0aea61b9a0..5dd571ec42 100644 --- a/crates/ui2/src/components/language_selector.rs +++ b/crates/ui2/src/components/language_selector.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{OrderMethod, Palette, PaletteItem}; -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct LanguageSelector { id: ElementId, state_type: PhantomData, @@ -17,7 +17,7 @@ impl LanguageSelector { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div().id(self.id.clone()).child( Palette::new("palette") .items(vec![ @@ -48,7 +48,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct LanguageSelectorStory { state_type: PhantomData, } @@ -60,7 +60,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, LanguageSelector>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/list.rs b/crates/ui2/src/components/list.rs index b7557b44d4..00684a7eb9 100644 --- a/crates/ui2/src/components/list.rs +++ b/crates/ui2/src/components/list.rs @@ -17,7 +17,7 @@ pub enum ListItemVariant { Inset, } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct ListHeader { state_type: PhantomData, label: SharedString, @@ -92,7 +92,7 @@ impl ListHeader { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let is_toggleable = self.toggleable != Toggleable::NotToggleable; @@ -134,7 +134,7 @@ impl ListHeader { } } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct ListSubHeader { state_type: PhantomData, label: SharedString, @@ -157,7 +157,7 @@ impl ListSubHeader { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { h_stack().flex_1().w_full().relative().py_1().child( div() .h_6() @@ -197,7 +197,7 @@ pub enum ListEntrySize { Medium, } -#[derive(Element)] +#[derive(IntoAnyElement)] pub enum ListItem { Entry(ListEntry), Details(ListDetailsEntry), @@ -230,7 +230,7 @@ impl From> for ListItem { } impl ListItem { - fn render(&mut self, view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { match self { ListItem::Entry(entry) => div().child(entry.render(view, cx)), ListItem::Separator(separator) => div().child(separator.render(view, cx)), @@ -252,7 +252,7 @@ impl ListItem { } } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct ListEntry { disclosure_control_style: DisclosureControlVisibility, indent_level: u32, @@ -364,7 +364,7 @@ impl ListEntry { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let settings = user_settings(cx); let theme = theme(cx); @@ -430,7 +430,7 @@ impl Default for ListDetailsEntryHandlers { } } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct ListDetailsEntry { label: SharedString, meta: Option, @@ -474,7 +474,7 @@ impl ListDetailsEntry { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let settings = user_settings(cx); @@ -519,7 +519,7 @@ impl ListDetailsEntry { } } -#[derive(Clone, Element)] +#[derive(Clone, IntoAnyElement)] pub struct ListSeparator { state_type: PhantomData, } @@ -531,14 +531,14 @@ impl ListSeparator { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); div().h_px().w_full().bg(theme.border) } } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct List { items: Vec>, empty_message: SharedString, @@ -571,7 +571,7 @@ impl List { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let is_toggleable = self.toggleable != Toggleable::NotToggleable; let is_toggled = Toggleable::is_toggled(&self.toggleable); diff --git a/crates/ui2/src/components/modal.rs b/crates/ui2/src/components/modal.rs index 63e7bc7c1a..c8fbfc0c6d 100644 --- a/crates/ui2/src/components/modal.rs +++ b/crates/ui2/src/components/modal.rs @@ -5,7 +5,7 @@ use smallvec::SmallVec; use crate::{h_stack, prelude::*, v_stack, Button, Icon, IconButton, Label}; -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct Modal { id: ElementId, state_type: PhantomData, @@ -42,7 +42,7 @@ impl Modal { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); v_stack() diff --git a/crates/ui2/src/components/multi_buffer.rs b/crates/ui2/src/components/multi_buffer.rs index 3bd3057d65..86e89c896c 100644 --- a/crates/ui2/src/components/multi_buffer.rs +++ b/crates/ui2/src/components/multi_buffer.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{v_stack, Buffer, Icon, IconButton, Label}; -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct MultiBuffer { state_type: PhantomData, buffers: Vec>, @@ -17,7 +17,7 @@ impl MultiBuffer { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); v_stack() @@ -50,7 +50,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct MultiBufferStory { state_type: PhantomData, } @@ -62,7 +62,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); Story::container(cx) diff --git a/crates/ui2/src/components/notification_toast.rs b/crates/ui2/src/components/notification_toast.rs index cf68738a7e..6a1011207b 100644 --- a/crates/ui2/src/components/notification_toast.rs +++ b/crates/ui2/src/components/notification_toast.rs @@ -4,7 +4,7 @@ use gpui2::rems; use crate::{h_stack, prelude::*, Icon}; -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct NotificationToast { state_type: PhantomData, label: SharedString, @@ -28,7 +28,7 @@ impl NotificationToast { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); h_stack() diff --git a/crates/ui2/src/components/notifications_panel.rs b/crates/ui2/src/components/notifications_panel.rs index 1937c8e060..44af3696c2 100644 --- a/crates/ui2/src/components/notifications_panel.rs +++ b/crates/ui2/src/components/notifications_panel.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::{prelude::*, static_new_notification_items, static_read_notification_items}; use crate::{List, ListHeader}; -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct NotificationsPanel { id: ElementId, state_type: PhantomData, @@ -17,7 +17,7 @@ impl NotificationsPanel { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); div() @@ -58,7 +58,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct NotificationsPanelStory { state_type: PhantomData, } @@ -70,7 +70,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, NotificationsPanel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/palette.rs b/crates/ui2/src/components/palette.rs index b7cb7033bc..5b52f41aec 100644 --- a/crates/ui2/src/components/palette.rs +++ b/crates/ui2/src/components/palette.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{h_stack, v_stack, Keybinding, Label, LabelColor}; -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct Palette { id: ElementId, state_type: PhantomData, @@ -46,7 +46,7 @@ impl Palette { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); v_stack() @@ -101,7 +101,7 @@ impl Palette { } } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct PaletteItem { pub label: SharedString, pub sublabel: Option, @@ -135,7 +135,7 @@ impl PaletteItem { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div() .flex() .flex_row() @@ -160,7 +160,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct PaletteStory { state_type: PhantomData, } @@ -172,7 +172,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, Palette>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/panel.rs b/crates/ui2/src/components/panel.rs index 67b00d881b..e6bca5afa7 100644 --- a/crates/ui2/src/components/panel.rs +++ b/crates/ui2/src/components/panel.rs @@ -40,7 +40,7 @@ pub enum PanelSide { use std::collections::HashSet; -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct Panel { id: ElementId, state_type: PhantomData, @@ -96,7 +96,7 @@ impl Panel { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let current_size = self.width.unwrap_or(self.initial_width); @@ -136,7 +136,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct PanelStory { state_type: PhantomData, } @@ -148,7 +148,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, Panel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/panes.rs b/crates/ui2/src/components/panes.rs index bf135d85b6..118bb5f197 100644 --- a/crates/ui2/src/components/panes.rs +++ b/crates/ui2/src/components/panes.rs @@ -75,7 +75,7 @@ impl ParentElement for Pane { } } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct PaneGroup { state_type: PhantomData, groups: Vec>, @@ -102,7 +102,7 @@ impl PaneGroup { } } - fn render(&mut self, view: &mut V, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, view: &mut V, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); if !self.panes.is_empty() { @@ -129,7 +129,7 @@ impl PaneGroup { .w_full() .h_full() .bg(theme.editor) - .children(self.groups.iter_mut().map(|group| group.render(view, cx))); + .children(self.groups.drain(..).map(|group| group.render(view, cx))); if self.split_direction == SplitDirection::Horizontal { return el; diff --git a/crates/ui2/src/components/player_stack.rs b/crates/ui2/src/components/player_stack.rs index 6ca16d14e6..88b2833dda 100644 --- a/crates/ui2/src/components/player_stack.rs +++ b/crates/ui2/src/components/player_stack.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{Avatar, Facepile, PlayerWithCallStatus}; -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct PlayerStack { state_type: PhantomData, player_with_call_status: PlayerWithCallStatus, @@ -17,7 +17,7 @@ impl PlayerStack { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let player = self.player_with_call_status.get_player(); self.player_with_call_status.get_call_status(); diff --git a/crates/ui2/src/components/project_panel.rs b/crates/ui2/src/components/project_panel.rs index 5a4591cadd..5771f996c5 100644 --- a/crates/ui2/src/components/project_panel.rs +++ b/crates/ui2/src/components/project_panel.rs @@ -5,7 +5,7 @@ use crate::{ static_project_panel_project_items, static_project_panel_single_items, Input, List, ListHeader, }; -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct ProjectPanel { id: ElementId, state_type: PhantomData, @@ -19,7 +19,7 @@ impl ProjectPanel { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); div() @@ -67,7 +67,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct ProjectPanelStory { state_type: PhantomData, } @@ -79,7 +79,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, ProjectPanel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/recent_projects.rs b/crates/ui2/src/components/recent_projects.rs index bab96444a5..d29caa2fd2 100644 --- a/crates/ui2/src/components/recent_projects.rs +++ b/crates/ui2/src/components/recent_projects.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{OrderMethod, Palette, PaletteItem}; -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct RecentProjects { id: ElementId, state_type: PhantomData, @@ -17,7 +17,7 @@ impl RecentProjects { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div().id(self.id.clone()).child( Palette::new("palette") .items(vec![ @@ -44,7 +44,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct RecentProjectsStory { state_type: PhantomData, } @@ -56,7 +56,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, RecentProjects>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/status_bar.rs b/crates/ui2/src/components/status_bar.rs index 2e4399539c..4ea0fe4eeb 100644 --- a/crates/ui2/src/components/status_bar.rs +++ b/crates/ui2/src/components/status_bar.rs @@ -36,15 +36,6 @@ pub struct StatusBar { bottom_tools: Option, } -// impl IntoAnyElement for StatusBar { -// fn into_any(self) -> gpui2::AnyElement { -// (move |workspace: &mut Workspace, cx: &mut ViewContext<'_, '_, Workspace>| { -// self.render(workspace, cx) -// }) -// .into_any() -// } -// } - impl StatusBar { pub fn new() -> Self { Self { diff --git a/crates/ui2/src/components/tab.rs b/crates/ui2/src/components/tab.rs index daff5ea66c..02a2420580 100644 --- a/crates/ui2/src/components/tab.rs +++ b/crates/ui2/src/components/tab.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{Icon, IconColor, IconElement, Label, LabelColor}; -#[derive(Element, Clone)] +#[derive(IntoAnyElement, Clone)] pub struct Tab { state_type: PhantomData, id: ElementId, @@ -81,7 +81,7 @@ impl Tab { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let has_fs_conflict = self.fs_status == FileSystemStatus::Conflict; let is_deleted = self.fs_status == FileSystemStatus::Deleted; @@ -176,7 +176,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct TabStory { state_type: PhantomData, } @@ -188,7 +188,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let git_statuses = GitStatus::iter(); let fs_statuses = FileSystemStatus::iter(); diff --git a/crates/ui2/src/components/tab_bar.rs b/crates/ui2/src/components/tab_bar.rs index 4e49ef289a..38dd9edade 100644 --- a/crates/ui2/src/components/tab_bar.rs +++ b/crates/ui2/src/components/tab_bar.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{Icon, IconButton, Tab}; -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct TabBar { id: ElementId, state_type: PhantomData, @@ -27,7 +27,7 @@ impl TabBar { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let (can_navigate_back, can_navigate_forward) = self.can_navigate; @@ -100,7 +100,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct TabBarStory { state_type: PhantomData, } @@ -112,7 +112,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, TabBar>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/terminal.rs b/crates/ui2/src/components/terminal.rs index 2061d42ad2..55ab3e02fc 100644 --- a/crates/ui2/src/components/terminal.rs +++ b/crates/ui2/src/components/terminal.rs @@ -5,7 +5,7 @@ use gpui2::{relative, rems, Size}; use crate::prelude::*; use crate::{Icon, IconButton, Pane, Tab}; -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct Terminal { state_type: PhantomData, } @@ -17,7 +17,7 @@ impl Terminal { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let can_navigate_back = true; @@ -93,7 +93,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct TerminalStory { state_type: PhantomData, } @@ -105,7 +105,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, Terminal>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/theme_selector.rs b/crates/ui2/src/components/theme_selector.rs index 0758cf643b..1851aea954 100644 --- a/crates/ui2/src/components/theme_selector.rs +++ b/crates/ui2/src/components/theme_selector.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{OrderMethod, Palette, PaletteItem}; -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct ThemeSelector { id: ElementId, state_type: PhantomData, @@ -17,7 +17,7 @@ impl ThemeSelector { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div().child( Palette::new(self.id.clone()) .items(vec![ @@ -49,7 +49,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct ThemeSelectorStory { state_type: PhantomData, } @@ -61,7 +61,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, ThemeSelector>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/toast.rs b/crates/ui2/src/components/toast.rs index faf58467a2..268042144b 100644 --- a/crates/ui2/src/components/toast.rs +++ b/crates/ui2/src/components/toast.rs @@ -22,7 +22,7 @@ pub enum ToastOrigin { /// they are actively showing the a process in progress. /// /// Only one toast may be visible at a time. -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct Toast { origin: ToastOrigin, children: SmallVec<[AnyElement; 2]>, @@ -36,7 +36,7 @@ impl Toast { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let mut div = div(); @@ -57,7 +57,7 @@ impl Toast { .shadow_md() .overflow_hidden() .bg(theme.elevated_surface) - .children(self.children.drain(..)) + .children(self.children) } } @@ -78,7 +78,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct ToastStory { state_type: PhantomData, } @@ -90,7 +90,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, Toast>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/toolbar.rs b/crates/ui2/src/components/toolbar.rs index 74b2c92578..e18c81314d 100644 --- a/crates/ui2/src/components/toolbar.rs +++ b/crates/ui2/src/components/toolbar.rs @@ -6,7 +6,7 @@ use crate::prelude::*; #[derive(Clone)] pub struct ToolbarItem {} -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct Toolbar { left_items: SmallVec<[AnyElement; 2]>, right_items: SmallVec<[AnyElement; 2]>, @@ -54,7 +54,7 @@ impl Toolbar { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); div() @@ -80,7 +80,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct ToolbarStory { state_type: PhantomData, } @@ -92,7 +92,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); Story::container(cx) diff --git a/crates/ui2/src/components/traffic_lights.rs b/crates/ui2/src/components/traffic_lights.rs index 8ac76439f8..cfe589b463 100644 --- a/crates/ui2/src/components/traffic_lights.rs +++ b/crates/ui2/src/components/traffic_lights.rs @@ -9,7 +9,7 @@ enum TrafficLightColor { Green, } -#[derive(Element)] +#[derive(IntoAnyElement)] struct TrafficLight { state_type: PhantomData, color: TrafficLightColor, @@ -25,7 +25,7 @@ impl TrafficLight { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let fill = match (self.window_has_focus, self.color) { @@ -39,7 +39,7 @@ impl TrafficLight { } } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct TrafficLights { state_type: PhantomData, window_has_focus: bool, @@ -58,7 +58,7 @@ impl TrafficLights { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div() .flex() .items_center() @@ -87,7 +87,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct TrafficLightsStory { state_type: PhantomData, } @@ -99,7 +99,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, TrafficLights>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/element_ext.rs b/crates/ui2/src/element_ext.rs index 813f01dd24..fb31307d12 100644 --- a/crates/ui2/src/element_ext.rs +++ b/crates/ui2/src/element_ext.rs @@ -1,18 +1,15 @@ use gpui2::Element; pub trait ElementExt: Element { - /// Applies a given function `then` to the current element if `condition` is true. - /// This function is used to conditionally modify the element based on a given condition. - /// If `condition` is false, it just returns the current element as it is. - fn when(mut self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self - where - Self: Sized, - { - if condition { - self = then(self); - } - self - } + // fn when(mut self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self + // where + // Self: Sized, + // { + // if condition { + // self = then(self); + // } + // self + // } // fn when_some(mut self, option: Option, then: impl FnOnce(Self, T) -> U) -> U // where diff --git a/crates/ui2/src/elements/avatar.rs b/crates/ui2/src/elements/avatar.rs index 555818a87c..7d2e91ae8c 100644 --- a/crates/ui2/src/elements/avatar.rs +++ b/crates/ui2/src/elements/avatar.rs @@ -4,7 +4,7 @@ use gpui2::img; use crate::prelude::*; -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct Avatar { state_type: PhantomData, src: SharedString, @@ -25,7 +25,7 @@ impl Avatar { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let mut img = img(); @@ -51,7 +51,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct AvatarStory { state_type: PhantomData, } @@ -63,7 +63,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, Avatar>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/elements/button.rs b/crates/ui2/src/elements/button.rs index 9f399ea331..843a786aff 100644 --- a/crates/ui2/src/elements/button.rs +++ b/crates/ui2/src/elements/button.rs @@ -61,7 +61,7 @@ impl Default for ButtonHandlers { } } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct Button { state_type: PhantomData, disabled: bool, @@ -150,7 +150,7 @@ impl Button { self.icon.map(|i| IconElement::new(i).color(icon_color)) } - pub fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + pub fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let icon_color = self.icon_color(); let mut button = h_stack() @@ -193,7 +193,7 @@ impl Button { } } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct ButtonGroup { state_type: PhantomData, buttons: Vec>, @@ -207,10 +207,10 @@ impl ButtonGroup { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let mut el = h_stack().text_size(ui_size(cx, 1.)); - for button in &mut self.buttons { + for button in self.buttons { el = el.child(button.render(_view, cx)); } @@ -230,7 +230,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct ButtonStory { state_type: PhantomData, } @@ -242,7 +242,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let states = InteractionState::iter(); Story::container(cx) diff --git a/crates/ui2/src/elements/details.rs b/crates/ui2/src/elements/details.rs index ea05436401..5f0676f9f4 100644 --- a/crates/ui2/src/elements/details.rs +++ b/crates/ui2/src/elements/details.rs @@ -2,7 +2,7 @@ use std::marker::PhantomData; use crate::{prelude::*, v_stack, ButtonGroup}; -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct Details { state_type: PhantomData, text: &'static str, @@ -30,7 +30,7 @@ impl Details { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); v_stack() @@ -54,7 +54,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct DetailsStory { state_type: PhantomData, } @@ -66,7 +66,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, Details>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/elements/icon.rs b/crates/ui2/src/elements/icon.rs index 2a0f6b3a0b..18d6050dd1 100644 --- a/crates/ui2/src/elements/icon.rs +++ b/crates/ui2/src/elements/icon.rs @@ -148,7 +148,7 @@ impl Icon { } } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct IconElement { state_type: PhantomData, icon: Icon, @@ -176,7 +176,7 @@ impl IconElement { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let fill = self.color.color(cx); let svg_size = match self.size { IconSize::Small => ui_size(cx, 12. / 14.), @@ -202,7 +202,7 @@ mod stories { use super::*; - #[derive(Element, Default)] + #[derive(IntoAnyElement)] pub struct IconStory { state_type: PhantomData, } @@ -214,7 +214,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let icons = Icon::iter(); Story::container(cx) diff --git a/crates/ui2/src/elements/input.rs b/crates/ui2/src/elements/input.rs index 142acc8870..6a70c9cf79 100644 --- a/crates/ui2/src/elements/input.rs +++ b/crates/ui2/src/elements/input.rs @@ -11,7 +11,7 @@ pub enum InputVariant { Filled, } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct Input { state_type: PhantomData, placeholder: SharedString, @@ -60,7 +60,7 @@ impl Input { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let (input_bg, input_hover_bg, input_active_bg) = match self.variant { @@ -120,7 +120,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct InputStory { state_type: PhantomData, } @@ -132,7 +132,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, Input>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/elements/label.rs b/crates/ui2/src/elements/label.rs index f8d4a8d115..2d522a27b1 100644 --- a/crates/ui2/src/elements/label.rs +++ b/crates/ui2/src/elements/label.rs @@ -48,7 +48,7 @@ pub enum LineHeightStyle { UILabel, } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct Label { state_type: PhantomData, label: SharedString, @@ -83,7 +83,7 @@ impl Label { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div() .when(self.strikethrough, |this| { this.relative().child( @@ -105,7 +105,7 @@ impl Label { } } -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct HighlightedLabel { state_type: PhantomData, label: SharedString, @@ -135,7 +135,7 @@ impl HighlightedLabel { self } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); let highlight_color = theme.text_accent; @@ -211,7 +211,7 @@ mod stories { use super::*; - #[derive(Element)] + #[derive(IntoAnyElement)] pub struct LabelStory { state_type: PhantomData, } @@ -223,7 +223,7 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, Label>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/elements/tool_divider.rs b/crates/ui2/src/elements/tool_divider.rs index f73c8953ee..b388894d1a 100644 --- a/crates/ui2/src/elements/tool_divider.rs +++ b/crates/ui2/src/elements/tool_divider.rs @@ -2,7 +2,7 @@ use std::marker::PhantomData; use crate::prelude::*; -#[derive(Element)] +#[derive(IntoAnyElement)] pub struct ToolDivider { state_type: PhantomData, } @@ -14,7 +14,7 @@ impl ToolDivider { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { let theme = theme(cx); div().w_px().h_3().bg(theme.border) From 0285284ae1fe8c3878eb56aaaeecc4ad96804e43 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 26 Oct 2023 12:46:52 +0200 Subject: [PATCH 12/17] Rename IntoAnyElement trait to Component --- crates/gpui2/src/element.rs | 32 +++++----- crates/gpui2/src/elements/div.rs | 10 +-- crates/gpui2/src/elements/img.rs | 8 +-- crates/gpui2/src/elements/svg.rs | 8 +-- crates/gpui2/src/elements/text.rs | 26 ++++---- crates/gpui2/src/interactive.rs | 12 ++-- crates/gpui2/src/view.rs | 22 +++---- ...nto_any_element.rs => derive_component.rs} | 10 +-- crates/gpui2_macros/src/gpui2_macros.rs | 8 +-- crates/storybook2/src/components.rs | 2 +- crates/storybook2/src/stories/kitchen_sink.rs | 2 +- crates/storybook2/src/stories/scroll.rs | 5 +- crates/storybook2/src/stories/z_index.rs | 8 +-- crates/storybook2/src/story_selector.rs | 62 +++++++++---------- crates/storybook2/src/storybook2.rs | 2 +- crates/ui2/src/components/assistant_panel.rs | 10 +-- crates/ui2/src/components/breadcrumb.rs | 8 +-- crates/ui2/src/components/buffer.rs | 12 ++-- crates/ui2/src/components/buffer_search.rs | 2 +- crates/ui2/src/components/chat_panel.rs | 12 ++-- crates/ui2/src/components/collab_panel.rs | 8 +-- crates/ui2/src/components/command_palette.rs | 8 +-- crates/ui2/src/components/context_menu.rs | 8 +-- crates/ui2/src/components/copilot.rs | 8 +-- crates/ui2/src/components/editor_pane.rs | 2 +- crates/ui2/src/components/facepile.rs | 8 +-- crates/ui2/src/components/icon_button.rs | 4 +- crates/ui2/src/components/keybinding.rs | 12 ++-- .../ui2/src/components/language_selector.rs | 8 +-- crates/ui2/src/components/list.rs | 30 ++++----- crates/ui2/src/components/modal.rs | 4 +- crates/ui2/src/components/multi_buffer.rs | 8 +-- .../ui2/src/components/notification_toast.rs | 4 +- .../ui2/src/components/notifications_panel.rs | 8 +-- crates/ui2/src/components/palette.rs | 12 ++-- crates/ui2/src/components/panel.rs | 8 +-- crates/ui2/src/components/panes.rs | 8 +-- crates/ui2/src/components/player_stack.rs | 4 +- crates/ui2/src/components/project_panel.rs | 8 +-- crates/ui2/src/components/recent_projects.rs | 8 +-- crates/ui2/src/components/status_bar.rs | 10 +-- crates/ui2/src/components/tab.rs | 8 +-- crates/ui2/src/components/tab_bar.rs | 8 +-- crates/ui2/src/components/terminal.rs | 8 +-- crates/ui2/src/components/theme_selector.rs | 8 +-- crates/ui2/src/components/title_bar.rs | 4 +- crates/ui2/src/components/toast.rs | 8 +-- crates/ui2/src/components/toolbar.rs | 24 +++---- crates/ui2/src/components/traffic_lights.rs | 12 ++-- crates/ui2/src/components/workspace.rs | 2 +- crates/ui2/src/elements/avatar.rs | 8 +-- crates/ui2/src/elements/button.rs | 12 ++-- crates/ui2/src/elements/details.rs | 8 +-- crates/ui2/src/elements/icon.rs | 8 +-- crates/ui2/src/elements/input.rs | 8 +-- crates/ui2/src/elements/label.rs | 12 ++-- crates/ui2/src/elements/tool_divider.rs | 4 +- crates/ui2/src/prelude.rs | 2 +- crates/ui2/src/story.rs | 8 +-- crates/ui2/src/theme.rs | 6 +- 60 files changed, 297 insertions(+), 300 deletions(-) rename crates/gpui2_macros/src/{derive_into_any_element.rs => derive_component.rs} (84%) diff --git a/crates/gpui2/src/element.rs b/crates/gpui2/src/element.rs index 39b7898d16..762c887342 100644 --- a/crates/gpui2/src/element.rs +++ b/crates/gpui2/src/element.rs @@ -46,20 +46,20 @@ pub struct GlobalElementId(SmallVec<[ElementId; 32]>); pub trait ParentElement { fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]>; - fn child(mut self, child: impl IntoAnyElement) -> Self + fn child(mut self, child: impl Component) -> Self where Self: Sized, { - self.children_mut().push(child.into_any()); + self.children_mut().push(child.render()); self } - fn children(mut self, iter: impl IntoIterator>) -> Self + fn children(mut self, iter: impl IntoIterator>) -> Self where Self: Sized, { self.children_mut() - .extend(iter.into_iter().map(|item| item.into_any())); + .extend(iter.into_iter().map(|item| item.render())); self } } @@ -207,8 +207,8 @@ impl AnyElement { } } -pub trait IntoAnyElement { - fn into_any(self) -> AnyElement; +pub trait Component { + fn render(self) -> AnyElement; fn when(mut self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self where @@ -221,8 +221,8 @@ pub trait IntoAnyElement { } } -impl IntoAnyElement for AnyElement { - fn into_any(self) -> AnyElement { +impl Component for AnyElement { + fn render(self) -> AnyElement { self } } @@ -230,7 +230,7 @@ impl IntoAnyElement for AnyElement { impl Element for Option where V: 'static, - E: 'static + IntoAnyElement + Send + Sync, + E: 'static + Component + Send + Sync, F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + Send + Sync + 'static, { type ElementState = AnyElement; @@ -246,7 +246,7 @@ where cx: &mut ViewContext, ) -> Self::ElementState { let render = self.take().unwrap(); - (render)(view_state, cx).into_any() + (render)(view_state, cx).render() } fn layout( @@ -269,24 +269,24 @@ where } } -impl IntoAnyElement for Option +impl Component for Option where V: 'static, - E: 'static + IntoAnyElement + Send + Sync, + E: 'static + Component + Send + Sync, F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + Send + Sync + 'static, { - fn into_any(self) -> AnyElement { + fn render(self) -> AnyElement { AnyElement::new(self) } } -impl IntoAnyElement for F +impl Component for F where V: 'static, - E: 'static + IntoAnyElement + Send + Sync, + E: 'static + Component + Send + Sync, F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + Send + Sync + 'static, { - fn into_any(self) -> AnyElement { + fn render(self) -> AnyElement { AnyElement::new(Some(self)) } } diff --git a/crates/gpui2/src/elements/div.rs b/crates/gpui2/src/elements/div.rs index fbef75ab1c..6fe10d94a3 100644 --- a/crates/gpui2/src/elements/div.rs +++ b/crates/gpui2/src/elements/div.rs @@ -1,7 +1,7 @@ use crate::{ - point, AnyElement, BorrowWindow, Bounds, Element, ElementFocus, ElementId, ElementInteraction, - FocusDisabled, FocusEnabled, FocusHandle, FocusListeners, Focusable, GlobalElementId, - GroupBounds, InteractiveElementState, IntoAnyElement, LayoutId, Overflow, ParentElement, + point, AnyElement, BorrowWindow, Bounds, Component, Element, ElementFocus, ElementId, + ElementInteraction, FocusDisabled, FocusEnabled, FocusHandle, FocusListeners, Focusable, + GlobalElementId, GroupBounds, InteractiveElementState, LayoutId, Overflow, ParentElement, Pixels, Point, SharedString, StatefulInteraction, StatefulInteractive, StatelessInteraction, StatelessInteractive, Style, StyleRefinement, Styled, ViewContext, }; @@ -303,13 +303,13 @@ where } } -impl IntoAnyElement for Div +impl Component for Div where // V: Any + Send + Sync, I: ElementInteraction, F: ElementFocus, { - fn into_any(self) -> AnyElement { + fn render(self) -> AnyElement { AnyElement::new(self) } } diff --git a/crates/gpui2/src/elements/img.rs b/crates/gpui2/src/elements/img.rs index d64536a7ed..747e573ea5 100644 --- a/crates/gpui2/src/elements/img.rs +++ b/crates/gpui2/src/elements/img.rs @@ -1,6 +1,6 @@ use crate::{ - div, AnyElement, BorrowWindow, Bounds, Div, DivState, Element, ElementFocus, ElementId, - ElementInteraction, FocusDisabled, FocusEnabled, FocusListeners, Focusable, IntoAnyElement, + div, AnyElement, BorrowWindow, Bounds, Component, Div, DivState, Element, ElementFocus, + ElementId, ElementInteraction, FocusDisabled, FocusEnabled, FocusListeners, Focusable, LayoutId, Pixels, SharedString, StatefulInteraction, StatefulInteractive, StatelessInteraction, StatelessInteractive, StyleRefinement, Styled, ViewContext, }; @@ -55,12 +55,12 @@ where } } -impl IntoAnyElement for Img +impl Component for Img where I: ElementInteraction, F: ElementFocus, { - fn into_any(self) -> AnyElement { + fn render(self) -> AnyElement { AnyElement::new(self) } } diff --git a/crates/gpui2/src/elements/svg.rs b/crates/gpui2/src/elements/svg.rs index 409094d740..7db4c5cf6d 100644 --- a/crates/gpui2/src/elements/svg.rs +++ b/crates/gpui2/src/elements/svg.rs @@ -1,6 +1,6 @@ use crate::{ - div, AnyElement, Bounds, Div, DivState, Element, ElementFocus, ElementId, ElementInteraction, - FocusDisabled, FocusEnabled, FocusListeners, Focusable, IntoAnyElement, LayoutId, Pixels, + div, AnyElement, Bounds, Component, Div, DivState, Element, ElementFocus, ElementId, + ElementInteraction, FocusDisabled, FocusEnabled, FocusListeners, Focusable, LayoutId, Pixels, SharedString, StatefulInteraction, StatefulInteractive, StatelessInteraction, StatelessInteractive, StyleRefinement, Styled, ViewContext, }; @@ -45,12 +45,12 @@ where } } -impl IntoAnyElement for Svg +impl Component for Svg where I: ElementInteraction, F: ElementFocus, { - fn into_any(self) -> AnyElement { + fn render(self) -> AnyElement { AnyElement::new(self) } } diff --git a/crates/gpui2/src/elements/text.rs b/crates/gpui2/src/elements/text.rs index e054da87a6..3aff568c4c 100644 --- a/crates/gpui2/src/elements/text.rs +++ b/crates/gpui2/src/elements/text.rs @@ -1,41 +1,41 @@ use crate::{ - AnyElement, BorrowWindow, Bounds, Element, IntoAnyElement, LayoutId, Line, Pixels, - SharedString, Size, ViewContext, + AnyElement, BorrowWindow, Bounds, Component, Element, LayoutId, Line, Pixels, SharedString, + Size, ViewContext, }; use parking_lot::Mutex; use smallvec::SmallVec; use std::{marker::PhantomData, sync::Arc}; use util::ResultExt; -impl IntoAnyElement for SharedString { - fn into_any(self) -> AnyElement { +impl Component for SharedString { + fn render(self) -> AnyElement { Text { text: self, state_type: PhantomData, } - .into_any() + .render() } } -impl IntoAnyElement for &'static str { - fn into_any(self) -> AnyElement { +impl Component for &'static str { + fn render(self) -> AnyElement { Text { text: self.into(), state_type: PhantomData, } - .into_any() + .render() } } // TODO: Figure out how to pass `String` to `child` without this. // This impl doesn't exist in the `gpui2` crate. -impl IntoAnyElement for String { - fn into_any(self) -> AnyElement { +impl Component for String { + fn render(self) -> AnyElement { Text { text: self.into(), state_type: PhantomData, } - .into_any() + .render() } } @@ -47,8 +47,8 @@ pub struct Text { unsafe impl Send for Text {} unsafe impl Sync for Text {} -impl IntoAnyElement for Text { - fn into_any(self) -> AnyElement { +impl Component for Text { + fn render(self) -> AnyElement { AnyElement::new(self) } } diff --git a/crates/gpui2/src/interactive.rs b/crates/gpui2/src/interactive.rs index f51516dbe5..9ec6c38dfe 100644 --- a/crates/gpui2/src/interactive.rs +++ b/crates/gpui2/src/interactive.rs @@ -1,7 +1,7 @@ use crate::{ - point, px, view, Action, AnyBox, AnyDrag, AppContext, BorrowWindow, Bounds, DispatchContext, - DispatchPhase, Element, ElementId, FocusHandle, IntoAnyElement, KeyMatch, Keystroke, Modifiers, - Overflow, Pixels, Point, SharedString, Size, Style, StyleRefinement, ViewContext, + point, px, view, Action, AnyBox, AnyDrag, AppContext, BorrowWindow, Bounds, Component, + DispatchContext, DispatchPhase, Element, ElementId, FocusHandle, KeyMatch, Keystroke, + Modifiers, Overflow, Pixels, Point, SharedString, Size, Style, StyleRefinement, ViewContext, }; use collections::HashMap; use derive_more::{Deref, DerefMut}; @@ -327,7 +327,7 @@ pub trait StatefulInteractive: StatelessInteractive { S: Any + Send + Sync, R: Fn(&mut V, &mut ViewContext) -> E, R: 'static + Send + Sync, - E: IntoAnyElement, + E: Component, { debug_assert!( self.stateful_interaction().drag_listener.is_none(), @@ -871,7 +871,7 @@ pub struct Drag where R: Fn(&mut V, &mut ViewContext) -> E, V: 'static, - E: IntoAnyElement, + E: Component, { pub state: S, pub render_drag_handle: R, @@ -882,7 +882,7 @@ impl Drag where R: Fn(&mut V, &mut ViewContext) -> E, V: 'static, - E: IntoAnyElement, + E: Component, { pub fn new(state: S, render_drag_handle: R) -> Self { Drag { diff --git a/crates/gpui2/src/view.rs b/crates/gpui2/src/view.rs index b1b287c4ab..a27faed07d 100644 --- a/crates/gpui2/src/view.rs +++ b/crates/gpui2/src/view.rs @@ -1,7 +1,7 @@ use parking_lot::Mutex; use crate::{ - AnyBox, AnyElement, BorrowWindow, Bounds, Element, ElementId, EntityId, Handle, IntoAnyElement, + AnyBox, AnyElement, BorrowWindow, Bounds, Component, Element, ElementId, EntityId, Handle, LayoutId, Pixels, ViewContext, WindowContext, }; use std::{marker::PhantomData, sync::Arc}; @@ -33,16 +33,16 @@ pub fn view( render: impl Fn(&mut V, &mut ViewContext) -> E + Send + Sync + 'static, ) -> View where - E: IntoAnyElement, + E: Component, { View { state, - render: Arc::new(move |state, cx| render(state, cx).into_any()), + render: Arc::new(move |state, cx| render(state, cx).render()), } } -impl IntoAnyElement for View { - fn into_any(self) -> AnyElement { +impl Component for View { + fn render(self) -> AnyElement { AnyElement::new(EraseViewState { view: self, parent_view_state_type: PhantomData, @@ -98,8 +98,8 @@ struct EraseViewState { unsafe impl Send for EraseViewState {} unsafe impl Sync for EraseViewState {} -impl IntoAnyElement for EraseViewState { - fn into_any(self) -> AnyElement { +impl Component for EraseViewState { + fn render(self) -> AnyElement { AnyElement::new(self) } } @@ -185,8 +185,8 @@ pub struct AnyView { view: Arc>, } -impl IntoAnyElement for AnyView { - fn into_any(self) -> AnyElement { +impl Component for AnyView { + fn render(self) -> AnyElement { AnyElement::new(EraseAnyViewState { view: self, parent_view_state_type: PhantomData, @@ -238,8 +238,8 @@ struct EraseAnyViewState { unsafe impl Send for EraseAnyViewState {} unsafe impl Sync for EraseAnyViewState {} -impl IntoAnyElement for EraseAnyViewState { - fn into_any(self) -> AnyElement { +impl Component for EraseAnyViewState { + fn render(self) -> AnyElement { AnyElement::new(self) } } diff --git a/crates/gpui2_macros/src/derive_into_any_element.rs b/crates/gpui2_macros/src/derive_component.rs similarity index 84% rename from crates/gpui2_macros/src/derive_into_any_element.rs rename to crates/gpui2_macros/src/derive_component.rs index 9f339f1b44..45f4b44c85 100644 --- a/crates/gpui2_macros/src/derive_into_any_element.rs +++ b/crates/gpui2_macros/src/derive_component.rs @@ -2,7 +2,7 @@ use proc_macro::TokenStream; use quote::quote; use syn::{parse_macro_input, DeriveInput}; -pub fn derive_into_any_element(input: TokenStream) -> TokenStream { +pub fn derive_component(input: TokenStream) -> TokenStream { let ast = parse_macro_input!(input as DeriveInput); let name = &ast.ident; let generics = &ast.generics; @@ -11,7 +11,7 @@ pub fn derive_into_any_element(input: TokenStream) -> TokenStream { let specified_view_type = ast .attrs .iter() - .find(|attr| attr.path.is_ident("element")) + .find(|attr| attr.path.is_ident("component")) .and_then(|attr| { if let Ok(syn::Meta::List(meta_list)) = attr.parse_meta() { meta_list.nested.iter().find_map(|nested| { @@ -42,10 +42,10 @@ pub fn derive_into_any_element(input: TokenStream) -> TokenStream { }); let expanded = quote! { - impl #impl_generics gpui2::IntoAnyElement<#view_type> for #name #ty_generics #where_clause { - fn into_any(self) -> gpui2::AnyElement<#view_type> { + impl #impl_generics gpui2::Component<#view_type> for #name #ty_generics #where_clause { + fn render(self) -> gpui2::AnyElement<#view_type> { (move |view_state: &mut #view_type, cx: &mut gpui2::ViewContext<'_, '_, #view_type>| self.render(view_state, cx)) - .into_any() + .render() } } }; diff --git a/crates/gpui2_macros/src/gpui2_macros.rs b/crates/gpui2_macros/src/gpui2_macros.rs index 3635320d55..2e0c0547f7 100644 --- a/crates/gpui2_macros/src/gpui2_macros.rs +++ b/crates/gpui2_macros/src/gpui2_macros.rs @@ -1,6 +1,6 @@ use proc_macro::TokenStream; -mod derive_into_any_element; +mod derive_component; mod style_helpers; mod test; @@ -9,9 +9,9 @@ pub fn style_helpers(args: TokenStream) -> TokenStream { style_helpers::style_helpers(args) } -#[proc_macro_derive(IntoAnyElement, attributes(element))] -pub fn derive_into_any_element(input: TokenStream) -> TokenStream { - derive_into_any_element::derive_into_any_element(input) +#[proc_macro_derive(Component, attributes(component))] +pub fn derive_component(input: TokenStream) -> TokenStream { + derive_component::derive_component(input) } #[proc_macro_attribute] diff --git a/crates/storybook2/src/components.rs b/crates/storybook2/src/components.rs index 5eaa894302..a3dca51adc 100644 --- a/crates/storybook2/src/components.rs +++ b/crates/storybook2/src/components.rs @@ -14,7 +14,7 @@ impl Default for ButtonHandlers { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Button { handlers: ButtonHandlers, label: Option>, diff --git a/crates/storybook2/src/stories/kitchen_sink.rs b/crates/storybook2/src/stories/kitchen_sink.rs index fbb4f5099c..ec89238ac4 100644 --- a/crates/storybook2/src/stories/kitchen_sink.rs +++ b/crates/storybook2/src/stories/kitchen_sink.rs @@ -16,7 +16,7 @@ impl KitchenSinkStory { view(cx.entity(|cx| Self::new()), Self::render) } - fn render(&mut self, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(&mut self, cx: &mut ViewContext) -> impl Component { let element_stories = ElementStory::iter() .map(|selector| selector.story(cx)) .collect::>(); diff --git a/crates/storybook2/src/stories/scroll.rs b/crates/storybook2/src/stories/scroll.rs index 86a8ca41c8..a1e3c6700e 100644 --- a/crates/storybook2/src/stories/scroll.rs +++ b/crates/storybook2/src/stories/scroll.rs @@ -1,7 +1,6 @@ use crate::themes::rose_pine; use gpui2::{ - div, px, view, Context, IntoAnyElement, ParentElement, SharedString, Styled, View, - WindowContext, + div, px, view, Component, Context, ParentElement, SharedString, Styled, View, WindowContext, }; pub struct ScrollStory { @@ -16,7 +15,7 @@ impl ScrollStory { } } -fn checkerboard(depth: usize) -> impl IntoAnyElement +fn checkerboard(depth: usize) -> impl Component where S: 'static + Send + Sync, { diff --git a/crates/storybook2/src/stories/z_index.rs b/crates/storybook2/src/stories/z_index.rs index 270bd08640..d68b4916c2 100644 --- a/crates/storybook2/src/stories/z_index.rs +++ b/crates/storybook2/src/stories/z_index.rs @@ -7,7 +7,7 @@ use crate::story::Story; /// A reimplementation of the MDN `z-index` example, found here: /// [https://developer.mozilla.org/en-US/docs/Web/CSS/z-index](https://developer.mozilla.org/en-US/docs/Web/CSS/z-index). -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct ZIndexStory { state_type: PhantomData, } @@ -19,7 +19,7 @@ impl ZIndexStory { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title(cx, "z-index")) .child( @@ -88,7 +88,7 @@ trait Styles: Styled + Sized { impl Styles for Div {} -#[derive(IntoAnyElement)] +#[derive(Component)] struct ZIndexExample { view_type: PhantomData, z_index: u32, @@ -102,7 +102,7 @@ impl ZIndexExample { } } - fn render(self, _view: &mut V, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut V, cx: &mut ViewContext) -> impl Component { div() .relative() .size_full() diff --git a/crates/storybook2/src/story_selector.rs b/crates/storybook2/src/story_selector.rs index 8cd3f9e329..5f60ad14ea 100644 --- a/crates/storybook2/src/story_selector.rs +++ b/crates/storybook2/src/story_selector.rs @@ -28,29 +28,29 @@ impl ElementStory { pub fn story(&self, cx: &mut WindowContext) -> AnyView { match self { Self::Avatar => { - view(cx.entity(|cx| ()), |_, _| ui::AvatarStory::new().into_any()).into_any() + view(cx.entity(|cx| ()), |_, _| ui::AvatarStory::new().render()).into_any() } Self::Button => { - view(cx.entity(|cx| ()), |_, _| ui::ButtonStory::new().into_any()).into_any() + view(cx.entity(|cx| ()), |_, _| ui::ButtonStory::new().render()).into_any() } Self::Details => view(cx.entity(|cx| ()), |_, _| { - ui::DetailsStory::new().into_any() + ui::DetailsStory::new().render() }) .into_any(), Self::Focus => FocusStory::view(cx).into_any(), Self::Icon => { - view(cx.entity(|cx| ()), |_, _| ui::IconStory::new().into_any()).into_any() + view(cx.entity(|cx| ()), |_, _| ui::IconStory::new().render()).into_any() } Self::Input => { - view(cx.entity(|cx| ()), |_, _| ui::InputStory::new().into_any()).into_any() + view(cx.entity(|cx| ()), |_, _| ui::InputStory::new().render()).into_any() } Self::Label => { - view(cx.entity(|cx| ()), |_, _| ui::LabelStory::new().into_any()).into_any() + view(cx.entity(|cx| ()), |_, _| ui::LabelStory::new().render()).into_any() } Self::Scroll => ScrollStory::view(cx).into_any(), Self::Text => TextStory::view(cx).into_any(), Self::ZIndex => { - view(cx.entity(|cx| ()), |_, _| ZIndexStory::new().into_any()).into_any() + view(cx.entity(|cx| ()), |_, _| ZIndexStory::new().render()).into_any() } } } @@ -91,93 +91,93 @@ impl ComponentStory { pub fn story(&self, cx: &mut WindowContext) -> AnyView { match self { Self::AssistantPanel => view(cx.entity(|cx| ()), |_, _| { - ui::AssistantPanelStory::new().into_any() + ui::AssistantPanelStory::new().render() }) .into_any(), Self::Buffer => { - view(cx.entity(|cx| ()), |_, _| ui::BufferStory::new().into_any()).into_any() + view(cx.entity(|cx| ()), |_, _| ui::BufferStory::new().render()).into_any() } Self::Breadcrumb => view(cx.entity(|cx| ()), |_, _| { - ui::BreadcrumbStory::new().into_any() + ui::BreadcrumbStory::new().render() }) .into_any(), Self::ChatPanel => view(cx.entity(|cx| ()), |_, _| { - ui::ChatPanelStory::new().into_any() + ui::ChatPanelStory::new().render() }) .into_any(), Self::CollabPanel => view(cx.entity(|cx| ()), |_, _| { - ui::CollabPanelStory::new().into_any() + ui::CollabPanelStory::new().render() }) .into_any(), Self::CommandPalette => view(cx.entity(|cx| ()), |_, _| { - ui::CommandPaletteStory::new().into_any() + ui::CommandPaletteStory::new().render() }) .into_any(), Self::ContextMenu => view(cx.entity(|cx| ()), |_, _| { - ui::ContextMenuStory::new().into_any() + ui::ContextMenuStory::new().render() }) .into_any(), Self::Facepile => view(cx.entity(|cx| ()), |_, _| { - ui::FacepileStory::new().into_any() + ui::FacepileStory::new().render() }) .into_any(), Self::Keybinding => view(cx.entity(|cx| ()), |_, _| { - ui::KeybindingStory::new().into_any() + ui::KeybindingStory::new().render() }) .into_any(), Self::LanguageSelector => view(cx.entity(|cx| ()), |_, _| { - ui::LanguageSelectorStory::new().into_any() + ui::LanguageSelectorStory::new().render() }) .into_any(), Self::MultiBuffer => view(cx.entity(|cx| ()), |_, _| { - ui::MultiBufferStory::new().into_any() + ui::MultiBufferStory::new().render() }) .into_any(), Self::NotificationsPanel => view(cx.entity(|cx| ()), |_, _| { - ui::NotificationsPanelStory::new().into_any() + ui::NotificationsPanelStory::new().render() }) .into_any(), Self::Palette => view(cx.entity(|cx| ()), |_, _| { - ui::PaletteStory::new().into_any() + ui::PaletteStory::new().render() }) .into_any(), Self::Panel => { - view(cx.entity(|cx| ()), |_, _| ui::PanelStory::new().into_any()).into_any() + view(cx.entity(|cx| ()), |_, _| ui::PanelStory::new().render()).into_any() } Self::ProjectPanel => view(cx.entity(|cx| ()), |_, _| { - ui::ProjectPanelStory::new().into_any() + ui::ProjectPanelStory::new().render() }) .into_any(), Self::RecentProjects => view(cx.entity(|cx| ()), |_, _| { - ui::RecentProjectsStory::new().into_any() + ui::RecentProjectsStory::new().render() }) .into_any(), - Self::Tab => view(cx.entity(|cx| ()), |_, _| ui::TabStory::new().into_any()).into_any(), + Self::Tab => view(cx.entity(|cx| ()), |_, _| ui::TabStory::new().render()).into_any(), Self::TabBar => { - view(cx.entity(|cx| ()), |_, _| ui::TabBarStory::new().into_any()).into_any() + view(cx.entity(|cx| ()), |_, _| ui::TabBarStory::new().render()).into_any() } Self::Terminal => view(cx.entity(|cx| ()), |_, _| { - ui::TerminalStory::new().into_any() + ui::TerminalStory::new().render() }) .into_any(), Self::ThemeSelector => view(cx.entity(|cx| ()), |_, _| { - ui::ThemeSelectorStory::new().into_any() + ui::ThemeSelectorStory::new().render() }) .into_any(), Self::TitleBar => ui::TitleBarStory::view(cx).into_any(), Self::Toast => { - view(cx.entity(|cx| ()), |_, _| ui::ToastStory::new().into_any()).into_any() + view(cx.entity(|cx| ()), |_, _| ui::ToastStory::new().render()).into_any() } Self::Toolbar => view(cx.entity(|cx| ()), |_, _| { - ui::ToolbarStory::new().into_any() + ui::ToolbarStory::new().render() }) .into_any(), Self::TrafficLights => view(cx.entity(|cx| ()), |_, _| { - ui::TrafficLightsStory::new().into_any() + ui::TrafficLightsStory::new().render() }) .into_any(), Self::Copilot => view(cx.entity(|cx| ()), |_, _| { - ui::CopilotModalStory::new().into_any() + ui::CopilotModalStory::new().render() }) .into_any(), Self::Workspace => ui::WorkspaceStory::view(cx).into_any(), diff --git a/crates/storybook2/src/storybook2.rs b/crates/storybook2/src/storybook2.rs index 4db1fd434b..29ff5eaa98 100644 --- a/crates/storybook2/src/storybook2.rs +++ b/crates/storybook2/src/storybook2.rs @@ -107,7 +107,7 @@ impl StoryWrapper { Self { story, theme } } - fn render(&mut self, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(&mut self, cx: &mut ViewContext) -> impl Component { themed(self.theme.clone(), cx, |cx| { div() .flex() diff --git a/crates/ui2/src/components/assistant_panel.rs b/crates/ui2/src/components/assistant_panel.rs index fa5ac38dc1..c07723cedb 100644 --- a/crates/ui2/src/components/assistant_panel.rs +++ b/crates/ui2/src/components/assistant_panel.rs @@ -5,7 +5,7 @@ use gpui2::{rems, AbsoluteLength}; use crate::prelude::*; use crate::{Icon, IconButton, Label, Panel, PanelSide}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct AssistantPanel { id: ElementId, state_type: PhantomData, @@ -26,7 +26,7 @@ impl AssistantPanel { self } - fn render(self, view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, view: &mut S, cx: &mut ViewContext) -> impl Component { Panel::new(self.id.clone(), cx) .children(vec![div() .flex() @@ -69,7 +69,7 @@ impl AssistantPanel { .overflow_y_scroll() .child(Label::new("Is this thing on?")), ) - .into_any()]) + .render()]) .side(self.current_side) .width(AbsoluteLength::Rems(rems(32.))) } @@ -84,7 +84,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct AssistantPanelStory { state_type: PhantomData, } @@ -96,7 +96,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, AssistantPanel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/breadcrumb.rs b/crates/ui2/src/components/breadcrumb.rs index 00a471e7cc..289c071021 100644 --- a/crates/ui2/src/components/breadcrumb.rs +++ b/crates/ui2/src/components/breadcrumb.rs @@ -9,7 +9,7 @@ use crate::{h_stack, HighlightedText}; #[derive(Clone)] pub struct Symbol(pub Vec); -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Breadcrumb { state_type: PhantomData, path: PathBuf, @@ -31,7 +31,7 @@ impl Breadcrumb { div().child(" › ").text_color(theme.text_muted) } - fn render(self, view_state: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, view_state: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let symbols_len = self.symbols.len(); @@ -86,7 +86,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct BreadcrumbStory { state_type: PhantomData, } @@ -98,7 +98,7 @@ mod stories { } } - fn render(self, view_state: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, view_state: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); Story::container(cx) diff --git a/crates/ui2/src/components/buffer.rs b/crates/ui2/src/components/buffer.rs index 662ccd5736..ffef5c4039 100644 --- a/crates/ui2/src/components/buffer.rs +++ b/crates/ui2/src/components/buffer.rs @@ -109,7 +109,7 @@ impl BufferRow { } } -#[derive(IntoAnyElement, Clone)] +#[derive(Component, Clone)] pub struct Buffer { id: ElementId, state_type: PhantomData, @@ -158,7 +158,7 @@ impl Buffer { self } - fn render_row(row: BufferRow, cx: &WindowContext) -> impl IntoAnyElement { + fn render_row(row: BufferRow, cx: &WindowContext) -> impl Component { let theme = theme(cx); let line_background = if row.current { @@ -208,7 +208,7 @@ impl Buffer { })) } - fn render_rows(&self, cx: &WindowContext) -> Vec> { + fn render_rows(&self, cx: &WindowContext) -> Vec> { match &self.rows { Some(rows) => rows .rows @@ -219,7 +219,7 @@ impl Buffer { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let rows = self.render_rows(cx); @@ -246,7 +246,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct BufferStory { state_type: PhantomData, } @@ -258,7 +258,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); Story::container(cx) diff --git a/crates/ui2/src/components/buffer_search.rs b/crates/ui2/src/components/buffer_search.rs index e3e92aa073..b5e74a4810 100644 --- a/crates/ui2/src/components/buffer_search.rs +++ b/crates/ui2/src/components/buffer_search.rs @@ -25,7 +25,7 @@ impl BufferSearch { view(cx.entity(|cx| Self::new()), Self::render) } - fn render(&mut self, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(&mut self, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); h_stack().bg(theme.toolbar).p_2().child( diff --git a/crates/ui2/src/components/chat_panel.rs b/crates/ui2/src/components/chat_panel.rs index db0f573485..2800207b34 100644 --- a/crates/ui2/src/components/chat_panel.rs +++ b/crates/ui2/src/components/chat_panel.rs @@ -5,7 +5,7 @@ use chrono::NaiveDateTime; use crate::prelude::*; use crate::{Icon, IconButton, Input, Label, LabelColor}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct ChatPanel { element_id: ElementId, messages: Vec>, @@ -24,7 +24,7 @@ impl ChatPanel { self } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div() .id(self.element_id.clone()) .flex() @@ -70,7 +70,7 @@ impl ChatPanel { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct ChatMessage { state_type: PhantomData, author: String, @@ -88,7 +88,7 @@ impl ChatMessage { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div() .flex() .flex_col() @@ -117,7 +117,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct ChatPanelStory { state_type: PhantomData, } @@ -129,7 +129,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, ChatPanel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/collab_panel.rs b/crates/ui2/src/components/collab_panel.rs index 050b7c2b85..8f30b33da0 100644 --- a/crates/ui2/src/components/collab_panel.rs +++ b/crates/ui2/src/components/collab_panel.rs @@ -5,7 +5,7 @@ use crate::{ }; use std::marker::PhantomData; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct CollabPanel { id: ElementId, state_type: PhantomData, @@ -19,7 +19,7 @@ impl CollabPanel { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); v_stack() @@ -98,7 +98,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct CollabPanelStory { state_type: PhantomData, } @@ -110,7 +110,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, CollabPanel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/command_palette.rs b/crates/ui2/src/components/command_palette.rs index f79038b172..d00b9b7743 100644 --- a/crates/ui2/src/components/command_palette.rs +++ b/crates/ui2/src/components/command_palette.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{example_editor_actions, OrderMethod, Palette}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct CommandPalette { id: ElementId, state_type: PhantomData, @@ -17,7 +17,7 @@ impl CommandPalette { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div().id(self.id.clone()).child( Palette::new("palette") .items(example_editor_actions()) @@ -37,7 +37,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct CommandPaletteStory { state_type: PhantomData, } @@ -49,7 +49,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, CommandPalette>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/context_menu.rs b/crates/ui2/src/components/context_menu.rs index 5463cb29e7..b52051daa3 100644 --- a/crates/ui2/src/components/context_menu.rs +++ b/crates/ui2/src/components/context_menu.rs @@ -31,7 +31,7 @@ impl ContextMenuItem { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct ContextMenu { items: Vec>, } @@ -42,7 +42,7 @@ impl ContextMenu { items: items.into_iter().collect(), } } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); v_stack() @@ -73,7 +73,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct ContextMenuStory { state_type: PhantomData, } @@ -85,7 +85,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, ContextMenu>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/copilot.rs b/crates/ui2/src/components/copilot.rs index ca82ea5a0a..9e5454ee8a 100644 --- a/crates/ui2/src/components/copilot.rs +++ b/crates/ui2/src/components/copilot.rs @@ -2,7 +2,7 @@ use std::marker::PhantomData; use crate::{prelude::*, Button, Label, LabelColor, Modal}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct CopilotModal { id: ElementId, state_type: PhantomData, @@ -16,7 +16,7 @@ impl CopilotModal { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div().id(self.id.clone()).child( Modal::new("some-id") .title("Connect Copilot to Zed") @@ -35,7 +35,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct CopilotModalStory { state_type: PhantomData, } @@ -47,7 +47,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, CopilotModal>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/editor_pane.rs b/crates/ui2/src/components/editor_pane.rs index 3fc41d7db6..fb26dad791 100644 --- a/crates/ui2/src/components/editor_pane.rs +++ b/crates/ui2/src/components/editor_pane.rs @@ -49,7 +49,7 @@ impl EditorPane { ) } - fn render(&mut self, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(&mut self, cx: &mut ViewContext) -> impl Component { v_stack() .w_full() .h_full() diff --git a/crates/ui2/src/components/facepile.rs b/crates/ui2/src/components/facepile.rs index c87de6a2a2..565396e733 100644 --- a/crates/ui2/src/components/facepile.rs +++ b/crates/ui2/src/components/facepile.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{Avatar, Player}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Facepile { state_type: PhantomData, players: Vec, @@ -17,7 +17,7 @@ impl Facepile { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let player_count = self.players.len(); let player_list = self.players.iter().enumerate().map(|(ix, player)| { let isnt_last = ix < player_count - 1; @@ -39,7 +39,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct FacepileStory { state_type: PhantomData, } @@ -51,7 +51,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let players = static_players(); Story::container(cx) diff --git a/crates/ui2/src/components/icon_button.rs b/crates/ui2/src/components/icon_button.rs index 0801c5ac23..fe41de15a0 100644 --- a/crates/ui2/src/components/icon_button.rs +++ b/crates/ui2/src/components/icon_button.rs @@ -16,7 +16,7 @@ impl Default for IconButtonHandlers { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct IconButton { state_type: PhantomData, id: ElementId, @@ -68,7 +68,7 @@ impl IconButton { self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let icon_color = match (self.state, self.color) { diff --git a/crates/ui2/src/components/keybinding.rs b/crates/ui2/src/components/keybinding.rs index 7a240aa39c..d77798ad6c 100644 --- a/crates/ui2/src/components/keybinding.rs +++ b/crates/ui2/src/components/keybinding.rs @@ -5,7 +5,7 @@ use strum::{EnumIter, IntoEnumIterator}; use crate::prelude::*; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Keybinding { state_type: PhantomData, @@ -34,7 +34,7 @@ impl Keybinding { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div() .flex() .gap_2() @@ -54,7 +54,7 @@ impl Keybinding { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Key { state_type: PhantomData, key: SharedString, @@ -68,7 +68,7 @@ impl Key { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); div() @@ -173,7 +173,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct KeybindingStory { state_type: PhantomData, } @@ -185,7 +185,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let all_modifier_permutations = ModifierKey::iter().permutations(2); Story::container(cx) diff --git a/crates/ui2/src/components/language_selector.rs b/crates/ui2/src/components/language_selector.rs index 5dd571ec42..ebb8f152f8 100644 --- a/crates/ui2/src/components/language_selector.rs +++ b/crates/ui2/src/components/language_selector.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{OrderMethod, Palette, PaletteItem}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct LanguageSelector { id: ElementId, state_type: PhantomData, @@ -17,7 +17,7 @@ impl LanguageSelector { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div().id(self.id.clone()).child( Palette::new("palette") .items(vec![ @@ -48,7 +48,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct LanguageSelectorStory { state_type: PhantomData, } @@ -60,7 +60,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, LanguageSelector>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/list.rs b/crates/ui2/src/components/list.rs index 00684a7eb9..b1b3f506ea 100644 --- a/crates/ui2/src/components/list.rs +++ b/crates/ui2/src/components/list.rs @@ -17,7 +17,7 @@ pub enum ListItemVariant { Inset, } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct ListHeader { state_type: PhantomData, label: SharedString, @@ -92,7 +92,7 @@ impl ListHeader { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let is_toggleable = self.toggleable != Toggleable::NotToggleable; @@ -134,7 +134,7 @@ impl ListHeader { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct ListSubHeader { state_type: PhantomData, label: SharedString, @@ -157,7 +157,7 @@ impl ListSubHeader { self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { h_stack().flex_1().w_full().relative().py_1().child( div() .h_6() @@ -197,7 +197,7 @@ pub enum ListEntrySize { Medium, } -#[derive(IntoAnyElement)] +#[derive(Component)] pub enum ListItem { Entry(ListEntry), Details(ListDetailsEntry), @@ -230,7 +230,7 @@ impl From> for ListItem { } impl ListItem { - fn render(self, view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, view: &mut S, cx: &mut ViewContext) -> impl Component { match self { ListItem::Entry(entry) => div().child(entry.render(view, cx)), ListItem::Separator(separator) => div().child(separator.render(view, cx)), @@ -252,7 +252,7 @@ impl ListItem { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct ListEntry { disclosure_control_style: DisclosureControlVisibility, indent_level: u32, @@ -344,7 +344,7 @@ impl ListEntry { } } - fn disclosure_control(&mut self, cx: &mut ViewContext) -> Option> { + fn disclosure_control(&mut self, cx: &mut ViewContext) -> Option> { let disclosure_control_icon = if let Some(ToggleState::Toggled) = self.toggle { IconElement::new(Icon::ChevronDown) } else { @@ -364,7 +364,7 @@ impl ListEntry { } } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let settings = user_settings(cx); let theme = theme(cx); @@ -430,7 +430,7 @@ impl Default for ListDetailsEntryHandlers { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct ListDetailsEntry { label: SharedString, meta: Option, @@ -474,7 +474,7 @@ impl ListDetailsEntry { self } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let settings = user_settings(cx); @@ -519,7 +519,7 @@ impl ListDetailsEntry { } } -#[derive(Clone, IntoAnyElement)] +#[derive(Clone, Component)] pub struct ListSeparator { state_type: PhantomData, } @@ -531,14 +531,14 @@ impl ListSeparator { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); div().h_px().w_full().bg(theme.border) } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct List { items: Vec>, empty_message: SharedString, @@ -571,7 +571,7 @@ impl List { self } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let is_toggleable = self.toggleable != Toggleable::NotToggleable; let is_toggled = Toggleable::is_toggled(&self.toggleable); diff --git a/crates/ui2/src/components/modal.rs b/crates/ui2/src/components/modal.rs index c8fbfc0c6d..0d57013e5d 100644 --- a/crates/ui2/src/components/modal.rs +++ b/crates/ui2/src/components/modal.rs @@ -5,7 +5,7 @@ use smallvec::SmallVec; use crate::{h_stack, prelude::*, v_stack, Button, Icon, IconButton, Label}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Modal { id: ElementId, state_type: PhantomData, @@ -42,7 +42,7 @@ impl Modal { self } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); v_stack() diff --git a/crates/ui2/src/components/multi_buffer.rs b/crates/ui2/src/components/multi_buffer.rs index 86e89c896c..30fcb935bb 100644 --- a/crates/ui2/src/components/multi_buffer.rs +++ b/crates/ui2/src/components/multi_buffer.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{v_stack, Buffer, Icon, IconButton, Label}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct MultiBuffer { state_type: PhantomData, buffers: Vec>, @@ -17,7 +17,7 @@ impl MultiBuffer { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); v_stack() @@ -50,7 +50,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct MultiBufferStory { state_type: PhantomData, } @@ -62,7 +62,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); Story::container(cx) diff --git a/crates/ui2/src/components/notification_toast.rs b/crates/ui2/src/components/notification_toast.rs index 6a1011207b..6460c2f693 100644 --- a/crates/ui2/src/components/notification_toast.rs +++ b/crates/ui2/src/components/notification_toast.rs @@ -4,7 +4,7 @@ use gpui2::rems; use crate::{h_stack, prelude::*, Icon}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct NotificationToast { state_type: PhantomData, label: SharedString, @@ -28,7 +28,7 @@ impl NotificationToast { self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); h_stack() diff --git a/crates/ui2/src/components/notifications_panel.rs b/crates/ui2/src/components/notifications_panel.rs index 44af3696c2..39ec9ea73f 100644 --- a/crates/ui2/src/components/notifications_panel.rs +++ b/crates/ui2/src/components/notifications_panel.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::{prelude::*, static_new_notification_items, static_read_notification_items}; use crate::{List, ListHeader}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct NotificationsPanel { id: ElementId, state_type: PhantomData, @@ -17,7 +17,7 @@ impl NotificationsPanel { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); div() @@ -58,7 +58,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct NotificationsPanelStory { state_type: PhantomData, } @@ -70,7 +70,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, NotificationsPanel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/palette.rs b/crates/ui2/src/components/palette.rs index 5b52f41aec..56928d4192 100644 --- a/crates/ui2/src/components/palette.rs +++ b/crates/ui2/src/components/palette.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{h_stack, v_stack, Keybinding, Label, LabelColor}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Palette { id: ElementId, state_type: PhantomData, @@ -46,7 +46,7 @@ impl Palette { self } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); v_stack() @@ -101,7 +101,7 @@ impl Palette { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct PaletteItem { pub label: SharedString, pub sublabel: Option, @@ -135,7 +135,7 @@ impl PaletteItem { self } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div() .flex() .flex_row() @@ -160,7 +160,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct PaletteStory { state_type: PhantomData, } @@ -172,7 +172,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, Palette>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/panel.rs b/crates/ui2/src/components/panel.rs index e6bca5afa7..63c694a7a3 100644 --- a/crates/ui2/src/components/panel.rs +++ b/crates/ui2/src/components/panel.rs @@ -40,7 +40,7 @@ pub enum PanelSide { use std::collections::HashSet; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Panel { id: ElementId, state_type: PhantomData, @@ -96,7 +96,7 @@ impl Panel { self } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let current_size = self.width.unwrap_or(self.initial_width); @@ -136,7 +136,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct PanelStory { state_type: PhantomData, } @@ -148,7 +148,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, Panel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/panes.rs b/crates/ui2/src/components/panes.rs index 118bb5f197..fafa2dd2a1 100644 --- a/crates/ui2/src/components/panes.rs +++ b/crates/ui2/src/components/panes.rs @@ -12,7 +12,7 @@ pub enum SplitDirection { Vertical, } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Pane { id: ElementId, size: Size, @@ -44,7 +44,7 @@ impl Pane { self } - fn render(self, view: &mut V, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, view: &mut V, cx: &mut ViewContext) -> impl Component { div() .id(self.id.clone()) .flex() @@ -75,7 +75,7 @@ impl ParentElement for Pane { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct PaneGroup { state_type: PhantomData, groups: Vec>, @@ -102,7 +102,7 @@ impl PaneGroup { } } - fn render(mut self, view: &mut V, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, view: &mut V, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); if !self.panes.is_empty() { diff --git a/crates/ui2/src/components/player_stack.rs b/crates/ui2/src/components/player_stack.rs index 88b2833dda..f1a8df8218 100644 --- a/crates/ui2/src/components/player_stack.rs +++ b/crates/ui2/src/components/player_stack.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{Avatar, Facepile, PlayerWithCallStatus}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct PlayerStack { state_type: PhantomData, player_with_call_status: PlayerWithCallStatus, @@ -17,7 +17,7 @@ impl PlayerStack { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let player = self.player_with_call_status.get_player(); self.player_with_call_status.get_call_status(); diff --git a/crates/ui2/src/components/project_panel.rs b/crates/ui2/src/components/project_panel.rs index 5771f996c5..e0791ab323 100644 --- a/crates/ui2/src/components/project_panel.rs +++ b/crates/ui2/src/components/project_panel.rs @@ -5,7 +5,7 @@ use crate::{ static_project_panel_project_items, static_project_panel_single_items, Input, List, ListHeader, }; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct ProjectPanel { id: ElementId, state_type: PhantomData, @@ -19,7 +19,7 @@ impl ProjectPanel { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); div() @@ -67,7 +67,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct ProjectPanelStory { state_type: PhantomData, } @@ -79,7 +79,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, ProjectPanel>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/recent_projects.rs b/crates/ui2/src/components/recent_projects.rs index d29caa2fd2..94d4c467f8 100644 --- a/crates/ui2/src/components/recent_projects.rs +++ b/crates/ui2/src/components/recent_projects.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{OrderMethod, Palette, PaletteItem}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct RecentProjects { id: ElementId, state_type: PhantomData, @@ -17,7 +17,7 @@ impl RecentProjects { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div().id(self.id.clone()).child( Palette::new("palette") .items(vec![ @@ -44,7 +44,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct RecentProjectsStory { state_type: PhantomData, } @@ -56,7 +56,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, RecentProjects>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/status_bar.rs b/crates/ui2/src/components/status_bar.rs index 4ea0fe4eeb..e2fcfe9e02 100644 --- a/crates/ui2/src/components/status_bar.rs +++ b/crates/ui2/src/components/status_bar.rs @@ -28,8 +28,8 @@ impl Default for ToolGroup { } } -#[derive(IntoAnyElement)] -#[element(view_type = "Workspace")] +#[derive(Component)] +#[component(view_type = "Workspace")] pub struct StatusBar { left_tools: Option, right_tools: Option, @@ -86,7 +86,7 @@ impl StatusBar { self, view: &mut Workspace, cx: &mut ViewContext, - ) -> impl IntoAnyElement { + ) -> impl Component { let theme = theme(cx); div() @@ -105,7 +105,7 @@ impl StatusBar { &self, workspace: &mut Workspace, cx: &WindowContext, - ) -> impl IntoAnyElement { + ) -> impl Component { div() .flex() .items_center() @@ -136,7 +136,7 @@ impl StatusBar { &self, workspace: &mut Workspace, cx: &WindowContext, - ) -> impl IntoAnyElement { + ) -> impl Component { div() .flex() .items_center() diff --git a/crates/ui2/src/components/tab.rs b/crates/ui2/src/components/tab.rs index 02a2420580..63cdd55b76 100644 --- a/crates/ui2/src/components/tab.rs +++ b/crates/ui2/src/components/tab.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{Icon, IconColor, IconElement, Label, LabelColor}; -#[derive(IntoAnyElement, Clone)] +#[derive(Component, Clone)] pub struct Tab { state_type: PhantomData, id: ElementId, @@ -81,7 +81,7 @@ impl Tab { self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let has_fs_conflict = self.fs_status == FileSystemStatus::Conflict; let is_deleted = self.fs_status == FileSystemStatus::Deleted; @@ -176,7 +176,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct TabStory { state_type: PhantomData, } @@ -188,7 +188,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let git_statuses = GitStatus::iter(); let fs_statuses = FileSystemStatus::iter(); diff --git a/crates/ui2/src/components/tab_bar.rs b/crates/ui2/src/components/tab_bar.rs index 38dd9edade..344baaab4b 100644 --- a/crates/ui2/src/components/tab_bar.rs +++ b/crates/ui2/src/components/tab_bar.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{Icon, IconButton, Tab}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct TabBar { id: ElementId, state_type: PhantomData, @@ -27,7 +27,7 @@ impl TabBar { self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let (can_navigate_back, can_navigate_forward) = self.can_navigate; @@ -100,7 +100,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct TabBarStory { state_type: PhantomData, } @@ -112,7 +112,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, TabBar>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/terminal.rs b/crates/ui2/src/components/terminal.rs index 55ab3e02fc..1f00a50685 100644 --- a/crates/ui2/src/components/terminal.rs +++ b/crates/ui2/src/components/terminal.rs @@ -5,7 +5,7 @@ use gpui2::{relative, rems, Size}; use crate::prelude::*; use crate::{Icon, IconButton, Pane, Tab}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Terminal { state_type: PhantomData, } @@ -17,7 +17,7 @@ impl Terminal { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let can_navigate_back = true; @@ -93,7 +93,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct TerminalStory { state_type: PhantomData, } @@ -105,7 +105,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, Terminal>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/theme_selector.rs b/crates/ui2/src/components/theme_selector.rs index 1851aea954..e0865c3bcb 100644 --- a/crates/ui2/src/components/theme_selector.rs +++ b/crates/ui2/src/components/theme_selector.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::prelude::*; use crate::{OrderMethod, Palette, PaletteItem}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct ThemeSelector { id: ElementId, state_type: PhantomData, @@ -17,7 +17,7 @@ impl ThemeSelector { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div().child( Palette::new(self.id.clone()) .items(vec![ @@ -49,7 +49,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct ThemeSelectorStory { state_type: PhantomData, } @@ -61,7 +61,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, ThemeSelector>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/title_bar.rs b/crates/ui2/src/components/title_bar.rs index a20c7877b2..2d080ac649 100644 --- a/crates/ui2/src/components/title_bar.rs +++ b/crates/ui2/src/components/title_bar.rs @@ -87,7 +87,7 @@ impl TitleBar { ) } - fn render(&mut self, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(&mut self, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let settings = user_settings(cx); @@ -204,7 +204,7 @@ mod stories { ) } - fn render(&mut self, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(&mut self, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, TitleBar>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/toast.rs b/crates/ui2/src/components/toast.rs index 268042144b..78bb467aa6 100644 --- a/crates/ui2/src/components/toast.rs +++ b/crates/ui2/src/components/toast.rs @@ -22,7 +22,7 @@ pub enum ToastOrigin { /// they are actively showing the a process in progress. /// /// Only one toast may be visible at a time. -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Toast { origin: ToastOrigin, children: SmallVec<[AnyElement; 2]>, @@ -36,7 +36,7 @@ impl Toast { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let mut div = div(); @@ -78,7 +78,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct ToastStory { state_type: PhantomData, } @@ -90,7 +90,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, Toast>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/toolbar.rs b/crates/ui2/src/components/toolbar.rs index e18c81314d..3f629f93ad 100644 --- a/crates/ui2/src/components/toolbar.rs +++ b/crates/ui2/src/components/toolbar.rs @@ -6,7 +6,7 @@ use crate::prelude::*; #[derive(Clone)] pub struct ToolbarItem {} -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Toolbar { left_items: SmallVec<[AnyElement; 2]>, right_items: SmallVec<[AnyElement; 2]>, @@ -20,41 +20,41 @@ impl Toolbar { } } - pub fn left_item(mut self, child: impl IntoAnyElement) -> Self + pub fn left_item(mut self, child: impl Component) -> Self where Self: Sized, { - self.left_items.push(child.into_any()); + self.left_items.push(child.render()); self } - pub fn left_items(mut self, iter: impl IntoIterator>) -> Self + pub fn left_items(mut self, iter: impl IntoIterator>) -> Self where Self: Sized, { self.left_items - .extend(iter.into_iter().map(|item| item.into_any())); + .extend(iter.into_iter().map(|item| item.render())); self } - pub fn right_item(mut self, child: impl IntoAnyElement) -> Self + pub fn right_item(mut self, child: impl Component) -> Self where Self: Sized, { - self.right_items.push(child.into_any()); + self.right_items.push(child.render()); self } - pub fn right_items(mut self, iter: impl IntoIterator>) -> Self + pub fn right_items(mut self, iter: impl IntoIterator>) -> Self where Self: Sized, { self.right_items - .extend(iter.into_iter().map(|item| item.into_any())); + .extend(iter.into_iter().map(|item| item.render())); self } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); div() @@ -80,7 +80,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct ToolbarStory { state_type: PhantomData, } @@ -92,7 +92,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); Story::container(cx) diff --git a/crates/ui2/src/components/traffic_lights.rs b/crates/ui2/src/components/traffic_lights.rs index cfe589b463..25b6d535c5 100644 --- a/crates/ui2/src/components/traffic_lights.rs +++ b/crates/ui2/src/components/traffic_lights.rs @@ -9,7 +9,7 @@ enum TrafficLightColor { Green, } -#[derive(IntoAnyElement)] +#[derive(Component)] struct TrafficLight { state_type: PhantomData, color: TrafficLightColor, @@ -25,7 +25,7 @@ impl TrafficLight { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let fill = match (self.window_has_focus, self.color) { @@ -39,7 +39,7 @@ impl TrafficLight { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct TrafficLights { state_type: PhantomData, window_has_focus: bool, @@ -58,7 +58,7 @@ impl TrafficLights { self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div() .flex() .items_center() @@ -87,7 +87,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct TrafficLightsStory { state_type: PhantomData, } @@ -99,7 +99,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, TrafficLights>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/components/workspace.rs b/crates/ui2/src/components/workspace.rs index 34158c9918..e979de6d7c 100644 --- a/crates/ui2/src/components/workspace.rs +++ b/crates/ui2/src/components/workspace.rs @@ -174,7 +174,7 @@ impl Workspace { view(cx.entity(|cx| Self::new(cx)), Self::render) } - pub fn render(&mut self, cx: &mut ViewContext) -> impl IntoAnyElement { + pub fn render(&mut self, cx: &mut ViewContext) -> impl Component { let theme = old_theme(cx).clone(); // HACK: This should happen inside of `debug_toggle_user_settings`, but diff --git a/crates/ui2/src/elements/avatar.rs b/crates/ui2/src/elements/avatar.rs index 7d2e91ae8c..53f3dab58a 100644 --- a/crates/ui2/src/elements/avatar.rs +++ b/crates/ui2/src/elements/avatar.rs @@ -4,7 +4,7 @@ use gpui2::img; use crate::prelude::*; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Avatar { state_type: PhantomData, src: SharedString, @@ -25,7 +25,7 @@ impl Avatar { self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let mut img = img(); @@ -51,7 +51,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct AvatarStory { state_type: PhantomData, } @@ -63,7 +63,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, Avatar>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/elements/button.rs b/crates/ui2/src/elements/button.rs index 843a786aff..7c4290bd54 100644 --- a/crates/ui2/src/elements/button.rs +++ b/crates/ui2/src/elements/button.rs @@ -61,7 +61,7 @@ impl Default for ButtonHandlers { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Button { state_type: PhantomData, disabled: bool, @@ -150,7 +150,7 @@ impl Button { self.icon.map(|i| IconElement::new(i).color(icon_color)) } - pub fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + pub fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let icon_color = self.icon_color(); let mut button = h_stack() @@ -193,7 +193,7 @@ impl Button { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct ButtonGroup { state_type: PhantomData, buttons: Vec>, @@ -207,7 +207,7 @@ impl ButtonGroup { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let mut el = h_stack().text_size(ui_size(cx, 1.)); for button in self.buttons { @@ -230,7 +230,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct ButtonStory { state_type: PhantomData, } @@ -242,7 +242,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let states = InteractionState::iter(); Story::container(cx) diff --git a/crates/ui2/src/elements/details.rs b/crates/ui2/src/elements/details.rs index 5f0676f9f4..84af82500b 100644 --- a/crates/ui2/src/elements/details.rs +++ b/crates/ui2/src/elements/details.rs @@ -2,7 +2,7 @@ use std::marker::PhantomData; use crate::{prelude::*, v_stack, ButtonGroup}; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Details { state_type: PhantomData, text: &'static str, @@ -30,7 +30,7 @@ impl Details { self } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); v_stack() @@ -54,7 +54,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct DetailsStory { state_type: PhantomData, } @@ -66,7 +66,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, Details>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/elements/icon.rs b/crates/ui2/src/elements/icon.rs index 18d6050dd1..a29202aca0 100644 --- a/crates/ui2/src/elements/icon.rs +++ b/crates/ui2/src/elements/icon.rs @@ -148,7 +148,7 @@ impl Icon { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct IconElement { state_type: PhantomData, icon: Icon, @@ -176,7 +176,7 @@ impl IconElement { self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let fill = self.color.color(cx); let svg_size = match self.size { IconSize::Small => ui_size(cx, 12. / 14.), @@ -202,7 +202,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct IconStory { state_type: PhantomData, } @@ -214,7 +214,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let icons = Icon::iter(); Story::container(cx) diff --git a/crates/ui2/src/elements/input.rs b/crates/ui2/src/elements/input.rs index 6a70c9cf79..d65dc62d65 100644 --- a/crates/ui2/src/elements/input.rs +++ b/crates/ui2/src/elements/input.rs @@ -11,7 +11,7 @@ pub enum InputVariant { Filled, } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Input { state_type: PhantomData, placeholder: SharedString, @@ -60,7 +60,7 @@ impl Input { self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let (input_bg, input_hover_bg, input_active_bg) = match self.variant { @@ -120,7 +120,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct InputStory { state_type: PhantomData, } @@ -132,7 +132,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, Input>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/elements/label.rs b/crates/ui2/src/elements/label.rs index 2d522a27b1..0910a59b55 100644 --- a/crates/ui2/src/elements/label.rs +++ b/crates/ui2/src/elements/label.rs @@ -48,7 +48,7 @@ pub enum LineHeightStyle { UILabel, } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct Label { state_type: PhantomData, label: SharedString, @@ -83,7 +83,7 @@ impl Label { self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div() .when(self.strikethrough, |this| { this.relative().child( @@ -105,7 +105,7 @@ impl Label { } } -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct HighlightedLabel { state_type: PhantomData, label: SharedString, @@ -135,7 +135,7 @@ impl HighlightedLabel { self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let highlight_color = theme.text_accent; @@ -211,7 +211,7 @@ mod stories { use super::*; - #[derive(IntoAnyElement)] + #[derive(Component)] pub struct LabelStory { state_type: PhantomData, } @@ -223,7 +223,7 @@ mod stories { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, Label>(cx)) .child(Story::label(cx, "Default")) diff --git a/crates/ui2/src/elements/tool_divider.rs b/crates/ui2/src/elements/tool_divider.rs index b388894d1a..1c80bca05e 100644 --- a/crates/ui2/src/elements/tool_divider.rs +++ b/crates/ui2/src/elements/tool_divider.rs @@ -2,7 +2,7 @@ use std::marker::PhantomData; use crate::prelude::*; -#[derive(IntoAnyElement)] +#[derive(Component)] pub struct ToolDivider { state_type: PhantomData, } @@ -14,7 +14,7 @@ impl ToolDivider { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); div().w_px().h_3().bg(theme.border) diff --git a/crates/ui2/src/prelude.rs b/crates/ui2/src/prelude.rs index 141c20c505..8098d3e40b 100644 --- a/crates/ui2/src/prelude.rs +++ b/crates/ui2/src/prelude.rs @@ -1,5 +1,5 @@ pub use gpui2::{ - div, Element, ElementId, IntoAnyElement, ParentElement, SharedString, StatefulInteractive, + div, Element, ElementId, Component, ParentElement, SharedString, StatefulInteractive, StatelessInteractive, Styled, ViewContext, WindowContext, }; diff --git a/crates/ui2/src/story.rs b/crates/ui2/src/story.rs index c4bf9c3caa..c35ddff0a9 100644 --- a/crates/ui2/src/story.rs +++ b/crates/ui2/src/story.rs @@ -21,7 +21,7 @@ impl Story { pub fn title( cx: &mut ViewContext, title: &str, - ) -> impl IntoAnyElement { + ) -> impl Component { let theme = theme(cx); div() @@ -30,16 +30,14 @@ impl Story { .child(title.to_owned()) } - pub fn title_for( - cx: &mut ViewContext, - ) -> impl IntoAnyElement { + pub fn title_for(cx: &mut ViewContext) -> impl Component { Self::title(cx, std::any::type_name::()) } pub fn label( cx: &mut ViewContext, label: &str, - ) -> impl IntoAnyElement { + ) -> impl Component { let theme = theme(cx); div() diff --git a/crates/ui2/src/theme.rs b/crates/ui2/src/theme.rs index b585140cf7..d8d924dbb0 100644 --- a/crates/ui2/src/theme.rs +++ b/crates/ui2/src/theme.rs @@ -1,5 +1,5 @@ use gpui2::{ - AnyElement, Bounds, Element, Hsla, IntoAnyElement, LayoutId, Pixels, Result, ViewContext, + AnyElement, Bounds, Component, Element, Hsla, LayoutId, Pixels, Result, ViewContext, WindowContext, }; use serde::{de::Visitor, Deserialize, Deserializer}; @@ -149,13 +149,13 @@ pub struct Themed { pub(crate) child: E, } -impl IntoAnyElement for Themed +impl Component for Themed where V: 'static, E: 'static + Element + Send + Sync, E::ElementState: Send + Sync, { - fn into_any(self) -> AnyElement { + fn render(self) -> AnyElement { AnyElement::new(self) } } From f4cff697297198a46c0a8387e45ed20fa1304097 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 26 Oct 2023 13:18:58 +0200 Subject: [PATCH 13/17] WIP: Macro not working fully yet --- crates/gpui2_macros/src/derive_component.rs | 22 +++++++++++++++++--- crates/ui2/src/components/assistant_panel.rs | 16 ++++++-------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/crates/gpui2_macros/src/derive_component.rs b/crates/gpui2_macros/src/derive_component.rs index 45f4b44c85..6c0384c95a 100644 --- a/crates/gpui2_macros/src/derive_component.rs +++ b/crates/gpui2_macros/src/derive_component.rs @@ -1,9 +1,21 @@ use proc_macro::TokenStream; use quote::quote; -use syn::{parse_macro_input, DeriveInput}; +use syn::{parse_macro_input, parse_quote, DeriveInput}; pub fn derive_component(input: TokenStream) -> TokenStream { - let ast = parse_macro_input!(input as DeriveInput); + let mut ast = parse_macro_input!(input as DeriveInput); + + if !ast + .generics + .params + .iter() + .any(|param| matches!(param, syn::GenericParam::Type(_))) + { + ast.generics.params.push(parse_quote! { + V: 'static + }); + } + let name = &ast.ident; let generics = &ast.generics; let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); @@ -37,7 +49,7 @@ pub fn derive_component(input: TokenStream) -> TokenStream { if let Some(syn::GenericParam::Type(type_param)) = generics.params.first() { type_param.ident.clone() } else { - panic!("Expected first type parameter"); + panic!("Expected first type parameter to be a view type"); } }); @@ -50,5 +62,9 @@ pub fn derive_component(input: TokenStream) -> TokenStream { } }; + if name == "AssistantPanelStory" { + println!("Expanded tokens: {}", expanded.to_string()); + } + TokenStream::from(expanded) } diff --git a/crates/ui2/src/components/assistant_panel.rs b/crates/ui2/src/components/assistant_panel.rs index c07723cedb..c5eeb22a4c 100644 --- a/crates/ui2/src/components/assistant_panel.rs +++ b/crates/ui2/src/components/assistant_panel.rs @@ -69,7 +69,7 @@ impl AssistantPanel { .overflow_y_scroll() .child(Label::new("Is this thing on?")), ) - .render()]) + .renderinto_any()]) .side(self.current_side) .width(AbsoluteLength::Rems(rems(32.))) } @@ -85,20 +85,16 @@ mod stories { use super::*; #[derive(Component)] - pub struct AssistantPanelStory { - state_type: PhantomData, - } + pub struct AssistantPanelStory {} - impl AssistantPanelStory { + impl AssistantPanelStory { pub fn new() -> Self { - Self { - state_type: PhantomData, - } + Self {} } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut V, cx: &mut ViewContext) -> impl Component { Story::container(cx) - .child(Story::title_for::<_, AssistantPanel>(cx)) + .child(Story::title_for::<_, AssistantPanel>(cx)) .child(Story::label(cx, "Default")) .child(AssistantPanel::new("assistant-panel")) } From c9c9db903d07c18c48fed86e3e9debb04783e54f Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Thu, 26 Oct 2023 14:20:25 +0200 Subject: [PATCH 14/17] Fix Component derive macro --- crates/gpui2_macros/src/derive_component.rs | 84 ++++++++++---------- crates/ui2/src/components/assistant_panel.rs | 4 +- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/crates/gpui2_macros/src/derive_component.rs b/crates/gpui2_macros/src/derive_component.rs index 6c0384c95a..97cfac1ae5 100644 --- a/crates/gpui2_macros/src/derive_component.rs +++ b/crates/gpui2_macros/src/derive_component.rs @@ -3,55 +3,29 @@ use quote::quote; use syn::{parse_macro_input, parse_quote, DeriveInput}; pub fn derive_component(input: TokenStream) -> TokenStream { - let mut ast = parse_macro_input!(input as DeriveInput); - - if !ast - .generics - .params - .iter() - .any(|param| matches!(param, syn::GenericParam::Type(_))) - { - ast.generics.params.push(parse_quote! { - V: 'static - }); - } - + let ast = parse_macro_input!(input as DeriveInput); let name = &ast.ident; - let generics = &ast.generics; - let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); - let specified_view_type = ast - .attrs - .iter() - .find(|attr| attr.path.is_ident("component")) - .and_then(|attr| { - if let Ok(syn::Meta::List(meta_list)) = attr.parse_meta() { - meta_list.nested.iter().find_map(|nested| { - if let syn::NestedMeta::Meta(syn::Meta::NameValue(nv)) = nested { - if nv.path.is_ident("view_type") { - if let syn::Lit::Str(lit_str) = &nv.lit { - return Some( - lit_str - .parse::() - .expect("Failed to parse view_type"), - ); - } - } - } - None - }) + let mut trait_generics = ast.generics.clone(); + let view_type = if let Some(view_type) = specified_view_type(&ast) { + quote! { #view_type } + } else { + if let Some(first_type_param) = ast.generics.params.iter().find_map(|param| { + if let syn::GenericParam::Type(type_param) = param { + Some(type_param.ident.clone()) } else { None } - }); - - let view_type = specified_view_type.unwrap_or_else(|| { - if let Some(syn::GenericParam::Type(type_param)) = generics.params.first() { - type_param.ident.clone() + }) { + quote! { #first_type_param } } else { - panic!("Expected first type parameter to be a view type"); + trait_generics.params.push(parse_quote! { V: 'static + Send + Sync }); + quote! { V } } - }); + }; + + let (impl_generics, _, where_clause) = trait_generics.split_for_impl(); + let (_, ty_generics, _) = ast.generics.split_for_impl(); let expanded = quote! { impl #impl_generics gpui2::Component<#view_type> for #name #ty_generics #where_clause { @@ -68,3 +42,29 @@ pub fn derive_component(input: TokenStream) -> TokenStream { TokenStream::from(expanded) } + +fn specified_view_type(ast: &DeriveInput) -> Option { + let component_attr = ast + .attrs + .iter() + .find(|attr| attr.path.is_ident("component"))?; + + if let Ok(syn::Meta::List(meta_list)) = component_attr.parse_meta() { + meta_list.nested.iter().find_map(|nested| { + if let syn::NestedMeta::Meta(syn::Meta::NameValue(nv)) = nested { + if nv.path.is_ident("view_type") { + if let syn::Lit::Str(lit_str) = &nv.lit { + return Some( + lit_str + .parse::() + .expect("Failed to parse view_type"), + ); + } + } + } + None + }) + } else { + None + } +} diff --git a/crates/ui2/src/components/assistant_panel.rs b/crates/ui2/src/components/assistant_panel.rs index c5eeb22a4c..25f24f1483 100644 --- a/crates/ui2/src/components/assistant_panel.rs +++ b/crates/ui2/src/components/assistant_panel.rs @@ -69,7 +69,7 @@ impl AssistantPanel { .overflow_y_scroll() .child(Label::new("Is this thing on?")), ) - .renderinto_any()]) + .render()]) .side(self.current_side) .width(AbsoluteLength::Rems(rems(32.))) } @@ -92,7 +92,7 @@ mod stories { Self {} } - fn render(self, _view: &mut V, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut V, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title_for::<_, AssistantPanel>(cx)) .child(Story::label(cx, "Default")) From 88ef74ec8f1ac1544e4b97544132df4d87f1f0d8 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Thu, 26 Oct 2023 15:20:38 +0200 Subject: [PATCH 15/17] Checkpoint: Compiling after view type removal --- crates/gpui2_macros/src/derive_component.rs | 2 +- crates/storybook2/src/stories/z_index.rs | 27 ++---- crates/ui2/src/components/assistant_panel.rs | 14 +-- crates/ui2/src/components/breadcrumb.rs | 26 ++---- crates/ui2/src/components/buffer.rs | 28 ++---- crates/ui2/src/components/chat_panel.rs | 34 +++---- crates/ui2/src/components/collab_panel.rs | 27 ++---- crates/ui2/src/components/command_palette.rs | 28 ++---- crates/ui2/src/components/context_menu.rs | 36 +++----- crates/ui2/src/components/copilot.rs | 28 ++---- crates/ui2/src/components/editor_pane.rs | 8 +- crates/ui2/src/components/facepile.rs | 24 ++--- crates/ui2/src/components/icon_button.rs | 16 +--- crates/ui2/src/components/keybinding.rs | 37 +++----- .../ui2/src/components/language_selector.rs | 28 ++---- crates/ui2/src/components/list.rs | 91 +++++++++---------- crates/ui2/src/components/modal.rs | 10 +- crates/ui2/src/components/multi_buffer.rs | 32 +++---- .../ui2/src/components/notification_toast.rs | 10 +- .../ui2/src/components/notifications_panel.rs | 23 ++--- crates/ui2/src/components/palette.rs | 38 +++----- crates/ui2/src/components/panel.rs | 22 ++--- crates/ui2/src/components/panes.rs | 9 +- crates/ui2/src/components/player_stack.rs | 10 +- crates/ui2/src/components/project_panel.rs | 28 ++---- crates/ui2/src/components/recent_projects.rs | 28 ++---- crates/ui2/src/components/tab.rs | 24 ++--- crates/ui2/src/components/tab_bar.rs | 28 ++---- crates/ui2/src/components/terminal.rs | 28 ++---- crates/ui2/src/components/theme_selector.rs | 28 ++---- crates/ui2/src/components/toast.rs | 20 ++-- crates/ui2/src/components/toolbar.rs | 19 ++-- crates/ui2/src/components/traffic_lights.rs | 32 +++---- crates/ui2/src/element_ext.rs | 4 +- crates/ui2/src/elements/avatar.rs | 24 ++--- crates/ui2/src/elements/button.rs | 50 +++++----- crates/ui2/src/elements/details.rs | 24 ++--- crates/ui2/src/elements/icon.rs | 24 ++--- crates/ui2/src/elements/input.rs | 24 ++--- crates/ui2/src/elements/label.rs | 32 +++---- crates/ui2/src/elements/stack.rs | 6 +- crates/ui2/src/elements/tool_divider.rs | 14 +-- crates/ui2/src/static_data.rs | 34 +++---- crates/ui2/src/story.rs | 8 +- 44 files changed, 392 insertions(+), 695 deletions(-) diff --git a/crates/gpui2_macros/src/derive_component.rs b/crates/gpui2_macros/src/derive_component.rs index 97cfac1ae5..f30ff3748f 100644 --- a/crates/gpui2_macros/src/derive_component.rs +++ b/crates/gpui2_macros/src/derive_component.rs @@ -19,7 +19,7 @@ pub fn derive_component(input: TokenStream) -> TokenStream { }) { quote! { #first_type_param } } else { - trait_generics.params.push(parse_quote! { V: 'static + Send + Sync }); + trait_generics.params.push(parse_quote! { V: 'static }); quote! { V } } }; diff --git a/crates/storybook2/src/stories/z_index.rs b/crates/storybook2/src/stories/z_index.rs index d68b4916c2..7fa078c4e3 100644 --- a/crates/storybook2/src/stories/z_index.rs +++ b/crates/storybook2/src/stories/z_index.rs @@ -1,4 +1,3 @@ -use std::marker::PhantomData; use gpui2::{px, rgb, Div, Hsla}; use ui::prelude::*; @@ -8,18 +7,14 @@ use crate::story::Story; /// A reimplementation of the MDN `z-index` example, found here: /// [https://developer.mozilla.org/en-US/docs/Web/CSS/z-index](https://developer.mozilla.org/en-US/docs/Web/CSS/z-index). #[derive(Component)] -pub struct ZIndexStory { - state_type: PhantomData, -} +pub struct ZIndexStory; -impl ZIndexStory { +impl ZIndexStory { pub fn new() -> Self { - Self { - state_type: PhantomData, - } + Self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title(cx, "z-index")) .child( @@ -86,23 +81,19 @@ trait Styles: Styled + Sized { } } -impl Styles for Div {} +impl Styles for Div {} #[derive(Component)] -struct ZIndexExample { - view_type: PhantomData, +struct ZIndexExample { z_index: u32, } -impl ZIndexExample { +impl ZIndexExample { pub fn new(z_index: u32) -> Self { - Self { - view_type: PhantomData, - z_index, - } + Self { z_index } } - fn render(self, _view: &mut V, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut V, cx: &mut ViewContext) -> impl Component { div() .relative() .size_full() diff --git a/crates/ui2/src/components/assistant_panel.rs b/crates/ui2/src/components/assistant_panel.rs index 25f24f1483..defd05f500 100644 --- a/crates/ui2/src/components/assistant_panel.rs +++ b/crates/ui2/src/components/assistant_panel.rs @@ -1,22 +1,18 @@ -use std::marker::PhantomData; - use gpui2::{rems, AbsoluteLength}; use crate::prelude::*; use crate::{Icon, IconButton, Label, Panel, PanelSide}; #[derive(Component)] -pub struct AssistantPanel { +pub struct AssistantPanel { id: ElementId, - state_type: PhantomData, current_side: PanelSide, } -impl AssistantPanel { +impl AssistantPanel { pub fn new(id: impl Into) -> Self { Self { id: id.into(), - state_type: PhantomData, current_side: PanelSide::default(), } } @@ -26,7 +22,7 @@ impl AssistantPanel { self } - fn render(self, view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, view: &mut V, cx: &mut ViewContext) -> impl Component { Panel::new(self.id.clone(), cx) .children(vec![div() .flex() @@ -92,9 +88,9 @@ mod stories { Self {} } - fn render(self, _view: &mut V, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut V, cx: &mut ViewContext) -> impl Component { Story::container(cx) - .child(Story::title_for::<_, AssistantPanel>(cx)) + .child(Story::title_for::<_, AssistantPanel>(cx)) .child(Story::label(cx, "Default")) .child(AssistantPanel::new("assistant-panel")) } diff --git a/crates/ui2/src/components/breadcrumb.rs b/crates/ui2/src/components/breadcrumb.rs index 289c071021..3cba3b7248 100644 --- a/crates/ui2/src/components/breadcrumb.rs +++ b/crates/ui2/src/components/breadcrumb.rs @@ -1,8 +1,6 @@ -use std::marker::PhantomData; use std::path::PathBuf; use gpui2::Div; - use crate::prelude::*; use crate::{h_stack, HighlightedText}; @@ -10,28 +8,26 @@ use crate::{h_stack, HighlightedText}; pub struct Symbol(pub Vec); #[derive(Component)] -pub struct Breadcrumb { - state_type: PhantomData, +pub struct Breadcrumb { path: PathBuf, symbols: Vec, } -impl Breadcrumb { +impl Breadcrumb { pub fn new(path: PathBuf, symbols: Vec) -> Self { Self { - state_type: PhantomData, path, symbols, } } - fn render_separator(&self, cx: &WindowContext) -> Div { + fn render_separator(&self, cx: &WindowContext) -> Div { let theme = theme(cx); div().child(" › ").text_color(theme.text_muted) } - fn render(self, view_state: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, view_state: &mut V, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let symbols_len = self.symbols.len(); @@ -87,22 +83,18 @@ mod stories { use super::*; #[derive(Component)] - pub struct BreadcrumbStory { - state_type: PhantomData, - } + pub struct BreadcrumbStory; - impl BreadcrumbStory { + impl BreadcrumbStory { pub fn new() -> Self { - Self { - state_type: PhantomData, - } + Self } - fn render(self, view_state: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, view_state: &mut V, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); Story::container(cx) - .child(Story::title_for::<_, Breadcrumb>(cx)) + .child(Story::title_for::<_, Breadcrumb>(cx)) .child(Story::label(cx, "Default")) .child(Breadcrumb::new( PathBuf::from_str("crates/ui/src/components/toolbar.rs").unwrap(), diff --git a/crates/ui2/src/components/buffer.rs b/crates/ui2/src/components/buffer.rs index ffef5c4039..b4ccb89b5c 100644 --- a/crates/ui2/src/components/buffer.rs +++ b/crates/ui2/src/components/buffer.rs @@ -1,5 +1,3 @@ -use std::marker::PhantomData; - use gpui2::{Hsla, WindowContext}; use crate::prelude::*; @@ -110,9 +108,8 @@ impl BufferRow { } #[derive(Component, Clone)] -pub struct Buffer { +pub struct Buffer { id: ElementId, - state_type: PhantomData, rows: Option, readonly: bool, language: Option, @@ -120,11 +117,10 @@ pub struct Buffer { path: Option, } -impl Buffer { +impl Buffer { pub fn new(id: impl Into) -> Self { Self { id: id.into(), - state_type: PhantomData, rows: Some(BufferRows::default()), readonly: false, language: None, @@ -158,7 +154,7 @@ impl Buffer { self } - fn render_row(row: BufferRow, cx: &WindowContext) -> impl Component { + fn render_row(row: BufferRow, cx: &WindowContext) -> impl Component { let theme = theme(cx); let line_background = if row.current { @@ -208,7 +204,7 @@ impl Buffer { })) } - fn render_rows(&self, cx: &WindowContext) -> Vec> { + fn render_rows(&self, cx: &WindowContext) -> Vec> { match &self.rows { Some(rows) => rows .rows @@ -219,7 +215,7 @@ impl Buffer { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let rows = self.render_rows(cx); @@ -247,22 +243,18 @@ mod stories { use super::*; #[derive(Component)] - pub struct BufferStory { - state_type: PhantomData, - } + pub struct BufferStory; - impl BufferStory { + impl BufferStory { pub fn new() -> Self { - Self { - state_type: PhantomData, - } + Self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); Story::container(cx) - .child(Story::title_for::<_, Buffer>(cx)) + .child(Story::title_for::<_, Buffer>(cx)) .child(Story::label(cx, "Default")) .child(div().w(rems(64.)).h_96().child(empty_buffer_example())) .child(Story::label(cx, "Hello World (Rust)")) diff --git a/crates/ui2/src/components/chat_panel.rs b/crates/ui2/src/components/chat_panel.rs index 2800207b34..e4494f4614 100644 --- a/crates/ui2/src/components/chat_panel.rs +++ b/crates/ui2/src/components/chat_panel.rs @@ -1,17 +1,15 @@ -use std::marker::PhantomData; - use chrono::NaiveDateTime; use crate::prelude::*; use crate::{Icon, IconButton, Input, Label, LabelColor}; #[derive(Component)] -pub struct ChatPanel { +pub struct ChatPanel { element_id: ElementId, - messages: Vec>, + messages: Vec, } -impl ChatPanel { +impl ChatPanel { pub fn new(element_id: impl Into) -> Self { Self { element_id: element_id.into(), @@ -19,12 +17,12 @@ impl ChatPanel { } } - pub fn messages(mut self, messages: Vec>) -> Self { + pub fn messages(mut self, messages: Vec) -> Self { self.messages = messages; self } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div() .id(self.element_id.clone()) .flex() @@ -71,24 +69,22 @@ impl ChatPanel { } #[derive(Component)] -pub struct ChatMessage { - state_type: PhantomData, +pub struct ChatMessage { author: String, text: String, sent_at: NaiveDateTime, } -impl ChatMessage { +impl ChatMessage { pub fn new(author: String, text: String, sent_at: NaiveDateTime) -> Self { Self { - state_type: PhantomData, author, text, sent_at, } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div() .flex() .flex_col() @@ -118,20 +114,16 @@ mod stories { use super::*; #[derive(Component)] - pub struct ChatPanelStory { - state_type: PhantomData, - } + pub struct ChatPanelStory; - impl ChatPanelStory { + impl ChatPanelStory { pub fn new() -> Self { - Self { - state_type: PhantomData, - } + Self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) - .child(Story::title_for::<_, ChatPanel>(cx)) + .child(Story::title_for::<_, ChatPanel>(cx)) .child(Story::label(cx, "Default")) .child( Panel::new("chat-panel-1-outer", cx) diff --git a/crates/ui2/src/components/collab_panel.rs b/crates/ui2/src/components/collab_panel.rs index 8f30b33da0..6d2cbd8e14 100644 --- a/crates/ui2/src/components/collab_panel.rs +++ b/crates/ui2/src/components/collab_panel.rs @@ -3,23 +3,18 @@ use crate::{ static_collab_panel_channels, static_collab_panel_current_call, v_stack, Icon, List, ListHeader, ToggleState, }; -use std::marker::PhantomData; #[derive(Component)] -pub struct CollabPanel { +pub struct CollabPanel { id: ElementId, - state_type: PhantomData, } -impl CollabPanel { +impl CollabPanel { pub fn new(id: impl Into) -> Self { - Self { - id: id.into(), - state_type: PhantomData, - } + Self { id: id.into() } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); v_stack() @@ -99,20 +94,16 @@ mod stories { use super::*; #[derive(Component)] - pub struct CollabPanelStory { - state_type: PhantomData, - } + pub struct CollabPanelStory; - impl CollabPanelStory { + impl CollabPanelStory { pub fn new() -> Self { - Self { - state_type: PhantomData, - } + Self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) - .child(Story::title_for::<_, CollabPanel>(cx)) + .child(Story::title_for::<_, CollabPanel>(cx)) .child(Story::label(cx, "Default")) .child(CollabPanel::new("collab-panel")) } diff --git a/crates/ui2/src/components/command_palette.rs b/crates/ui2/src/components/command_palette.rs index d00b9b7743..065ee9a052 100644 --- a/crates/ui2/src/components/command_palette.rs +++ b/crates/ui2/src/components/command_palette.rs @@ -1,23 +1,17 @@ -use std::marker::PhantomData; - use crate::prelude::*; use crate::{example_editor_actions, OrderMethod, Palette}; #[derive(Component)] -pub struct CommandPalette { +pub struct CommandPalette { id: ElementId, - state_type: PhantomData, } -impl CommandPalette { +impl CommandPalette { pub fn new(id: impl Into) -> Self { - Self { - id: id.into(), - state_type: PhantomData, - } + Self { id: id.into() } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div().id(self.id.clone()).child( Palette::new("palette") .items(example_editor_actions()) @@ -38,20 +32,16 @@ mod stories { use super::*; #[derive(Component)] - pub struct CommandPaletteStory { - state_type: PhantomData, - } + pub struct CommandPaletteStory; - impl CommandPaletteStory { + impl CommandPaletteStory { pub fn new() -> Self { - Self { - state_type: PhantomData, - } + Self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) - .child(Story::title_for::<_, CommandPalette>(cx)) + .child(Story::title_for::<_, CommandPalette>(cx)) .child(Story::label(cx, "Default")) .child(CommandPalette::new("command-palette")) } diff --git a/crates/ui2/src/components/context_menu.rs b/crates/ui2/src/components/context_menu.rs index b52051daa3..3e0323d942 100644 --- a/crates/ui2/src/components/context_menu.rs +++ b/crates/ui2/src/components/context_menu.rs @@ -1,14 +1,14 @@ use crate::{prelude::*, ListItemVariant}; use crate::{v_stack, Label, List, ListEntry, ListItem, ListSeparator, ListSubHeader}; -pub enum ContextMenuItem { +pub enum ContextMenuItem { Header(SharedString), - Entry(Label), + Entry(Label), Separator, } -impl ContextMenuItem { - fn to_list_item(self) -> ListItem { +impl ContextMenuItem { + fn to_list_item(self) -> ListItem { match self { ContextMenuItem::Header(label) => ListSubHeader::new(label).into(), ContextMenuItem::Entry(label) => { @@ -26,23 +26,23 @@ impl ContextMenuItem { Self::Separator } - pub fn entry(label: Label) -> Self { + pub fn entry(label: Label) -> Self { Self::Entry(label) } } #[derive(Component)] -pub struct ContextMenu { - items: Vec>, +pub struct ContextMenu { + items: Vec, } -impl ContextMenu { - pub fn new(items: impl IntoIterator>) -> Self { +impl ContextMenu { + pub fn new(items: impl IntoIterator) -> Self { Self { items: items.into_iter().collect(), } } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); v_stack() @@ -67,27 +67,21 @@ pub use stories::*; #[cfg(feature = "stories")] mod stories { - use std::marker::PhantomData; - use crate::story::Story; use super::*; #[derive(Component)] - pub struct ContextMenuStory { - state_type: PhantomData, - } + pub struct ContextMenuStory; - impl ContextMenuStory { + impl ContextMenuStory { pub fn new() -> Self { - Self { - state_type: PhantomData, - } + Self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) - .child(Story::title_for::<_, ContextMenu>(cx)) + .child(Story::title_for::<_, ContextMenu>(cx)) .child(Story::label(cx, "Default")) .child(ContextMenu::new([ ContextMenuItem::header("Section header"), diff --git a/crates/ui2/src/components/copilot.rs b/crates/ui2/src/components/copilot.rs index 9e5454ee8a..3c48ef20d0 100644 --- a/crates/ui2/src/components/copilot.rs +++ b/crates/ui2/src/components/copilot.rs @@ -1,22 +1,16 @@ -use std::marker::PhantomData; - use crate::{prelude::*, Button, Label, LabelColor, Modal}; #[derive(Component)] -pub struct CopilotModal { +pub struct CopilotModal { id: ElementId, - state_type: PhantomData, } -impl CopilotModal { +impl CopilotModal { pub fn new(id: impl Into) -> Self { - Self { - id: id.into(), - state_type: PhantomData, - } + Self { id: id.into() } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div().id(self.id.clone()).child( Modal::new("some-id") .title("Connect Copilot to Zed") @@ -36,20 +30,16 @@ mod stories { use super::*; #[derive(Component)] - pub struct CopilotModalStory { - state_type: PhantomData, - } + pub struct CopilotModalStory; - impl CopilotModalStory { + impl CopilotModalStory { pub fn new() -> Self { - Self { - state_type: PhantomData, - } + Self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) - .child(Story::title_for::<_, CopilotModal>(cx)) + .child(Story::title_for::<_, CopilotModal>(cx)) .child(Story::label(cx, "Default")) .child(CopilotModal::new("copilot-modal")) } diff --git a/crates/ui2/src/components/editor_pane.rs b/crates/ui2/src/components/editor_pane.rs index fb26dad791..9c9638d057 100644 --- a/crates/ui2/src/components/editor_pane.rs +++ b/crates/ui2/src/components/editor_pane.rs @@ -10,10 +10,10 @@ use crate::{ #[derive(Clone)] pub struct EditorPane { - tabs: Vec>, + tabs: Vec, path: PathBuf, symbols: Vec, - buffer: Buffer, + buffer: Buffer, buffer_search: View, is_buffer_search_open: bool, } @@ -21,10 +21,10 @@ pub struct EditorPane { impl EditorPane { pub fn new( cx: &mut WindowContext, - tabs: Vec>, + tabs: Vec, path: PathBuf, symbols: Vec, - buffer: Buffer, + buffer: Buffer, ) -> Self { Self { tabs, diff --git a/crates/ui2/src/components/facepile.rs b/crates/ui2/src/components/facepile.rs index 565396e733..898489f1ed 100644 --- a/crates/ui2/src/components/facepile.rs +++ b/crates/ui2/src/components/facepile.rs @@ -1,23 +1,19 @@ -use std::marker::PhantomData; - use crate::prelude::*; use crate::{Avatar, Player}; #[derive(Component)] -pub struct Facepile { - state_type: PhantomData, +pub struct Facepile { players: Vec, } -impl Facepile { +impl Facepile { pub fn new>(players: P) -> Self { Self { - state_type: PhantomData, players: players.collect(), } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let player_count = self.players.len(); let player_list = self.players.iter().enumerate().map(|(ix, player)| { let isnt_last = ix < player_count - 1; @@ -40,22 +36,18 @@ mod stories { use super::*; #[derive(Component)] - pub struct FacepileStory { - state_type: PhantomData, - } + pub struct FacepileStory; - impl FacepileStory { + impl FacepileStory { pub fn new() -> Self { - Self { - state_type: PhantomData, - } + Self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let players = static_players(); Story::container(cx) - .child(Story::title_for::<_, Facepile>(cx)) + .child(Story::title_for::<_, Facepile>(cx)) .child(Story::label(cx, "Default")) .child( div() diff --git a/crates/ui2/src/components/icon_button.rs b/crates/ui2/src/components/icon_button.rs index fe41de15a0..2891ce6bd8 100644 --- a/crates/ui2/src/components/icon_button.rs +++ b/crates/ui2/src/components/icon_button.rs @@ -1,4 +1,3 @@ -use std::marker::PhantomData; use std::sync::Arc; use gpui2::MouseButton; @@ -6,19 +5,18 @@ use gpui2::MouseButton; use crate::{h_stack, prelude::*}; use crate::{ClickHandler, Icon, IconColor, IconElement}; -struct IconButtonHandlers { +struct IconButtonHandlers { click: Option>, } -impl Default for IconButtonHandlers { +impl Default for IconButtonHandlers { fn default() -> Self { Self { click: None } } } #[derive(Component)] -pub struct IconButton { - state_type: PhantomData, +pub struct IconButton { id: ElementId, icon: Icon, color: IconColor, @@ -27,10 +25,9 @@ pub struct IconButton { handlers: IconButtonHandlers, } -impl IconButton { +impl IconButton { pub fn new(id: impl Into, icon: Icon) -> Self { Self { - state_type: PhantomData, id: id.into(), icon, color: IconColor::default(), @@ -60,10 +57,7 @@ impl IconButton { self } - pub fn on_click( - mut self, - handler: impl Fn(&mut S, &mut ViewContext) + 'static + Send + Sync, - ) -> Self { + pub fn on_click(mut self, handler: impl 'static + Fn(&mut S, &mut ViewContext) + Send + Sync) -> Self { self.handlers.click = Some(Arc::new(handler)); self } diff --git a/crates/ui2/src/components/keybinding.rs b/crates/ui2/src/components/keybinding.rs index d77798ad6c..2b0eefa4ea 100644 --- a/crates/ui2/src/components/keybinding.rs +++ b/crates/ui2/src/components/keybinding.rs @@ -1,14 +1,11 @@ use std::collections::HashSet; -use std::marker::PhantomData; use strum::{EnumIter, IntoEnumIterator}; use crate::prelude::*; #[derive(Component)] -pub struct Keybinding { - state_type: PhantomData, - +pub struct Keybinding { /// A keybinding consists of a key and a set of modifier keys. /// More then one keybinding produces a chord. /// @@ -16,10 +13,9 @@ pub struct Keybinding { keybinding: Vec<(String, ModifierKeys)>, } -impl Keybinding { +impl Keybinding { pub fn new(key: String, modifiers: ModifierKeys) -> Self { Self { - state_type: PhantomData, keybinding: vec![(key, modifiers)], } } @@ -29,12 +25,11 @@ impl Keybinding { second_note: (String, ModifierKeys), ) -> Self { Self { - state_type: PhantomData, keybinding: vec![first_note, second_note], } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div() .flex() .gap_2() @@ -55,20 +50,16 @@ impl Keybinding { } #[derive(Component)] -pub struct Key { - state_type: PhantomData, +pub struct Key { key: SharedString, } -impl Key { +impl Key { pub fn new(key: impl Into) -> Self { - Self { - state_type: PhantomData, - key: key.into(), - } + Self { key: key.into() } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); div() @@ -174,22 +165,18 @@ mod stories { use super::*; #[derive(Component)] - pub struct KeybindingStory { - state_type: PhantomData, - } + pub struct KeybindingStory; - impl KeybindingStory { + impl KeybindingStory { pub fn new() -> Self { - Self { - state_type: PhantomData, - } + Self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut V, cx: &mut ViewContext) -> impl Component { let all_modifier_permutations = ModifierKey::iter().permutations(2); Story::container(cx) - .child(Story::title_for::<_, Keybinding>(cx)) + .child(Story::title_for::<_, Keybinding>(cx)) .child(Story::label(cx, "Single Key")) .child(Keybinding::new("Z".to_string(), ModifierKeys::new())) .child(Story::label(cx, "Single Key with Modifier")) diff --git a/crates/ui2/src/components/language_selector.rs b/crates/ui2/src/components/language_selector.rs index ebb8f152f8..db42b28281 100644 --- a/crates/ui2/src/components/language_selector.rs +++ b/crates/ui2/src/components/language_selector.rs @@ -1,23 +1,17 @@ -use std::marker::PhantomData; - use crate::prelude::*; use crate::{OrderMethod, Palette, PaletteItem}; #[derive(Component)] -pub struct LanguageSelector { +pub struct LanguageSelector { id: ElementId, - state_type: PhantomData, } -impl LanguageSelector { +impl LanguageSelector { pub fn new(id: impl Into) -> Self { - Self { - id: id.into(), - state_type: PhantomData, - } + Self { id: id.into() } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div().id(self.id.clone()).child( Palette::new("palette") .items(vec![ @@ -49,20 +43,16 @@ mod stories { use super::*; #[derive(Component)] - pub struct LanguageSelectorStory { - state_type: PhantomData, - } + pub struct LanguageSelectorStory; - impl LanguageSelectorStory { + impl LanguageSelectorStory { pub fn new() -> Self { - Self { - state_type: PhantomData, - } + Self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) - .child(Story::title_for::<_, LanguageSelector>(cx)) + .child(Story::title_for::<_, LanguageSelector>(cx)) .child(Story::label(cx, "Default")) .child(LanguageSelector::new("language-selector")) } diff --git a/crates/ui2/src/components/list.rs b/crates/ui2/src/components/list.rs index b1b3f506ea..0bf413e217 100644 --- a/crates/ui2/src/components/list.rs +++ b/crates/ui2/src/components/list.rs @@ -1,5 +1,3 @@ -use std::marker::PhantomData; - use gpui2::{div, relative, Div}; use crate::settings::user_settings; @@ -18,8 +16,7 @@ pub enum ListItemVariant { } #[derive(Component)] -pub struct ListHeader { - state_type: PhantomData, +pub struct ListHeader { label: SharedString, left_icon: Option, variant: ListItemVariant, @@ -27,10 +24,9 @@ pub struct ListHeader { toggleable: Toggleable, } -impl ListHeader { +impl ListHeader { pub fn new(label: impl Into) -> Self { Self { - state_type: PhantomData, label: label.into(), left_icon: None, variant: ListItemVariant::default(), @@ -59,7 +55,7 @@ impl ListHeader { self } - fn disclosure_control(&self) -> Div { + fn disclosure_control(&self) -> Div { let is_toggleable = self.toggleable != Toggleable::NotToggleable; let is_toggled = Toggleable::is_toggled(&self.toggleable); @@ -92,7 +88,7 @@ impl ListHeader { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let is_toggleable = self.toggleable != Toggleable::NotToggleable; @@ -135,17 +131,15 @@ impl ListHeader { } #[derive(Component)] -pub struct ListSubHeader { - state_type: PhantomData, +pub struct ListSubHeader { label: SharedString, left_icon: Option, variant: ListItemVariant, } -impl ListSubHeader { +impl ListSubHeader { pub fn new(label: impl Into) -> Self { Self { - state_type: PhantomData, label: label.into(), left_icon: None, variant: ListItemVariant::default(), @@ -157,7 +151,7 @@ impl ListSubHeader { self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { h_stack().flex_1().w_full().relative().py_1().child( div() .h_6() @@ -198,38 +192,38 @@ pub enum ListEntrySize { } #[derive(Component)] -pub enum ListItem { - Entry(ListEntry), +pub enum ListItem { + Entry(ListEntry), Details(ListDetailsEntry), - Separator(ListSeparator), - Header(ListSubHeader), + Separator(ListSeparator), + Header(ListSubHeader), } -impl From> for ListItem { - fn from(entry: ListEntry) -> Self { +impl From for ListItem { + fn from(entry: ListEntry) -> Self { Self::Entry(entry) } } -impl From> for ListItem { +impl From> for ListItem { fn from(entry: ListDetailsEntry) -> Self { Self::Details(entry) } } -impl From> for ListItem { - fn from(entry: ListSeparator) -> Self { +impl From for ListItem { + fn from(entry: ListSeparator) -> Self { Self::Separator(entry) } } -impl From> for ListItem { - fn from(entry: ListSubHeader) -> Self { +impl From for ListItem { + fn from(entry: ListSubHeader) -> Self { Self::Header(entry) } } -impl ListItem { +impl ListItem { fn render(self, view: &mut S, cx: &mut ViewContext) -> impl Component { match self { ListItem::Entry(entry) => div().child(entry.render(view, cx)), @@ -239,11 +233,11 @@ impl ListItem { } } - pub fn new(label: Label) -> Self { + pub fn new(label: Label) -> Self { Self::Entry(ListEntry::new(label)) } - pub fn as_entry(&mut self) -> Option<&mut ListEntry> { + pub fn as_entry(&mut self) -> Option<&mut ListEntry> { if let Self::Entry(entry) = self { Some(entry) } else { @@ -253,10 +247,10 @@ impl ListItem { } #[derive(Component)] -pub struct ListEntry { +pub struct ListEntry { disclosure_control_style: DisclosureControlVisibility, indent_level: u32, - label: Option>, + label: Option