From 8b972f6d8ebbbf73955f26a3e77764a0a7be8c23 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Thu, 26 Oct 2023 09:51:33 +0200 Subject: [PATCH] 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 e20d26b3d711fb52b36180eb80dde0a34129df81..c6707049a6857bc1823217cae4a1763c1b529ce9 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 9e1414e91af583e38185fb494bc155df2736ec75..fbef75ab1c02f765eed5c5148bf6fc751d16c5ef 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 e52b1ca3326d0e9926f194ea96d30b88ce464419..d64536a7ed74a967bd2ca770255d6dcf6a694600 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 ae388efb3f002b9d34b7f429920876b71fb07c10..409094d740ef2bc3a523d14f07430b9c41af685d 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 7b0052826cd4e5086fbfea95fb5646d4bb9d8656..e054da87a68bb3266142d90785c45b476631553c 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 0d2e09ec49f4c76a4cc47521ac8ddd1571797b8a..c283998ca26c575d0bd8373eb7fe6c2a33dd914e 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 7cc014e7231caba7ca71cad5d4358f98f1e96e9c..f00e24b4724e53bee26ecbb281f5c3aa74df7e6c 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 13f29e641d0233a091caa0b4c37002ee133731b1..b1b287c4ab20e186351783b5591d0e45f6be9c59 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) }