From 639b446ffef5d5a82f0a1fa641e24cf5d9d34946 Mon Sep 17 00:00:00 2001 From: rmsff <17902130+rmsff@users.noreply.github.com> Date: Wed, 11 Nov 2026 01:14:33 +0300 Subject: [PATCH 1/2] Warp: a Split button places one split, then its mode ends The options-bar Split buttons stayed armed after the split, so every further click on the canvas added another line. The release that places a split now clears split_tool, as in the reference; a release that places none keeps the mode armed, as today. The existing test now expects the mode to end instead of staying armed. --- crates/ui-egui/src/tools/transform_tool/tests.rs | 2 +- crates/ui-egui/src/tools/transform_tool/warp.rs | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/tools/transform_tool/tests.rs b/crates/ui-egui/src/tools/transform_tool/tests.rs index f355c3c4bd..3c40b1712f 100644 --- a/crates/ui-egui/src/tools/transform_tool/tests.rs +++ b/crates/ui-egui/src/tools/transform_tool/tests.rs @@ -883,7 +883,7 @@ fn split_tool_places_the_line_where_the_pointer_releases() { assert!(us.len() == 3 && has(&us, 0.25), "{us:?}"); let vs = app.ui.transform.as_ref().unwrap().warp.as_ref().unwrap().mesh.as_ref().unwrap().vs.clone(); assert!(has(&vs, 1.0 / 3.0) && has(&vs, 2.0 / 3.0), "horizontal sections stay: {vs:?}"); - assert!(app.transform_preview.as_ref().unwrap().split_tool.is_some(), "the tool stays armed"); + assert!(app.transform_preview.as_ref().unwrap().split_tool.is_none(), "one split ends the mode"); // Option-click in the open places both lines, without a button armed. app.transform_preview.as_mut().unwrap().split_tool = None; let alt = egui::Modifiers::ALT; diff --git a/crates/ui-egui/src/tools/transform_tool/warp.rs b/crates/ui-egui/src/tools/transform_tool/warp.rs index cc882ea64c..67a73968bf 100644 --- a/crates/ui-egui/src/tools/transform_tool/warp.rs +++ b/crates/ui-egui/src/tools/transform_tool/warp.rs @@ -67,6 +67,7 @@ pub(super) fn split_cursor(m: &BezierMesh, tool: SplitTool, (s, t): (f64, f64), } /// Armed split tool, or Option held: the guide tracks the pointer and the split lands on release. +/// A Split button is one-shot, as in the reference: the release that splits ends its mode (#12498). /// Returns false when this event is an ordinary control-point drag. fn split_gesture(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui::Modifiers) -> bool { let armed = app.transform_preview.as_ref().and_then(|p| p.split_tool); @@ -103,9 +104,12 @@ fn split_gesture(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui::Modifiers) } else { None }; - if let Some(kind) = kind { - // On an existing line, or a click the drag path also delivers, this is a no-op. - let _ = split(app, kind.command(), Some([x, y])); + // Outside the grid or on an existing line this is a no-op, and the mode stays armed. + if let Some(kind) = kind + && split(app, kind.command(), Some([x, y])).is_ok() + && let Some(pv) = app.transform_preview.as_mut() + { + pv.split_tool = None; } true } From 0cb2e8cc991be5b80ebae35ed568534c8ffde9ac Mon Sep 17 00:00:00 2001 From: rmsff <17902130+rmsff@users.noreply.github.com> Date: Wed, 11 Nov 2026 01:14:33 +0300 Subject: [PATCH 2/2] Test the one-shot Warp split buttons --- .../ui-egui/src/tools/transform_tool/warp.rs | 4 + .../warp_split_one_shot_tests.rs | 139 ++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 crates/ui-egui/src/tools/transform_tool/warp_split_one_shot_tests.rs diff --git a/crates/ui-egui/src/tools/transform_tool/warp.rs b/crates/ui-egui/src/tools/transform_tool/warp.rs index 67a73968bf..fc8f220846 100644 --- a/crates/ui-egui/src/tools/transform_tool/warp.rs +++ b/crates/ui-egui/src/tools/transform_tool/warp.rs @@ -193,3 +193,7 @@ pub fn split(app: &mut PhotocraftApp, id: &str, at: Option<[f64; 2]>) -> Result< } edit_session_warp(app, id, &p) } + +#[cfg(test)] +#[path = "warp_split_one_shot_tests.rs"] +mod warp_split_one_shot_tests; diff --git a/crates/ui-egui/src/tools/transform_tool/warp_split_one_shot_tests.rs b/crates/ui-egui/src/tools/transform_tool/warp_split_one_shot_tests.rs new file mode 100644 index 0000000000..85bc3822ea --- /dev/null +++ b/crates/ui-egui/src/tools/transform_tool/warp_split_one_shot_tests.rs @@ -0,0 +1,139 @@ +//! #12498: an options-bar Split button places one split line, then its mode ends, as in the +//! reference. Quick splits and the menu / control-channel commands keep their behaviour. + +use super::super::tests::app_with_square; +use super::*; +use egui::PointerButton; +use egui_kittest::kittest::Queryable; + +type Harness = egui_kittest::Harness<'static, PhotocraftApp>; + +/// A 400 × 300 layer in Warp with the Default grid. +fn warping() -> Harness { + let app = app_with_square(512, photocraft_geom::Rect::new(56, 56, 456, 356)); + let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).with_max_steps(64).build_eframe(move |cc| { + PhotocraftApp::setup_context(&cc.egui_ctx, Default::default()); + app + }); + run(&mut h, "edit.transform.warp", json!({})); + h +} + +/// A menu / control-channel command, then a few frames. +fn run(h: &mut Harness, id: &str, params: serde_json::Value) { + h.run_steps(3); + let ctx = h.ctx.clone(); + crate::menus::invoke(h.state_mut(), &ctx, id, params).unwrap(); + h.run_steps(3); +} + +fn warp(h: &Harness) -> Option { + h.state().ui.transform.as_ref().unwrap().warp.clone() +} + +/// The grid's horizontal knots (`vs`): one more per horizontal split line. +fn rows(h: &Harness) -> usize { + warp(h).and_then(|w| w.mesh).map_or(2, |m| m.vs.len()) +} + +fn armed(h: &Harness) -> Option { + h.state().transform_preview.as_ref().unwrap().split_tool +} + +fn press_button(h: &mut Harness, tip: &str) { + h.get_by_label(tip).click(); + h.run_steps(3); +} + +/// A click on the canvas at document point `p`, through the real pointer path. +fn click_doc(h: &mut Harness, p: [f32; 2], m: egui::Modifiers) { + let at = ViewXform::active(h.state()).unwrap().to_screen(p[0], p[1]); + h.event(egui::Event::ModifiersChanged(m)); + h.event(egui::Event::PointerMoved(at)); + h.run_steps(1); + for pressed in [true, false] { + h.event(egui::Event::PointerButton { pos: at, button: PointerButton::Primary, pressed, modifiers: m }); + h.run_steps(2); + } + h.event(egui::Event::ModifiersChanged(egui::Modifiers::NONE)); + h.run_steps(2); +} + +#[test] +fn a_split_button_places_one_line_and_then_the_mode_ends() { + let mut h = warping(); + press_button(&mut h, "Split Warp Horizontally"); + assert!(armed(&h) == Some(SplitTool::Horizontal), "the button arms its mode"); + let before = rows(&h); + click_doc(&mut h, [256.0, 156.0], egui::Modifiers::NONE); + assert_eq!(rows(&h), before + 1, "one split line at the click"); + // The bar draws the button pressed only while `split_tool` names it. + assert!(armed(&h).is_none(), "the mode ends after one split"); + let placed = rows(&h); + click_doc(&mut h, [256.0, 300.0], egui::Modifiers::NONE); + assert_eq!(rows(&h), placed, "the next click is an ordinary press, not another split"); + assert!(armed(&h).is_none()); +} + +#[test] +fn every_split_button_is_one_shot() { + for tip in ["Split Warp Crosswise", "Split Warp Vertically", "Split Warp Horizontally"] { + let mut h = warping(); + press_button(&mut h, tip); + assert!(armed(&h).is_some(), "{tip} arms its mode"); + let before = warp(&h); + click_doc(&mut h, [200.0, 150.0], egui::Modifiers::NONE); + assert!(warp(&h) != before, "{tip} split the grid"); + assert!(armed(&h).is_none(), "{tip} ends after one split"); + } +} + +#[test] +fn a_second_press_on_the_button_still_cancels_without_a_split() { + let mut h = warping(); + let before = warp(&h); + press_button(&mut h, "Split Warp Vertically"); + press_button(&mut h, "Split Warp Vertically"); + assert!(armed(&h).is_none(), "the second press cancels the mode"); + assert_eq!(warp(&h), before, "nothing was split"); +} + +/// Not measured: a release that places no line keeps the mode armed, as today. +#[test] +fn a_release_that_places_no_line_keeps_the_mode() { + let mut h = warping(); + run(&mut h, "edit.transform.splitWarpHorizontally", json!({"at": [256.0, 156.0]})); + press_button(&mut h, "Split Warp Horizontally"); + let before = rows(&h); + click_doc(&mut h, [256.0, 20.0], egui::Modifiers::NONE); + assert_eq!(rows(&h), before, "above the grid nothing is split"); + assert!(armed(&h) == Some(SplitTool::Horizontal), "the mode stays after a miss above the grid"); + click_doc(&mut h, [256.0, 156.0], egui::Modifiers::NONE); + assert_eq!(rows(&h), before, "the line is already there"); + assert!(armed(&h) == Some(SplitTool::Horizontal), "the mode stays after a click on an existing line"); +} + +#[test] +fn quick_splits_still_place_one_split_per_click() { + let mut h = warping(); + let before = rows(&h); + // On the Default grid a crosswise split also keeps both thirds, so it adds more than one row. + click_doc(&mut h, [256.0, 131.0], egui::Modifiers::ALT); + let first = rows(&h); + assert!(first > before, "the first Option-click splits"); + click_doc(&mut h, [356.0, 281.0], egui::Modifiers::ALT); + assert_eq!(rows(&h), first + 1, "the second Option-click adds one more line"); + click_doc(&mut h, [156.0, 206.0], egui::Modifiers::COMMAND); + assert_eq!(rows(&h), first + 2, "a Ctrl/Cmd-click splits the same way"); + assert!(armed(&h).is_none(), "no mode is armed"); +} + +#[test] +fn menu_and_control_channel_splits_still_split_at_once() { + let mut h = warping(); + let before = rows(&h); + run(&mut h, "edit.transform.splitWarpHorizontally", json!({})); + run(&mut h, "edit.transform.splitWarpHorizontally", json!({"at": [256.0, 300.0]})); + assert_eq!(rows(&h), before + 2, "at the box centre, then at `at`"); + assert!(armed(&h).is_none(), "a command never arms the mode"); +}