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
This commit is contained in:
skylartaylor committed 2026-11-25 10:05:08 +01:00
1 parent 6fcf61c816
commit 0ffa541fea
10 files changed
+64 -24

No files matched your search

+6 -3
View File
@@ -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(),
_ => {}
}
+7 -6
View File
@@ -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(), &divider);
if let Some(Drag::Start(_)) = dragged {
*cx.press_slot::<Anchor>() = 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::<Anchor>() = Some(Anchor(edges));
cx.begin();
}
Some(Drag::To(coord)) => {
Some(Drag::Start(coord) | Drag::To(coord)) => {
let anchor = cx.press_slot::<Anchor>().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))]);
}
+6 -3
View File
@@ -457,9 +457,12 @@ impl<D: Clone + Send + Sync + 'static> SplitViews<'_, D> {
fn resize<D: Clone + Send + Sync + 'static>(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 => {}
}
+17 -4
View File
@@ -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<f32> {
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<C: Component>(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<Drag> {
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,
}
+2 -2
View File
@@ -401,7 +401,7 @@ fn body_plan<P>(
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, &divider) {
if let Some(coord) = drags(key, &divider).and_then(Drag::coord) {
plan.move_divider(index, coord - divider.at);
}
}
@@ -521,7 +521,7 @@ impl<P: Value + Debug + Hash + 'static> 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) {
+1 -1
View File
@@ -645,7 +645,7 @@ impl<P: Value + Hash + Debug + 'static> 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) {
+7 -3
View File
@@ -448,9 +448,13 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> 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, &divider) {
Some(Drag::Start) => cx.begin(),
Some(Drag::To(coord)) => {
let dragged = divider::pointer(cx, HANDLE, at as u64, &divider);
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);
}
+1 -1
View File
@@ -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 &dividers {
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);
}
}
@@ -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));
+1 -1
View File
@@ -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]]