Reveal notes after creating one with the Note tool

This commit is contained in:
yoriswind committed 2026-11-06 23:12:35 -08:00
1 parent f68e227026
commit 3b3c648f61
2 files changed
+98 -6

No files matched your search

+16 -6
View File
@@ -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<Value, String> {
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);
}
}
}
@@ -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);
}