Checkpoint

This commit is contained in:
Antonio Scandurra 2023-10-18 16:30:03 +02:00
parent f4d50c4dca
commit f58a9bad42

View file

@ -1,18 +1,19 @@
use crate::{ use crate::{
div, Active, Anonymous, AnyElement, BorrowWindow, Bounds, Click, Div, DivState, Element, div, Active, Anonymous, AnyElement, BorrowWindow, Bounds, Click, Div, DivState, Element,
ElementId, ElementIdentity, EventListeners, Hover, Identified, Interactive, IntoAnyElement, ElementFocusability, ElementId, ElementIdentity, EventListeners, Focus, Focusable, Hover,
LayoutId, NonFocusable, Pixels, SharedString, StyleRefinement, Styled, ViewContext, Identified, Interactive, IntoAnyElement, LayoutId, NonFocusable, Pixels, SharedString,
StyleRefinement, Styled, ViewContext,
}; };
use futures::FutureExt; use futures::FutureExt;
use util::ResultExt; use util::ResultExt;
pub struct Img<V: 'static + Send + Sync, K: ElementIdentity = Anonymous> { pub struct Img<V: 'static + Send + Sync, I: ElementIdentity, F: ElementFocusability> {
base: Div<V, K, NonFocusable>, base: Div<V, I, F>,
uri: Option<SharedString>, uri: Option<SharedString>,
grayscale: bool, grayscale: bool,
} }
pub fn img<V>() -> Img<V, Anonymous> pub fn img<V>() -> Img<V, Anonymous, NonFocusable>
where where
V: 'static + Send + Sync, V: 'static + Send + Sync,
{ {
@ -23,10 +24,11 @@ where
} }
} }
impl<V, K> Img<V, K> impl<V, I, F> Img<V, I, F>
where where
V: 'static + Send + Sync, V: 'static + Send + Sync,
K: ElementIdentity, I: ElementIdentity,
F: ElementFocusability,
{ {
pub fn uri(mut self, uri: impl Into<SharedString>) -> Self { pub fn uri(mut self, uri: impl Into<SharedString>) -> Self {
self.uri = Some(uri.into()); self.uri = Some(uri.into());
@ -39,8 +41,12 @@ where
} }
} }
impl<V: 'static + Send + Sync> Img<V, Anonymous> { impl<V, F> Img<V, Anonymous, F>
pub fn id(self, id: impl Into<ElementId>) -> Img<V, Identified> { where
V: 'static + Send + Sync,
F: ElementFocusability,
{
pub fn id(self, id: impl Into<ElementId>) -> Img<V, Identified, F> {
Img { Img {
base: self.base.id(id), base: self.base.id(id),
uri: self.uri, uri: self.uri,
@ -49,20 +55,22 @@ impl<V: 'static + Send + Sync> Img<V, Anonymous> {
} }
} }
impl<V, K> IntoAnyElement<V> for Img<V, K> impl<V, I, F> IntoAnyElement<V> for Img<V, I, F>
where where
V: 'static + Send + Sync, V: 'static + Send + Sync,
K: ElementIdentity, I: ElementIdentity,
F: ElementFocusability,
{ {
fn into_any(self) -> AnyElement<V> { fn into_any(self) -> AnyElement<V> {
AnyElement::new(self) AnyElement::new(self)
} }
} }
impl<V, K> Element for Img<V, K> impl<V, I, F> Element for Img<V, I, F>
where where
V: Send + Sync + 'static, V: Send + Sync + 'static,
K: ElementIdentity, I: ElementIdentity,
F: ElementFocusability,
{ {
type ViewState = V; type ViewState = V;
type ElementState = DivState; type ElementState = DivState;
@ -127,43 +135,74 @@ where
} }
} }
impl<V, K> Styled for Img<V, K> impl<V, I, F> Styled for Img<V, I, F>
where where
V: 'static + Send + Sync, V: 'static + Send + Sync,
K: ElementIdentity, I: ElementIdentity,
F: ElementFocusability,
{ {
fn style(&mut self) -> &mut StyleRefinement { fn style(&mut self) -> &mut StyleRefinement {
self.base.style() self.base.style()
} }
} }
impl<V, K> Interactive for Img<V, K> impl<V, I, F> Interactive for Img<V, I, F>
where where
V: 'static + Send + Sync, V: 'static + Send + Sync,
K: ElementIdentity, I: ElementIdentity,
F: ElementFocusability,
{ {
fn listeners(&mut self) -> &mut EventListeners<V> { fn listeners(&mut self) -> &mut EventListeners<V> {
self.base.listeners() self.base.listeners()
} }
} }
impl<V, K> Hover for Img<V, K> impl<V, I, F> Hover for Img<V, I, F>
where where
V: 'static + Send + Sync, V: 'static + Send + Sync,
K: ElementIdentity, I: ElementIdentity,
F: ElementFocusability,
{ {
fn set_hover_style(&mut self, group: Option<SharedString>, style: StyleRefinement) { fn set_hover_style(&mut self, group: Option<SharedString>, style: StyleRefinement) {
self.base.set_hover_style(group, style); self.base.set_hover_style(group, style);
} }
} }
impl<V> Click for Img<V, Identified> where V: 'static + Send + Sync {} impl<V, F> Click for Img<V, Identified, F>
impl<V> Active for Img<V, Identified>
where where
V: 'static + Send + Sync, V: 'static + Send + Sync,
F: ElementFocusability,
{
}
impl<V, F> Active for Img<V, Identified, F>
where
V: 'static + Send + Sync,
F: ElementFocusability,
{ {
fn set_active_style(&mut self, group: Option<SharedString>, style: StyleRefinement) { fn set_active_style(&mut self, group: Option<SharedString>, style: StyleRefinement) {
self.base.set_active_style(group, style) self.base.set_active_style(group, style)
} }
} }
impl<V, I> Focus for Img<V, I, Focusable>
where
V: 'static + Send + Sync,
I: ElementIdentity,
{
fn set_focus_style(&mut self, style: StyleRefinement) {
self.base.set_focus_style(style)
}
fn set_focus_in_style(&mut self, style: StyleRefinement) {
self.base.set_focus_in_style(style)
}
fn set_in_focus_style(&mut self, style: StyleRefinement) {
self.base.set_in_focus_style(style)
}
fn handle(&self) -> &crate::FocusHandle {
self.base.handle()
}
}