diff --git a/crates/ui-panels/src/docking/group.rs b/crates/ui-panels/src/docking/group.rs index ac658d7f7..a49635af1 100644 --- a/crates/ui-panels/src/docking/group.rs +++ b/crates/ui-panels/src/docking/group.rs @@ -20,7 +20,7 @@ use crate::runtime::focus::{self, FocusTarget}; use crate::runtime::memory::sub; use crate::style::{ComponentStyle, Corners, RuleLook, RuleWidth, StyleColor, StyleCx, SurfaceKind}; use crate::tabs::{Tab, TabKind, TabStrip, TornOff}; -use craft_behavior::{DockSide, IconId, Metrics, PartKey, PressPhase, Sense, keyed}; +use craft_behavior::{CursorIcon, CursorPriority, DockSide, IconId, Metrics, PartKey, PressPhase, Sense, keyed}; use craft_theme::{ControlSize, GripMark, GripShape, Tokens}; use egui::{Id, Pos2, Rect, Response, Ui, Vec2}; use std::borrow::Cow; @@ -164,10 +164,20 @@ impl Component for GroupGrip

{ fn update(&mut self, cx: &mut Cx<'_, Self>) { self.double = cx.press().double_pressed(); - if self.movable && matches!(cx.press().phase, PressPhase::DragStart { .. }) { + let phase = cx.press().phase; + if self.movable && matches!(phase, PressPhase::DragStart { .. }) { start_group_drag(cx, self.unit.clone(), self.active, None, self.ghost.clone()); self.started = true; } + // A marked grip is a handle: the grab cursor over it and grabbing while it is held or dragged, as the grips of + // a collapsed column declare (photocraft#16467). A drop target's cursor during the drag still wins. + if self.ticks && self.movable { + if phase.button_down() { + cx.cursor(CursorIcon::Grabbing, CursorPriority::Part); + } else if cx.hit() { + cx.cursor(CursorIcon::Grab, CursorPriority::Part); + } + } } fn paint(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) { diff --git a/crates/ui-panels/tests/it/dock_group.rs b/crates/ui-panels/tests/it/dock_group.rs index 8c33f84f1..1b9511cc0 100644 --- a/crates/ui-panels/tests/it/dock_group.rs +++ b/crates/ui-panels/tests/it/dock_group.rs @@ -2,8 +2,8 @@ use craft_ui::buttons::Button; use craft_ui::contract::{Show as _, ShowContainer as _}; -use craft_ui::docking::{DockGroup, PanelKey, PanelTitle, Titles}; -use craft_ui::testing::{Fixture, trial}; +use craft_ui::docking::{DockGroup, DragUnit, GroupGrip, PanelKey, PanelTitle, Titles}; +use craft_ui::testing::{Fixture, Frames, pointer, trial}; use egui::{Pos2, Rect, Vec2}; use std::cell::Cell; use std::rc::Rc; @@ -33,3 +33,28 @@ fn a_minimized_group_runs_no_body() { assert!(runs > 0 && found, "an expanded group shows its body: {runs} runs, node {found}"); assert_eq!(body(true), (0, false), "a minimized group runs no body and leaves no node"); } + +// A toolbar's marked grip is a handle (photocraft#16467): the grab cursor over it and grabbing while it is held, as +// the grips of a collapsed column show. An unmarked band and a grip that does not move keep the plain arrow. +#[trial] +fn a_marked_grip_shows_the_grab_cursor() { + let strip = Rect::from_min_size(Pos2::new(10.0, 10.0), Vec2::new(60.0, 16.0)); + for (ticks, movable) in [(true, true), (false, true), (true, false)] { + let mut frames = Frames::new(); + let mut show = |ui: &mut egui::Ui| { + GroupGrip::new(DragUnit::Group(1usize), PanelKey::new(1)).ticks(ticks).movable(movable).show_at(ui, strip); + }; + frames.frame(vec![], &mut show); + frames.frame(vec![pointer::moved(strip.center())], &mut show); + frames.frame(vec![], &mut show); + let (over, held) = if ticks && movable { + (egui::CursorIcon::Grab, egui::CursorIcon::Grabbing) + } else { + (egui::CursorIcon::Default, egui::CursorIcon::Default) + }; + assert_eq!(frames.cursor_icon(), over, "over the grip (ticks {ticks}, movable {movable})"); + frames.frame(vec![pointer::press(strip.center())], &mut show); + frames.frame(vec![], &mut show); + assert_eq!(frames.cursor_icon(), held, "the grip held (ticks {ticks}, movable {movable})"); + } +}