diff --git a/crates/gpui3/src/element.rs b/crates/gpui3/src/element.rs index d384498259f366436d2dd13cd5edead3464e2e73..ee9501d21e838b2e31b6bba33da7de18ec9afc05 100644 --- a/crates/gpui3/src/element.rs +++ b/crates/gpui3/src/element.rs @@ -44,9 +44,9 @@ pub trait Element: 'static + Send + Sync + IntoAnyElement { #[derive(Deref, DerefMut, Default, Clone, Debug, Eq, PartialEq, Hash)] pub struct GlobalElementId(SmallVec<[ElementId; 32]>); -pub trait ElementInteractivity: 'static + Send + Sync { - fn as_stateless(&self) -> &StatelessInteractivity; - fn as_stateless_mut(&mut self) -> &mut StatelessInteractivity; +pub trait ElementInteraction: 'static + Send + Sync { + fn as_stateless(&self) -> &StatelessInteraction; + fn as_stateless_mut(&mut self) -> &mut StatelessInteraction; fn as_stateful(&self) -> Option<&StatefulInteractivity>; fn as_stateful_mut(&mut self) -> Option<&mut StatefulInteractivity>; @@ -233,13 +233,13 @@ pub struct StatefulInteractivity { pub id: ElementId, #[deref] #[deref_mut] - stateless: StatelessInteractivity, + stateless: StatelessInteraction, pub mouse_click_listeners: SmallVec<[MouseClickListener; 2]>, pub active_style: StyleRefinement, pub group_active_style: Option, } -impl ElementInteractivity for StatefulInteractivity +impl ElementInteraction for StatefulInteractivity where V: 'static + Send + Sync, { @@ -251,11 +251,11 @@ where Some(self) } - fn as_stateless(&self) -> &StatelessInteractivity { + fn as_stateless(&self) -> &StatelessInteraction { &self.stateless } - fn as_stateless_mut(&mut self) -> &mut StatelessInteractivity { + fn as_stateless_mut(&mut self) -> &mut StatelessInteraction { &mut self.stateless } } @@ -267,7 +267,7 @@ where fn from(id: ElementId) -> Self { Self { id, - stateless: StatelessInteractivity::default(), + stateless: StatelessInteraction::default(), mouse_click_listeners: SmallVec::new(), active_style: StyleRefinement::default(), group_active_style: None, @@ -275,7 +275,7 @@ where } } -pub struct StatelessInteractivity { +pub struct StatelessInteraction { pub mouse_down_listeners: SmallVec<[MouseDownListener; 2]>, pub mouse_up_listeners: SmallVec<[MouseUpListener; 2]>, pub mouse_move_listeners: SmallVec<[MouseMoveListener; 2]>, @@ -337,7 +337,7 @@ pub struct InteractiveElementState { pending_click: Arc>>, } -impl Default for StatelessInteractivity { +impl Default for StatelessInteraction { fn default() -> Self { Self { mouse_down_listeners: SmallVec::new(), @@ -351,7 +351,7 @@ impl Default for StatelessInteractivity { } } -impl ElementInteractivity for StatelessInteractivity +impl ElementInteraction for StatelessInteraction where V: 'static + Send + Sync, { @@ -363,17 +363,17 @@ where None } - fn as_stateless(&self) -> &StatelessInteractivity { + fn as_stateless(&self) -> &StatelessInteraction { self } - fn as_stateless_mut(&mut self) -> &mut StatelessInteractivity { + fn as_stateless_mut(&mut self) -> &mut StatelessInteraction { self } } -pub trait ElementFocusability: 'static + Send + Sync { - fn as_focusable(&self) -> Option<&Focusable>; +pub trait ElementFocus: 'static + Send + Sync { + fn as_focusable(&self) -> Option<&FocusEnabled>; fn initialize( &self, @@ -421,7 +421,7 @@ pub trait ElementFocusability: 'static + Send + Sync { } } -pub struct Focusable { +pub struct FocusEnabled { pub focus_handle: FocusHandle, pub focus_listeners: FocusListeners, pub focus_style: StyleRefinement, @@ -429,16 +429,16 @@ pub struct Focusable { pub in_focus_style: StyleRefinement, } -impl ElementFocusability for Focusable +impl ElementFocus for FocusEnabled where V: 'static + Send + Sync, { - fn as_focusable(&self) -> Option<&Focusable> { + fn as_focusable(&self) -> Option<&FocusEnabled> { Some(self) } } -impl From for Focusable +impl From for FocusEnabled where V: 'static + Send + Sync, { @@ -453,13 +453,13 @@ where } } -pub struct NonFocusable; +pub struct FocusDisabled; -impl ElementFocusability for NonFocusable +impl ElementFocus for FocusDisabled where V: 'static + Send + Sync, { - fn as_focusable(&self) -> Option<&Focusable> { + fn as_focusable(&self) -> Option<&FocusEnabled> { None } } diff --git a/crates/gpui3/src/elements/div.rs b/crates/gpui3/src/elements/div.rs index 299efbbf0248a0c2cff99d676415d2c0263d274b..14f1757c3f00ebf9ed0767d5081914b7e0ae4d36 100644 --- a/crates/gpui3/src/elements/div.rs +++ b/crates/gpui3/src/elements/div.rs @@ -1,9 +1,9 @@ use crate::{ - AnyElement, BorrowWindow, Bounds, Element, ElementFocusability, ElementId, - ElementInteractivity, Focus, FocusHandle, FocusListeners, Focusable, GlobalElementId, - GroupBounds, InteractiveElementState, IntoAnyElement, LayoutId, NonFocusable, Overflow, - ParentElement, Pixels, Point, SharedString, StatefulInteractivity, StatefullyInteractive, - StatelessInteractivity, StatelesslyInteractive, Style, StyleRefinement, Styled, ViewContext, + AnyElement, BorrowWindow, Bounds, Element, ElementFocus, ElementId, ElementInteraction, + FocusDisabled, FocusEnabled, FocusHandle, FocusListeners, Focusable, GlobalElementId, + GroupBounds, InteractiveElementState, IntoAnyElement, LayoutId, Overflow, ParentElement, + Pixels, Point, SharedString, StatefulInteractivity, StatefullyInteractive, + StatelessInteraction, StatelesslyInteractive, Style, StyleRefinement, Styled, ViewContext, }; use parking_lot::Mutex; use refineable::Refineable; @@ -33,38 +33,38 @@ impl ScrollState { pub struct Div< V: 'static + Send + Sync, - I: ElementInteractivity = StatelessInteractivity, - F: ElementFocusability = NonFocusable, + I: ElementInteraction = StatelessInteraction, + F: ElementFocus = FocusDisabled, > { - interactivity: I, - focusability: F, + interaction: I, + focus: F, children: SmallVec<[AnyElement; 2]>, group: Option, base_style: StyleRefinement, } -pub fn div() -> Div, NonFocusable> +pub fn div() -> Div, FocusDisabled> where V: 'static + Send + Sync, { Div { - interactivity: StatelessInteractivity::default(), - focusability: NonFocusable, + interaction: StatelessInteraction::default(), + focus: FocusDisabled, children: SmallVec::new(), group: None, base_style: StyleRefinement::default(), } } -impl Div, F> +impl Div, F> where - F: ElementFocusability, + F: ElementFocus, V: 'static + Send + Sync, { pub fn id(self, id: impl Into) -> Div, F> { Div { - interactivity: id.into().into(), - focusability: self.focusability, + interaction: id.into().into(), + focus: self.focus, children: self.children, group: self.group, base_style: self.base_style, @@ -74,8 +74,8 @@ where impl Div where - I: ElementInteractivity, - F: ElementFocusability, + I: ElementInteraction, + F: ElementFocus, V: 'static + Send + Sync, { pub fn group(mut self, group: impl Into) -> Self { @@ -146,22 +146,22 @@ where ) -> Style { let mut computed_style = Style::default(); computed_style.refine(&self.base_style); - self.focusability.refine_style(&mut computed_style, cx); - self.interactivity + self.focus.refine_style(&mut computed_style, cx); + self.interaction .refine_style(&mut computed_style, bounds, state, cx); computed_style } } -impl Div +impl Div where - I: ElementInteractivity, + I: ElementInteraction, V: 'static + Send + Sync, { - pub fn focusable(self, handle: &FocusHandle) -> Div> { + pub fn focusable(self, handle: &FocusHandle) -> Div> { Div { - interactivity: self.interactivity, - focusability: handle.clone().into(), + interaction: self.interaction, + focus: handle.clone().into(), children: self.children, group: self.group, base_style: self.base_style, @@ -169,43 +169,43 @@ where } } -impl Focus for Div> +impl Focusable for Div> where - I: ElementInteractivity, + I: ElementInteraction, V: 'static + Send + Sync, { fn focus_listeners(&mut self) -> &mut FocusListeners { - &mut self.focusability.focus_listeners + &mut self.focus.focus_listeners } fn handle(&self) -> &FocusHandle { - &self.focusability.focus_handle + &self.focus.focus_handle } fn set_focus_style(&mut self, style: StyleRefinement) { - self.focusability.focus_style = style; + self.focus.focus_style = style; } fn set_focus_in_style(&mut self, style: StyleRefinement) { - self.focusability.focus_in_style = style; + self.focus.focus_in_style = style; } fn set_in_focus_style(&mut self, style: StyleRefinement) { - self.focusability.in_focus_style = style; + self.focus.in_focus_style = style; } } impl Element for Div where - I: ElementInteractivity, - F: ElementFocusability, + I: ElementInteraction, + F: ElementFocus, V: 'static + Send + Sync, { type ViewState = V; type ElementState = InteractiveElementState; fn id(&self) -> Option { - self.interactivity + self.interaction .as_stateful() .map(|identified| identified.id.clone()) } @@ -216,8 +216,8 @@ where element_state: Option, cx: &mut ViewContext, ) -> Self::ElementState { - self.interactivity.initialize(cx, |cx| { - self.focusability.initialize(cx, |cx| { + self.interaction.initialize(cx, |cx| { + self.focus.initialize(cx, |cx| { for child in &mut self.children { child.initialize(view_state, cx); } @@ -265,8 +265,8 @@ where cx.stack(0, |cx| { style.paint(bounds, cx); - this.focusability.paint(bounds, cx); - this.interactivity.paint(bounds, element_state, cx); + this.focus.paint(bounds, cx); + this.interaction.paint(bounds, element_state, cx); }); cx.stack(1, |cx| { @@ -289,8 +289,8 @@ where impl IntoAnyElement for Div where - I: ElementInteractivity, - F: ElementFocusability, + I: ElementInteraction, + F: ElementFocus, V: 'static + Send + Sync, { fn into_any(self) -> AnyElement { @@ -300,8 +300,8 @@ where impl ParentElement for Div where - I: ElementInteractivity, - F: ElementFocusability, + I: ElementInteraction, + F: ElementFocus, V: 'static + Send + Sync, { fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> { @@ -311,8 +311,8 @@ where impl Styled for Div where - I: ElementInteractivity, - F: ElementFocusability, + I: ElementInteraction, + F: ElementFocus, V: 'static + Send + Sync, { fn style(&mut self) -> &mut StyleRefinement { @@ -322,21 +322,21 @@ where impl StatelesslyInteractive for Div where - I: ElementInteractivity, - F: ElementFocusability, + I: ElementInteraction, + F: ElementFocus, V: 'static + Send + Sync, { - fn stateless_interactivity(&mut self) -> &mut StatelessInteractivity { - self.interactivity.as_stateless_mut() + fn stateless_interactivity(&mut self) -> &mut StatelessInteraction { + self.interaction.as_stateless_mut() } } impl StatefullyInteractive for Div, F> where - F: ElementFocusability, + F: ElementFocus, V: 'static + Send + Sync, { fn stateful_interactivity(&mut self) -> &mut StatefulInteractivity { - &mut self.interactivity + &mut self.interaction } } diff --git a/crates/gpui3/src/elements/img.rs b/crates/gpui3/src/elements/img.rs index 84664ef9f9bd98f69f74d693e535d1366f6fd0f9..d478ca35e6a8511ae607a5cf8bd50eedb76916ba 100644 --- a/crates/gpui3/src/elements/img.rs +++ b/crates/gpui3/src/elements/img.rs @@ -1,8 +1,8 @@ use crate::{ - div, AnyElement, BorrowWindow, Bounds, Div, Element, ElementFocusability, ElementId, - ElementInteractivity, Focus, FocusListeners, Focusable, InteractiveElementState, - IntoAnyElement, LayoutId, NonFocusable, Pixels, SharedString, StatefulInteractivity, - StatefullyInteractive, StatelessInteractivity, StatelesslyInteractive, StyleRefinement, Styled, + div, AnyElement, BorrowWindow, Bounds, Div, Element, ElementFocus, ElementId, + ElementInteraction, FocusDisabled, FocusEnabled, FocusListeners, Focusable, + InteractiveElementState, IntoAnyElement, LayoutId, Pixels, SharedString, StatefulInteractivity, + StatefullyInteractive, StatelessInteraction, StatelesslyInteractive, StyleRefinement, Styled, ViewContext, }; use futures::FutureExt; @@ -10,15 +10,15 @@ use util::ResultExt; pub struct Img< V: 'static + Send + Sync, - I: ElementInteractivity = StatelessInteractivity, - F: ElementFocusability = NonFocusable, + I: ElementInteraction = StatelessInteraction, + F: ElementFocus = FocusDisabled, > { base: Div, uri: Option, grayscale: bool, } -pub fn img() -> Img, NonFocusable> +pub fn img() -> Img, FocusDisabled> where V: 'static + Send + Sync, { @@ -32,8 +32,8 @@ where impl Img where V: 'static + Send + Sync, - I: ElementInteractivity, - F: ElementFocusability, + I: ElementInteraction, + F: ElementFocus, { pub fn uri(mut self, uri: impl Into) -> Self { self.uri = Some(uri.into()); @@ -46,10 +46,10 @@ where } } -impl Img, F> +impl Img, F> where V: 'static + Send + Sync, - F: ElementFocusability, + F: ElementFocus, { pub fn id(self, id: impl Into) -> Img, F> { Img { @@ -63,8 +63,8 @@ where impl IntoAnyElement for Img where V: 'static + Send + Sync, - I: ElementInteractivity, - F: ElementFocusability, + I: ElementInteraction, + F: ElementFocus, { fn into_any(self) -> AnyElement { AnyElement::new(self) @@ -74,8 +74,8 @@ where impl Element for Img where V: Send + Sync + 'static, - I: ElementInteractivity, - F: ElementFocusability, + I: ElementInteraction, + F: ElementFocus, { type ViewState = V; type ElementState = InteractiveElementState; @@ -143,8 +143,8 @@ where impl Styled for Img where V: 'static + Send + Sync, - I: ElementInteractivity, - F: ElementFocusability, + I: ElementInteraction, + F: ElementFocus, { fn style(&mut self) -> &mut StyleRefinement { self.base.style() @@ -154,10 +154,10 @@ where impl StatelesslyInteractive for Img where V: 'static + Send + Sync, - I: ElementInteractivity, - F: ElementFocusability, + I: ElementInteraction, + F: ElementFocus, { - fn stateless_interactivity(&mut self) -> &mut StatelessInteractivity { + fn stateless_interactivity(&mut self) -> &mut StatelessInteraction { self.base.stateless_interactivity() } } @@ -165,17 +165,17 @@ where impl StatefullyInteractive for Img, F> where V: 'static + Send + Sync, - F: ElementFocusability, + F: ElementFocus, { fn stateful_interactivity(&mut self) -> &mut StatefulInteractivity { self.base.stateful_interactivity() } } -impl Focus for Img> +impl Focusable for Img> where V: 'static + Send + Sync, - I: ElementInteractivity, + I: ElementInteraction, { fn focus_listeners(&mut self) -> &mut FocusListeners { self.base.focus_listeners() diff --git a/crates/gpui3/src/elements/svg.rs b/crates/gpui3/src/elements/svg.rs index 038a6c5404061cd9a5e698242e0ea3004b5fbceb..efd8031577d30fd3cf02417d37b0a8b60ee4bfd4 100644 --- a/crates/gpui3/src/elements/svg.rs +++ b/crates/gpui3/src/elements/svg.rs @@ -1,21 +1,21 @@ use crate::{ - div, AnyElement, Bounds, Div, Element, ElementFocusability, ElementId, ElementInteractivity, - Focus, FocusListeners, Focusable, InteractiveElementState, IntoAnyElement, LayoutId, - NonFocusable, Pixels, SharedString, StatefulInteractivity, StatefullyInteractive, - StatelessInteractivity, StatelesslyInteractive, StyleRefinement, Styled, ViewContext, + div, AnyElement, Bounds, Div, Element, ElementFocus, ElementId, ElementInteraction, + FocusDisabled, FocusEnabled, FocusListeners, Focusable, InteractiveElementState, + IntoAnyElement, LayoutId, Pixels, SharedString, StatefulInteractivity, StatefullyInteractive, + StatelessInteraction, StatelesslyInteractive, StyleRefinement, Styled, ViewContext, }; use util::ResultExt; pub struct Svg< V: 'static + Send + Sync, - I: ElementInteractivity = StatelessInteractivity, - F: ElementFocusability = NonFocusable, + I: ElementInteraction = StatelessInteraction, + F: ElementFocus = FocusDisabled, > { base: Div, path: Option, } -pub fn svg() -> Svg, NonFocusable> +pub fn svg() -> Svg, FocusDisabled> where V: 'static + Send + Sync, { @@ -28,8 +28,8 @@ where impl Svg where V: 'static + Send + Sync, - I: ElementInteractivity, - F: ElementFocusability, + I: ElementInteraction, + F: ElementFocus, { pub fn path(mut self, path: impl Into) -> Self { self.path = Some(path.into()); @@ -37,10 +37,10 @@ where } } -impl Svg, F> +impl Svg, F> where V: 'static + Send + Sync, - F: ElementFocusability, + F: ElementFocus, { pub fn id(self, id: impl Into) -> Svg, F> { Svg { @@ -53,8 +53,8 @@ where impl IntoAnyElement for Svg where V: 'static + Send + Sync, - I: ElementInteractivity, - F: ElementFocusability, + I: ElementInteraction, + F: ElementFocus, { fn into_any(self) -> AnyElement { AnyElement::new(self) @@ -64,8 +64,8 @@ where impl Element for Svg where V: 'static + Send + Sync, - I: ElementInteractivity, - F: ElementFocusability, + I: ElementInteraction, + F: ElementFocus, { type ViewState = V; type ElementState = InteractiveElementState; @@ -116,8 +116,8 @@ where impl Styled for Svg where V: 'static + Send + Sync, - I: ElementInteractivity, - F: ElementFocusability, + I: ElementInteraction, + F: ElementFocus, { fn style(&mut self) -> &mut StyleRefinement { self.base.style() @@ -127,10 +127,10 @@ where impl StatelesslyInteractive for Svg where V: 'static + Send + Sync, - I: ElementInteractivity, - F: ElementFocusability, + I: ElementInteraction, + F: ElementFocus, { - fn stateless_interactivity(&mut self) -> &mut StatelessInteractivity { + fn stateless_interactivity(&mut self) -> &mut StatelessInteraction { self.base.stateless_interactivity() } } @@ -138,17 +138,17 @@ where impl StatefullyInteractive for Svg, F> where V: 'static + Send + Sync, - F: ElementFocusability, + F: ElementFocus, { fn stateful_interactivity(&mut self) -> &mut StatefulInteractivity { self.base.stateful_interactivity() } } -impl Focus for Svg> +impl Focusable for Svg> where V: 'static + Send + Sync, - I: ElementInteractivity, + I: ElementInteraction, { fn focus_listeners(&mut self) -> &mut FocusListeners { self.base.focus_listeners() diff --git a/crates/gpui3/src/focus.rs b/crates/gpui3/src/focusable.rs similarity index 99% rename from crates/gpui3/src/focus.rs rename to crates/gpui3/src/focusable.rs index 16595f2e808e28fde14d373084cccab4c70d439f..0665e5fb60c70671eaccfe2b0a88711f05759b12 100644 --- a/crates/gpui3/src/focus.rs +++ b/crates/gpui3/src/focusable.rs @@ -7,7 +7,7 @@ pub type FocusListeners = SmallVec<[FocusListener; 2]>; pub type FocusListener = Arc) + Send + Sync + 'static>; -pub trait Focus: Element { +pub trait Focusable: Element { fn focus_listeners(&mut self) -> &mut FocusListeners; fn set_focus_style(&mut self, style: StyleRefinement); fn set_focus_in_style(&mut self, style: StyleRefinement); diff --git a/crates/gpui3/src/gpui3.rs b/crates/gpui3/src/gpui3.rs index f89b1c7bc179ecf2e2134014c768caae3faf417d..fcd21598f223bc56807b5c2cf70fb4751abe0e95 100644 --- a/crates/gpui3/src/gpui3.rs +++ b/crates/gpui3/src/gpui3.rs @@ -5,7 +5,7 @@ mod color; mod element; mod elements; mod executor; -mod focus; +mod focusable; mod geometry; mod image_cache; mod interactive; @@ -30,7 +30,7 @@ pub use color::*; pub use element::*; pub use elements::*; pub use executor::*; -pub use focus::*; +pub use focusable::*; pub use geometry::*; pub use gpui3_macros::*; pub use image_cache::*; diff --git a/crates/gpui3/src/interactive.rs b/crates/gpui3/src/interactive.rs index 25a69b57dd3e50d3e3688622f2ff5517c44ce641..c917a1aaac963eb3d079ba2f2dfd19dd8b34ae74 100644 --- a/crates/gpui3/src/interactive.rs +++ b/crates/gpui3/src/interactive.rs @@ -1,7 +1,7 @@ use crate::{ point, Action, Bounds, DispatchContext, DispatchPhase, Element, FocusHandle, GroupStyle, - Keystroke, Modifiers, Pixels, Point, SharedString, StatefulInteractivity, - StatelessInteractivity, StyleRefinement, ViewContext, + Keystroke, Modifiers, Pixels, Point, SharedString, StatefulInteractivity, StatelessInteraction, + StyleRefinement, ViewContext, }; use std::{ any::{Any, TypeId}, @@ -10,7 +10,7 @@ use std::{ }; pub trait StatelesslyInteractive: Element { - fn stateless_interactivity(&mut self) -> &mut StatelessInteractivity; + fn stateless_interactivity(&mut self) -> &mut StatelessInteraction; fn on_mouse_down( mut self, diff --git a/crates/storybook2/src/stories/focus.rs b/crates/storybook2/src/stories/focus.rs index 0133a890bee611087a48f6352c1b1ce7c8f2c8da..c2869ac2a65f79bbc56b1ed92d744c969aee4738 100644 --- a/crates/storybook2/src/stories/focus.rs +++ b/crates/storybook2/src/stories/focus.rs @@ -1,4 +1,4 @@ -use std::any::Any; +use std::any::Any;Focusable use gpui3::{ div, view, Action, Context, Focus, KeyBinding, ParentElement, StatelesslyInteractive, Styled,