From 18bb80398f23f524d3ca5bef6c09f29dbcd0a688 Mon Sep 17 00:00:00 2001 From: aiongg Date: Sun, 22 Nov 2026 23:19:24 +0000 Subject: [PATCH] Notes panel empty state and counter, Import Notes outside alert, Count Label Size, Select and Mask stale-document reason, Selective Color drops stale single-colour keys --- .../src/dialogs/adjust_editors/values.rs | 5 ++ crates/ui-egui/src/dialogs/select_mask_ui.rs | 14 +++-- crates/ui-egui/src/tools/analysis/canvas.rs | 26 ++++++--- crates/ui-egui/src/tools/analysis/mod.rs | 11 +++- .../ui-egui/src/tools/analysis/notes_panel.rs | 56 +++++++++++-------- 5 files changed, 77 insertions(+), 35 deletions(-) diff --git a/crates/ui-egui/src/dialogs/adjust_editors/values.rs b/crates/ui-egui/src/dialogs/adjust_editors/values.rs index ed43071230..6efab6b80e 100644 --- a/crates/ui-egui/src/dialogs/adjust_editors/values.rs +++ b/crates/ui-egui/src/dialogs/adjust_editors/values.rs @@ -514,6 +514,11 @@ fn write_params(value: &AdjustValue, cx: &ValueCx) -> Value { } AdjustValue::GradientMap { value } => write_gradient_map(&mut out, value), AdjustValue::SelectiveColor { value } => { + // The rows carry every range: the single-colour form and `relative` the dialog was opened with would be + // read after them (and over them) by the engine. + for key in ["colors", "cyan", "magenta", "yellow", "black", "relative"] { + out.remove(key); + } out.insert("method".into(), json!(if value.method == SelectiveMethod::Absolute { "absolute" } else { "relative" })); for (key, row) in photocraft_engine::adjust_cmds::RANGES.iter().zip(value.ranges) { out.insert((*key).into(), json!(row)); diff --git a/crates/ui-egui/src/dialogs/select_mask_ui.rs b/crates/ui-egui/src/dialogs/select_mask_ui.rs index 9743c7ced6..66caae676c 100644 --- a/crates/ui-egui/src/dialogs/select_mask_ui.rs +++ b/crates/ui-egui/src/dialogs/select_mask_ui.rs @@ -340,12 +340,15 @@ pub fn open(app: &mut PhotocraftApp) -> Result { Ok(dialog) } -/// Why the open workspace's work no longer applies: the active layer is not the one it was opened on (another layer -/// selected by a shortcut or the control channel). `select.refineEdge` works on the active layer, so its edits must -/// not run there. A document switch is `distort_ui::drop_foreign`'s. +/// Why the open workspace's work no longer applies: the active document is not the one it was opened on, or the active +/// layer is not the one it was opened on (another layer selected by a shortcut or the control channel). +/// `select.refineEdge` works on the active layer of the active document, so its edits must not run there. pub(crate) fn stale(app: &PhotocraftApp) -> Option<&'static str> { let (_, document, opened_on, _) = app.select_mask_target.as_ref()?; - let st = app.session.active().filter(|st| st.doc.id == *document)?; + let st = app.session.active()?; + if st.doc.id != *document { + return Some(tl!("Select and Mask was closed: its document is no longer the active one")); + } let layer = st.active_layer.filter(|id| st.doc.layer(*id).is_some()); (layer != Some(*opened_on)).then_some(tl!("Select and Mask was closed: another layer was selected")) } @@ -538,3 +541,6 @@ fn compute(job: Job, cancel: &Cancel) -> Result { let shown = shown.ok_or("the preview failed")?; Ok(Computed { shown, cache: Cache { base: base_cache, proxy } }) } + +#[cfg(test)] +mod tests; diff --git a/crates/ui-egui/src/tools/analysis/canvas.rs b/crates/ui-egui/src/tools/analysis/canvas.rs index fea9fb07fc..edf05fdbbb 100644 --- a/crates/ui-egui/src/tools/analysis/canvas.rs +++ b/crates/ui-egui/src/tools/analysis/canvas.rs @@ -10,7 +10,8 @@ use craft::color_ui::ui::{ColorSamplerMarks, ColorSamplerTool, ColorSamplers, Sa use craft::draw::ui::{RulerLine, RulerTool}; use craft::ui::canvas::{CanvasTool, NoTool, ToolAction, ToolClaims, ToolContext, ToolHostResponse, ToolKey, ToolPath, ToolPointer, canvas_space}; use craft::ui::contract::{Access, Common, Component, Cx, MeasureCx, PaintUi, Props as _, Role, Show as _}; -use craft::ui::primitives::{Draw, PaintShape, StrokeWidth, TextRun}; +use craft::ui::fonts::FontRef; +use craft::ui::primitives::{DocRun, DocText, Draw, PaintShape, StrokeWidth}; use craft::ui::runtime::env::Label; use craft::ui::style::{ComponentStyle, DataColor, StyleColor, StyleCx}; use egui::{Color32, CornerRadius, Pos2, Rect, Response, Vec2, vec2}; @@ -196,7 +197,12 @@ pub(crate) fn body(app: &mut PhotocraftApp, ui: &mut egui::Ui, rect: Rect) { .count_groups .iter() .filter(|g| g.visible) - .map(|g| CountGroupMarks { color: color32(g.color.to_rgb()), radius: 1.0 + g.marker_size as f32, points: g.points.clone() }) + .map(|g| CountGroupMarks { + color: color32(g.color.to_rgb()), + radius: 1.0 + g.marker_size as f32, + label_size: g.label_size as f32, + points: g.points.clone(), + }) .collect() }) } else { @@ -438,10 +444,15 @@ impl CanvasTool for NotePass<'_> { // ------------------------------------------------------------------ paint +/// The width a marker's number is laid out in, wide enough for any count at the largest Label Size. +const NUMBER_ROOM: f32 = 1000.0; + /// One visible count group's marks. struct CountGroupMarks { color: Color32, radius: f32, + /// The numbers' font size in screen points: the group's Label Size. + label_size: f32, points: Vec<[f64; 2]>, } @@ -462,8 +473,7 @@ fn overlay_style(cx: &StyleCx<'_>) -> OverlayStyle { OverlayStyle { metrics: Metrics::new(), ink: cx.color(tokens.color.overlay.stroke), halo: cx.color(tokens.color.overlay.halo), shadow: tokens.stroke.thin } } -/// The count markers of the visible groups, numbered in each group. Paint only. -// PLAN: the group's label size is not applied; `TextRun` takes a `TypeRole`, not a point size. +/// The count markers of the visible groups, numbered in each group, the numbers at the group's Label Size. Paint only. #[derive(craft::ui::contract::Component, craft::ui::contract::Props)] #[component(canvas_control)] pub(crate) struct CountMarks { @@ -507,9 +517,11 @@ impl Component for CountMarks { let number = (i + 1).to_string(); let anchor = at + vec2(2.0 + group.radius, -1.0); for (offset, color) in [(Vec2::splat(style.shadow), style.halo), (Vec2::ZERO, style.ink)] { - let run = TextRun::new(number.as_str()).role(craft::theme::TypeRole::Caption).color(color); - let layout = draw.layout(&run, f32::INFINITY); - draw.galley(anchor + offset - vec2(0.0, layout.size().y), &layout); + let runs = [DocRun::new(number.as_str(), FontRef::proportional(), group.label_size, DataColor::new(color.egui()))]; + let text = DocText::new(&runs); + let height = cx.layout_doc(&text).size().y; + let top_left = anchor + offset - vec2(0.0, height); + draw.doc(Rect::from_min_size(top_left, vec2(NUMBER_ROOM, height)), &text); } } } diff --git a/crates/ui-egui/src/tools/analysis/mod.rs b/crates/ui-egui/src/tools/analysis/mod.rs index e0a0006db7..bfc32dd16c 100644 --- a/crates/ui-egui/src/tools/analysis/mod.rs +++ b/crates/ui-egui/src/tools/analysis/mod.rs @@ -75,6 +75,9 @@ pub struct AnalysisUi { pub log_selected: Selection, /// Notes panel: the note shown (index). pub note_selected: Option, + /// A note was just made with a click: the panel's text field takes the keyboard when it next shows the note. + #[serde(skip)] + pub focus_note_text: bool, /// Note tool options: author of new notes. pub note_author: String, /// Note tool options: colour of new notes. @@ -88,6 +91,7 @@ impl Default for AnalysisUi { Self { log_selected: Selection::default(), note_selected: None, + focus_note_text: false, note_author: String::new(), note_color: photocraft_engine::notes_cmds::DEFAULT_NOTE_COLOR, use_measurement_scale: false, @@ -172,9 +176,13 @@ pub fn menu(app: &mut PhotocraftApp, id: &str, params: &Value) -> Option app.pick_file_bytes(move |app, name, bytes| { app.refocus(doc)?; let r = photocraft_engine::notes_cmds::import_notes_from(&mut app.session, &name, &bytes).map_err(|e| e.to_string()); - if r.is_ok() { + if let Ok(v) = &r { let _ = crate::panel_docking::show_panel(app, NOTES, Some(true)); app.sync_views(); + // Notes whose icon landed off the canvas stay there; the alert says so (#13914). + if v["outside"] == json!(true) { + crate::dialogs::alerts::alert(app, tl!("Some notes are placed outside the canvas.")); + } } r }), @@ -205,6 +213,7 @@ pub(crate) fn create_note(app: &mut PhotocraftApp, x: f64, y: f64) -> Result (d.doc.notes.len(), Some(&d.doc.notes)), None => (0, None), }; - let shown = app.ui.analysis.note_selected.filter(|i| *i < n).or((n > 0).then_some(0)); + let shown = app.ui.analysis.note_selected.filter(|i| *i < n); // The shown note's author and text, owned so the edits below may run commands. let current = shown.and_then(|i| note.and_then(|notes| notes.get(i)).map(|note| (i, note.author.clone(), note.text.clone()))); - match current { - Some((i, author, text)) => { - let author = if author.is_empty() { tl!("No author").to_string() } else { author }; - Text::new(Label::from(author)).show(ui); - // PLAN: assumed `TextField::lines(usize)` sets the line count of a multi-line field. - let events = TextField::new(Label::from(tl!("Notes")), Bind::given(text)).lines(6).show(ui).events; - for event in events.iter() { - let Some(value) = event.landed() else { continue }; - let mut params = json!({"index": i, "text": value}); - if let Some(key) = history_keys::coalesce(&format!("note-{i}"), event) { - params["coalesce"] = json!(key); - } - let _ = app.run("notes.set", params); + let (author, text) = current.as_ref().map_or((String::new(), String::new()), |(_, author, text)| (author.clone(), text.clone())); + Text::new(Label::from(author)).show(ui); + let field = TextField::new(Label::from(tl!("Notes")), Bind::given(text)) + .lines(6) + .placeholder(Label::from(tl!("Click a note to view or edit"))) + .doc_key(NOTE_TEXT) + .enabled(current.is_some()); + let events = field.show(ui).events; + if current.is_some() && std::mem::take(&mut app.ui.analysis.focus_note_text) { + let _ = focus::request(ui.ctx(), FocusTarget::Doc(NOTE_TEXT)); + } + if let Some((i, ..)) = current { + for event in events.iter() { + let Some(value) = event.landed() else { continue }; + let mut params = json!({"index": i, "text": value}); + if let Some(key) = history_keys::coalesce(&format!("note-{i}"), event) { + params["coalesce"] = json!(key); } - } - None => { - Text::new(Label::from(tl!("Click with the Note tool to add a note."))).show(ui); + let _ = app.run("notes.set", params); } } let mut moved = None; let mut delete = false; Row::new().show(ui, |ui, _| { let step = |ui: &mut egui::Ui, icon: &'static str, name: &str| { - IconButton::new(IconId::new(icon)).label(Label::from(name.to_owned())).enabled(n > 1).show(ui).clicked() + IconButton::new(IconId::new(icon)).label(Label::from(name.to_owned())).enabled(n > 1 && shown.is_some()).show(ui).clicked() }; if step(ui, "chevrons_left", tl!("Previous note")) { moved = shown.map(|i| (i + n - 1) % n); @@ -53,9 +60,7 @@ pub(crate) fn body(app: &mut PhotocraftApp, ui: &mut egui::Ui) { if step(ui, "chevrons_right", tl!("Next note")) { moved = shown.map(|i| (i + 1) % n); } - let template = "{index} of {total}"; - let position = crate::i18n::fmt(tl!(template), &[("index", &shown.map_or(0, |i| i + 1).to_string()), ("total", &n.to_string())]); - Text::new(Label::from(position)).show(ui); + Text::new(Label::from(note_counter(shown, n))).show(ui); delete = IconButton::new(IconId::new("trash")).label(Label::from(tl!("Delete note"))).enabled(shown.is_some()).show(ui).clicked(); }); if let Some(i) = moved { @@ -66,3 +71,8 @@ pub(crate) fn body(app: &mut PhotocraftApp, ui: &mut egui::Ui) { note_alerts::ask_delete_note(app, i); } } + +/// The counter: "N / M" for note N of M, blank with no note selected. +fn note_counter(shown: Option, n: usize) -> String { + shown.map_or_else(String::new, |i| format!("{} / {n}", i + 1)) +}