From 2121d228ed685cfd05ef123c3593a8e2bcdc35d9 Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 23:40:54 +0000 Subject: [PATCH] Dock drags: one region mark that carries the panel's name, no frame at the pointer (photocraft#15526) --- crates/ui-contract/src/contract/ghost.rs | 27 ++++++++++++++++++++---- crates/ui-contract/src/runtime/drag.rs | 7 ++++-- crates/ui-panels/src/docking/drop.rs | 19 +++++++---------- crates/ui-panels/src/docking/group.rs | 11 +++++----- 4 files changed, 41 insertions(+), 23 deletions(-) diff --git a/crates/ui-contract/src/contract/ghost.rs b/crates/ui-contract/src/contract/ghost.rs index 7a30d1267..fe9127f8c 100644 --- a/crates/ui-contract/src/contract/ghost.rs +++ b/crates/ui-contract/src/contract/ghost.rs @@ -1,14 +1,14 @@ //! The ghost layer's content (8.4, 8.5): the running drag's preview beside the pointer, the mark of the drop target that -//! would take the payload, and the painted pointer the cursor service settled on, which goes to the window as its -//! cursor image instead where the window takes one. They come from the drag session's data and the cursor record; the -//! layer takes no input. +//! would take the payload (with the payload's name inside a region mark, for a drag that names it), and the painted +//! pointer the cursor service settled on, which goes to the window as its cursor image instead where the window takes +//! one. They come from the drag session's data and the cursor record; the layer takes no input. use crate::primitives::pointer_art::{self as pointers, Art}; use crate::primitives::{Draw, DrawEnv, IconSet, Mirror, PaintRecord, PaintShape, RuleKind, SvgIcon, TextRun, outline}; use crate::runtime::drag::{self, DragPreview, DropMark}; use crate::runtime::egui::areas; -use crate::runtime::env::Env; +use crate::runtime::env::{Env, Label}; use crate::runtime::{cursor, pointer}; use crate::style::{Corners, Ink, RuleWidth, SurfaceKind, rule_look}; use craft_behavior::Flow; @@ -116,6 +116,9 @@ fn pointer_art(env: &Env, cursor: &craft_behavior::PaintedCursor, closed: bool, fn paint_drag(ctx: &Context, env: &Env, painter: &egui::Painter, draw: &Draw<'_>, session: &drag::Ghost) { if let Some(mark) = session.mark { paint_mark(painter, env, mark); + if let (DropMark::Region { area, .. }, DragPreview::Named(name)) = (mark, &session.preview) { + paint_region_name(draw, env, area, name); + } } let Some(at) = pointer::frame(ctx).pos else { return }; match &session.preview { @@ -139,6 +142,22 @@ fn paint_drag(ctx: &Context, env: &Env, painter: &egui::Painter, draw: &Draw<'_> } } +/// The payload's name inside the region `area` a drop would take: at the reading start of its top, inside the mark's +/// band, on one line elided to the area's width. A region too small for the line shows no name. +fn paint_region_name(draw: &Draw<'_>, env: &Env, area: Rect, name: &Label) { + let name = env.view().resolve(name); + let inner = area.shrink(env.tokens.space.pad.control); + if inner.width() <= 0.0 { + return; + } + let layout = draw.layout(&TextRun::new(name.as_str()).elide(), inner.width()); + if layout.size().y > inner.height() { + return; + } + let (at, _) = Flow::new(inner, env.direction.is_rtl()).take_start(layout.size().x.min(inner.width())); + draw.galley(at.min, &layout); +} + fn paint_drag_badge(draw: &Draw<'_>, env: &Env, at: Pos2, text: &str) { let space = &env.tokens.space; let run = TextRun::new(text); diff --git a/crates/ui-contract/src/runtime/drag.rs b/crates/ui-contract/src/runtime/drag.rs index 01f86fa21..017a50ee4 100644 --- a/crates/ui-contract/src/runtime/drag.rs +++ b/crates/ui-contract/src/runtime/drag.rs @@ -28,8 +28,11 @@ pub enum DragPreview { None, /// A badge with a short text ("3 files"). Badge(Label), - /// A frame-sized outline centred on the pointer, with an optional label inside its top corner: the ghost of a - /// panel or window being moved. + /// Nothing beside the pointer: the payload's name shows inside the area of a region mark, as a panel or group + /// being moved names the place it would take. With no mark, nothing shows. + Named(Label), + /// An outline of `size` centred on the pointer, with an optional label inside its top corner: the ghost of a part + /// dragged out of a row (a thumbnail). #[non_exhaustive] Frame { /// The size of the frame, in points. diff --git a/crates/ui-panels/src/docking/drop.rs b/crates/ui-panels/src/docking/drop.rs index 2936b673d..736913aa5 100644 --- a/crates/ui-panels/src/docking/drop.rs +++ b/crates/ui-panels/src/docking/drop.rs @@ -262,7 +262,7 @@ pub fn float_drop( DragUnit::Panel(panel) if edge.is_none() => Action::float(panel.clone(), rect), _ => to_target(unit, Target::float_with_edge(rect, edge)), }; - DockDropped { action, mark: DropMark::Into(mark) } + DockDropped { action, mark: DropMark::region(mark) } } /// The action a release of `drag` at `at` makes in the dock `dock`, by the spots of the previous pass; `None` where @@ -439,31 +439,28 @@ pub(crate) fn started(env: &EnvView<'_>) -> Option { } /// Starts the drag of `unit`, whose shown panel is `active` and whose size where it starts is `source`. A group or a -/// column drags a ghost frame; `ghost` gives its size and label. A window moves itself, so its drag has no ghost and -/// `ghost` is `None`. -pub fn start_group_drag(cx: &mut Cx<'_, C>, unit: DragUnit

, active: PanelKey, source: Option, ghost: Option<(Vec2, Label)>) +/// column shows `name` inside the region its drop would take ([`DragPreview::Named`]). A window moves itself, so its +/// drag shows nothing and `name` is `None`. +pub fn start_group_drag(cx: &mut Cx<'_, C>, unit: DragUnit

, active: PanelKey, source: Option, name: Option

, active: PanelKey, strip: Vec2, label: Label) where P: Clone + Send + Sync + 'static, C: Component, { let started = started(&cx.env); - cx.start_drag(GroupDrag { unit, active, source: None, strip: Some(strip), started }, DragPreview::frame(strip, Some(label))); + cx.start_drag(GroupDrag { unit, active, source: None, strip: Some(strip), started }, DragPreview::Named(label)); } /// Ends a running tab or group drag that started on `shown`'s dock under another revision: another arrangement diff --git a/crates/ui-panels/src/docking/group.rs b/crates/ui-panels/src/docking/group.rs index ed67a5f33..299406a8b 100644 --- a/crates/ui-panels/src/docking/group.rs +++ b/crates/ui-panels/src/docking/group.rs @@ -62,7 +62,7 @@ pub struct GroupGrip { common: Common, unit: DragUnit

, active: PanelKey, - /// The ghost the drag shows: its extent and its label. + /// The unit's extent where the drag starts and the name its drop region shows. #[prop] ghost: Option<(Vec2, Label)>, /// A drag on the grip drags the unit. @@ -109,7 +109,7 @@ impl Component for GroupGrip

{ match self.ghost.clone() { Some((strip, label)) if self.icons => start_icon_drag(cx, self.unit.clone(), self.active, strip, label), // The ghost's extent is the group's own. - ghost => start_group_drag(cx, self.unit.clone(), self.active, ghost.as_ref().map(|(size, _)| *size), ghost), + ghost => start_group_drag(cx, self.unit.clone(), self.active, ghost.as_ref().map(|(size, _)| *size), ghost.map(|(_, label)| label)), } self.started = true; } @@ -260,7 +260,7 @@ pub struct DockGroup<'a, P: Clone + Hash + Send + Sync + 'static> { /// The host's items before the tab strip. #[prop(func = "FnMut(&mut egui::Ui, &mut BodyCx<'_>)")] extra: Option>, - /// The size of the group this pass, for the drag ghost. + /// The size of the group this pass, where its drag starts. size: Vec2, reported: Reported, } @@ -306,10 +306,9 @@ impl<'a, P: Clone + Hash + Send + Sync + 'static> DockGroup<'a, P> { IconButton::new(IconId::new("more")).size(ControlSize::Sm).popup(PopupKind::Menu).label(name) } - /// Starts a drag of the whole group: its ghost is the group's frame with its name. + /// Starts a drag of the whole group: its drop region shows the group's name. fn start_drag(&mut self, cx: &mut Cx<'_, Self>) { - let ghost = (self.size, cx.label()); - start_group_drag(cx, DragUnit::Group(self.anchor.clone()), self.active, Some(self.size), Some(ghost)); + start_group_drag(cx, DragUnit::Group(self.anchor.clone()), self.active, Some(self.size), Some(cx.label())); self.reported.drag_started = true; } }