diff --git a/gpui/src/elements/container.rs b/gpui/src/elements/container.rs index 464776b5c3..ae45544952 100644 --- a/gpui/src/elements/container.rs +++ b/gpui/src/elements/container.rs @@ -271,10 +271,10 @@ impl ToJson for Margin { #[derive(Clone, Debug, Default)] pub struct Padding { - top: f32, - left: f32, - bottom: f32, - right: f32, + pub top: f32, + pub left: f32, + pub bottom: f32, + pub right: f32, } impl<'de> Deserialize<'de> for Padding { diff --git a/gpui/src/elements/mouse_event_handler.rs b/gpui/src/elements/mouse_event_handler.rs index 1d09075179..3b28409f9f 100644 --- a/gpui/src/elements/mouse_event_handler.rs +++ b/gpui/src/elements/mouse_event_handler.rs @@ -1,12 +1,15 @@ -use std::ops::DerefMut; - +use super::Padding; use crate::{ - geometry::{rect::RectF, vector::Vector2F}, + geometry::{ + rect::RectF, + vector::{vec2f, Vector2F}, + }, platform::CursorStyle, CursorStyleHandle, DebugContext, Element, ElementBox, ElementStateHandle, ElementStateId, Event, EventContext, LayoutContext, MutableAppContext, PaintContext, SizeConstraint, }; use serde_json::json; +use std::ops::DerefMut; pub struct MouseEventHandler { state: ElementStateHandle, @@ -15,6 +18,7 @@ pub struct MouseEventHandler { mouse_down_handler: Option>, click_handler: Option>, drag_handler: Option>, + padding: Padding, } #[derive(Default)] @@ -42,6 +46,7 @@ impl MouseEventHandler { mouse_down_handler: None, click_handler: None, drag_handler: None, + padding: Default::default(), } } @@ -64,6 +69,11 @@ impl MouseEventHandler { self.drag_handler = Some(Box::new(handler)); self } + + pub fn with_padding(mut self, padding: Padding) -> Self { + self.padding = padding; + self + } } impl Element for MouseEventHandler { @@ -103,13 +113,18 @@ impl Element for MouseEventHandler { let handled_in_child = self.child.dispatch_event(event, cx); + let hit_bounds = RectF::from_points( + bounds.origin() - vec2f(self.padding.left, self.padding.top), + bounds.lower_right() + vec2f(self.padding.right, self.padding.bottom), + ); + self.state.update(cx, |state, cx| match event { Event::MouseMoved { position, left_mouse_down, } => { if !left_mouse_down { - let mouse_in = bounds.contains_point(*position); + let mouse_in = hit_bounds.contains_point(*position); if state.hovered != mouse_in { state.hovered = mouse_in; if let Some(cursor_style) = cursor_style { @@ -129,7 +144,7 @@ impl Element for MouseEventHandler { handled_in_child } Event::LeftMouseDown { position, .. } => { - if !handled_in_child && bounds.contains_point(*position) { + if !handled_in_child && hit_bounds.contains_point(*position) { state.clicked = true; state.prev_drag_position = Some(*position); cx.notify(); @@ -150,7 +165,7 @@ impl Element for MouseEventHandler { } cx.notify(); if let Some(handler) = click_handler { - if bounds.contains_point(*position) { + if hit_bounds.contains_point(*position) { handler(cx); } } diff --git a/zed/assets/themes/_base.toml b/zed/assets/themes/_base.toml index dac10bfbd9..70c13a5fad 100644 --- a/zed/assets/themes/_base.toml +++ b/zed/assets/themes/_base.toml @@ -23,7 +23,8 @@ text = "$text.0" padding = { left = 10, right = 10 } [workspace.sidebar.resize_handle] -margin = { left = 6 } +padding = { left = 1 } +background = "$surface.1" [workspace.sidebar.icon] color = "$text.2.color" diff --git a/zed/src/workspace/sidebar.rs b/zed/src/workspace/sidebar.rs index 909d5be33b..1ce1358795 100644 --- a/zed/src/workspace/sidebar.rs +++ b/zed/src/workspace/sidebar.rs @@ -158,6 +158,11 @@ impl Sidebar { .with_style(&self.theme(settings).resize_handle) .boxed() }) + .with_padding(Padding { + left: 4., + right: 4., + ..Default::default() + }) .with_cursor_style(CursorStyle::ResizeLeftRight) .on_drag(move |delta, cx| { let prev_width = *width.borrow();