Detailed changes
@@ -50,7 +50,7 @@ impl<V> Element<V> for Img<V> {
fn initialize(
&mut self,
- view_state: &mut V,
+ _view_state: &mut V,
element_state: Option<Self::ElementState>,
cx: &mut ViewContext<V>,
) -> Self::ElementState {
@@ -59,7 +59,7 @@ impl<V> Element<V> for Img<V> {
fn layout(
&mut self,
- view_state: &mut V,
+ _view_state: &mut V,
element_state: &mut Self::ElementState,
cx: &mut ViewContext<V>,
) -> LayoutId {
@@ -71,7 +71,7 @@ impl<V> Element<V> for Img<V> {
fn paint(
&mut self,
bounds: Bounds<Pixels>,
- view: &mut V,
+ _view_state: &mut V,
element_state: &mut Self::ElementState,
cx: &mut ViewContext<V>,
) {
@@ -80,7 +80,7 @@ impl<V> Element<V> for Img<V> {
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() {
@@ -39,7 +39,7 @@ impl<V> Element<V> for Svg<V> {
fn initialize(
&mut self,
- view_state: &mut V,
+ _view_state: &mut V,
element_state: Option<Self::ElementState>,
cx: &mut ViewContext<V>,
) -> Self::ElementState {
@@ -48,7 +48,7 @@ impl<V> Element<V> for Svg<V> {
fn layout(
&mut self,
- view_state: &mut V,
+ _view_state: &mut V,
element_state: &mut Self::ElementState,
cx: &mut ViewContext<V>,
) -> LayoutId {
@@ -60,7 +60,7 @@ impl<V> Element<V> for Svg<V> {
fn paint(
&mut self,
bounds: Bounds<Pixels>,
- view: &mut V,
+ _view_state: &mut V,
element_state: &mut Self::ElementState,
cx: &mut ViewContext<V>,
) where
@@ -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<Pixels> = 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<FocusHandle>,
}
-pub type MouseDownListener<V> = Box<
- dyn Fn(&mut V, &MouseDownEvent, &Bounds<Pixels>, DispatchPhase, &mut ViewContext<V>) + 'static,
->;
-pub type MouseUpListener<V> = Box<
- dyn Fn(&mut V, &MouseUpEvent, &Bounds<Pixels>, DispatchPhase, &mut ViewContext<V>) + 'static,
->;
-
-pub type MouseMoveListener<V> = Box<
- dyn Fn(&mut V, &MouseMoveEvent, &Bounds<Pixels>, DispatchPhase, &mut ViewContext<V>) + 'static,
->;
-
-pub type ScrollWheelListener<V> = Box<
- dyn Fn(&mut V, &ScrollWheelEvent, &Bounds<Pixels>, DispatchPhase, &mut ViewContext<V>)
- + 'static,
->;
-
-pub type ClickListener<V> = Box<dyn Fn(&mut V, &ClickEvent, &mut ViewContext<V>) + 'static>;
-
-pub(crate) type DragListener<V> =
- Box<dyn Fn(&mut V, Point<Pixels>, &mut ViewContext<V>) -> AnyDrag + 'static>;
-
-pub(crate) type HoverListener<V> = Box<dyn Fn(&mut V, bool, &mut ViewContext<V>) + 'static>;
-
-pub(crate) type TooltipBuilder<V> = Arc<dyn Fn(&mut V, &mut ViewContext<V>) -> AnyView + 'static>;
-
-pub(crate) type KeyDownListener<V> =
- Box<dyn Fn(&mut V, &KeyDownEvent, DispatchPhase, &mut ViewContext<V>) + 'static>;
-
-pub(crate) type KeyUpListener<V> =
- Box<dyn Fn(&mut V, &KeyUpEvent, DispatchPhase, &mut ViewContext<V>) + 'static>;
-
-pub type ActionListener<V> =
- Box<dyn Fn(&mut V, &dyn Any, DispatchPhase, &mut ViewContext<V>) + 'static>;
-
#[cfg(test)]
mod test {
use crate::{
@@ -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<V> = SmallVec<[FocusListener<V>; 2]>;
-pub type FocusListener<V> =
- Box<dyn Fn(&mut V, &FocusHandle, &FocusEvent, &mut ViewContext<V>) + '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<V: 'static>: 'static {
- fn as_focusable(&self) -> Option<&FocusableKeyDispatch<V>>;
- fn as_focusable_mut(&mut self) -> Option<&mut FocusableKeyDispatch<V>>;
- fn key_context(&self) -> &KeyContext;
- fn key_context_mut(&mut self) -> &mut KeyContext;
-
- fn initialize<R>(
- &mut self,
- focus_handle: Option<FocusHandle>,
- cx: &mut ViewContext<V>,
- f: impl FnOnce(Option<FocusHandle>, &mut ViewContext<V>) -> 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<Pixels>, 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<V> {
- pub non_focusable: NonFocusableKeyDispatch,
- pub focus_handle: Option<FocusHandle>,
- pub focus_listeners: FocusListeners<V>,
- pub focus_style: StyleRefinement,
- pub focus_in_style: StyleRefinement,
- pub in_focus_style: StyleRefinement,
-}
-
-impl<V> FocusableKeyDispatch<V> {
- 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<V: 'static> KeyDispatch<V> for FocusableKeyDispatch<V> {
- fn as_focusable(&self) -> Option<&FocusableKeyDispatch<V>> {
- Some(self)
- }
-
- fn as_focusable_mut(&mut self) -> Option<&mut FocusableKeyDispatch<V>> {
- 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<V: 'static> KeyDispatch<V> for NonFocusableKeyDispatch {
- fn as_focusable(&self) -> Option<&FocusableKeyDispatch<V>> {
- None
- }
-
- fn as_focusable_mut(&mut self) -> Option<&mut FocusableKeyDispatch<V>> {
- None
- }
-
- fn key_context(&self) -> &KeyContext {
- &self.key_context
- }
-
- fn key_context_mut(&mut self) -> &mut KeyContext {
- &mut self.key_context
- }
-}
@@ -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;
@@ -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;