Docking: a floating tool rail's grip moves its window (photocraft#16426)

The grip under a tool rail's column bar starts a drag of the rail's group;
released over empty room it floated the group under the pointer, which the
model refuses for a group that floats already, so a floating toolbar's grip
did nothing. A unit that is a whole floating window now moves that window
under the pointer (Action::MoveFloating), as its title row does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David Mann
2026-11-22 18:18:21 +01:00
co-authored by Claude Opus 5.5
parent 9b25308edc
commit daf0a8d827
2 changed files with 56 additions and 5 deletions
+21 -5
View File
@@ -243,10 +243,7 @@ pub fn float_drop<P: Clone + PartialEq>(
rtl: bool,
) -> DockDropped<P> {
let size = space.size_of(unit, source).min(space.area.size());
let under = |size: Vec2| {
let min = (at - Vec2::new(size.x * 0.5, space.chrome * 0.5)).min(space.area.max - size).max(space.area.min);
Rect::from_min_size(min, size)
};
let under = |size: Vec2| under_pointer(space, at, size);
let (rect, edge, mark) = match strip.filter(|_| !matches!(unit, DragUnit::Window(_))) {
Some(strip) => {
let shown = under((strip + Vec2::new(0.0, space.chrome)).min(space.area.size()));
@@ -265,6 +262,12 @@ pub fn float_drop<P: Clone + PartialEq>(
DockDropped { action, mark: DropMark::region(mark) }
}
/// A floating window of `size` under the pointer at `at`: its title row's middle at the pointer, inside the float area.
fn under_pointer<P>(space: &FloatSpace<P>, at: Pos2, size: Vec2) -> Rect {
let min = (at - Vec2::new(size.x * 0.5, space.chrome * 0.5)).min(space.area.max - size).max(space.area.min);
Rect::from_min_size(min, size)
}
/// The action a release of `drag` at `at` makes in the dock `dock`, by the spots of the previous pass; `None` where
/// no spot takes the drag. Call it from the dock's `DropTarget::accept` only (see `DockTargets::resolve`).
pub fn resolve_drop<P, D>(
@@ -367,8 +370,21 @@ impl<P: Clone + Eq + Hash + Send + 'static> DockDropTarget<'_, P> {
/// The unit floated under `at`, when it may float and the model takes it; `source` is its size where the drag
/// started, `strip` the size of the icons it started on ([`float_drop`]).
///
/// A unit that is the whole of a floating window already (a floating tool rail dragged by its grip,
/// photocraft#16426) moves that window under `at`: it is floating, so floating it again would be refused.
fn float(&self, unit: &DragUnit<P>, at: Pos2, source: Option<Vec2>, strip: Option<Vec2>) -> Option<DockDropped<P>> {
let floated = float_drop(unit, self.space?, at, source, strip, self.rtl);
let space = self.space?;
if let Some(window) = self.layout.floating.iter().find(|window| window.contains(unit.lead()))
&& window.panels().all(|panel| moving_panels(self.layout, unit).contains(panel))
{
let rect = under_pointer(space, at, space.size_of(unit, source).min(space.area.size()));
let moved = Action::move_floating(unit.lead().clone(), rect);
// A move keeps the arrangement (`takes` asks for a change of it): the model need only take the action.
let taken = self.layout.clone().apply_with_permissions(moved.clone(), self.permissions).is_ok();
return ((self.permissions)(unit.lead()).movable && taken).then_some(DockDropped { action: moved, mark: DropMark::region(rect) });
}
let floated = float_drop(unit, space, at, source, strip, self.rtl);
((self.permissions)(unit.lead()).floatable && takes(self.layout, &floated.action, self.permissions)).then_some(floated)
}
}
@@ -165,3 +165,38 @@ fn a_tool_rails_grip_strip_replays_while_the_pointer_moves_elsewhere() {
assert_eq!(grips(&fixture), 0, "pointer step {step}: the rail's grip replays its last run");
}
}
/// A tool rail floating in a window of its own is moved by its grip strip, as its title row moves it: a drag on the
/// grip released over empty room puts the window under the pointer (photocraft#16426). Before, the drag tried to float
/// the group again, which the model refuses for a floating group, and the window stayed.
#[trial]
fn a_floating_tool_rails_grip_moves_its_window() {
let seen = Rc::new(Cell::new(None));
let at = Rect::from_min_size(egui::pos2(300.0, 100.0), Vec2::new(60.0, RAIL_HEIGHT + 60.0));
let window = craft_behavior::dock::Floating::new(100, Column::new(vec![Group::new(vec![RAIL], 0)]).with_steps(1), at);
let mut workspace = Arc::new(Workspace::new(Layout::new(None, vec![window])));
let (mut panels, specs) = (RailPanels { seen: seen.clone() }, Tracked::new(RailSpecs));
let layout: Rc<RefCell<Option<Layout<usize>>>> = Rc::default();
let kept = Rc::clone(&layout);
let mut fixture = Fixture::new(move |ui| {
let _ = DockArea::new("Rail dock", Bind::bound(&mut workspace), &specs, &mut panels, DockConfig::default()).show(ui);
*kept.borrow_mut() = Some(workspace.layout().clone());
});
fixture.room(Vec2::new(800.0, 600.0)).settle();
let sizes = DockSizes::of(fixture.ctx());
let view = seen.get().expect("the host showed the floating rail");
let grip = egui::pos2(view.center().x, view.top() - sizes.grip * 0.5);
let before = layout.borrow().as_ref().and_then(|l| l.floating.first().map(|w| w.rect)).expect("the rail floats");
fixture.drag_hold_at(grip, Vec2::new(-200.0, 150.0));
assert_eq!(
drag::active::<GroupDrag<usize>>(fixture.ctx()).map(|drag| drag.unit.clone()),
Some(DragUnit::Group(RAIL)),
"a drag on the floating rail's grip drags its group"
);
let to = grip + Vec2::new(-200.0, 150.0);
fixture.release_at(to).settle();
let after = layout.borrow().as_ref().and_then(|l| l.floating.first().map(|w| w.rect)).expect("the rail still floats");
assert!(after.min.x < before.min.x - 100.0 && after.min.y > before.min.y + 100.0, "the window moved with the drag: {before:?} -> {after:?}");
assert!(after.contains(to), "the window lies under the release: {after:?} at {to:?}");
assert_eq!(layout.borrow().as_ref().map(|l| l.floating.len()), Some(1), "still one floating window");
}