diff --git a/crates/gpui3/src/elements/div.rs b/crates/gpui3/src/elements/div.rs index 1cada008f22eb01d340df488cdecad68b825f22d..6919247c53085c01dcd0cf50358266126341cdd3 100644 --- a/crates/gpui3/src/elements/div.rs +++ b/crates/gpui3/src/elements/div.rs @@ -60,7 +60,7 @@ impl ScrollState { } } -pub fn div() -> Div +pub fn div() -> Div where V: 'static + Send + Sync, { @@ -81,7 +81,7 @@ where } } -pub struct Div { +pub struct Div { identity: I, focusability: F, children: SmallVec<[AnyElement; 2]>, @@ -102,12 +102,12 @@ struct GroupStyle { style: StyleRefinement, } -impl Div +impl Div where F: ElementFocusability, V: 'static + Send + Sync, { - pub fn id(self, id: impl Into) -> Div { + pub fn id(self, id: impl Into) -> Div { Div { identity: Identified(id.into()), focusability: self.focusability, @@ -126,7 +126,7 @@ where } } -impl Div +impl Div where I: ElementIdentity, F: ElementFocusability, @@ -341,12 +341,12 @@ where } } -impl Div +impl Div where I: ElementIdentity, V: 'static + Send + Sync, { - pub fn focusable(self, handle: &FocusHandle) -> Div { + pub fn focusable(self, handle: &FocusHandle) -> Div { Div { identity: self.identity, focusability: handle.clone().into(), @@ -365,7 +365,7 @@ where } } -impl Focus for Div +impl Focus for Div where I: ElementIdentity, V: 'static + Send + Sync, @@ -387,7 +387,7 @@ where } } -impl Element for Div +impl Element for Div where I: ElementIdentity, F: ElementFocusability, @@ -502,7 +502,7 @@ where } } -impl IntoAnyElement for Div +impl IntoAnyElement for Div where I: ElementIdentity, F: ElementFocusability, @@ -513,7 +513,7 @@ where } } -impl ParentElement for Div +impl ParentElement for Div where I: ElementIdentity, F: ElementFocusability, @@ -524,7 +524,7 @@ where } } -impl Styled for Div +impl Styled for Div where I: ElementIdentity, F: ElementFocusability, @@ -535,7 +535,7 @@ where } } -impl Interactive for Div +impl Interactive for Div where I: ElementIdentity, F: ElementFocusability, @@ -546,7 +546,7 @@ where } } -impl Hover for Div +impl Hover for Div where I: ElementIdentity, F: ElementFocusability, @@ -561,14 +561,14 @@ where } } -impl Click for Div +impl Click for Div where F: ElementFocusability, V: 'static + Send + Sync, { } -impl Active for Div +impl Active for Div where F: ElementFocusability, V: 'static + Send + Sync, diff --git a/crates/gpui3/src/elements/img.rs b/crates/gpui3/src/elements/img.rs index 261062a5b942035c0ae3b0694791c00f2de6ab71..6d9ba59251e5cc98ed460fdc87bf874dd90b86d6 100644 --- a/crates/gpui3/src/elements/img.rs +++ b/crates/gpui3/src/elements/img.rs @@ -7,7 +7,7 @@ use futures::FutureExt; use util::ResultExt; pub struct Img { - base: Div, + base: Div, uri: Option, grayscale: bool, } diff --git a/crates/gpui3/src/elements/svg.rs b/crates/gpui3/src/elements/svg.rs index f0d6956503aee723f4c6c9c51c675c61d41f313e..c3f4972cb66dfcefae599252a4cefd2100874147 100644 --- a/crates/gpui3/src/elements/svg.rs +++ b/crates/gpui3/src/elements/svg.rs @@ -1,16 +1,17 @@ use crate::{ - div, Active, Anonymous, AnyElement, Bounds, Click, Div, DivState, Element, ElementId, - ElementIdentity, EventListeners, Hover, Identified, Interactive, IntoAnyElement, LayoutId, - NonFocusable, Pixels, SharedString, StyleRefinement, Styled, ViewContext, + div, Active, Anonymous, AnyElement, Bounds, Click, Div, DivState, Element, ElementFocusability, + ElementId, ElementIdentity, EventListeners, Focus, Focusable, Hover, Identified, Interactive, + IntoAnyElement, LayoutId, NonFocusable, Pixels, SharedString, StyleRefinement, Styled, + ViewContext, }; use util::ResultExt; -pub struct Svg { - base: Div, +pub struct Svg { + base: Div, path: Option, } -pub fn svg() -> Svg +pub fn svg() -> Svg where V: 'static + Send + Sync, { @@ -20,10 +21,11 @@ where } } -impl Svg +impl Svg where V: 'static + Send + Sync, - K: ElementIdentity, + I: ElementIdentity, + F: ElementFocusability, { pub fn path(mut self, path: impl Into) -> Self { self.path = Some(path.into()); @@ -31,8 +33,12 @@ where } } -impl Svg { - pub fn id(self, id: impl Into) -> Svg { +impl Svg +where + V: 'static + Send + Sync, + F: ElementFocusability, +{ + pub fn id(self, id: impl Into) -> Svg { Svg { base: self.base.id(id), path: self.path, @@ -40,20 +46,22 @@ impl Svg { } } -impl IntoAnyElement for Svg +impl IntoAnyElement for Svg where V: 'static + Send + Sync, - K: ElementIdentity, + I: ElementIdentity, + F: ElementFocusability, { fn into_any(self) -> AnyElement { AnyElement::new(self) } } -impl Element for Svg +impl Element for Svg where V: 'static + Send + Sync, - K: ElementIdentity, + I: ElementIdentity, + F: ElementFocusability, { type ViewState = V; type ElementState = DivState; @@ -101,43 +109,74 @@ where } } -impl Styled for Svg +impl Styled for Svg where V: 'static + Send + Sync, - K: ElementIdentity, + I: ElementIdentity, + F: ElementFocusability, { fn style(&mut self) -> &mut StyleRefinement { self.base.style() } } -impl Interactive for Svg +impl Interactive for Svg where V: 'static + Send + Sync, - K: ElementIdentity, + I: ElementIdentity, + F: ElementFocusability, { fn listeners(&mut self) -> &mut EventListeners { self.base.listeners() } } -impl Hover for Svg +impl Hover for Svg 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 Svg where V: 'static + Send + Sync {} +impl Click for Svg +where + V: 'static + Send + Sync, + F: ElementFocusability, +{ +} -impl Active for Svg +impl Active for Svg 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 Svg +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() + } +}