Improve cursor style behavior for some draggable elements (#31965)
Follow-up to #24797 This PR ensures some cursor styles do not change for draggable elements during dragging. The linked PR covered this on the higher level for draggable divs. However, e.g. the pane divider inbetween two editors is not a draggable div and thus still has the issue that the cursor style changes during dragging. This PR fixes this issue by setting the hitbox to `None` in cases where the element is currently being dragged, which ensures the cursor style is applied to the cursor no matter what during dragging. Namely, this change fixes this for - non-div pane dividers - minimap slider and the - editor scrollbars and implements it for the UI scrollbars (Notably, UI scrollbars do already have `cursor_default` on their parent container but would not keep this during dragging. I opted out on removing this from the parent containers until #30194 or a similar PR is merged). https://github.com/user-attachments/assets/f97859dd-5f1d-4449-ab92-c27f2d933c4a Release Notes: - N/A
This commit is contained in:
parent
e0057ccd0f
commit
2fe1293fba
11 changed files with 88 additions and 43 deletions
|
@ -330,7 +330,7 @@ mod uniform_list {
|
|||
});
|
||||
let mut hovered_hitbox_id = None;
|
||||
for (i, hitbox) in hitboxes.iter().enumerate() {
|
||||
window.set_cursor_style(gpui::CursorStyle::PointingHand, Some(hitbox));
|
||||
window.set_cursor_style(gpui::CursorStyle::PointingHand, hitbox);
|
||||
let indent_guide = &self.indent_guides[i];
|
||||
let fill_color = if hitbox.is_hovered(window) {
|
||||
hovered_hitbox_id = Some(hitbox.id);
|
||||
|
|
|
@ -2,10 +2,10 @@ use std::{any::Any, cell::Cell, fmt::Debug, ops::Range, rc::Rc, sync::Arc};
|
|||
|
||||
use crate::{IntoElement, prelude::*, px, relative};
|
||||
use gpui::{
|
||||
Along, App, Axis as ScrollbarAxis, BorderStyle, Bounds, ContentMask, Corners, Edges, Element,
|
||||
ElementId, Entity, EntityId, GlobalElementId, Hitbox, HitboxBehavior, Hsla, IsZero, LayoutId,
|
||||
ListState, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Pixels, Point, ScrollHandle,
|
||||
ScrollWheelEvent, Size, Style, UniformListScrollHandle, Window, quad,
|
||||
Along, App, Axis as ScrollbarAxis, BorderStyle, Bounds, ContentMask, Corners, CursorStyle,
|
||||
Edges, Element, ElementId, Entity, EntityId, GlobalElementId, Hitbox, HitboxBehavior, Hsla,
|
||||
IsZero, LayoutId, ListState, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Pixels, Point,
|
||||
ScrollHandle, ScrollWheelEvent, Size, Style, UniformListScrollHandle, Window, quad,
|
||||
};
|
||||
|
||||
pub struct Scrollbar {
|
||||
|
@ -22,6 +22,12 @@ enum ThumbState {
|
|||
Dragging(Pixels),
|
||||
}
|
||||
|
||||
impl ThumbState {
|
||||
fn is_dragging(&self) -> bool {
|
||||
matches!(*self, ThumbState::Dragging(_))
|
||||
}
|
||||
}
|
||||
|
||||
impl ScrollableHandle for UniformListScrollHandle {
|
||||
fn content_size(&self) -> Size<Pixels> {
|
||||
self.0.borrow().base_handle.content_size()
|
||||
|
@ -236,7 +242,7 @@ impl Element for Scrollbar {
|
|||
_inspector_id: Option<&gpui::InspectorElementId>,
|
||||
bounds: Bounds<Pixels>,
|
||||
_request_layout: &mut Self::RequestLayoutState,
|
||||
_prepaint: &mut Self::PrepaintState,
|
||||
hitbox: &mut Self::PrepaintState,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) {
|
||||
|
@ -244,7 +250,8 @@ impl Element for Scrollbar {
|
|||
window.with_content_mask(Some(ContentMask { bounds }), |window| {
|
||||
let axis = self.kind;
|
||||
let colors = cx.theme().colors();
|
||||
let thumb_base_color = match self.state.thumb_state.get() {
|
||||
let thumb_state = self.state.thumb_state.get();
|
||||
let thumb_base_color = match thumb_state {
|
||||
ThumbState::Dragging(_) => colors.scrollbar_thumb_active_background,
|
||||
ThumbState::Hover => colors.scrollbar_thumb_hover_background,
|
||||
ThumbState::Inactive => colors.scrollbar_thumb_background,
|
||||
|
@ -285,6 +292,12 @@ impl Element for Scrollbar {
|
|||
BorderStyle::default(),
|
||||
));
|
||||
|
||||
if thumb_state.is_dragging() {
|
||||
window.set_window_cursor_style(CursorStyle::Arrow);
|
||||
} else {
|
||||
window.set_cursor_style(CursorStyle::Arrow, hitbox);
|
||||
}
|
||||
|
||||
let scroll = self.state.scroll_handle.clone();
|
||||
|
||||
enum ScrollbarMouseEvent {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue