From 4d063494d8224de0fbb2c07b4e605db0d96a5a90 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Nov 2026 10:52:11 +0000 Subject: [PATCH] #10101: the grip takes the press, and the minimum holds on a short axis Three review findings: - A grip overlaps the active document's edge, where the press started a brush stroke as well as the drag. The frame now records that the press began on a grip (`arrange_grip_press`) and the canvases ignore it, the way the inactive-document path already did. - `drag_border` capped the gap at half the even spacing, so on a 300 pt axis a 2-up cell stopped at 75 pt although 80 would have fitted. The cap is gone; the limit is MIN_CELL itself. - With the neighbours closer together than two minimum cells, the clamp wrote a value from the wrong side of them and put the list out of order. That case now leaves the border, and the list, as they were. The tests cover the short axis and both directions of the no-room case, and each fails with its own change reverted. --- crates/ui-egui/src/app.rs | 1 + crates/ui-egui/src/canvas.rs | 4 +++- crates/ui-egui/src/canvas/tabs.rs | 6 +++++- crates/ui-egui/src/lib.rs | 3 +++ crates/ui-egui/src/menus/view_cmds/arrange.rs | 11 +++++++++-- crates/ui-egui/src/menus/view_cmds/tests.rs | 18 ++++++++++++++++++ 6 files changed, 39 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index c1660d75f9..b5101c1fc5 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -94,6 +94,7 @@ impl PhotocraftApp { fonts_ready: false, last_canvas_rect: egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(800.0, 600.0)), arrange_start: 0, + arrange_grip_press: false, ppp: 1.0, drop_canvas_rect: None, tab_strip: None, diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 3196f4951f..71cce10d95 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -1792,7 +1792,9 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect: // never maps through a camera that is still moving under the pointer. let (pointer_here, hover_here) = ctx.input(|i| { ( - (i.pointer.any_pressed() || i.pointer.any_down()) && i.pointer.press_origin().is_some_and(|p| rect.contains(p)), + // A press that began on an arrangement's border grip belongs to that border, not to + // the canvas it overlaps (#10101 review). + !app.arrange_grip_press && (i.pointer.any_pressed() || i.pointer.any_down()) && i.pointer.press_origin().is_some_and(|p| rect.contains(p)), i.pointer.hover_pos().is_some_and(|p| rect.contains(p)), ) }); diff --git a/crates/ui-egui/src/canvas/tabs.rs b/crates/ui-egui/src/canvas/tabs.rs index ab1b2f56a5..e3b2471f43 100644 --- a/crates/ui-egui/src/canvas/tabs.rs +++ b/crates/ui-egui/src/canvas/tabs.rs @@ -85,8 +85,12 @@ fn documents(app: &mut PhotocraftApp, ui: &mut egui::Ui) { if let Some(shown) = arranged_cells(app, rect) { app.arrange_start = shown.first().map_or(0, |(d, _)| *d); let t = crate::theme::Tokens::get(ui.ctx()); - // A press on a border grip drags the border (`drag_borders`); it activates no document. + // A press on a border grip drags the border (`drag_borders`): it activates no document, + // and the canvas under it takes no tool input from it either — a grip overlaps the + // active document's edge, where a press would otherwise start a stroke (#10101 review). let grips: Vec = border_grips(app, rect).into_iter().map(|(_, grip)| grip).collect(); + app.arrange_grip_press = + ui.input(|i| (i.pointer.any_pressed() || i.pointer.any_down()) && i.pointer.press_origin().is_some_and(|p| grips.iter().any(|g| g.contains(p)))); for (d, cell) in shown { let cell = cell.shrink(1.0); let view = app.ui.views[d].clone(); diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 50b0174631..2a8cd5b199 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -465,6 +465,9 @@ pub struct PhotocraftApp { /// Window › Arrange: the first document of the shown run of tiles, when there are more /// documents than tiles (`canvas::arranged_cells`). pub(crate) arrange_start: usize, + /// Window › Arrange: this frame's pointer press began on a border grip, so the canvases take + /// no tool input from it — the press drags the border (`canvas::tabs::drag_borders`, #10101). + pub(crate) arrange_grip_press: bool, /// Physical pixels per egui point of the canvas last frame (`ctx.pixels_per_point`, which /// folds in both the display scale and Interface › UI Scale). The canvas maps document pixels /// to physical pixels, so point-space geometry divides the view zoom by this (see diff --git a/crates/ui-egui/src/menus/view_cmds/arrange.rs b/crates/ui-egui/src/menus/view_cmds/arrange.rs index e662ae14a1..04ec1600b8 100644 --- a/crates/ui-egui/src/menus/view_cmds/arrange.rs +++ b/crates/ui-egui/src/menus/view_cmds/arrange.rs @@ -215,11 +215,18 @@ pub fn drag_border(layout: &str, rect: egui::Rect, n: usize, splits: &mut Vec::to_vec).unwrap_or_default(); let k = split - first; - let gap = (MIN_CELL / axis_len).min(0.5 / own.len().saturating_add(1) as f32); + // [`MIN_CELL`] in fractions of this axis, whatever the number of cells: capping it by the + // even spacing would let a cell fall under the minimum on a long axis (#10101 review). + let gap = MIN_CELL / axis_len; let lo = if k == 0 { 0.0 } else { own.get(k - 1).copied().unwrap_or(0.0) } + gap; let hi = own.get(k + 1).copied().unwrap_or(1.0) - gap; + // The neighbours leave no room for a cell of the minimum width: the border stays where it is, + // rather than taking a value out of order that would invalidate the whole list. + if lo > hi { + return; + } if let Some(f) = fractions.get_mut(split) { - *f = ((pos - axis_start) / axis_len).clamp(lo.min(hi), hi.max(lo)); + *f = ((pos - axis_start) / axis_len).clamp(lo, hi); } *splits = fractions; } diff --git a/crates/ui-egui/src/menus/view_cmds/tests.rs b/crates/ui-egui/src/menus/view_cmds/tests.rs index d6de7d3cb5..ddf9a11729 100644 --- a/crates/ui-egui/src/menus/view_cmds/tests.rs +++ b/crates/ui-egui/src/menus/view_cmds/tests.rs @@ -263,6 +263,24 @@ fn dragged_arrange_borders_resize_the_cells_beside_them() { drag_border("threeUpVertical", rect, 3, &mut splits, 0, egui::pos2(800.0, 0.0)); let c = cells("threeUpVertical", rect, 3, &splits).unwrap(); assert!((c[0].max.x - (600.0 - MIN_CELL)).abs() < 0.01 && (c[1].width() - MIN_CELL).abs() < 0.01); + + // #10101 review: the limit is MIN_CELL itself, not the even spacing. On a 300 pt axis a + // 2-up cell may still be dragged down to 80 pt, where capping the gap at 0.5/(n+1) would + // have stopped it at 75. + let narrow = egui::Rect::from_min_max(egui::pos2(0.0, 0.0), egui::pos2(300.0, 200.0)); + let mut splits = Vec::new(); + drag_border("twoUpVertical", narrow, 2, &mut splits, 0, egui::pos2(-100.0, 0.0)); + assert!((cells("twoUpVertical", narrow, 2, &splits).unwrap()[0].width() - MIN_CELL).abs() < 0.01); + + // And when the neighbours leave no room for a cell of that width, the border stays put and + // the list keeps its order rather than taking a value from the wrong side of them. + let tight = egui::Rect::from_min_max(egui::pos2(0.0, 0.0), egui::pos2(200.0, 200.0)); + let mut splits = vec![0.45, 0.55]; + drag_border("threeUpVertical", tight, 3, &mut splits, 1, egui::pos2(10.0, 0.0)); + assert_eq!(splits, vec![0.45, 0.55], "no room: unchanged"); + let mut splits = vec![0.45, 0.55]; + drag_border("threeUpVertical", tight, 3, &mut splits, 0, egui::pos2(190.0, 0.0)); + assert_eq!(splits, vec![0.45, 0.55], "and from the other side too"); } #[test]