From 4c33342af15c5f3e208d19ff446e498e3febdcd0 Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Thu, 5 Nov 2026 15:15:55 -0500 Subject: [PATCH] Artboard placing mode: reported by ui.inspect, cleared on every tool change, and the button is tested (#11386) ui.inspect now returns an artboardTool entry with the adding flag. tool_memory::select clears the mode whenever the new tool is not the Artboard tool, so switching away and back in one pass leaves it off. A harness test clicks Add New Artboard twice and checks the mode and that no board is added. Co-Authored-By: Claude Fable 5.1 --- crates/ui-egui/src/artboard_add_mode_tests.rs | 56 +++++++++++++++++++ crates/ui-egui/src/control/inspect.rs | 1 + crates/ui-egui/src/tool_memory.rs | 4 ++ 3 files changed, 61 insertions(+) diff --git a/crates/ui-egui/src/artboard_add_mode_tests.rs b/crates/ui-egui/src/artboard_add_mode_tests.rs index 6e4ff13720..383e68cdc3 100644 --- a/crates/ui-egui/src/artboard_add_mode_tests.rs +++ b/crates/ui-egui/src/artboard_add_mode_tests.rs @@ -131,3 +131,59 @@ fn another_tool_turns_the_mode_off() { click(&mut app, 3000.0, 100.0); assert_eq!(boards(&app), before); } + +#[test] +fn ui_inspect_reports_the_mode_on_and_off() { + let ctx = egui::Context::default(); + let mut app = app_with_selected_board(); + let adding = |app: &mut PhotocraftApp| { + let (req, _) = crate::control::ControlRequest::new("ui.inspect", json!({})); + let crate::control::Outcome::Done(v) = crate::control::handle(app, &ctx, &req) else { panic!("inspect") }; + v["result"]["artboardTool"]["adding"].clone() + }; + assert_eq!(adding(&mut app), json!(false)); + app.ui.artboard_tool.adding = true; + assert_eq!(adding(&mut app), json!(true)); +} + +#[test] +fn selecting_another_tool_and_coming_back_leaves_the_mode_off() { + let mut app = app_with_selected_board(); + app.ui.artboard_tool.adding = true; + // Both changes in one pass, with no pointer or options-bar call between them. + crate::tool_memory::select(&mut app, Tool::Move); + crate::tool_memory::select(&mut app, Tool::Artboard); + assert!(!app.ui.artboard_tool.adding); + let before = boards(&app); + click(&mut app, 222.0, 600.0); + assert_eq!(boards(&app), before); +} + +#[test] +fn the_add_new_artboard_button_toggles_the_mode_and_adds_no_board() { + use egui_kittest::Harness; + use egui_kittest::kittest::Queryable; + + let mut app = app_with_selected_board(); + app.ui.tool = Tool::Artboard; + let before = boards(&app); + let mut h = Harness::builder().with_size(egui::vec2(1400.0, 200.0)).build_ui_state( + |ui, app: &mut PhotocraftApp| { + if ui.ctx().fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) { + crate::panels::options_bar(app, ui); + } + }, + app, + ); + PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::Pro); + h.run_steps(4); + assert!(!h.state().ui.artboard_tool.adding); + h.get_by_label("Add New Artboard").click(); + h.run_steps(4); + assert!(h.state().ui.artboard_tool.adding, "the first click turns the mode on"); + assert_eq!(boards(h.state()), before); + h.get_by_label("Add New Artboard").click(); + h.run_steps(4); + assert!(!h.state().ui.artboard_tool.adding, "the second click turns it off"); + assert_eq!(boards(h.state()), before); +} diff --git a/crates/ui-egui/src/control/inspect.rs b/crates/ui-egui/src/control/inspect.rs index 53df5d373f..5b3b952f65 100644 --- a/crates/ui-egui/src/control/inspect.rs +++ b/crates/ui-egui/src/control/inspect.rs @@ -35,6 +35,7 @@ pub fn inspect(app: &PhotocraftApp, ctx: &egui::Context) -> Value { "memory": photocraft_raster::memory::stats(), "tool": app.ui.tool, "toolOptions": app.ui.tool_options, + "artboardTool": app.ui.artboard_tool, "perspectiveCrop": app.ui.perspective_crop, "strokeEditor": app.ui.stroke_editor, "magnetic": app.ui.magnetic, diff --git a/crates/ui-egui/src/tool_memory.rs b/crates/ui-egui/src/tool_memory.rs index 960fb83a07..5bdc4a235d 100644 --- a/crates/ui-egui/src/tool_memory.rs +++ b/crates/ui-egui/src/tool_memory.rs @@ -28,6 +28,10 @@ pub(crate) fn select(app: &mut PhotocraftApp, tool: Tool) { if app.ui.tool == Tool::Frame && tool != Tool::Frame { crate::frame_tool::cancel(app); } + if tool != Tool::Artboard { + // Add New Artboard's placing mode ends with the tool (#11386). + app.ui.artboard_tool.adding = false; + } app.ui.tool = tool; }