From 0ffa541fea9dc94ea6fc37069aaa4d53d63f52b1 Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Wed, 25 Nov 2026 10:05:08 +0100 Subject: [PATCH] docking divider: a drag moves the divider with the move that starts it The move that carries a press past slop arrives as PressPhase::DragStart with the pointer position, but divider::drag dropped it, so every container moved its divider a pass later. Drag::Start now carries its coordinate (Start(f32), mirrored for right-to-left like To) and Drag::coord gives the coordinate of either. SplitArea, DockColumn, StackSections, the iconic column's edge, SplitViews, the column bar and the margin handles begin their gesture as before and then apply the start's coordinate in the same pass. Drag is public, so Start(f32) is an API change for code that matches Drag::Start. Trial a_column_divider_follows_the_move_that_starts_its_drag_in_the_same_pass --- crates/pages/src/ui/column_bar.rs | 9 ++++++--- crates/pages/src/ui/margins.rs | 13 ++++++------ crates/ui-canvas/src/canvas/split/mod.rs | 9 ++++++--- crates/ui-panels/src/docking/divider.rs | 21 ++++++++++++++++---- crates/ui-panels/src/docking/dock_column.rs | 4 ++-- crates/ui-panels/src/docking/iconic.rs | 2 +- crates/ui-panels/src/docking/mod.rs | 10 +++++++--- crates/ui-panels/src/docking/stack.rs | 2 +- crates/ui-patterns/tests/it/docking/split.rs | 16 +++++++++++++++ migration/api-map/docking-and-panes.toml | 2 +- 10 files changed, 64 insertions(+), 24 deletions(-) diff --git a/crates/pages/src/ui/column_bar.rs b/crates/pages/src/ui/column_bar.rs index 3568d6c6c9..be9d3b1946 100644 --- a/crates/pages/src/ui/column_bar.rs +++ b/crates/pages/src/ui/column_bar.rs @@ -247,9 +247,12 @@ impl Component for ColumnBar<'_> { if cx.part(part).press.double_pressed() { self.double_clicked = Some(*at as usize); } - match divider::pointer(cx, DIVIDER, *at, divider) { - Some(Drag::Start) => cx.begin(), - Some(Drag::To(x)) => cx.propose(resized(&widths, *at as usize, x - rect.left(), width)), + let dragged = divider::pointer(cx, DIVIDER, *at, divider); + if let Some(Drag::Start(_)) = dragged { + cx.begin(); + } + match dragged { + Some(Drag::Start(x) | Drag::To(x)) => cx.propose(resized(&widths, *at as usize, x - rect.left(), width)), Some(Drag::Release) => cx.commit(), _ => {} } diff --git a/crates/pages/src/ui/margins.rs b/crates/pages/src/ui/margins.rs index efcf5c34d8..81d4a5aa6b 100644 --- a/crates/pages/src/ui/margins.rs +++ b/crates/pages/src/ui/margins.rs @@ -479,16 +479,17 @@ impl Component for MarginHandles<'_> { let snap = if press.mods.alt { 0.0 } else { self.snap }; let origin = if visible.horizontal() { self.page.rect.min.x } else { self.page.rect.min.y }; let dragged = divider::pointer(cx, EDGE, visible.index(), ÷r); + if let Some(Drag::Start(_)) = dragged { + *cx.press_slot::() = Some(Anchor(edges)); + cx.begin(); + } + // The drag's start moves the edge as each later move does, in the same pass. match dragged { - Some(Drag::Start) => { - *cx.press_slot::() = Some(Anchor(edges)); - cx.begin(); - } - Some(Drag::To(coord)) => { + Some(Drag::Start(coord) | Drag::To(coord)) => { let anchor = cx.press_slot::().map_or(edges, |anchor| anchor.0); let change = dragged_margin(visible, f64::from(coord - origin) / scale, &self.rules(anchor, snap)); cx.propose(anchor.with(change)); - if let PressPhase::Drag { pos, .. } = press.phase { + if let PressPhase::DragStart { pos, .. } | PressPhase::Drag { pos, .. } = press.phase { let name = visible.name(&words).clone(); readout(cx, pos, &[(name, self.shown(&units, change.points))]); } diff --git a/crates/ui-canvas/src/canvas/split/mod.rs b/crates/ui-canvas/src/canvas/split/mod.rs index d2639e109f..8932f62963 100644 --- a/crates/ui-canvas/src/canvas/split/mod.rs +++ b/crates/ui-canvas/src/canvas/split/mod.rs @@ -457,9 +457,12 @@ impl SplitViews<'_, D> { fn resize(cx: &mut Cx<'_, SplitViews<'_, D>>, at: &SplitAt, laid: &Laid, dividers: &[Divider]) { let rect = cx.rect; for (index, divider) in dividers.iter().enumerate() { - match divider::pointer(cx, DIVIDER, index as u64, divider) { - Some(Drag::Start) => cx.begin(), - Some(Drag::To(coord)) => cx.propose(moved(laid, index, divider, coord, rect)), + let dragged = divider::pointer(cx, DIVIDER, index as u64, divider); + if let Some(Drag::Start(_)) = dragged { + cx.begin(); + } + match dragged { + Some(Drag::Start(coord) | Drag::To(coord)) => cx.propose(moved(laid, index, divider, coord, rect)), Some(Drag::Release) => cx.commit(), None => {} } diff --git a/crates/ui-panels/src/docking/divider.rs b/crates/ui-panels/src/docking/divider.rs index 11aab955dd..8a1164545d 100644 --- a/crates/ui-panels/src/docking/divider.rs +++ b/crates/ui-panels/src/docking/divider.rs @@ -66,14 +66,26 @@ impl Divider { /// What the pointer did to a divider this pass. #[derive(Clone, Copy, Debug, PartialEq)] pub enum Drag { - /// The drag started. - Start, + /// The drag started: the press moved past slop, and the pointer is at this coordinate along the divider's axis, + /// in reading order. The container begins its gesture and moves the divider to the coordinate in the same pass, + /// as it does for [`To`](Self::To), so the move that starts the drag shows in the pass it happens. + Start(f32), /// The pointer is at this coordinate along the divider's axis, in reading order. To(f32), /// The pointer was released. Release, } +impl Drag { + /// The coordinate the divider is dragged to this pass: the start's and each later move's; `None` for a release. + pub fn coord(self) -> Option { + match self { + Drag::Start(coord) | Drag::To(coord) => Some(coord), + Drag::Release => None, + } + } +} + /// `x` as a coordinate from the start edge of `rect`: unchanged for left-to-right, mirrored for right-to-left. fn logical_x(rect: Rect, rtl: bool, x: f32) -> f32 { if rtl { rect.right() - (x - rect.left()) } else { x } @@ -113,9 +125,10 @@ pub fn pointer(cx: &Cx<'_, C>, key: PartKey, index: u64, divider: /// What the press phase of a divider's part says the pointer did to `divider`, for a container `rect` that is /// mirrored for right-to-left. A body reads the phase from `BodyCx::part_press`. pub fn drag(phase: PressPhase, rect: Rect, rtl: bool, divider: &Divider) -> Option { + let along = |pos: Pos2| if divider.axis == Axis::X { logical_x(rect, rtl, pos.x) } else { pos.y }; match phase { - PressPhase::DragStart { .. } => Some(Drag::Start), - PressPhase::Drag { pos, .. } => Some(Drag::To(if divider.axis == Axis::X { logical_x(rect, rtl, pos.x) } else { pos.y })), + PressPhase::DragStart { pos, .. } => Some(Drag::Start(along(pos))), + PressPhase::Drag { pos, .. } => Some(Drag::To(along(pos))), PressPhase::Release { .. } => Some(Drag::Release), _ => None, } diff --git a/crates/ui-panels/src/docking/dock_column.rs b/crates/ui-panels/src/docking/dock_column.rs index 5747b69c5f..54f7501da7 100644 --- a/crates/ui-panels/src/docking/dock_column.rs +++ b/crates/ui-panels/src/docking/dock_column.rs @@ -401,7 +401,7 @@ fn body_plan

( let open = (0..group_sizes.len()).filter(|at| !group_sizes[*at].minimized).collect(); let mut plan = Plan { bar, body, groups, heights, mins: group_sizes.iter().map(|size| size.min).collect(), open }; for (key, index, divider) in plan.dividers(body, sizes.reach) { - if let Some(Drag::To(coord)) = drags(key, ÷r) { + if let Some(coord) = drags(key, ÷r).and_then(Drag::coord) { plan.move_divider(index, coord - divider.at); } } @@ -521,7 +521,7 @@ impl Component for DockColumn<'_, P> { } if own { let edge = self.edge_divider(rect, &sizes); - if let Some(Drag::To(coord)) = divider::pointer(cx, EDGE, 0, &edge) { + if let Some(coord) = divider::pointer(cx, EDGE, 0, &edge).and_then(Drag::coord) { self.move_edge(rect, &edge, coord); } if let Some((_, coord)) = divider::keys(cx, EDGE, &[(0, edge)], sizes.step, sizes.jump) { diff --git a/crates/ui-panels/src/docking/iconic.rs b/crates/ui-panels/src/docking/iconic.rs index f33dc4557b..ae8fe2694d 100644 --- a/crates/ui-panels/src/docking/iconic.rs +++ b/crates/ui-panels/src/docking/iconic.rs @@ -645,7 +645,7 @@ impl Component for IconicColumn<'_, P> { } if self.bar == ColumnBar::Own { let edge = self.edge_divider(rect, &sizes.column); - if let Some(Drag::To(coord)) = divider::pointer(cx, EDGE, 0, &edge) { + if let Some(coord) = divider::pointer(cx, EDGE, 0, &edge).and_then(Drag::coord) { self.move_edge(rect, &edge, coord); } if let Some((_, coord)) = divider::keys(cx, EDGE, &[(0, edge)], sizes.column.step, sizes.column.jump) { diff --git a/crates/ui-panels/src/docking/mod.rs b/crates/ui-panels/src/docking/mod.rs index cf6341c92c..ea8ab9a5dc 100644 --- a/crates/ui-panels/src/docking/mod.rs +++ b/crates/ui-panels/src/docking/mod.rs @@ -448,9 +448,13 @@ impl Component for SplitAr let handles = handles(&layout, rect, &sizes, &rules, rtl); for (at, handle) in handles.iter().enumerate() { let divider = divider_of(&layout, handle, rect, &sizes, &rules, rtl, false); - match divider::pointer(cx, HANDLE, at as u64, ÷r) { - Some(Drag::Start) => cx.begin(), - Some(Drag::To(coord)) => { + let dragged = divider::pointer(cx, HANDLE, at as u64, ÷r); + if let Some(Drag::Start(_)) = dragged { + cx.begin(); + } + // The drag's start moves the handle as each later move does, in the same pass. + match dragged { + Some(Drag::Start(coord) | Drag::To(coord)) => { if let Some(next) = moved(&layout, rect, &sizes, &rules, handle, coord - divider.at) { cx.propose(next); } diff --git a/crates/ui-panels/src/docking/stack.rs b/crates/ui-panels/src/docking/stack.rs index 7837c814ca..3c537a89b3 100644 --- a/crates/ui-panels/src/docking/stack.rs +++ b/crates/ui-panels/src/docking/stack.rs @@ -207,7 +207,7 @@ impl Component for StackSections { let sizes = cx.style.sizes; let Plan { open, row, dividers } = self.plan(cx.rect, &sizes); for (key, index, divider) in ÷rs { - if let Some(Drag::To(coord)) = divider::pointer(cx, DIVIDER, *key, divider) { + if let Some(coord) = divider::pointer(cx, DIVIDER, *key, divider).and_then(Drag::coord) { self.move_divider(&open, &row, *index, coord - divider.at, sizes.strip); } } diff --git a/crates/ui-patterns/tests/it/docking/split.rs b/crates/ui-patterns/tests/it/docking/split.rs index 2d89727a44..fee1b8efc2 100644 --- a/crates/ui-patterns/tests/it/docking/split.rs +++ b/crates/ui-patterns/tests/it/docking/split.rs @@ -61,6 +61,22 @@ fn a_column_divider_dragged_past_a_minimum_and_back_stays_under_the_pointer() { ); } +/// The move that carries the press past slop moves the divider in its own pass, not the pass after it. +#[trial] +fn a_column_divider_follows_the_move_that_starts_its_drag_in_the_same_pass() { + let (mut fixture, rects) = column(); + fixture.settle(); + let settled = rects.borrow()[0].bottom(); + let grip = divider(&fixture); + let at = grip.center(); + fixture.press(&grip); + let pressed = rects.borrow()[0].bottom(); + assert!((pressed - settled).abs() < f32::EPSILON, "a press with no move leaves the divider where it was: {pressed} for {settled}"); + fixture.frame(vec![pointer::moved(Pos2::new(at.x, at.y + 20.0))]); + let bottom = rects.borrow()[0].bottom(); + assert!((bottom - (at.y + 20.0)).abs() < 1.0, "the divider is at the pointer in the pass the drag starts: {bottom} for {}", at.y + 20.0); +} + #[trial] fn a_resize_under_a_pruned_view_keeps_the_hidden_panels() { let rest = Node::split(Axis::X, SplitSize::Ratio(0.5), Node::tabs(vec![1], 0), Node::tabs(vec![2], 0)); diff --git a/migration/api-map/docking-and-panes.toml b/migration/api-map/docking-and-panes.toml index aceeba9ae5..759970d51a 100644 --- a/migration/api-map/docking-and-panes.toml +++ b/migration/api-map/docking-and-panes.toml @@ -546,7 +546,7 @@ name = "Drag" old = "" new = "craft_ui::docking::divider::Drag" status = "replaced" -note = "What the pointer did to a divider this pass (`divider::pointer`): `Start`, `To(coordinate in reading order)`, `Release`." +note = "What the pointer did to a divider this pass (`divider::pointer`): `Start(coordinate in reading order)`, `To(coordinate in reading order)`, `Release`. A container begins its gesture on `Start` and moves the divider to its coordinate in the same pass; `Drag::coord` gives the coordinate of either." # One entry per renamed, removed or reshaped setter or constructor. # [[setter]]