From c3a917f8b3fa923d4e100a7864e1f6081d1a751f Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 20 Oct 2023 11:02:00 +0200 Subject: [PATCH] Checkpoint --- crates/gpui3/src/elements/div.rs | 8 +++--- crates/gpui3/src/elements/img.rs | 10 ++++---- crates/gpui3/src/elements/svg.rs | 8 +++--- crates/gpui3/src/interactive.rs | 44 ++++++++++++++++---------------- 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/crates/gpui3/src/elements/div.rs b/crates/gpui3/src/elements/div.rs index bef0478e7fabfc780ec522b66ab71072f2bd3d3e..b2fe20530dd0ac491657615c7ee10299f3677373 100644 --- a/crates/gpui3/src/elements/div.rs +++ b/crates/gpui3/src/elements/div.rs @@ -2,7 +2,7 @@ use crate::{ AnyElement, BorrowWindow, Bounds, Element, ElementFocus, ElementId, ElementInteraction, FocusDisabled, FocusEnabled, FocusHandle, FocusListeners, Focusable, GlobalElementId, GroupBounds, InteractiveElementState, IntoAnyElement, LayoutId, Overflow, ParentElement, - Pixels, Point, SharedString, StatefulInteractive, StatefulInteractivity, StatelessInteraction, + Pixels, Point, SharedString, StatefulInteraction, StatefulInteractive, StatelessInteraction, StatelessInteractive, Style, StyleRefinement, Styled, ViewContext, }; use parking_lot::Mutex; @@ -61,7 +61,7 @@ where F: ElementFocus, V: 'static + Send + Sync, { - pub fn id(self, id: impl Into) -> Div, F> { + pub fn id(self, id: impl Into) -> Div, F> { Div { interaction: id.into().into(), focus: self.focus, @@ -331,12 +331,12 @@ where } } -impl StatefulInteractive for Div, F> +impl StatefulInteractive for Div, F> where F: ElementFocus, V: 'static + Send + Sync, { - fn stateful_interactivity(&mut self) -> &mut StatefulInteractivity { + fn stateful_interactivity(&mut self) -> &mut StatefulInteraction { &mut self.interaction } } diff --git a/crates/gpui3/src/elements/img.rs b/crates/gpui3/src/elements/img.rs index ff00d40a58b45db041d206f812d547694d29e883..273126313633905d9b30865c5c42ff0f583a4433 100644 --- a/crates/gpui3/src/elements/img.rs +++ b/crates/gpui3/src/elements/img.rs @@ -1,8 +1,8 @@ use crate::{ div, AnyElement, BorrowWindow, Bounds, Div, Element, ElementFocus, ElementId, ElementInteraction, FocusDisabled, FocusEnabled, FocusListeners, Focusable, - InteractiveElementState, IntoAnyElement, LayoutId, Pixels, SharedString, StatefulInteractive, - StatefulInteractivity, StatelessInteraction, StatelessInteractive, StyleRefinement, Styled, + InteractiveElementState, IntoAnyElement, LayoutId, Pixels, SharedString, StatefulInteraction, + StatefulInteractive, StatelessInteraction, StatelessInteractive, StyleRefinement, Styled, ViewContext, }; use futures::FutureExt; @@ -51,7 +51,7 @@ where V: 'static + Send + Sync, F: ElementFocus, { - pub fn id(self, id: impl Into) -> Img, F> { + pub fn id(self, id: impl Into) -> Img, F> { Img { base: self.base.id(id), uri: self.uri, @@ -162,12 +162,12 @@ where } } -impl StatefulInteractive for Img, F> +impl StatefulInteractive for Img, F> where V: 'static + Send + Sync, F: ElementFocus, { - fn stateful_interactivity(&mut self) -> &mut StatefulInteractivity { + fn stateful_interactivity(&mut self) -> &mut StatefulInteraction { self.base.stateful_interactivity() } } diff --git a/crates/gpui3/src/elements/svg.rs b/crates/gpui3/src/elements/svg.rs index 941ad5a5293ef3c4c76cc24db318e95b08283fde..d59c1b8f04dcdaad825437ec296c806ae6633e85 100644 --- a/crates/gpui3/src/elements/svg.rs +++ b/crates/gpui3/src/elements/svg.rs @@ -1,7 +1,7 @@ use crate::{ div, AnyElement, Bounds, Div, Element, ElementFocus, ElementId, ElementInteraction, FocusDisabled, FocusEnabled, FocusListeners, Focusable, InteractiveElementState, - IntoAnyElement, LayoutId, Pixels, SharedString, StatefulInteractive, StatefulInteractivity, + IntoAnyElement, LayoutId, Pixels, SharedString, StatefulInteraction, StatefulInteractive, StatelessInteraction, StatelessInteractive, StyleRefinement, Styled, ViewContext, }; use util::ResultExt; @@ -42,7 +42,7 @@ where V: 'static + Send + Sync, F: ElementFocus, { - pub fn id(self, id: impl Into) -> Svg, F> { + pub fn id(self, id: impl Into) -> Svg, F> { Svg { base: self.base.id(id), path: self.path, @@ -135,12 +135,12 @@ where } } -impl StatefulInteractive for Svg, F> +impl StatefulInteractive for Svg, F> where V: 'static + Send + Sync, F: ElementFocus, { - fn stateful_interactivity(&mut self) -> &mut StatefulInteractivity { + fn stateful_interactivity(&mut self) -> &mut StatefulInteraction { self.base.stateful_interactivity() } } diff --git a/crates/gpui3/src/interactive.rs b/crates/gpui3/src/interactive.rs index 4cf0e3f0148398106873aff3de5dff6a6e015aae..d5c5239934f3616f8d2316aabdf5b0433ad0bdb9 100644 --- a/crates/gpui3/src/interactive.rs +++ b/crates/gpui3/src/interactive.rs @@ -176,14 +176,10 @@ pub trait StatelessInteractive: Element { self } - fn on_key_down( + fn on_action( mut self, - listener: impl Fn( - &mut Self::ViewState, - &KeyDownEvent, - DispatchPhase, - &mut ViewContext, - ) + Send + listener: impl Fn(&mut Self::ViewState, &A, DispatchPhase, &mut ViewContext) + + Send + Sync + 'static, ) -> Self @@ -191,7 +187,7 @@ pub trait StatelessInteractive: Element { Self: Sized, { self.stateless_interactivity().key_listeners.push(( - TypeId::of::(), + TypeId::of::(), Arc::new(move |view, event, _, phase, cx| { let event = event.downcast_ref().unwrap(); listener(view, event, phase, cx); @@ -201,10 +197,14 @@ pub trait StatelessInteractive: Element { self } - fn on_action( + fn on_key_down( mut self, - listener: impl Fn(&mut Self::ViewState, &A, DispatchPhase, &mut ViewContext) - + Send + listener: impl Fn( + &mut Self::ViewState, + &KeyDownEvent, + DispatchPhase, + &mut ViewContext, + ) + Send + Sync + 'static, ) -> Self @@ -212,7 +212,7 @@ pub trait StatelessInteractive: Element { Self: Sized, { self.stateless_interactivity().key_listeners.push(( - TypeId::of::(), + TypeId::of::(), Arc::new(move |view, event, _, phase, cx| { let event = event.downcast_ref().unwrap(); listener(view, event, phase, cx); @@ -245,7 +245,7 @@ pub trait StatelessInteractive: Element { } pub trait StatefulInteractive: StatelessInteractive { - fn stateful_interactivity(&mut self) -> &mut StatefulInteractivity; + fn stateful_interactivity(&mut self) -> &mut StatefulInteraction; fn active(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self where @@ -290,8 +290,8 @@ pub trait StatefulInteractive: StatelessInteractive { pub trait ElementInteraction: 'static + Send + Sync { fn as_stateless(&self) -> &StatelessInteraction; fn as_stateless_mut(&mut self) -> &mut StatelessInteraction; - fn as_stateful(&self) -> Option<&StatefulInteractivity>; - fn as_stateful_mut(&mut self) -> Option<&mut StatefulInteractivity>; + fn as_stateful(&self) -> Option<&StatefulInteraction>; + fn as_stateful_mut(&mut self) -> Option<&mut StatefulInteraction>; fn initialize( &mut self, @@ -472,7 +472,7 @@ where } #[derive(Deref, DerefMut)] -pub struct StatefulInteractivity { +pub struct StatefulInteraction { pub id: ElementId, #[deref] #[deref_mut] @@ -482,15 +482,15 @@ pub struct StatefulInteractivity { pub group_active_style: Option, } -impl ElementInteraction for StatefulInteractivity +impl ElementInteraction for StatefulInteraction where V: 'static + Send + Sync, { - fn as_stateful(&self) -> Option<&StatefulInteractivity> { + fn as_stateful(&self) -> Option<&StatefulInteraction> { Some(self) } - fn as_stateful_mut(&mut self) -> Option<&mut StatefulInteractivity> { + fn as_stateful_mut(&mut self) -> Option<&mut StatefulInteraction> { Some(self) } @@ -503,7 +503,7 @@ where } } -impl From for StatefulInteractivity +impl From for StatefulInteraction where V: 'static + Send + Sync, { @@ -598,11 +598,11 @@ impl ElementInteraction for StatelessInteraction where V: 'static + Send + Sync, { - fn as_stateful(&self) -> Option<&StatefulInteractivity> { + fn as_stateful(&self) -> Option<&StatefulInteraction> { None } - fn as_stateful_mut(&mut self) -> Option<&mut StatefulInteractivity> { + fn as_stateful_mut(&mut self) -> Option<&mut StatefulInteraction> { None }