diff --git a/crates/gpui2/src/elements/img.rs b/crates/gpui2/src/elements/img.rs index bfa3c6cfae26f71b50d329c9f64628fab7950ed5..c5c5fb628e31989f6a575a9b26f11f4336d7857d 100644 --- a/crates/gpui2/src/elements/img.rs +++ b/crates/gpui2/src/elements/img.rs @@ -50,7 +50,7 @@ impl Element for Img { fn initialize( &mut self, - view_state: &mut V, + _view_state: &mut V, element_state: Option, cx: &mut ViewContext, ) -> Self::ElementState { @@ -59,7 +59,7 @@ impl Element for Img { fn layout( &mut self, - view_state: &mut V, + _view_state: &mut V, element_state: &mut Self::ElementState, cx: &mut ViewContext, ) -> LayoutId { @@ -71,7 +71,7 @@ impl Element for Img { fn paint( &mut self, bounds: Bounds, - view: &mut V, + _view_state: &mut V, element_state: &mut Self::ElementState, cx: &mut ViewContext, ) { @@ -80,7 +80,7 @@ impl Element for Img { bounds.size, element_state, cx, - |style, scroll_offset, cx| { + |style, _scroll_offset, cx| { let corner_radii = style.corner_radii; if let Some(uri) = self.uri.clone() { diff --git a/crates/gpui2/src/elements/svg.rs b/crates/gpui2/src/elements/svg.rs index d0b321c0e2619deb31c04efbff63954712037f53..4b441ad425ee1bc4fe9b860635d8214ace1c21c3 100644 --- a/crates/gpui2/src/elements/svg.rs +++ b/crates/gpui2/src/elements/svg.rs @@ -39,7 +39,7 @@ impl Element for Svg { fn initialize( &mut self, - view_state: &mut V, + _view_state: &mut V, element_state: Option, cx: &mut ViewContext, ) -> Self::ElementState { @@ -48,7 +48,7 @@ impl Element for Svg { fn layout( &mut self, - view_state: &mut V, + _view_state: &mut V, element_state: &mut Self::ElementState, cx: &mut ViewContext, ) -> LayoutId { @@ -60,7 +60,7 @@ impl Element for Svg { fn paint( &mut self, bounds: Bounds, - view: &mut V, + _view_state: &mut V, element_state: &mut Self::ElementState, cx: &mut ViewContext, ) where diff --git a/crates/gpui2/src/interactive.rs b/crates/gpui2/src/interactive.rs index 702a7ca5dbfacf0849e5496f991e8effa3183815..cb8be7c2962db30df0c29409245ad6882dd9360a 100644 --- a/crates/gpui2/src/interactive.rs +++ b/crates/gpui2/src/interactive.rs @@ -1,16 +1,9 @@ use crate::{ - div, point, px, AnyDrag, AnyTooltip, AnyView, AppContext, Bounds, Component, DispatchPhase, - FocusHandle, Keystroke, Modifiers, Node, Pixels, Point, Render, SharedString, StyleRefinement, - Task, ViewContext, + div, point, Component, FocusHandle, Keystroke, Modifiers, Node, Pixels, Point, Render, + ViewContext, }; use smallvec::SmallVec; -use std::{ - any::Any, fmt::Debug, marker::PhantomData, ops::Deref, path::PathBuf, sync::Arc, time::Duration, -}; - -const DRAG_THRESHOLD: f64 = 2.; -const TOOLTIP_DELAY: Duration = Duration::from_millis(500); -const TOOLTIP_OFFSET: Point = Point::new(px(10.0), px(8.0)); +use std::{any::Any, fmt::Debug, marker::PhantomData, ops::Deref, path::PathBuf}; #[derive(Clone, Debug, Eq, PartialEq)] pub struct KeyDownEvent { @@ -290,40 +283,6 @@ pub struct FocusEvent { pub focused: Option, } -pub type MouseDownListener = Box< - dyn Fn(&mut V, &MouseDownEvent, &Bounds, DispatchPhase, &mut ViewContext) + 'static, ->; -pub type MouseUpListener = Box< - dyn Fn(&mut V, &MouseUpEvent, &Bounds, DispatchPhase, &mut ViewContext) + 'static, ->; - -pub type MouseMoveListener = Box< - dyn Fn(&mut V, &MouseMoveEvent, &Bounds, DispatchPhase, &mut ViewContext) + 'static, ->; - -pub type ScrollWheelListener = Box< - dyn Fn(&mut V, &ScrollWheelEvent, &Bounds, DispatchPhase, &mut ViewContext) - + 'static, ->; - -pub type ClickListener = Box) + 'static>; - -pub(crate) type DragListener = - Box, &mut ViewContext) -> AnyDrag + 'static>; - -pub(crate) type HoverListener = Box) + 'static>; - -pub(crate) type TooltipBuilder = Arc) -> AnyView + 'static>; - -pub(crate) type KeyDownListener = - Box) + 'static>; - -pub(crate) type KeyUpListener = - Box) + 'static>; - -pub type ActionListener = - Box) + 'static>; - #[cfg(test)] mod test { use crate::{ diff --git a/crates/gpui2/src/key_dispatch.rs b/crates/gpui2/src/key_dispatch.rs index afe0b0f3e22e44e34476cb990d1a38e640f9a221..b06acae43d86f196d2d50d16d120afc26a7313b1 100644 --- a/crates/gpui2/src/key_dispatch.rs +++ b/crates/gpui2/src/key_dispatch.rs @@ -1,11 +1,9 @@ use crate::{ - build_action_from_type, Action, Bounds, DispatchPhase, FocusEvent, FocusHandle, FocusId, - KeyContext, KeyMatch, Keymap, Keystroke, KeystrokeMatcher, MouseDownEvent, Pixels, Style, - StyleRefinement, ViewContext, WindowContext, + build_action_from_type, Action, DispatchPhase, FocusId, KeyContext, KeyMatch, Keymap, + Keystroke, KeystrokeMatcher, WindowContext, }; use collections::HashMap; use parking_lot::Mutex; -use refineable::Refineable; use smallvec::SmallVec; use std::{ any::{Any, TypeId}, @@ -14,10 +12,6 @@ use std::{ }; use util::ResultExt; -pub type FocusListeners = SmallVec<[FocusListener; 2]>; -pub type FocusListener = - Box) + 'static>; - #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] pub struct DispatchNodeId(usize); @@ -199,146 +193,3 @@ impl DispatchTree { *self.node_stack.last().unwrap() } } - -pub trait KeyDispatch: 'static { - fn as_focusable(&self) -> Option<&FocusableKeyDispatch>; - fn as_focusable_mut(&mut self) -> Option<&mut FocusableKeyDispatch>; - fn key_context(&self) -> &KeyContext; - fn key_context_mut(&mut self) -> &mut KeyContext; - - fn initialize( - &mut self, - focus_handle: Option, - cx: &mut ViewContext, - f: impl FnOnce(Option, &mut ViewContext) -> R, - ) -> R { - let focus_handle = if let Some(focusable) = self.as_focusable_mut() { - let focus_handle = focusable - .focus_handle - .get_or_insert_with(|| focus_handle.unwrap_or_else(|| cx.focus_handle())) - .clone(); - for listener in focusable.focus_listeners.drain(..) { - let focus_handle = focus_handle.clone(); - cx.on_focus_changed(move |view, event, cx| { - listener(view, &focus_handle, event, cx) - }); - } - Some(focus_handle) - } else { - None - }; - - cx.with_key_dispatch(self.key_context().clone(), focus_handle, f) - } - - fn refine_style(&self, style: &mut Style, cx: &WindowContext) { - if let Some(focusable) = self.as_focusable() { - let focus_handle = focusable - .focus_handle - .as_ref() - .expect("must call initialize before refine_style"); - if focus_handle.contains_focused(cx) { - style.refine(&focusable.focus_in_style); - } - - if focus_handle.within_focused(cx) { - style.refine(&focusable.in_focus_style); - } - - if focus_handle.is_focused(cx) { - style.refine(&focusable.focus_style); - } - } - } - - fn paint(&self, bounds: Bounds, cx: &mut WindowContext) { - if let Some(focusable) = self.as_focusable() { - let focus_handle = focusable - .focus_handle - .clone() - .expect("must call initialize before paint"); - cx.on_mouse_event(move |event: &MouseDownEvent, phase, cx| { - if phase == DispatchPhase::Bubble && bounds.contains_point(&event.position) { - if !cx.default_prevented() { - cx.focus(&focus_handle); - cx.prevent_default(); - } - } - }) - } - } -} - -pub struct FocusableKeyDispatch { - pub non_focusable: NonFocusableKeyDispatch, - pub focus_handle: Option, - pub focus_listeners: FocusListeners, - pub focus_style: StyleRefinement, - pub focus_in_style: StyleRefinement, - pub in_focus_style: StyleRefinement, -} - -impl FocusableKeyDispatch { - pub fn new(non_focusable: NonFocusableKeyDispatch) -> Self { - Self { - non_focusable, - focus_handle: None, - focus_listeners: FocusListeners::default(), - focus_style: StyleRefinement::default(), - focus_in_style: StyleRefinement::default(), - in_focus_style: StyleRefinement::default(), - } - } - - pub fn tracked(non_focusable: NonFocusableKeyDispatch, handle: &FocusHandle) -> Self { - Self { - non_focusable, - focus_handle: Some(handle.clone()), - focus_listeners: FocusListeners::default(), - focus_style: StyleRefinement::default(), - focus_in_style: StyleRefinement::default(), - in_focus_style: StyleRefinement::default(), - } - } -} - -impl KeyDispatch for FocusableKeyDispatch { - fn as_focusable(&self) -> Option<&FocusableKeyDispatch> { - Some(self) - } - - fn as_focusable_mut(&mut self) -> Option<&mut FocusableKeyDispatch> { - Some(self) - } - - fn key_context(&self) -> &KeyContext { - &self.non_focusable.key_context - } - - fn key_context_mut(&mut self) -> &mut KeyContext { - &mut self.non_focusable.key_context - } -} - -#[derive(Default)] -pub struct NonFocusableKeyDispatch { - pub(crate) key_context: KeyContext, -} - -impl KeyDispatch for NonFocusableKeyDispatch { - fn as_focusable(&self) -> Option<&FocusableKeyDispatch> { - None - } - - fn as_focusable_mut(&mut self) -> Option<&mut FocusableKeyDispatch> { - None - } - - fn key_context(&self) -> &KeyContext { - &self.key_context - } - - fn key_context_mut(&mut self) -> &mut KeyContext { - &mut self.key_context - } -} diff --git a/crates/gpui2/src/styled.rs b/crates/gpui2/src/styled.rs index 71e38efd9b74e7a4cdf5731c28e15a3311dd2378..beaf664dd8a51fcd58eba73feb247992945f0217 100644 --- a/crates/gpui2/src/styled.rs +++ b/crates/gpui2/src/styled.rs @@ -1,10 +1,9 @@ use crate::{ self as gpui, hsla, point, px, relative, rems, AbsoluteLength, AlignItems, CursorStyle, DefiniteLength, Display, Fill, FlexDirection, Hsla, JustifyContent, Length, Position, - SharedString, Style, StyleRefinement, Visibility, + SharedString, StyleRefinement, Visibility, }; use crate::{BoxShadow, TextStyleRefinement}; -use refineable::Refineable; use smallvec::{smallvec, SmallVec}; use taffy::style::Overflow; diff --git a/crates/workspace2/src/modal_layer.rs b/crates/workspace2/src/modal_layer.rs index 8beaaed3c35c2f41bc8c1fd7513444259952f34f..6cc08d56a63ca776edda240a7ef611ea65f9a4ac 100644 --- a/crates/workspace2/src/modal_layer.rs +++ b/crates/workspace2/src/modal_layer.rs @@ -1,6 +1,6 @@ use gpui::{ - div, prelude::*, px, AnyView, EventEmitter, FocusHandle, InteractiveComponent, Node, - ParentComponent, Render, Styled, Subscription, View, ViewContext, VisualContext, WindowContext, + div, prelude::*, px, AnyView, EventEmitter, FocusHandle, Node, Render, Subscription, View, + ViewContext, WindowContext, }; use ui::v_stack;