Checkpoint

This commit is contained in:
Antonio Scandurra
2023-10-20 11:02:00 +02:00
parent 766ee836b5
commit c3a917f8b3
4 changed files with 44 additions and 44 deletions
+4 -4
View File
@@ -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>,
V: 'static + Send + Sync,
{
pub fn id(self, id: impl Into<ElementId>) -> Div<V, StatefulInteractivity<V>, F> {
pub fn id(self, id: impl Into<ElementId>) -> Div<V, StatefulInteraction<V>, F> {
Div {
interaction: id.into().into(),
focus: self.focus,
@@ -331,12 +331,12 @@ where
}
}
impl<V, F> StatefulInteractive for Div<V, StatefulInteractivity<V>, F>
impl<V, F> StatefulInteractive for Div<V, StatefulInteraction<V>, F>
where
F: ElementFocus<V>,
V: 'static + Send + Sync,
{
fn stateful_interactivity(&mut self) -> &mut StatefulInteractivity<Self::ViewState> {
fn stateful_interactivity(&mut self) -> &mut StatefulInteraction<Self::ViewState> {
&mut self.interaction
}
}
+5 -5
View File
@@ -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<V>,
{
pub fn id(self, id: impl Into<ElementId>) -> Img<V, StatefulInteractivity<V>, F> {
pub fn id(self, id: impl Into<ElementId>) -> Img<V, StatefulInteraction<V>, F> {
Img {
base: self.base.id(id),
uri: self.uri,
@@ -162,12 +162,12 @@ where
}
}
impl<V, F> StatefulInteractive for Img<V, StatefulInteractivity<V>, F>
impl<V, F> StatefulInteractive for Img<V, StatefulInteraction<V>, F>
where
V: 'static + Send + Sync,
F: ElementFocus<V>,
{
fn stateful_interactivity(&mut self) -> &mut StatefulInteractivity<Self::ViewState> {
fn stateful_interactivity(&mut self) -> &mut StatefulInteraction<Self::ViewState> {
self.base.stateful_interactivity()
}
}
+4 -4
View File
@@ -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<V>,
{
pub fn id(self, id: impl Into<ElementId>) -> Svg<V, StatefulInteractivity<V>, F> {
pub fn id(self, id: impl Into<ElementId>) -> Svg<V, StatefulInteraction<V>, F> {
Svg {
base: self.base.id(id),
path: self.path,
@@ -135,12 +135,12 @@ where
}
}
impl<V, F> StatefulInteractive for Svg<V, StatefulInteractivity<V>, F>
impl<V, F> StatefulInteractive for Svg<V, StatefulInteraction<V>, F>
where
V: 'static + Send + Sync,
F: ElementFocus<V>,
{
fn stateful_interactivity(&mut self) -> &mut StatefulInteractivity<Self::ViewState> {
fn stateful_interactivity(&mut self) -> &mut StatefulInteraction<Self::ViewState> {
self.base.stateful_interactivity()
}
}
+31 -31
View File
@@ -176,6 +176,27 @@ pub trait StatelessInteractive: Element {
self
}
fn on_action<A: 'static>(
mut self,
listener: impl Fn(&mut Self::ViewState, &A, DispatchPhase, &mut ViewContext<Self::ViewState>)
+ Send
+ Sync
+ 'static,
) -> Self
where
Self: Sized,
{
self.stateless_interactivity().key_listeners.push((
TypeId::of::<A>(),
Arc::new(move |view, event, _, phase, cx| {
let event = event.downcast_ref().unwrap();
listener(view, event, phase, cx);
None
}),
));
self
}
fn on_key_down(
mut self,
listener: impl Fn(
@@ -201,27 +222,6 @@ pub trait StatelessInteractive: Element {
self
}
fn on_action<A: 'static>(
mut self,
listener: impl Fn(&mut Self::ViewState, &A, DispatchPhase, &mut ViewContext<Self::ViewState>)
+ Send
+ Sync
+ 'static,
) -> Self
where
Self: Sized,
{
self.stateless_interactivity().key_listeners.push((
TypeId::of::<A>(),
Arc::new(move |view, event, _, phase, cx| {
let event = event.downcast_ref().unwrap();
listener(view, event, phase, cx);
None
}),
));
self
}
fn on_key_up(
mut self,
listener: impl Fn(&mut Self::ViewState, &KeyUpEvent, DispatchPhase, &mut ViewContext<Self::ViewState>)
@@ -245,7 +245,7 @@ pub trait StatelessInteractive: Element {
}
pub trait StatefulInteractive: StatelessInteractive {
fn stateful_interactivity(&mut self) -> &mut StatefulInteractivity<Self::ViewState>;
fn stateful_interactivity(&mut self) -> &mut StatefulInteraction<Self::ViewState>;
fn active(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self
where
@@ -290,8 +290,8 @@ pub trait StatefulInteractive: StatelessInteractive {
pub trait ElementInteraction<V: 'static + Send + Sync>: 'static + Send + Sync {
fn as_stateless(&self) -> &StatelessInteraction<V>;
fn as_stateless_mut(&mut self) -> &mut StatelessInteraction<V>;
fn as_stateful(&self) -> Option<&StatefulInteractivity<V>>;
fn as_stateful_mut(&mut self) -> Option<&mut StatefulInteractivity<V>>;
fn as_stateful(&self) -> Option<&StatefulInteraction<V>>;
fn as_stateful_mut(&mut self) -> Option<&mut StatefulInteraction<V>>;
fn initialize<R>(
&mut self,
@@ -472,7 +472,7 @@ where
}
#[derive(Deref, DerefMut)]
pub struct StatefulInteractivity<V: 'static + Send + Sync> {
pub struct StatefulInteraction<V: 'static + Send + Sync> {
pub id: ElementId,
#[deref]
#[deref_mut]
@@ -482,15 +482,15 @@ pub struct StatefulInteractivity<V: 'static + Send + Sync> {
pub group_active_style: Option<GroupStyle>,
}
impl<V> ElementInteraction<V> for StatefulInteractivity<V>
impl<V> ElementInteraction<V> for StatefulInteraction<V>
where
V: 'static + Send + Sync,
{
fn as_stateful(&self) -> Option<&StatefulInteractivity<V>> {
fn as_stateful(&self) -> Option<&StatefulInteraction<V>> {
Some(self)
}
fn as_stateful_mut(&mut self) -> Option<&mut StatefulInteractivity<V>> {
fn as_stateful_mut(&mut self) -> Option<&mut StatefulInteraction<V>> {
Some(self)
}
@@ -503,7 +503,7 @@ where
}
}
impl<V> From<ElementId> for StatefulInteractivity<V>
impl<V> From<ElementId> for StatefulInteraction<V>
where
V: 'static + Send + Sync,
{
@@ -598,11 +598,11 @@ impl<V> ElementInteraction<V> for StatelessInteraction<V>
where
V: 'static + Send + Sync,
{
fn as_stateful(&self) -> Option<&StatefulInteractivity<V>> {
fn as_stateful(&self) -> Option<&StatefulInteraction<V>> {
None
}
fn as_stateful_mut(&mut self) -> Option<&mut StatefulInteractivity<V>> {
fn as_stateful_mut(&mut self) -> Option<&mut StatefulInteraction<V>> {
None
}