From 3b3c648f61c8e481b2e528f3ec288490146f8461 Mon Sep 17 00:00:00 2001 From: yoriswind Date: Fri, 6 Nov 2026 23:12:35 -0800 Subject: [PATCH] Reveal notes after creating one with the Note tool --- crates/ui-egui/src/tools/analysis_ui.rs | 22 +++-- .../src/tools/note_show_on_new_tests.rs | 82 +++++++++++++++++++ 2 files changed, 98 insertions(+), 6 deletions(-) create mode 100644 crates/ui-egui/src/tools/note_show_on_new_tests.rs diff --git a/crates/ui-egui/src/tools/analysis_ui.rs b/crates/ui-egui/src/tools/analysis_ui.rs index 6cad2b2158a..277d89e5375 100644 --- a/crates/ui-egui/src/tools/analysis_ui.rs +++ b/crates/ui-egui/src/tools/analysis_ui.rs @@ -230,6 +230,21 @@ fn set_ruler(app: &mut PhotocraftApp, r: Ruler) { let _ = app.run("image.analysis.rulerTool", json!({"start": r.start, "end": r.end, "protractor": r.protractor})); } +#[cfg(test)] +#[path = "note_show_on_new_tests.rs"] +mod note_show_on_new_tests; + +/// Create a note with the tool's options and enable Show Notes after success. +pub(crate) fn create_note(app: &mut PhotocraftApp, x: f64, y: f64) -> Result { + let a = &app.ui.analysis; + let params = json!({"x": x.round(), "y": y.round(), "author": a.note_author, "color": a.note_color}); + let result = app.run("notes.add", params)?; + app.ui.analysis.note_selected = result["index"].as_u64().map(|v| v as usize); + app.ui.analysis.notes = true; + app.ui.view.show.notes = true; + Ok(result) +} + /// Pointer input for the Ruler, Count, Note and Color Sampler tools. Returns true when consumed. pub fn pointer(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui::Modifiers) -> bool { let tool = app.active_tool(); @@ -318,12 +333,7 @@ pub fn pointer(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui::Modifiers) -> app.ui.analysis.drag = Some(Drag::Note(i, [x - doc.notes[i].position[0], y - doc.notes[i].position[1]])); } None => { - let a = &app.ui.analysis; - let p = json!({"x": x.round(), "y": y.round(), "author": a.note_author, "color": [a.note_color[0], a.note_color[1], a.note_color[2]]}); - if let Ok(r) = app.run("notes.add", p) { - app.ui.analysis.note_selected = r["index"].as_u64().map(|v| v as usize); - app.ui.analysis.notes = true; - } + let _ = create_note(app, x, y); } } } diff --git a/crates/ui-egui/src/tools/note_show_on_new_tests.rs b/crates/ui-egui/src/tools/note_show_on_new_tests.rs new file mode 100644 index 00000000000..a2e2cb8e8c8 --- /dev/null +++ b/crates/ui-egui/src/tools/note_show_on_new_tests.rs @@ -0,0 +1,82 @@ +use super::{PhotocraftApp, Tool, ToolEvent, create_note, json}; + +fn note_tool() -> (PhotocraftApp, egui::Context) { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 200, "height": 120})).unwrap(); + app.ui.tool = Tool::Note; + (app, egui::Context::default()) +} + +fn gesture(app: &mut PhotocraftApp, [x, y]: [f64; 2], [end_x, end_y]: [f64; 2]) { + crate::canvas::tool_event(app, ToolEvent::Down { x, y, pressure: 1.0 }, egui::Modifiers::NONE); + if [x, y] != [end_x, end_y] { + crate::canvas::tool_event(app, ToolEvent::Move { x: end_x, y: end_y, pressure: 1.0 }, egui::Modifiers::NONE); + } + crate::canvas::tool_event(app, ToolEvent::Up { x: end_x, y: end_y }, egui::Modifiers::NONE); +} + +#[test] +fn creating_a_note_rechecks_show_notes_and_reveals_both_notes() { + let (mut app, ctx) = note_tool(); + crate::menus::invoke(&mut app, &ctx, "view.show.notes", json!({})).unwrap(); + app.run("notes.add", json!({"x": 20, "y": 20})).unwrap(); + assert!(!app.ui.view.show.notes && !app.ui.analysis.notes); + assert!(!app.ui.view.shows(app.ui.view.show.notes)); + + app.ui.analysis.note_author = "QA".into(); + app.ui.analysis.note_color = [0.25, 0.5, 1.0]; + gesture(&mut app, [130.0, 70.0], [130.0, 70.0]); + + let notes = &app.session.active().unwrap().doc.notes; + assert_eq!(notes.len(), 2); + assert_eq!(notes[0].position, [20.0, 20.0]); + assert_eq!(notes[1].position, [130.0, 70.0]); + assert_eq!(notes[1].author, "QA"); + assert_eq!(notes[1].color.to_rgb(), [0.25, 0.5, 1.0]); + assert_eq!(app.ui.analysis.note_selected, Some(1)); + assert!(app.ui.analysis.notes && app.ui.view.shows(app.ui.view.show.notes)); + + crate::menus::invoke(&mut app, &ctx, "view.show.notes", json!({})).unwrap(); + assert!(!app.ui.view.shows(app.ui.view.show.notes)); +} + +#[test] +fn selecting_and_dragging_an_existing_note_preserve_hidden_notes() { + let (mut app, ctx) = note_tool(); + app.run("notes.add", json!({"x": 30, "y": 40, "author": "QA"})).unwrap(); + crate::menus::invoke(&mut app, &ctx, "view.show.notes", json!({})).unwrap(); + + gesture(&mut app, [32.0, 42.0], [32.0, 42.0]); + assert!(!app.ui.view.show.notes); + assert_eq!(app.ui.analysis.note_selected, Some(0)); + assert_eq!(app.ui.analysis.note_author, "QA"); + + gesture(&mut app, [32.0, 42.0], [62.0, 52.0]); + assert!(!app.ui.view.show.notes); + let notes = &app.session.active().unwrap().doc.notes; + assert_eq!(notes.len(), 1); + assert_eq!(notes[0].position, [60.0, 50.0]); +} + +#[test] +fn creating_a_note_leaves_extras_off() { + let (mut app, ctx) = note_tool(); + crate::menus::invoke(&mut app, &ctx, "view.show.notes", json!({})).unwrap(); + crate::menus::invoke(&mut app, &ctx, "view.extras", json!({})).unwrap(); + assert!(!app.ui.view.show.notes && !app.ui.view.extras); + + gesture(&mut app, [130.0, 70.0], [130.0, 70.0]); + + assert_eq!(app.session.active().unwrap().doc.notes.len(), 1); + assert!(app.ui.view.show.notes); + assert!(!app.ui.view.extras && !app.ui.view.shows(app.ui.view.show.notes)); +} + +#[test] +fn rejected_note_creation_does_not_change_visibility_or_selection() { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.ui.view.show.notes = false; + assert!(create_note(&mut app, 20.0, 20.0).is_err()); + assert!(!app.ui.view.show.notes && !app.ui.analysis.notes); + assert_eq!(app.ui.analysis.note_selected, None); +}