diff --git a/crates/gpui3/src/active.rs b/crates/gpui3/src/active.rs deleted file mode 100644 index 93cdb9d8bbd858874c22b97e71a1f4f18f56ac11..0000000000000000000000000000000000000000 --- a/crates/gpui3/src/active.rs +++ /dev/null @@ -1,25 +0,0 @@ -use crate::{SharedString, StyleRefinement}; - -pub trait Active { - fn set_active_style(&mut self, group_name: Option, style: StyleRefinement); - - fn active(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self - where - Self: Sized, - { - self.set_active_style(None, f(StyleRefinement::default())); - self - } - - fn group_active( - mut self, - group_name: impl Into, - f: impl FnOnce(StyleRefinement) -> StyleRefinement, - ) -> Self - where - Self: Sized, - { - self.set_active_style(Some(group_name.into()), f(StyleRefinement::default())); - self - } -} diff --git a/crates/gpui3/src/elements/div.rs b/crates/gpui3/src/elements/div.rs index ec815ea92135e47d0a9dac8f10a21daf8383293b..299efbbf0248a0c2cff99d676415d2c0263d274b 100644 --- a/crates/gpui3/src/elements/div.rs +++ b/crates/gpui3/src/elements/div.rs @@ -1,10 +1,9 @@ use crate::{ - Active, AnyElement, BorrowWindow, Bounds, Element, ElementFocusability, ElementId, + AnyElement, BorrowWindow, Bounds, Element, ElementFocusability, ElementId, ElementInteractivity, Focus, FocusHandle, FocusListeners, Focusable, GlobalElementId, - GroupBounds, GroupStyle, Hover, InteractiveElementState, IntoAnyElement, LayoutId, - NonFocusable, Overflow, ParentElement, Pixels, Point, SharedString, StatefulInteractivity, - StatefullyInteractive, StatelessInteractivity, StatelesslyInteractive, Style, StyleRefinement, - Styled, ViewContext, + GroupBounds, InteractiveElementState, IntoAnyElement, LayoutId, NonFocusable, Overflow, + ParentElement, Pixels, Point, SharedString, StatefulInteractivity, StatefullyInteractive, + StatelessInteractivity, StatelesslyInteractive, Style, StyleRefinement, Styled, ViewContext, }; use parking_lot::Mutex; use refineable::Refineable; @@ -332,22 +331,6 @@ where } } -impl Hover for Div -where - I: ElementInteractivity, - F: ElementFocusability, - V: 'static + Send + Sync, -{ - fn set_hover_style(&mut self, group: Option, style: StyleRefinement) { - let stateless = self.interactivity.as_stateless_mut(); - if let Some(group) = group { - stateless.group_hover_style = Some(GroupStyle { group, style }); - } else { - stateless.hover_style = style; - } - } -} - impl StatefullyInteractive for Div, F> where F: ElementFocusability, @@ -357,17 +340,3 @@ where &mut self.interactivity } } - -impl Active for Div, F> -where - F: ElementFocusability, - V: 'static + Send + Sync, -{ - fn set_active_style(&mut self, group: Option, style: StyleRefinement) { - if let Some(group) = group { - self.interactivity.group_active_style = Some(GroupStyle { group, style }); - } else { - self.interactivity.active_style = style; - } - } -} diff --git a/crates/gpui3/src/elements/img.rs b/crates/gpui3/src/elements/img.rs index e6ebc986e27cee778aa66d0ce8c68f587a6191ff..84664ef9f9bd98f69f74d693e535d1366f6fd0f9 100644 --- a/crates/gpui3/src/elements/img.rs +++ b/crates/gpui3/src/elements/img.rs @@ -1,6 +1,6 @@ use crate::{ - div, Active, AnyElement, BorrowWindow, Bounds, Div, Element, ElementFocusability, ElementId, - ElementInteractivity, Focus, FocusListeners, Focusable, Hover, InteractiveElementState, + div, AnyElement, BorrowWindow, Bounds, Div, Element, ElementFocusability, ElementId, + ElementInteractivity, Focus, FocusListeners, Focusable, InteractiveElementState, IntoAnyElement, LayoutId, NonFocusable, Pixels, SharedString, StatefulInteractivity, StatefullyInteractive, StatelessInteractivity, StatelesslyInteractive, StyleRefinement, Styled, ViewContext, @@ -162,17 +162,6 @@ where } } -impl Hover for Img -where - V: 'static + Send + Sync, - I: ElementInteractivity, - F: ElementFocusability, -{ - fn set_hover_style(&mut self, group: Option, style: StyleRefinement) { - self.base.set_hover_style(group, style); - } -} - impl StatefullyInteractive for Img, F> where V: 'static + Send + Sync, @@ -183,16 +172,6 @@ where } } -impl Active for Img, F> -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, diff --git a/crates/gpui3/src/elements/svg.rs b/crates/gpui3/src/elements/svg.rs index 2af0e5aa6b5e99dd27259d66b4053a5c63c420ce..038a6c5404061cd9a5e698242e0ea3004b5fbceb 100644 --- a/crates/gpui3/src/elements/svg.rs +++ b/crates/gpui3/src/elements/svg.rs @@ -1,9 +1,8 @@ use crate::{ - div, Active, AnyElement, Bounds, Div, Element, ElementFocusability, ElementId, - ElementInteractivity, Focus, FocusListeners, Focusable, Hover, InteractiveElementState, - IntoAnyElement, LayoutId, NonFocusable, Pixels, SharedString, StatefulInteractivity, - StatefullyInteractive, StatelessInteractivity, StatelesslyInteractive, StyleRefinement, Styled, - ViewContext, + div, AnyElement, Bounds, Div, Element, ElementFocusability, ElementId, ElementInteractivity, + Focus, FocusListeners, Focusable, InteractiveElementState, IntoAnyElement, LayoutId, + NonFocusable, Pixels, SharedString, StatefulInteractivity, StatefullyInteractive, + StatelessInteractivity, StatelesslyInteractive, StyleRefinement, Styled, ViewContext, }; use util::ResultExt; @@ -136,17 +135,6 @@ where } } -impl Hover for Svg -where - V: 'static + Send + Sync, - I: ElementInteractivity, - F: ElementFocusability, -{ - fn set_hover_style(&mut self, group: Option, style: StyleRefinement) { - self.base.set_hover_style(group, style); - } -} - impl StatefullyInteractive for Svg, F> where V: 'static + Send + Sync, @@ -157,16 +145,6 @@ where } } -impl Active for Svg, F> -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, diff --git a/crates/gpui3/src/gpui3.rs b/crates/gpui3/src/gpui3.rs index 800593e4c189641f9a6bce65ceb982aa598ad08a..f89b1c7bc179ecf2e2134014c768caae3faf417d 100644 --- a/crates/gpui3/src/gpui3.rs +++ b/crates/gpui3/src/gpui3.rs @@ -1,5 +1,4 @@ mod action; -mod active; mod app; mod assets; mod color; @@ -8,7 +7,6 @@ mod elements; mod executor; mod focus; mod geometry; -mod hover; mod image_cache; mod interactive; mod keymap; @@ -25,7 +23,6 @@ mod view; mod window; pub use action::*; -pub use active::*; pub use anyhow::Result; pub use app::*; pub use assets::*; @@ -36,7 +33,6 @@ pub use executor::*; pub use focus::*; pub use geometry::*; pub use gpui3_macros::*; -pub use hover::*; pub use image_cache::*; pub use interactive::*; pub use keymap::*; diff --git a/crates/gpui3/src/hover.rs b/crates/gpui3/src/hover.rs deleted file mode 100644 index f69cd84f65fc432fe9cf0e97de5bf955db1212e4..0000000000000000000000000000000000000000 --- a/crates/gpui3/src/hover.rs +++ /dev/null @@ -1,25 +0,0 @@ -use crate::{SharedString, StyleRefinement}; - -pub trait Hover { - fn set_hover_style(&mut self, group_name: Option, style: StyleRefinement); - - fn hover(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self - where - Self: Sized, - { - self.set_hover_style(None, f(StyleRefinement::default())); - self - } - - fn group_hover( - mut self, - group_name: impl Into, - f: impl FnOnce(StyleRefinement) -> StyleRefinement, - ) -> Self - where - Self: Sized, - { - self.set_hover_style(Some(group_name.into()), f(StyleRefinement::default())); - self - } -} diff --git a/crates/gpui3/src/interactive.rs b/crates/gpui3/src/interactive.rs index 656162adf358d3e24b64e5f7144c78d741fc919c..25a69b57dd3e50d3e3688622f2ff5517c44ce641 100644 --- a/crates/gpui3/src/interactive.rs +++ b/crates/gpui3/src/interactive.rs @@ -1,6 +1,7 @@ use crate::{ - point, Action, Bounds, DispatchContext, DispatchPhase, Element, FocusHandle, Keystroke, - Modifiers, Pixels, Point, StatefulInteractivity, StatelessInteractivity, ViewContext, + point, Action, Bounds, DispatchContext, DispatchPhase, Element, FocusHandle, GroupStyle, + Keystroke, Modifiers, Pixels, Point, SharedString, StatefulInteractivity, + StatelessInteractivity, StyleRefinement, ViewContext, }; use std::{ any::{Any, TypeId}, @@ -147,6 +148,29 @@ pub trait StatelesslyInteractive: Element { self } + fn hover(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self + where + Self: Sized, + { + self.stateless_interactivity().hover_style = f(StyleRefinement::default()); + self + } + + fn group_hover( + mut self, + group_name: impl Into, + f: impl FnOnce(StyleRefinement) -> StyleRefinement, + ) -> Self + where + Self: Sized, + { + self.stateless_interactivity().group_hover_style = Some(GroupStyle { + group: group_name.into(), + style: f(StyleRefinement::default()), + }); + self + } + fn on_key_down( mut self, listener: impl Fn( @@ -218,6 +242,29 @@ pub trait StatelesslyInteractive: Element { pub trait StatefullyInteractive: StatelesslyInteractive { fn stateful_interactivity(&mut self) -> &mut StatefulInteractivity; + fn active(mut self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self + where + Self: Sized, + { + self.stateful_interactivity().active_style = f(StyleRefinement::default()); + self + } + + fn group_active( + mut self, + group_name: impl Into, + f: impl FnOnce(StyleRefinement) -> StyleRefinement, + ) -> Self + where + Self: Sized, + { + self.stateful_interactivity().group_active_style = Some(GroupStyle { + group: group_name.into(), + style: f(StyleRefinement::default()), + }); + self + } + fn on_click( mut self, handler: impl Fn(&mut Self::ViewState, &MouseClickEvent, &mut ViewContext)