Merge branch 'remove-view-state-associated-type' into gpui2-element-renderer

This commit is contained in:
Marshall Bowers 2023-10-26 10:10:17 +02:00
commit e31a9401a8
58 changed files with 240 additions and 305 deletions

View file

@ -3,36 +3,35 @@ use derive_more::{Deref, DerefMut};
pub(crate) use smallvec::SmallVec; pub(crate) use smallvec::SmallVec;
use std::{any::Any, mem}; use std::{any::Any, mem};
pub trait Element: IntoAnyElement<Self::ViewState> { pub trait Element<V: 'static>: IntoAnyElement<V> {
type ViewState: 'static;
type ElementState: 'static; type ElementState: 'static;
fn id(&self) -> Option<ElementId>; fn id(&self) -> Option<ElementId>;
fn initialize( fn initialize(
&mut self, &mut self,
view_state: &mut Self::ViewState, view_state: &mut V,
element_state: Option<Self::ElementState>, element_state: Option<Self::ElementState>,
cx: &mut ViewContext<Self::ViewState>, cx: &mut ViewContext<V>,
) -> Self::ElementState; ) -> Self::ElementState;
// where // where
// Self::ViewState: Any + Send + Sync; // V: Any + Send + Sync;
fn layout( fn layout(
&mut self, &mut self,
view_state: &mut Self::ViewState, view_state: &mut V,
element_state: &mut Self::ElementState, element_state: &mut Self::ElementState,
cx: &mut ViewContext<Self::ViewState>, cx: &mut ViewContext<V>,
) -> LayoutId; ) -> LayoutId;
// where // where
// Self::ViewState: Any + Send + Sync; // V: Any + Send + Sync;
fn paint( fn paint(
&mut self, &mut self,
bounds: Bounds<Pixels>, bounds: Bounds<Pixels>,
view_state: &mut Self::ViewState, view_state: &mut V,
element_state: &mut Self::ElementState, element_state: &mut Self::ElementState,
cx: &mut ViewContext<Self::ViewState>, cx: &mut ViewContext<V>,
); );
// where // where
@ -42,10 +41,10 @@ pub trait Element: IntoAnyElement<Self::ViewState> {
#[derive(Deref, DerefMut, Default, Clone, Debug, Eq, PartialEq, Hash)] #[derive(Deref, DerefMut, Default, Clone, Debug, Eq, PartialEq, Hash)]
pub struct GlobalElementId(SmallVec<[ElementId; 32]>); pub struct GlobalElementId(SmallVec<[ElementId; 32]>);
pub trait ParentElement: Element { pub trait ParentElement<V: 'static>: Element<V> {
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<Self::ViewState>; 2]>; fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<V>; 2]>;
fn child(mut self, child: impl IntoAnyElement<Self::ViewState>) -> Self fn child(mut self, child: impl IntoAnyElement<V>) -> Self
where where
Self: Sized, Self: Sized,
{ {
@ -53,10 +52,7 @@ pub trait ParentElement: Element {
self self
} }
fn children( fn children(mut self, iter: impl IntoIterator<Item = impl IntoAnyElement<V>>) -> Self
mut self,
iter: impl IntoIterator<Item = impl IntoAnyElement<Self::ViewState>>,
) -> Self
where where
Self: Sized, Self: Sized,
{ {
@ -72,7 +68,7 @@ trait ElementObject<V> {
fn paint(&mut self, view_state: &mut V, cx: &mut ViewContext<V>); fn paint(&mut self, view_state: &mut V, cx: &mut ViewContext<V>);
} }
struct RenderedElement<E: Element> { struct RenderedElement<V: 'static, E: Element<V>> {
element: E, element: E,
phase: ElementRenderPhase<E::ElementState>, phase: ElementRenderPhase<E::ElementState>,
} }
@ -94,7 +90,7 @@ enum ElementRenderPhase<V> {
/// Internal struct that wraps an element to store Layout and ElementState after the element is rendered. /// 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<E::State> for /// It's allocated as a trait object to erase the element type and wrapped in AnyElement<E::State> for
/// improved usability. /// improved usability.
impl<E: Element> RenderedElement<E> { impl<V, E: Element<V>> RenderedElement<V, E> {
fn new(element: E) -> Self { fn new(element: E) -> Self {
RenderedElement { RenderedElement {
element, element,
@ -103,13 +99,13 @@ impl<E: Element> RenderedElement<E> {
} }
} }
impl<E> ElementObject<E::ViewState> for RenderedElement<E> impl<V, E> ElementObject<V> for RenderedElement<V, E>
where where
E: Element, E: Element<V>,
// E::ViewState: Any + Send + Sync, // E::ViewState: Any + Send + Sync,
E::ElementState: Any + Send + Sync, E::ElementState: Any + Send + Sync,
{ {
fn initialize(&mut self, view_state: &mut E::ViewState, cx: &mut ViewContext<E::ViewState>) { fn initialize(&mut self, view_state: &mut V, cx: &mut ViewContext<V>) {
let frame_state = if let Some(id) = self.element.id() { let frame_state = if let Some(id) = self.element.id() {
cx.with_element_state(id, |element_state, cx| { cx.with_element_state(id, |element_state, cx| {
let element_state = self.element.initialize(view_state, 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 }; self.phase = ElementRenderPhase::Initialized { frame_state };
} }
fn layout(&mut self, state: &mut E::ViewState, cx: &mut ViewContext<E::ViewState>) -> LayoutId { fn layout(&mut self, state: &mut V, cx: &mut ViewContext<V>) -> LayoutId {
let layout_id; let layout_id;
let mut frame_state; let mut frame_state;
match mem::take(&mut self.phase) { match mem::take(&mut self.phase) {
@ -154,7 +150,7 @@ where
layout_id layout_id
} }
fn paint(&mut self, view_state: &mut E::ViewState, cx: &mut ViewContext<E::ViewState>) { fn paint(&mut self, view_state: &mut V, cx: &mut ViewContext<V>) {
self.phase = match mem::take(&mut self.phase) { self.phase = match mem::take(&mut self.phase) {
ElementRenderPhase::LayoutRequested { ElementRenderPhase::LayoutRequested {
layout_id, layout_id,
@ -185,8 +181,9 @@ pub struct AnyElement<V>(Box<dyn ElementObject<V> + Send + Sync>);
impl<V> AnyElement<V> { impl<V> AnyElement<V> {
pub fn new<E>(element: E) -> Self pub fn new<E>(element: E) -> Self
where where
V: 'static,
E: 'static + Send + Sync, E: 'static + Send + Sync,
E: Element<ViewState = V>, E: Element<V>,
E::ElementState: Any + Send + Sync, E::ElementState: Any + Send + Sync,
{ {
AnyElement(Box::new(RenderedElement::new(element))) AnyElement(Box::new(RenderedElement::new(element)))

View file

@ -160,7 +160,7 @@ impl<V: 'static> Div<V, StatelessInteraction<V>, FocusDisabled> {
} }
} }
impl<V, I> Focusable for Div<V, I, FocusEnabled<V>> impl<V, I> Focusable<V> for Div<V, I, FocusEnabled<V>>
where where
V: 'static, V: 'static,
I: ElementInteraction<V>, I: ElementInteraction<V>,
@ -189,12 +189,11 @@ pub struct DivState {
child_layout_ids: SmallVec<[LayoutId; 4]>, child_layout_ids: SmallVec<[LayoutId; 4]>,
} }
impl<V, I, F> Element for Div<V, I, F> impl<V, I, F> Element<V> for Div<V, I, F>
where where
I: ElementInteraction<V>, I: ElementInteraction<V>,
F: ElementFocus<V>, F: ElementFocus<V>,
{ {
type ViewState = V;
type ElementState = DivState; type ElementState = DivState;
fn id(&self) -> Option<ElementId> { fn id(&self) -> Option<ElementId> {
@ -205,9 +204,9 @@ where
fn initialize( fn initialize(
&mut self, &mut self,
view_state: &mut Self::ViewState, view_state: &mut V,
element_state: Option<Self::ElementState>, element_state: Option<Self::ElementState>,
cx: &mut ViewContext<Self::ViewState>, cx: &mut ViewContext<V>,
) -> Self::ElementState { ) -> Self::ElementState {
let mut element_state = element_state.unwrap_or_default(); let mut element_state = element_state.unwrap_or_default();
self.focus self.focus
@ -224,9 +223,9 @@ where
fn layout( fn layout(
&mut self, &mut self,
view_state: &mut Self::ViewState, view_state: &mut V,
element_state: &mut Self::ElementState, element_state: &mut Self::ElementState,
cx: &mut ViewContext<Self::ViewState>, cx: &mut ViewContext<V>,
) -> LayoutId { ) -> LayoutId {
let style = self.compute_style(Bounds::default(), element_state, cx); let style = self.compute_style(Bounds::default(), element_state, cx);
style.apply_text_style(cx, |cx| { style.apply_text_style(cx, |cx| {
@ -245,9 +244,9 @@ where
fn paint( fn paint(
&mut self, &mut self,
bounds: Bounds<Pixels>, bounds: Bounds<Pixels>,
view_state: &mut Self::ViewState, view_state: &mut V,
element_state: &mut Self::ElementState, element_state: &mut Self::ElementState,
cx: &mut ViewContext<Self::ViewState>, cx: &mut ViewContext<V>,
) { ) {
self.with_element_id(cx, |this, _global_id, cx| { self.with_element_id(cx, |this, _global_id, cx| {
if let Some(group) = this.group.clone() { if let Some(group) = this.group.clone() {
@ -315,12 +314,12 @@ where
} }
} }
impl<V, I, F> ParentElement for Div<V, I, F> impl<V, I, F> ParentElement<V> for Div<V, I, F>
where where
I: ElementInteraction<V>, I: ElementInteraction<V>,
F: ElementFocus<V>, F: ElementFocus<V>,
{ {
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<Self::ViewState>; 2]> { fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<V>; 2]> {
&mut self.children &mut self.children
} }
} }
@ -335,7 +334,7 @@ where
} }
} }
impl<V, I, F> StatelessInteractive for Div<V, I, F> impl<V, I, F> StatelessInteractive<V> for Div<V, I, F>
where where
I: ElementInteraction<V>, I: ElementInteraction<V>,
F: ElementFocus<V>, F: ElementFocus<V>,
@ -345,11 +344,11 @@ where
} }
} }
impl<V, F> StatefulInteractive for Div<V, StatefulInteraction<V>, F> impl<V, F> StatefulInteractive<V> for Div<V, StatefulInteraction<V>, F>
where where
F: ElementFocus<V>, F: ElementFocus<V>,
{ {
fn stateful_interaction(&mut self) -> &mut StatefulInteraction<Self::ViewState> { fn stateful_interaction(&mut self) -> &mut StatefulInteraction<V> {
&mut self.interaction &mut self.interaction
} }
} }

View file

@ -65,12 +65,11 @@ where
} }
} }
impl<V, I, F> Element for Img<V, I, F> impl<V, I, F> Element<V> for Img<V, I, F>
where where
I: ElementInteraction<V>, I: ElementInteraction<V>,
F: ElementFocus<V>, F: ElementFocus<V>,
{ {
type ViewState = V;
type ElementState = DivState; type ElementState = DivState;
fn id(&self) -> Option<crate::ElementId> { fn id(&self) -> Option<crate::ElementId> {
@ -90,7 +89,7 @@ where
&mut self, &mut self,
view_state: &mut V, view_state: &mut V,
element_state: &mut Self::ElementState, element_state: &mut Self::ElementState,
cx: &mut ViewContext<Self::ViewState>, cx: &mut ViewContext<V>,
) -> LayoutId { ) -> LayoutId {
self.base.layout(view_state, element_state, cx) self.base.layout(view_state, element_state, cx)
} }
@ -143,7 +142,7 @@ where
} }
} }
impl<V, I, F> StatelessInteractive for Img<V, I, F> impl<V, I, F> StatelessInteractive<V> for Img<V, I, F>
where where
I: ElementInteraction<V>, I: ElementInteraction<V>,
F: ElementFocus<V>, F: ElementFocus<V>,
@ -153,21 +152,21 @@ where
} }
} }
impl<V, F> StatefulInteractive for Img<V, StatefulInteraction<V>, F> impl<V, F> StatefulInteractive<V> for Img<V, StatefulInteraction<V>, F>
where where
F: ElementFocus<V>, F: ElementFocus<V>,
{ {
fn stateful_interaction(&mut self) -> &mut StatefulInteraction<Self::ViewState> { fn stateful_interaction(&mut self) -> &mut StatefulInteraction<V> {
self.base.stateful_interaction() self.base.stateful_interaction()
} }
} }
impl<V, I> Focusable for Img<V, I, FocusEnabled<V>> impl<V, I> Focusable<V> for Img<V, I, FocusEnabled<V>>
where where
V: 'static, V: 'static,
I: ElementInteraction<V>, I: ElementInteraction<V>,
{ {
fn focus_listeners(&mut self) -> &mut FocusListeners<Self::ViewState> { fn focus_listeners(&mut self) -> &mut FocusListeners<V> {
self.base.focus_listeners() self.base.focus_listeners()
} }

View file

@ -55,12 +55,11 @@ where
} }
} }
impl<V, I, F> Element for Svg<V, I, F> impl<V, I, F> Element<V> for Svg<V, I, F>
where where
I: ElementInteraction<V>, I: ElementInteraction<V>,
F: ElementFocus<V>, F: ElementFocus<V>,
{ {
type ViewState = V;
type ElementState = DivState; type ElementState = DivState;
fn id(&self) -> Option<crate::ElementId> { fn id(&self) -> Option<crate::ElementId> {
@ -80,7 +79,7 @@ where
&mut self, &mut self,
view_state: &mut V, view_state: &mut V,
element_state: &mut Self::ElementState, element_state: &mut Self::ElementState,
cx: &mut ViewContext<Self::ViewState>, cx: &mut ViewContext<V>,
) -> LayoutId { ) -> LayoutId {
self.base.layout(view_state, element_state, cx) self.base.layout(view_state, element_state, cx)
} }
@ -88,7 +87,7 @@ where
fn paint( fn paint(
&mut self, &mut self,
bounds: Bounds<Pixels>, bounds: Bounds<Pixels>,
view: &mut Self::ViewState, view: &mut V,
element_state: &mut Self::ElementState, element_state: &mut Self::ElementState,
cx: &mut ViewContext<V>, cx: &mut ViewContext<V>,
) where ) where
@ -116,7 +115,7 @@ where
} }
} }
impl<V, I, F> StatelessInteractive for Svg<V, I, F> impl<V, I, F> StatelessInteractive<V> for Svg<V, I, F>
where where
I: ElementInteraction<V>, I: ElementInteraction<V>,
F: ElementFocus<V>, F: ElementFocus<V>,
@ -126,21 +125,21 @@ where
} }
} }
impl<V, F> StatefulInteractive for Svg<V, StatefulInteraction<V>, F> impl<V, F> StatefulInteractive<V> for Svg<V, StatefulInteraction<V>, F>
where where
V: 'static, V: 'static,
F: ElementFocus<V>, F: ElementFocus<V>,
{ {
fn stateful_interaction(&mut self) -> &mut StatefulInteraction<Self::ViewState> { fn stateful_interaction(&mut self) -> &mut StatefulInteraction<V> {
self.base.stateful_interaction() self.base.stateful_interaction()
} }
} }
impl<V: 'static, I> Focusable for Svg<V, I, FocusEnabled<V>> impl<V: 'static, I> Focusable<V> for Svg<V, I, FocusEnabled<V>>
where where
I: ElementInteraction<V>, I: ElementInteraction<V>,
{ {
fn focus_listeners(&mut self) -> &mut FocusListeners<Self::ViewState> { fn focus_listeners(&mut self) -> &mut FocusListeners<V> {
self.base.focus_listeners() self.base.focus_listeners()
} }

View file

@ -53,8 +53,7 @@ impl<V: 'static> IntoAnyElement<V> for Text<V> {
} }
} }
impl<V: 'static> Element for Text<V> { impl<V: 'static> Element<V> for Text<V> {
type ViewState = V;
type ElementState = Arc<Mutex<Option<TextElementState>>>; type ElementState = Arc<Mutex<Option<TextElementState>>>;
fn id(&self) -> Option<crate::ElementId> { fn id(&self) -> Option<crate::ElementId> {

View file

@ -11,8 +11,8 @@ pub type FocusListeners<V> = SmallVec<[FocusListener<V>; 2]>;
pub type FocusListener<V> = pub type FocusListener<V> =
Arc<dyn Fn(&mut V, &FocusHandle, &FocusEvent, &mut ViewContext<V>) + Send + Sync + 'static>; Arc<dyn Fn(&mut V, &FocusHandle, &FocusEvent, &mut ViewContext<V>) + Send + Sync + 'static>;
pub trait Focusable: Element { pub trait Focusable<V: 'static>: Element<V> {
fn focus_listeners(&mut self) -> &mut FocusListeners<Self::ViewState>; fn focus_listeners(&mut self) -> &mut FocusListeners<V>;
fn set_focus_style(&mut self, style: StyleRefinement); fn set_focus_style(&mut self, style: StyleRefinement);
fn set_focus_in_style(&mut self, style: StyleRefinement); fn set_focus_in_style(&mut self, style: StyleRefinement);
fn set_in_focus_style(&mut self, style: StyleRefinement); fn set_in_focus_style(&mut self, style: StyleRefinement);
@ -43,10 +43,7 @@ pub trait Focusable: Element {
fn on_focus( fn on_focus(
mut self, mut self,
listener: impl Fn(&mut Self::ViewState, &FocusEvent, &mut ViewContext<Self::ViewState>) listener: impl Fn(&mut V, &FocusEvent, &mut ViewContext<V>) + Send + Sync + 'static,
+ Send
+ Sync
+ 'static,
) -> Self ) -> Self
where where
Self: Sized, Self: Sized,
@ -62,10 +59,7 @@ pub trait Focusable: Element {
fn on_blur( fn on_blur(
mut self, mut self,
listener: impl Fn(&mut Self::ViewState, &FocusEvent, &mut ViewContext<Self::ViewState>) listener: impl Fn(&mut V, &FocusEvent, &mut ViewContext<V>) + Send + Sync + 'static,
+ Send
+ Sync
+ 'static,
) -> Self ) -> Self
where where
Self: Sized, Self: Sized,
@ -81,10 +75,7 @@ pub trait Focusable: Element {
fn on_focus_in( fn on_focus_in(
mut self, mut self,
listener: impl Fn(&mut Self::ViewState, &FocusEvent, &mut ViewContext<Self::ViewState>) listener: impl Fn(&mut V, &FocusEvent, &mut ViewContext<V>) + Send + Sync + 'static,
+ Send
+ Sync
+ 'static,
) -> Self ) -> Self
where where
Self: Sized, Self: Sized,
@ -109,10 +100,7 @@ pub trait Focusable: Element {
fn on_focus_out( fn on_focus_out(
mut self, mut self,
listener: impl Fn(&mut Self::ViewState, &FocusEvent, &mut ViewContext<Self::ViewState>) listener: impl Fn(&mut V, &FocusEvent, &mut ViewContext<V>) + Send + Sync + 'static,
+ Send
+ Sync
+ 'static,
) -> Self ) -> Self
where where
Self: Sized, Self: Sized,

View file

@ -19,8 +19,8 @@ use std::{
const DRAG_THRESHOLD: f64 = 2.; const DRAG_THRESHOLD: f64 = 2.;
pub trait StatelessInteractive: Element { pub trait StatelessInteractive<V: 'static>: Element<V> {
fn stateless_interaction(&mut self) -> &mut StatelessInteraction<Self::ViewState>; fn stateless_interaction(&mut self) -> &mut StatelessInteraction<V>;
fn hover(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self fn hover(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self
where where
@ -48,10 +48,7 @@ pub trait StatelessInteractive: Element {
fn on_mouse_down( fn on_mouse_down(
mut self, mut self,
button: MouseButton, button: MouseButton,
handler: impl Fn(&mut Self::ViewState, &MouseDownEvent, &mut ViewContext<Self::ViewState>) handler: impl Fn(&mut V, &MouseDownEvent, &mut ViewContext<V>) + Send + Sync + 'static,
+ Send
+ Sync
+ 'static,
) -> Self ) -> Self
where where
Self: Sized, Self: Sized,
@ -72,10 +69,7 @@ pub trait StatelessInteractive: Element {
fn on_mouse_up( fn on_mouse_up(
mut self, mut self,
button: MouseButton, button: MouseButton,
handler: impl Fn(&mut Self::ViewState, &MouseUpEvent, &mut ViewContext<Self::ViewState>) handler: impl Fn(&mut V, &MouseUpEvent, &mut ViewContext<V>) + Send + Sync + 'static,
+ Send
+ Sync
+ 'static,
) -> Self ) -> Self
where where
Self: Sized, Self: Sized,
@ -96,10 +90,7 @@ pub trait StatelessInteractive: Element {
fn on_mouse_down_out( fn on_mouse_down_out(
mut self, mut self,
button: MouseButton, button: MouseButton,
handler: impl Fn(&mut Self::ViewState, &MouseDownEvent, &mut ViewContext<Self::ViewState>) handler: impl Fn(&mut V, &MouseDownEvent, &mut ViewContext<V>) + Send + Sync + 'static,
+ Send
+ Sync
+ 'static,
) -> Self ) -> Self
where where
Self: Sized, Self: Sized,
@ -120,10 +111,7 @@ pub trait StatelessInteractive: Element {
fn on_mouse_up_out( fn on_mouse_up_out(
mut self, mut self,
button: MouseButton, button: MouseButton,
handler: impl Fn(&mut Self::ViewState, &MouseUpEvent, &mut ViewContext<Self::ViewState>) handler: impl Fn(&mut V, &MouseUpEvent, &mut ViewContext<V>) + Send + Sync + 'static,
+ Send
+ Sync
+ 'static,
) -> Self ) -> Self
where where
Self: Sized, Self: Sized,
@ -143,10 +131,7 @@ pub trait StatelessInteractive: Element {
fn on_mouse_move( fn on_mouse_move(
mut self, mut self,
handler: impl Fn(&mut Self::ViewState, &MouseMoveEvent, &mut ViewContext<Self::ViewState>) handler: impl Fn(&mut V, &MouseMoveEvent, &mut ViewContext<V>) + Send + Sync + 'static,
+ Send
+ Sync
+ 'static,
) -> Self ) -> Self
where where
Self: Sized, Self: Sized,
@ -163,10 +148,7 @@ pub trait StatelessInteractive: Element {
fn on_scroll_wheel( fn on_scroll_wheel(
mut self, mut self,
handler: impl Fn(&mut Self::ViewState, &ScrollWheelEvent, &mut ViewContext<Self::ViewState>) handler: impl Fn(&mut V, &ScrollWheelEvent, &mut ViewContext<V>) + Send + Sync + 'static,
+ Send
+ Sync
+ 'static,
) -> Self ) -> Self
where where
Self: Sized, Self: Sized,
@ -194,10 +176,7 @@ pub trait StatelessInteractive: Element {
fn on_action<A: 'static>( fn on_action<A: 'static>(
mut self, mut self,
listener: impl Fn(&mut Self::ViewState, &A, DispatchPhase, &mut ViewContext<Self::ViewState>) listener: impl Fn(&mut V, &A, DispatchPhase, &mut ViewContext<V>) + Send + Sync + 'static,
+ Send
+ Sync
+ 'static,
) -> Self ) -> Self
where where
Self: Sized, Self: Sized,
@ -215,12 +194,8 @@ pub trait StatelessInteractive: Element {
fn on_key_down( fn on_key_down(
mut self, mut self,
listener: impl Fn( listener: impl Fn(&mut V, &KeyDownEvent, DispatchPhase, &mut ViewContext<V>)
&mut Self::ViewState, + Send
&KeyDownEvent,
DispatchPhase,
&mut ViewContext<Self::ViewState>,
) + Send
+ Sync + Sync
+ 'static, + 'static,
) -> Self ) -> Self
@ -240,7 +215,7 @@ pub trait StatelessInteractive: Element {
fn on_key_up( fn on_key_up(
mut self, mut self,
listener: impl Fn(&mut Self::ViewState, &KeyUpEvent, DispatchPhase, &mut ViewContext<Self::ViewState>) listener: impl Fn(&mut V, &KeyUpEvent, DispatchPhase, &mut ViewContext<V>)
+ Send + Send
+ Sync + Sync
+ 'static, + 'static,
@ -289,10 +264,7 @@ pub trait StatelessInteractive: Element {
fn on_drop<S: 'static>( fn on_drop<S: 'static>(
mut self, mut self,
listener: impl Fn(&mut Self::ViewState, S, &mut ViewContext<Self::ViewState>) listener: impl Fn(&mut V, S, &mut ViewContext<V>) + Send + Sync + 'static,
+ Send
+ Sync
+ 'static,
) -> Self ) -> Self
where where
Self: Sized, Self: Sized,
@ -307,8 +279,8 @@ pub trait StatelessInteractive: Element {
} }
} }
pub trait StatefulInteractive: StatelessInteractive { pub trait StatefulInteractive<V: 'static>: StatelessInteractive<V> {
fn stateful_interaction(&mut self) -> &mut StatefulInteraction<Self::ViewState>; fn stateful_interaction(&mut self) -> &mut StatefulInteraction<V>;
fn active(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self fn active(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self
where where
@ -335,10 +307,7 @@ pub trait StatefulInteractive: StatelessInteractive {
fn on_click( fn on_click(
mut self, mut self,
listener: impl Fn(&mut Self::ViewState, &ClickEvent, &mut ViewContext<Self::ViewState>) listener: impl Fn(&mut V, &ClickEvent, &mut ViewContext<V>) + Send + Sync + 'static,
+ Send
+ Sync
+ 'static,
) -> Self ) -> Self
where where
Self: Sized, Self: Sized,
@ -351,20 +320,14 @@ pub trait StatefulInteractive: StatelessInteractive {
fn on_drag<S, R, E>( fn on_drag<S, R, E>(
mut self, mut self,
listener: impl Fn( listener: impl Fn(&mut V, &mut ViewContext<V>) -> Drag<S, R, V, E> + Send + Sync + 'static,
&mut Self::ViewState,
&mut ViewContext<Self::ViewState>,
) -> Drag<S, R, Self::ViewState, E>
+ Send
+ Sync
+ 'static,
) -> Self ) -> Self
where where
Self: Sized, Self: Sized,
S: Any + Send + Sync, S: Any + Send + Sync,
R: Fn(&mut Self::ViewState, &mut ViewContext<Self::ViewState>) -> E, R: Fn(&mut V, &mut ViewContext<V>) -> E,
R: 'static + Send + Sync, R: 'static + Send + Sync,
E: Element<ViewState = Self::ViewState>, E: Element<V>,
{ {
debug_assert!( debug_assert!(
self.stateful_interaction().drag_listener.is_none(), self.stateful_interaction().drag_listener.is_none(),
@ -907,7 +870,8 @@ pub struct ClickEvent {
pub struct Drag<S, R, V, E> pub struct Drag<S, R, V, E>
where where
R: Fn(&mut V, &mut ViewContext<V>) -> E, R: Fn(&mut V, &mut ViewContext<V>) -> E,
E: Element<ViewState = V>, V: 'static,
E: Element<V>,
{ {
pub state: S, pub state: S,
pub render_drag_handle: R, pub render_drag_handle: R,
@ -917,7 +881,8 @@ where
impl<S, R, V, E> Drag<S, R, V, E> impl<S, R, V, E> Drag<S, R, V, E>
where where
R: Fn(&mut V, &mut ViewContext<V>) -> E, R: Fn(&mut V, &mut ViewContext<V>) -> E,
E: Element<ViewState = V>, V: 'static,
E: Element<V>,
{ {
pub fn new(state: S, render_drag_handle: R) -> Self { pub fn new(state: S, render_drag_handle: R) -> Self {
Drag { Drag {

View file

@ -50,8 +50,7 @@ impl<V: 'static, ParentViewState: 'static> IntoAnyElement<ParentViewState> for V
} }
} }
impl<V: 'static> Element for View<V> { impl<V: 'static> Element<()> for View<V> {
type ViewState = ();
type ElementState = AnyElement<V>; type ElementState = AnyElement<V>;
fn id(&self) -> Option<crate::ElementId> { fn id(&self) -> Option<crate::ElementId> {
@ -105,8 +104,7 @@ impl<V: 'static, ParentV: 'static> IntoAnyElement<ParentV> for EraseViewState<V,
} }
} }
impl<V: 'static, ParentV: 'static> Element for EraseViewState<V, ParentV> { impl<V: 'static, ParentV: 'static> Element<ParentV> for EraseViewState<V, ParentV> {
type ViewState = ParentV;
type ElementState = AnyBox; type ElementState = AnyBox;
fn id(&self) -> Option<crate::ElementId> { fn id(&self) -> Option<crate::ElementId> {
@ -115,18 +113,18 @@ impl<V: 'static, ParentV: 'static> Element for EraseViewState<V, ParentV> {
fn initialize( fn initialize(
&mut self, &mut self,
_: &mut Self::ViewState, _: &mut ParentV,
_: Option<Self::ElementState>, _: Option<Self::ElementState>,
cx: &mut ViewContext<Self::ViewState>, cx: &mut ViewContext<ParentV>,
) -> Self::ElementState { ) -> Self::ElementState {
ViewObject::initialize(&mut self.view, cx) ViewObject::initialize(&mut self.view, cx)
} }
fn layout( fn layout(
&mut self, &mut self,
_: &mut Self::ViewState, _: &mut ParentV,
element: &mut Self::ElementState, element: &mut Self::ElementState,
cx: &mut ViewContext<Self::ViewState>, cx: &mut ViewContext<ParentV>,
) -> LayoutId { ) -> LayoutId {
ViewObject::layout(&mut self.view, element, cx) ViewObject::layout(&mut self.view, element, cx)
} }
@ -134,9 +132,9 @@ impl<V: 'static, ParentV: 'static> Element for EraseViewState<V, ParentV> {
fn paint( fn paint(
&mut self, &mut self,
bounds: Bounds<Pixels>, bounds: Bounds<Pixels>,
_: &mut Self::ViewState, _: &mut ParentV,
element: &mut Self::ElementState, element: &mut Self::ElementState,
cx: &mut ViewContext<Self::ViewState>, cx: &mut ViewContext<ParentV>,
) { ) {
ViewObject::paint(&mut self.view, bounds, element, cx) ViewObject::paint(&mut self.view, bounds, element, cx)
} }
@ -196,8 +194,7 @@ impl<ParentV: 'static> IntoAnyElement<ParentV> for AnyView {
} }
} }
impl Element for AnyView { impl Element<()> for AnyView {
type ViewState = ();
type ElementState = AnyBox; type ElementState = AnyBox;
fn id(&self) -> Option<crate::ElementId> { fn id(&self) -> Option<crate::ElementId> {
@ -206,18 +203,18 @@ impl Element for AnyView {
fn initialize( fn initialize(
&mut self, &mut self,
_: &mut Self::ViewState, _: &mut (),
_: Option<Self::ElementState>, _: Option<Self::ElementState>,
cx: &mut ViewContext<Self::ViewState>, cx: &mut ViewContext<()>,
) -> Self::ElementState { ) -> Self::ElementState {
self.view.lock().initialize(cx) self.view.lock().initialize(cx)
} }
fn layout( fn layout(
&mut self, &mut self,
_: &mut Self::ViewState, _: &mut (),
element: &mut Self::ElementState, element: &mut Self::ElementState,
cx: &mut ViewContext<Self::ViewState>, cx: &mut ViewContext<()>,
) -> LayoutId { ) -> LayoutId {
self.view.lock().layout(element, cx) self.view.lock().layout(element, cx)
} }
@ -227,7 +224,7 @@ impl Element for AnyView {
bounds: Bounds<Pixels>, bounds: Bounds<Pixels>,
_: &mut (), _: &mut (),
element: &mut AnyBox, element: &mut AnyBox,
cx: &mut ViewContext<Self::ViewState>, cx: &mut ViewContext<()>,
) { ) {
self.view.lock().paint(bounds, element, cx) self.view.lock().paint(bounds, element, cx)
} }
@ -247,8 +244,7 @@ impl<ParentV: 'static> IntoAnyElement<ParentV> for EraseAnyViewState<ParentV> {
} }
} }
impl<ParentV: 'static> Element for EraseAnyViewState<ParentV> { impl<ParentV: 'static> Element<ParentV> for EraseAnyViewState<ParentV> {
type ViewState = ParentV;
type ElementState = AnyBox; type ElementState = AnyBox;
fn id(&self) -> Option<crate::ElementId> { fn id(&self) -> Option<crate::ElementId> {
@ -257,18 +253,18 @@ impl<ParentV: 'static> Element for EraseAnyViewState<ParentV> {
fn initialize( fn initialize(
&mut self, &mut self,
_: &mut Self::ViewState, _: &mut ParentV,
_: Option<Self::ElementState>, _: Option<Self::ElementState>,
cx: &mut ViewContext<Self::ViewState>, cx: &mut ViewContext<ParentV>,
) -> Self::ElementState { ) -> Self::ElementState {
self.view.view.lock().initialize(cx) self.view.view.lock().initialize(cx)
} }
fn layout( fn layout(
&mut self, &mut self,
_: &mut Self::ViewState, _: &mut ParentV,
element: &mut Self::ElementState, element: &mut Self::ElementState,
cx: &mut ViewContext<Self::ViewState>, cx: &mut ViewContext<ParentV>,
) -> LayoutId { ) -> LayoutId {
self.view.view.lock().layout(element, cx) self.view.view.lock().layout(element, cx)
} }
@ -276,9 +272,9 @@ impl<ParentV: 'static> Element for EraseAnyViewState<ParentV> {
fn paint( fn paint(
&mut self, &mut self,
bounds: Bounds<Pixels>, bounds: Bounds<Pixels>,
_: &mut Self::ViewState, _: &mut ParentV,
element: &mut Self::ElementState, element: &mut Self::ElementState,
cx: &mut ViewContext<Self::ViewState>, cx: &mut ViewContext<ParentV>,
) { ) {
self.view.view.lock().paint(bounds, element, cx) self.view.view.lock().paint(bounds, element, cx)
} }

View file

@ -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 #where_clause
{ {
type ViewState = #state_type;
type ElementState = gpui2::AnyElement<#state_type>; type ElementState = gpui2::AnyElement<#state_type>;
fn id(&self) -> Option<gpui2::ElementId> { fn id(&self) -> Option<gpui2::ElementId> {
@ -59,9 +58,9 @@ pub fn derive_element(input: TokenStream) -> TokenStream {
fn initialize( fn initialize(
&mut self, &mut self,
view_state: &mut Self::ViewState, view_state: &mut #state_type,
_: Option<Self::ElementState>, _: Option<Self::ElementState>,
cx: &mut gpui2::ViewContext<Self::ViewState> cx: &mut gpui2::ViewContext<#state_type>
) -> Self::ElementState { ) -> Self::ElementState {
use gpui2::IntoAnyElement; use gpui2::IntoAnyElement;
@ -72,9 +71,9 @@ pub fn derive_element(input: TokenStream) -> TokenStream {
fn layout( fn layout(
&mut self, &mut self,
view_state: &mut Self::ViewState, view_state: &mut #state_type,
rendered_element: &mut Self::ElementState, rendered_element: &mut Self::ElementState,
cx: &mut gpui2::ViewContext<Self::ViewState>, cx: &mut gpui2::ViewContext<#state_type>,
) -> gpui2::LayoutId { ) -> gpui2::LayoutId {
rendered_element.layout(view_state, cx) rendered_element.layout(view_state, cx)
} }
@ -82,9 +81,9 @@ pub fn derive_element(input: TokenStream) -> TokenStream {
fn paint( fn paint(
&mut self, &mut self,
bounds: gpui2::Bounds<gpui2::Pixels>, bounds: gpui2::Bounds<gpui2::Pixels>,
view_state: &mut Self::ViewState, view_state: &mut #state_type,
rendered_element: &mut Self::ElementState, rendered_element: &mut Self::ElementState,
cx: &mut gpui2::ViewContext<Self::ViewState>, cx: &mut gpui2::ViewContext<#state_type>,
) { ) {
rendered_element.paint(view_state, cx) rendered_element.paint(view_state, cx)
} }

View file

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

View file

@ -16,7 +16,7 @@ impl ScrollStory {
} }
} }
fn checkerboard<S>(depth: usize) -> impl Element<ViewState = S> fn checkerboard<S>(depth: usize) -> impl Element<S>
where where
S: 'static + Send + Sync, S: 'static + Send + Sync,
{ {

View file

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

View file

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

View file

@ -26,7 +26,7 @@ impl<S: 'static + Send + Sync> AssistantPanel<S> {
self self
} }
fn render(&mut self, view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
Panel::new(self.id.clone(), cx) Panel::new(self.id.clone(), cx)
.children(vec![div() .children(vec![div()
.flex() .flex()
@ -100,7 +100,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, AssistantPanel<S>>(cx)) .child(Story::title_for::<_, AssistantPanel<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -35,7 +35,7 @@ impl<S: 'static + Send + Sync> Breadcrumb<S> {
&mut self, &mut self,
view_state: &mut S, view_state: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
let symbols_len = self.symbols.len(); let symbols_len = self.symbols.len();
@ -106,7 +106,7 @@ mod stories {
&mut self, &mut self,
view_state: &mut S, view_state: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
Story::container(cx) Story::container(cx)

View file

@ -158,7 +158,7 @@ impl<S: 'static + Send + Sync + Clone> Buffer<S> {
self self
} }
fn render_row(row: BufferRow, cx: &WindowContext) -> impl Element<ViewState = S> { fn render_row(row: BufferRow, cx: &WindowContext) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
let line_background = if row.current { let line_background = if row.current {
@ -208,7 +208,7 @@ impl<S: 'static + Send + Sync + Clone> Buffer<S> {
})) }))
} }
fn render_rows(&self, cx: &WindowContext) -> Vec<impl Element<ViewState = S>> { fn render_rows(&self, cx: &WindowContext) -> Vec<impl Element<S>> {
match &self.rows { match &self.rows {
Some(rows) => rows Some(rows) => rows
.rows .rows
@ -219,7 +219,7 @@ impl<S: 'static + Send + Sync + Clone> Buffer<S> {
} }
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
let rows = self.render_rows(cx); let rows = self.render_rows(cx);
@ -262,7 +262,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
Story::container(cx) Story::container(cx)

View file

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

View file

@ -24,7 +24,7 @@ impl<S: 'static + Send + Sync> ChatPanel<S> {
self self
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
div() div()
.id(self.element_id.clone()) .id(self.element_id.clone())
.flex() .flex()
@ -88,7 +88,7 @@ impl<S: 'static + Send + Sync> ChatMessage<S> {
} }
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
div() div()
.flex() .flex()
.flex_col() .flex_col()
@ -133,7 +133,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, ChatPanel<S>>(cx)) .child(Story::title_for::<_, ChatPanel<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -19,7 +19,7 @@ impl<S: 'static + Send + Sync> CollabPanel<S> {
} }
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
v_stack() v_stack()
@ -114,7 +114,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, CollabPanel<S>>(cx)) .child(Story::title_for::<_, CollabPanel<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync> CommandPalette<S> {
} }
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
div().id(self.id.clone()).child( div().id(self.id.clone()).child(
Palette::new("palette") Palette::new("palette")
.items(example_editor_actions()) .items(example_editor_actions())
@ -53,7 +53,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, CommandPalette<S>>(cx)) .child(Story::title_for::<_, CommandPalette<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -42,7 +42,7 @@ impl<S: 'static + Send + Sync> ContextMenu<S> {
items: items.into_iter().collect(), items: items.into_iter().collect(),
} }
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
v_stack() v_stack()
@ -89,7 +89,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, ContextMenu<S>>(cx)) .child(Story::title_for::<_, ContextMenu<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -16,7 +16,7 @@ impl<S: 'static + Send + Sync + Clone> CopilotModal<S> {
} }
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
div().id(self.id.clone()).child( div().id(self.id.clone()).child(
Modal::new("some-id") Modal::new("some-id")
.title("Connect Copilot to Zed") .title("Connect Copilot to Zed")
@ -51,7 +51,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, CopilotModal<S>>(cx)) .child(Story::title_for::<_, CopilotModal<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

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

View file

@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync> Facepile<S> {
} }
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let player_count = self.players.len(); let player_count = self.players.len();
let player_list = self.players.iter().enumerate().map(|(ix, player)| { let player_list = self.players.iter().enumerate().map(|(ix, player)| {
let isnt_last = ix < player_count - 1; let isnt_last = ix < player_count - 1;
@ -55,7 +55,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
let players = static_players(); let players = static_players();
Story::container(cx) Story::container(cx)

View file

@ -68,7 +68,7 @@ impl<S: 'static + Send + Sync> IconButton<S> {
self self
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
let icon_color = match (self.state, self.color) { let icon_color = match (self.state, self.color) {

View file

@ -34,7 +34,7 @@ impl<S: 'static + Send + Sync> Keybinding<S> {
} }
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
div() div()
.flex() .flex()
.gap_2() .gap_2()
@ -68,7 +68,7 @@ impl<S: 'static + Send + Sync> Key<S> {
} }
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
div() div()
@ -189,7 +189,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
let all_modifier_permutations = ModifierKey::iter().permutations(2); let all_modifier_permutations = ModifierKey::iter().permutations(2);
Story::container(cx) Story::container(cx)

View file

@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync + Clone> LanguageSelector<S> {
} }
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
div().id(self.id.clone()).child( div().id(self.id.clone()).child(
Palette::new("palette") Palette::new("palette")
.items(vec![ .items(vec![
@ -64,7 +64,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, LanguageSelector<S>>(cx)) .child(Story::title_for::<_, LanguageSelector<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -92,7 +92,7 @@ impl<S: 'static + Send + Sync> ListHeader<S> {
} }
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
let is_toggleable = self.toggleable != Toggleable::NotToggleable; let is_toggleable = self.toggleable != Toggleable::NotToggleable;
@ -157,7 +157,7 @@ impl<S: 'static + Send + Sync> ListSubHeader<S> {
self self
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
h_stack().flex_1().w_full().relative().py_1().child( h_stack().flex_1().w_full().relative().py_1().child(
div() div()
.h_6() .h_6()
@ -230,7 +230,7 @@ impl<S: 'static + Send + Sync> From<ListSubHeader<S>> for ListItem<S> {
} }
impl<S: 'static + Send + Sync> ListItem<S> { impl<S: 'static + Send + Sync> ListItem<S> {
fn render(&mut self, view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
match self { match self {
ListItem::Entry(entry) => div().child(entry.render(view, cx)), ListItem::Entry(entry) => div().child(entry.render(view, cx)),
ListItem::Separator(separator) => div().child(separator.render(view, cx)), ListItem::Separator(separator) => div().child(separator.render(view, cx)),
@ -347,7 +347,7 @@ impl<S: 'static + Send + Sync> ListEntry<S> {
fn disclosure_control( fn disclosure_control(
&mut self, &mut self,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> Option<impl Element<ViewState = S>> { ) -> Option<impl Element<S>> {
let disclosure_control_icon = if let Some(ToggleState::Toggled) = self.toggle { let disclosure_control_icon = if let Some(ToggleState::Toggled) = self.toggle {
IconElement::new(Icon::ChevronDown) IconElement::new(Icon::ChevronDown)
} else { } else {
@ -367,7 +367,7 @@ impl<S: 'static + Send + Sync> ListEntry<S> {
} }
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let settings = user_settings(cx); let settings = user_settings(cx);
let theme = theme(cx); let theme = theme(cx);
@ -477,7 +477,7 @@ impl<S: 'static + Send + Sync> ListDetailsEntry<S> {
self self
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
let settings = user_settings(cx); let settings = user_settings(cx);
@ -534,7 +534,7 @@ impl<S: 'static + Send + Sync> ListSeparator<S> {
} }
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
div().h_px().w_full().bg(theme.border) div().h_px().w_full().bg(theme.border)
@ -574,7 +574,7 @@ impl<S: 'static + Send + Sync> List<S> {
self self
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let is_toggleable = self.toggleable != Toggleable::NotToggleable; let is_toggleable = self.toggleable != Toggleable::NotToggleable;
let is_toggled = Toggleable::is_toggled(&self.toggleable); let is_toggled = Toggleable::is_toggled(&self.toggleable);

View file

@ -42,7 +42,7 @@ impl<S: 'static + Send + Sync> Modal<S> {
self self
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
v_stack() v_stack()
@ -80,8 +80,8 @@ impl<S: 'static + Send + Sync> Modal<S> {
} }
} }
impl<S: 'static + Send + Sync> ParentElement for Modal<S> { impl<S: 'static + Send + Sync> ParentElement<S> for Modal<S> {
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<Self::ViewState>; 2]> { fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<S>; 2]> {
&mut self.children &mut self.children
} }
} }

View file

@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync + Clone> MultiBuffer<S> {
} }
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
v_stack() v_stack()
@ -66,7 +66,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
Story::container(cx) Story::container(cx)

View file

@ -28,7 +28,7 @@ impl<S: 'static + Send + Sync + Clone> NotificationToast<S> {
self self
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
h_stack() h_stack()

View file

@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync> NotificationsPanel<S> {
} }
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
div() div()
@ -74,7 +74,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, NotificationsPanel<S>>(cx)) .child(Story::title_for::<_, NotificationsPanel<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -46,7 +46,7 @@ impl<S: 'static + Send + Sync> Palette<S> {
self self
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
v_stack() v_stack()
@ -135,7 +135,7 @@ impl<S: 'static + Send + Sync> PaletteItem<S> {
self self
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
div() div()
.flex() .flex()
.flex_row() .flex_row()
@ -176,7 +176,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, Palette<S>>(cx)) .child(Story::title_for::<_, Palette<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -96,7 +96,7 @@ impl<S: 'static + Send + Sync> Panel<S> {
self self
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
let current_size = self.width.unwrap_or(self.initial_width); let current_size = self.width.unwrap_or(self.initial_width);
@ -121,8 +121,8 @@ impl<S: 'static + Send + Sync> Panel<S> {
} }
} }
impl<S: 'static + Send + Sync> ParentElement for Panel<S> { impl<S: 'static + Send + Sync> ParentElement<S> for Panel<S> {
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<Self::ViewState>; 2]> { fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<S>; 2]> {
&mut self.children &mut self.children
} }
} }
@ -152,7 +152,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, Panel<S>>(cx)) .child(Story::title_for::<_, Panel<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -118,7 +118,7 @@ impl<S: 'static + Send + Sync> Pane<S> {
self self
} }
fn render(&mut self, view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
div() div()
.id(self.id.clone()) .id(self.id.clone())
.flex() .flex()
@ -148,8 +148,8 @@ impl<S: 'static + Send + Sync> Pane<S> {
} }
} }
impl<S: 'static + Send + Sync> ParentElement for Pane<S> { impl<S: 'static + Send + Sync> ParentElement<S> for Pane<S> {
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<Self::ViewState>; 2]> { fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<S>; 2]> {
&mut self.children &mut self.children
} }
} }
@ -181,7 +181,7 @@ impl<S: 'static + Send + Sync> PaneGroup<S> {
} }
} }
fn render(&mut self, view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
if !self.panes.is_empty() { if !self.panes.is_empty() {

View file

@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync> PlayerStack<S> {
} }
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
let player = self.player_with_call_status.get_player(); let player = self.player_with_call_status.get_player();
self.player_with_call_status.get_call_status(); self.player_with_call_status.get_call_status();

View file

@ -19,7 +19,7 @@ impl<S: 'static + Send + Sync> ProjectPanel<S> {
} }
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
div() div()
@ -83,7 +83,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, ProjectPanel<S>>(cx)) .child(Story::title_for::<_, ProjectPanel<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync + Clone> RecentProjects<S> {
} }
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
div().id(self.id.clone()).child( div().id(self.id.clone()).child(
Palette::new("palette") Palette::new("palette")
.items(vec![ .items(vec![
@ -60,7 +60,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, RecentProjects<S>>(cx)) .child(Story::title_for::<_, RecentProjects<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -86,7 +86,7 @@ impl StatusBar {
&mut self, &mut self,
view: &mut Workspace, view: &mut Workspace,
cx: &mut ViewContext<Workspace>, cx: &mut ViewContext<Workspace>,
) -> impl Element<ViewState = Workspace> { ) -> impl Element<Workspace> {
let theme = theme(cx); let theme = theme(cx);
div() div()
@ -101,11 +101,7 @@ impl StatusBar {
.child(self.right_tools(view, cx)) .child(self.right_tools(view, cx))
} }
fn left_tools( fn left_tools(&self, workspace: &mut Workspace, cx: &WindowContext) -> impl Element<Workspace> {
&self,
workspace: &mut Workspace,
cx: &WindowContext,
) -> impl Element<ViewState = Workspace> {
div() div()
.flex() .flex()
.items_center() .items_center()
@ -136,7 +132,7 @@ impl StatusBar {
&self, &self,
workspace: &mut Workspace, workspace: &mut Workspace,
cx: &WindowContext, cx: &WindowContext,
) -> impl Element<ViewState = Workspace> { ) -> impl Element<Workspace> {
div() div()
.flex() .flex()
.items_center() .items_center()

View file

@ -81,7 +81,7 @@ impl<S: 'static + Send + Sync + Clone> Tab<S> {
self self
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
let has_fs_conflict = self.fs_status == FileSystemStatus::Conflict; let has_fs_conflict = self.fs_status == FileSystemStatus::Conflict;
let is_deleted = self.fs_status == FileSystemStatus::Deleted; let is_deleted = self.fs_status == FileSystemStatus::Deleted;
@ -192,7 +192,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
let git_statuses = GitStatus::iter(); let git_statuses = GitStatus::iter();
let fs_statuses = FileSystemStatus::iter(); let fs_statuses = FileSystemStatus::iter();

View file

@ -27,7 +27,7 @@ impl<S: 'static + Send + Sync + Clone> TabBar<S> {
self self
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
let (can_navigate_back, can_navigate_forward) = self.can_navigate; let (can_navigate_back, can_navigate_forward) = self.can_navigate;
@ -116,7 +116,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, TabBar<S>>(cx)) .child(Story::title_for::<_, TabBar<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync + Clone> Terminal<S> {
} }
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
let can_navigate_back = true; let can_navigate_back = true;
@ -109,7 +109,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, Terminal<S>>(cx)) .child(Story::title_for::<_, Terminal<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -17,7 +17,7 @@ impl<S: 'static + Send + Sync> ThemeSelector<S> {
} }
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
div().child( div().child(
Palette::new(self.id.clone()) Palette::new(self.id.clone())
.items(vec![ .items(vec![
@ -65,7 +65,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, ThemeSelector<S>>(cx)) .child(Story::title_for::<_, ThemeSelector<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

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

View file

@ -36,7 +36,7 @@ impl<S: 'static + Send + Sync> Toast<S> {
} }
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
let mut div = div(); let mut div = div();
@ -61,8 +61,8 @@ impl<S: 'static + Send + Sync> Toast<S> {
} }
} }
impl<S: 'static + Send + Sync> ParentElement for Toast<S> { impl<S: 'static + Send + Sync> ParentElement<S> for Toast<S> {
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<Self::ViewState>; 2]> { fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<S>; 2]> {
&mut self.children &mut self.children
} }
} }
@ -90,11 +90,7 @@ mod stories {
} }
} }
fn render( fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
&mut self,
_view: &mut S,
cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, Toast<S>>(cx)) .child(Story::title_for::<_, Toast<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -54,7 +54,7 @@ impl<S: 'static + Send + Sync> Toolbar<S> {
self self
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
div() div()
@ -96,7 +96,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
Story::container(cx) Story::container(cx)

View file

@ -25,7 +25,7 @@ impl<S: 'static + Send + Sync> TrafficLight<S> {
} }
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
let fill = match (self.window_has_focus, self.color) { let fill = match (self.window_has_focus, self.color) {
@ -58,7 +58,7 @@ impl<S: 'static + Send + Sync> TrafficLights<S> {
self self
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
div() div()
.flex() .flex()
.items_center() .items_center()
@ -103,7 +103,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, TrafficLights<S>>(cx)) .child(Story::title_for::<_, TrafficLights<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -3,13 +3,13 @@ use std::sync::Arc;
use chrono::DateTime; use chrono::DateTime;
use gpui2::{px, relative, rems, view, Context, Size, View}; use gpui2::{px, relative, rems, view, Context, Size, View};
use crate::{prelude::*, NotificationsPanel};
use crate::{ 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, ChatPanel, CollabPanel, EditorPane, FakeSettings, Label, LanguageSelector, Pane, PaneGroup,
Panel, PanelAllowedSides, PanelSide, ProjectPanel, SettingValue, SplitDirection, StatusBar, Panel, PanelAllowedSides, PanelSide, ProjectPanel, SettingValue, SplitDirection, StatusBar,
Terminal, TitleBar, Toast, ToastOrigin, Terminal, TitleBar, Toast, ToastOrigin,
}; };
use crate::{prelude::*, NotificationsPanel};
#[derive(Clone)] #[derive(Clone)]
pub struct Gpui2UiDebug { pub struct Gpui2UiDebug {
@ -174,7 +174,7 @@ impl Workspace {
view(cx.entity(|cx| Self::new(cx)), Self::render) view(cx.entity(|cx| Self::new(cx)), Self::render)
} }
pub fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element<ViewState = Self> { pub fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element<Self> {
let theme = old_theme(cx).clone(); let theme = old_theme(cx).clone();
// HACK: This should happen inside of `debug_toggle_user_settings`, but // HACK: This should happen inside of `debug_toggle_user_settings`, but

View file

@ -1,6 +1,6 @@
use gpui2::Element; use gpui2::Element;
pub trait ElementExt<S: 'static + Send + Sync>: Element<ViewState = S> { pub trait ElementExt<S: 'static + Send + Sync>: Element<S> {
/// Applies a given function `then` to the current element if `condition` is true. /// 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. /// 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. /// If `condition` is false, it just returns the current element as it is.
@ -25,4 +25,4 @@ pub trait ElementExt<S: 'static + Send + Sync>: Element<ViewState = S> {
// } // }
} }
impl<S: 'static + Send + Sync, E: Element<ViewState = S>> ElementExt<S> for E {} impl<S: 'static + Send + Sync, E: Element<S>> ElementExt<S> for E {}

View file

@ -25,7 +25,7 @@ impl<S: 'static + Send + Sync> Avatar<S> {
self self
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
let mut img = img(); let mut img = img();
@ -67,7 +67,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, Avatar<S>>(cx)) .child(Story::title_for::<_, Avatar<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -154,7 +154,7 @@ impl<S: 'static + Send + Sync> Button<S> {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
let icon_color = self.icon_color(); let icon_color = self.icon_color();
let mut button = h_stack() let mut button = h_stack()
@ -211,7 +211,7 @@ impl<S: 'static + Send + Sync> ButtonGroup<S> {
} }
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let mut el = h_stack().text_size(ui_size(cx, 1.)); let mut el = h_stack().text_size(ui_size(cx, 1.));
for button in &mut self.buttons { for button in &mut self.buttons {
@ -250,7 +250,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
let states = InteractionState::iter(); let states = InteractionState::iter();
Story::container(cx) Story::container(cx)

View file

@ -30,7 +30,7 @@ impl<S: 'static + Send + Sync> Details<S> {
self self
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
v_stack() v_stack()
@ -70,7 +70,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, Details<S>>(cx)) .child(Story::title_for::<_, Details<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -176,7 +176,7 @@ impl<S: 'static + Send + Sync> IconElement<S> {
self self
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let fill = self.color.color(cx); let fill = self.color.color(cx);
let svg_size = match self.size { let svg_size = match self.size {
IconSize::Small => ui_size(cx, 12. / 14.), IconSize::Small => ui_size(cx, 12. / 14.),
@ -218,7 +218,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
let icons = Icon::iter(); let icons = Icon::iter();
Story::container(cx) Story::container(cx)

View file

@ -60,7 +60,7 @@ impl<S: 'static + Send + Sync> Input<S> {
self self
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
let (input_bg, input_hover_bg, input_active_bg) = match self.variant { let (input_bg, input_hover_bg, input_active_bg) = match self.variant {
@ -136,7 +136,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, Input<S>>(cx)) .child(Story::title_for::<_, Input<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -83,7 +83,7 @@ impl<S: 'static + Send + Sync> Label<S> {
self self
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
div() div()
.when(self.strikethrough, |this| { .when(self.strikethrough, |this| {
this.relative().child( this.relative().child(
@ -135,7 +135,7 @@ impl<S: 'static + Send + Sync> HighlightedLabel<S> {
self self
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
let highlight_color = theme.text_accent; let highlight_color = theme.text_accent;
@ -227,7 +227,7 @@ mod stories {
&mut self, &mut self,
_view: &mut S, _view: &mut S,
cx: &mut ViewContext<S>, cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> { ) -> impl Element<S> {
Story::container(cx) Story::container(cx)
.child(Story::title_for::<_, Label<S>>(cx)) .child(Story::title_for::<_, Label<S>>(cx))
.child(Story::label(cx, "Default")) .child(Story::label(cx, "Default"))

View file

@ -14,7 +14,7 @@ impl<S: 'static + Send + Sync> ToolDivider<S> {
} }
} }
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> { fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<S> {
let theme = theme(cx); let theme = theme(cx);
div().w_px().h_3().bg(theme.border) div().w_px().h_3().bg(theme.border)

View file

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

View file

@ -132,10 +132,11 @@ where
deserializer.deserialize_map(SyntaxVisitor) deserializer.deserialize_map(SyntaxVisitor)
} }
pub fn themed<E, F>(theme: Theme, cx: &mut ViewContext<E::ViewState>, build_child: F) -> Themed<E> pub fn themed<V, E, F>(theme: Theme, cx: &mut ViewContext<V>, build_child: F) -> Themed<E>
where where
E: Element, V: 'static,
F: FnOnce(&mut ViewContext<E::ViewState>) -> E, E: Element<V>,
F: FnOnce(&mut ViewContext<V>) -> E,
{ {
cx.default_global::<ThemeStack>().0.push(theme.clone()); cx.default_global::<ThemeStack>().0.push(theme.clone());
let child = build_child(cx); let child = build_child(cx);
@ -148,12 +149,13 @@ pub struct Themed<E> {
pub(crate) child: E, pub(crate) child: E,
} }
impl<E> IntoAnyElement<E::ViewState> for Themed<E> impl<V, E> IntoAnyElement<V> for Themed<E>
where where
E: 'static + Element + Send + Sync, V: 'static,
E: 'static + Element<V> + Send + Sync,
E::ElementState: Send + Sync, E::ElementState: Send + Sync,
{ {
fn into_any(self) -> AnyElement<E::ViewState> { fn into_any(self) -> AnyElement<V> {
AnyElement::new(self) AnyElement::new(self)
} }
} }
@ -161,11 +163,11 @@ where
#[derive(Default)] #[derive(Default)]
struct ThemeStack(Vec<Theme>); struct ThemeStack(Vec<Theme>);
impl<E: 'static + Element + Send + Sync> Element for Themed<E> impl<V, E: 'static + Element<V> + Send + Sync> Element<V> for Themed<E>
where where
V: 'static,
E::ElementState: Send + Sync, E::ElementState: Send + Sync,
{ {
type ViewState = E::ViewState;
type ElementState = E::ElementState; type ElementState = E::ElementState;
fn id(&self) -> Option<gpui2::ElementId> { fn id(&self) -> Option<gpui2::ElementId> {
@ -174,9 +176,9 @@ where
fn initialize( fn initialize(
&mut self, &mut self,
view_state: &mut Self::ViewState, view_state: &mut V,
element_state: Option<Self::ElementState>, element_state: Option<Self::ElementState>,
cx: &mut ViewContext<Self::ViewState>, cx: &mut ViewContext<V>,
) -> Self::ElementState { ) -> Self::ElementState {
cx.default_global::<ThemeStack>().0.push(self.theme.clone()); cx.default_global::<ThemeStack>().0.push(self.theme.clone());
let element_state = self.child.initialize(view_state, element_state, cx); let element_state = self.child.initialize(view_state, element_state, cx);
@ -186,9 +188,9 @@ where
fn layout( fn layout(
&mut self, &mut self,
view_state: &mut E::ViewState, view_state: &mut V,
element_state: &mut Self::ElementState, element_state: &mut Self::ElementState,
cx: &mut ViewContext<E::ViewState>, cx: &mut ViewContext<V>,
) -> LayoutId ) -> LayoutId
where where
Self: Sized, Self: Sized,
@ -202,9 +204,9 @@ where
fn paint( fn paint(
&mut self, &mut self,
bounds: Bounds<Pixels>, bounds: Bounds<Pixels>,
view_state: &mut Self::ViewState, view_state: &mut V,
frame_state: &mut Self::ElementState, frame_state: &mut Self::ElementState,
cx: &mut ViewContext<Self::ViewState>, cx: &mut ViewContext<V>,
) where ) where
Self: Sized, Self: Sized,
{ {