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

This commit is contained in:
aiongg committed 2026-11-23 05:50:07 +00:00
1 parent b21f59905d
commit 18bb80398f
5 files changed
+77 -35

No files matched your search

@@ -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));
+10 -4
View File
@@ -340,12 +340,15 @@ pub fn open(app: &mut PhotocraftApp) -> Result<DialogId, String> {
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<Computed, String> {
let shown = shown.ok_or("the preview failed")?;
Ok(Computed { shown, cache: Cache { base: base_cache, proxy } })
}
#[cfg(test)]
mod tests;
+19 -7
View File
@@ -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);
}
}
}
+10 -1
View File
@@ -75,6 +75,9 @@ pub struct AnalysisUi {
pub log_selected: Selection<u64>,
/// Notes panel: the note shown (index).
pub note_selected: Option<usize>,
/// 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<Result<
Ok(doc) => 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<Val
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.focus_note_text = app.ui.analysis.note_selected.is_some();
let _ = crate::panel_docking::show_panel(app, NOTES, Some(true));
app.ui.view.show.notes = true;
Ok(result)
@@ -1,11 +1,12 @@
//! The Notes panel body.
use craft::behavior::IconId;
use craft::behavior::{DocKey, IconId};
use craft::ui::buttons::IconButton;
use craft::ui::contract::{Bind, Props as _, Show as _, ShowContainer as _};
use craft::ui::display::Text;
use craft::ui::layout_components::Row;
use craft::ui::runtime::env::Label;
use craft::ui::runtime::focus::{self, FocusTarget};
use craft::ui::text::TextField;
use serde_json::json;
@@ -13,39 +14,45 @@ use super::{note_alerts, show_note_options};
use crate::PhotocraftApp;
use crate::history_keys;
/// The panel body: the shown note's author and text, previous and next buttons with the position, and delete.
/// The text field's document key, the target of the focus request a note made with a click leaves.
const NOTE_TEXT: DocKey = DocKey::new("photocraft.note-text");
/// The panel body: the selected note's author and text, previous and next buttons with the position, and delete.
/// Nothing is selected until a note is clicked, so the text field is empty and disabled and the buttons are greyed.
pub(crate) fn body(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
let (n, note) = match app.session.active() {
Some(d) => (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<usize>, n: usize) -> String {
shown.map_or_else(String::new, |i| format!("{} / {n}", i + 1))
}