diff --git a/crates/gpui/src/elements/event_handler.rs b/crates/gpui/src/elements/event_handler.rs index 60fa0c564da5cf01a65709827fb66a321052ff4d..1fec838788e28217d94671877cae26439e03b467 100644 --- a/crates/gpui/src/elements/event_handler.rs +++ b/crates/gpui/src/elements/event_handler.rs @@ -91,7 +91,7 @@ impl Element for EventHandler { click: Some(Rc::new(|_, _, _| {})), right_mouse_down: Some(Rc::new(|_, _| {})), right_click: Some(Rc::new(|_, _, _| {})), - drag: Some(Rc::new(|_, _| {})), + drag: Some(Rc::new(|_, _, _| {})), mouse_down_out: Some(Rc::new(|_, _| {})), right_mouse_down_out: Some(Rc::new(|_, _| {})), }); diff --git a/crates/gpui/src/elements/mouse_event_handler.rs b/crates/gpui/src/elements/mouse_event_handler.rs index 8f70daf9e6d695a5c91bc9e1ecbbe508e5b878ae..832aafaa9e8b890cd613027c982cd2ef841c266e 100644 --- a/crates/gpui/src/elements/mouse_event_handler.rs +++ b/crates/gpui/src/elements/mouse_event_handler.rs @@ -24,7 +24,7 @@ pub struct MouseEventHandler { right_click: Option>, mouse_down_out: Option>, right_mouse_down_out: Option>, - drag: Option>, + drag: Option>, hover: Option>, padding: Padding, } @@ -106,7 +106,10 @@ impl MouseEventHandler { self } - pub fn on_drag(mut self, handler: impl Fn(Vector2F, &mut EventContext) + 'static) -> Self { + pub fn on_drag( + mut self, + handler: impl Fn(Vector2F, Vector2F, &mut EventContext) + 'static, + ) -> Self { self.drag = Some(Rc::new(handler)); self } diff --git a/crates/gpui/src/presenter.rs b/crates/gpui/src/presenter.rs index 0d7deec8031003e6ce71c29ec67fc9200778eca6..86a8c4cf3049e924cfcea798ae2ff703ea6132d8 100644 --- a/crates/gpui/src/presenter.rs +++ b/crates/gpui/src/presenter.rs @@ -317,7 +317,7 @@ impl Presenter { .zip(self.prev_drag_position.as_mut()) { dragged_region = - Some((clicked_region.clone(), position - *prev_drag_position)); + Some((clicked_region.clone(), *prev_drag_position, position)); *prev_drag_position = position; } @@ -379,11 +379,11 @@ impl Presenter { } } - if let Some((dragged_region, delta)) = dragged_region { + if let Some((dragged_region, prev_position, position)) = dragged_region { handled = true; if let Some(drag_callback) = dragged_region.drag { event_cx.with_current_view(dragged_region.view_id, |event_cx| { - drag_callback(delta, event_cx); + drag_callback(prev_position, position, event_cx); }) } } @@ -661,6 +661,16 @@ impl<'a> PaintContext<'a> { } } + #[inline] + pub fn paint_layer(&mut self, clip_bounds: Option, f: F) + where + F: FnOnce(&mut Self) -> (), + { + self.scene.push_layer(clip_bounds); + f(self); + self.scene.pop_layer(); + } + pub fn current_view_id(&self) -> usize { *self.view_stack.last().unwrap() } diff --git a/crates/gpui/src/scene.rs b/crates/gpui/src/scene.rs index 66f4fb0783b1db3847f48336c71f923f8ac47160..769eabe7e58372e13628d316381df24e0b0a2044 100644 --- a/crates/gpui/src/scene.rs +++ b/crates/gpui/src/scene.rs @@ -65,7 +65,7 @@ pub struct MouseRegion { pub click: Option>, pub right_mouse_down: Option>, pub right_click: Option>, - pub drag: Option>, + pub drag: Option>, pub mouse_down_out: Option>, pub right_mouse_down_out: Option>, } diff --git a/crates/workspace/src/sidebar.rs b/crates/workspace/src/sidebar.rs index 341026aecf3c064343e4d12fb9a0603a03c56ce7..a500f994924d09aaae9304c2d3c9b0326f8803f7 100644 --- a/crates/workspace/src/sidebar.rs +++ b/crates/workspace/src/sidebar.rs @@ -188,12 +188,13 @@ impl Sidebar { }) .with_cursor_style(CursorStyle::ResizeLeftRight) .on_mouse_down(|_, _| {}) // This prevents the mouse down event from being propagated elsewhere - .on_drag(move |delta, cx| { + .on_drag(move |old_position, new_position, cx| { + let delta = new_position.x() - old_position.x(); let prev_width = *actual_width.borrow(); *custom_width.borrow_mut() = 0f32 .max(match side { - Side::Left => prev_width + delta.x(), - Side::Right => prev_width - delta.x(), + Side::Left => prev_width + delta, + Side::Right => prev_width - delta, }) .round(); diff --git a/styles/package-lock.json b/styles/package-lock.json index 49304dc2fa98dfec942bf6687be56cefc13cdf80..2eb6d3a1bfaeaa206f0cc8a0a03efa0387d144c2 100644 --- a/styles/package-lock.json +++ b/styles/package-lock.json @@ -5,7 +5,6 @@ "requires": true, "packages": { "": { - "name": "styles", "version": "1.0.0", "license": "ISC", "dependencies": {