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