Let View Show hide artboard names

This commit is contained in:
Dan committed 2026-12-02 17:14:31 +00:00
1 parent bca050ed60
commit a208e03c70
16 files changed
+200 -20

No files matched your search

+23 -1
View File
@@ -1,5 +1,5 @@
//! Artboards: Layer › New › Artboard (from scratch, a group or the selected layers), artboard
//! properties (board rect, background, preset), View › Clear Selected Artboard Guides, and
//! properties (board rect, background, preset), artboard names and guides in the View menu, and
//! File › Export › Artboards to Files / to PDF.
//!
//! An artboard is a top-level group with [`photocraft_doc::Artboard`] set; the compositor clips
@@ -37,6 +37,9 @@ pub const PRESETS: &[(&str, u32, u32)] = &[
/// Gap Photoshop leaves between a new artboard and the rightmost existing one.
const GAP: i32 = 100;
/// Toggles the labels above artboards on the canvas.
pub const SHOW_NAMES_COMMAND: &str = "view.show.artboardNames";
fn bad(cmd: &str, msg: impl Into<String>) -> EngineError {
EngineError::BadParams { cmd: cmd.into(), msg: msg.into() }
}
@@ -50,6 +53,15 @@ fn has_artboards(s: &Session) -> std::result::Result<(), String> {
if d.doc.has_artboards() { Ok(()) } else { Err("the document has no artboards".into()) }
}
fn show_names(s: &mut Session, p: &Value) -> Result<Value> {
let on = match p.get("on") {
None | Some(Value::Null) => s.prefs().artboard_names_hidden,
Some(value) => value.as_bool().ok_or_else(|| bad(SHOW_NAMES_COMMAND, "on must be a boolean"))?,
};
s.prefs.edit(|prefs| prefs.artboard_names_hidden = !on);
Ok(json!(on))
}
fn export_artboards(s: &Session) -> std::result::Result<(), String> {
native_doc(s)?;
has_artboards(s)
@@ -1448,6 +1460,16 @@ pub fn specs() -> Vec<CommandSpec> {
};
}
vec![
CommandSpec {
id: SHOW_NAMES_COMMAND,
label: "Artboard Names",
menu: &["View", "Show"],
shortcut: None,
params: r##"{"on":bool?} (omitted: toggle)"##,
enabled: has_artboards,
journal: false,
run: show_names,
},
spec!(
"layer.new.artboard",
"Artboard…",
+2
View File
@@ -1715,6 +1715,8 @@ pub struct Preferences {
/// targets that differ from their defaults, saved as the user toggles them and restored at
/// launch, as Photoshop keeps them between sessions (#3762). JSON owned by the shell.
pub view_extras: Value,
/// View › Show › Artboard Names, remembered across documents and sessions.
pub artboard_names_hidden: bool,
/// Recently Used Colors (`"#rrggbb"`, newest first), shown by the shape Fill and Stroke
/// popovers and kept between sessions as in Photoshop. Owned by the shell.
pub recent_colors: Vec<String>,
@@ -814,6 +814,7 @@ layer.new.artboardFromLayers
layer.artboard.set
view.clearSelectedArtboardGuides
layer.artboard.addBeside
view.show.artboardNames
file.export.artboardsToFiles
file.export.artboardsToPdf
filter.liquify
+4
View File
@@ -296,6 +296,10 @@ impl PhotocraftApp {
// be edited at once, as in Photoshop (#4028). The layer is made whatever happens here.
let _ = panel_docking::show_panel(self, "properties", Some(true));
}
// Showing an overlay from View › Show turns Extras back on.
if id == photocraft_engine::artboard_cmds::SHOW_NAMES_COMMAND && matches!(result, Ok(Value::Bool(true))) {
self.ui.view.extras = true;
}
// Making a new selection reveals its outline after View > Extras was hidden (#5597).
// These interactive selection commands complete inline; a failed command, deselection,
// or painting inside an existing selection must leave the user's view choice alone.
+7 -5
View File
@@ -44,7 +44,7 @@ struct Entry {
copyrighted: Option<bool>,
empty_frames: Option<Arc<[LayerId]>>,
has_links: Option<bool>,
pages: Option<Arc<[PageFrame]>>,
pages: Option<(bool, Arc<[PageFrame]>)>,
moving: Option<MovingLayers>,
/// The uncovered rects and the display revision of the document they were measured on.
uncovered: Option<(u64, Arc<[DocRect]>)>,
@@ -121,10 +121,12 @@ impl DocQueries {
self.with(session, st, |entry, builds| *cached(builds, &mut entry.has_links, || !photocraft_engine::link_watch::linked_files(&st.doc).is_empty()))
}
/// The canvas's page frames of `st`, `compute`d on the first read after a change (the active layer, and so the
/// active frame, moves the revision).
pub(crate) fn pages(&self, session: &Session, st: &DocState, compute: impl FnOnce() -> Vec<PageFrame>) -> Arc<[PageFrame]> {
self.with(session, st, |entry, builds| cached(builds, &mut entry.pages, || compute().into()).clone())
/// The canvas's page frames of `st`, rebuilt when the document or the visibility of its names changes.
pub(crate) fn pages(&self, session: &Session, st: &DocState, show_names: bool, compute: impl FnOnce() -> Vec<PageFrame>) -> Arc<[PageFrame]> {
self.with(session, st, |entry, builds| match &entry.pages {
Some((shown, pages)) if *shown == show_names => pages.clone(),
_ => built(builds, &mut entry.pages, || (show_names, compute().into())).1.clone(),
})
}
/// The layers of `st` a Move drag moves, `compute`d on the first read after a change (a layer selection moves the
+10 -2
View File
@@ -27,9 +27,17 @@ fn doc_rect(r: photocraft_geom::Rect) -> DocRect {
/// picture paints each board's background.
pub(crate) fn pages(app: &PhotocraftApp, idx: usize) -> Arc<[PageFrame]> {
let Some(st) = app.session.documents().get(idx) else { return Arc::new([]) };
app.doc_queries.pages(&app.session, st, || {
let show_names = app.ui.view.shows(!app.session.prefs().artboard_names_hidden);
app.doc_queries.pages(&app.session, st, show_names, || {
let active = st.active_layer.and_then(|id| st.doc.artboard_of(id));
st.doc.artboards().into_iter().map(|(id, name, a)| PageFrame::new(doc_rect(a.rect)).name(name).active(active == Some(id))).collect()
st.doc
.artboards()
.into_iter()
.map(|(id, name, a)| {
let frame = PageFrame::new(doc_rect(a.rect)).active(active == Some(id));
if show_names { frame.name(name) } else { frame }
})
.collect()
})
}
+4 -2
View File
@@ -169,8 +169,10 @@ fn execute_command(app: &mut PhotocraftApp, ctx: &egui::Context, req: &ControlRe
// result). `ui.menu.invoke` behaves like a menu click, so it may open the dialog.
if req.method == "engine.execute" && photocraft_engine::commands::find(id).is_some() {
return run_waiting(app, wait, |app| {
// These bypass `menus::invoke`: a Type box drag in progress applies its box first.
crate::type_box_preview::end_drag(app);
// These bypass `menus::invoke`: apply a live Type box first unless only its view changes.
if id != photocraft_engine::artboard_cmds::SHOW_NAMES_COMMAND {
crate::type_box_preview::end_drag(app);
}
let revealed = (id == "layer.select").then(|| crate::layer_reveal::mark(app));
let previous = std::mem::replace(&mut app.programmatic_playback, true);
let result = app.run(id, params);
+1
View File
@@ -708,6 +708,7 @@ pub static CATALOG: &[(&[&str], &str, Option<&str>, &str)] = &[
(&["View", "Show"], "Guides", Some("Cmd+;"), "view.show.guides"),
(&["View", "Show"], "Canvas Guides", None, "view.show.canvasGuides"),
(&["View", "Show"], "Artboard Guides", None, "view.show.artboardGuides"),
(&["View", "Show"], "Artboard Names", None, "view.show.artboardNames"),
(&["View", "Show"], "Count", None, "view.show.count"),
(&["View", "Show"], "Smart Guides", None, "view.show.smartGuides"),
(&["View", "Show"], "Slices", None, "view.show.slices"),
+2
View File
@@ -138,6 +138,7 @@ struct UiRuleFacts<'a> {
struct ShownFacts<'a> {
extras: crate::state::Extras,
view: &'a crate::view_cmds::ViewOptions,
artboard_names_hidden: bool,
/// The options, status, menu and contextual task bars.
bars: (bool, bool, bool, bool),
palette: bool,
@@ -173,6 +174,7 @@ impl<'a> MenuFacts<'a> {
shown: ShownFacts {
extras: ui.extras,
view: &ui.view,
artboard_names_hidden: prefs.artboard_names_hidden,
bars: (ui.panels.options_bar, ui.panels.status_bar, ui.panels.menu_bar, ui.panels.context_task_bar),
palette: ui.palette.open,
theme: (ui.theme.id().as_str(), ui.theme.is_dark()),
+1
View File
@@ -63,6 +63,7 @@ fn keeps_box_drag(id: &str) -> bool {
"view.actualSize",
"view.rotateView",
"view.resetView",
photocraft_engine::artboard_cmds::SHOW_NAMES_COMMAND,
"view.darkenInterface",
"view.lightenInterface",
];
+4
View File
@@ -223,3 +223,7 @@ mod file_info_title_labels_tests;
#[cfg(test)]
#[path = "view_cmds/actual_size_tests.rs"]
mod actual_size_tests;
#[cfg(test)]
#[path = "view_show_artboard_names_tests.rs"]
mod view_show_artboard_names_tests;
@@ -1,4 +1,5 @@
use craft::ui::shell::ScreenMode;
use photocraft_engine::artboard_cmds::SHOW_NAMES_COMMAND;
use photocraft_engine::prefs::FontPreview;
use super::arrange::{arrange, command as arrange_command, layout_checked};
@@ -132,6 +133,9 @@ pub fn leave_full_screen_without_document(app: &mut PhotocraftApp) {
}
pub fn checked(app: &PhotocraftApp, id: &str) -> Option<bool> {
if id == SHOW_NAMES_COMMAND {
return Some(!app.session.prefs().artboard_names_hidden);
}
let o = &app.ui.view;
if let Some(k) = id.strip_prefix("view.show.") {
let mut s = o.show;
@@ -344,6 +348,7 @@ fn run(app: &mut PhotocraftApp, id: &str, p: &Value) -> Result<Value, String> {
o.extras = true;
app.ui.extras.grid = true;
app.ui.extras.guides = true;
app.session.prefs.edit(|prefs| prefs.artboard_names_hidden = false);
return Ok(json!(true));
}
let slot = show_slot(&mut o.show, k).ok_or("unknown Show item")?;
@@ -0,0 +1,125 @@
use craft::menu::ItemKind;
use egui::accesskit::Role;
use egui::vec2;
use egui_kittest::Harness;
use egui_kittest::kittest::{NodeT, Queryable};
use photocraft_engine::Session;
use serde_json::{Value, json};
use crate::PhotocraftApp;
use crate::control::{ControlRequest, Reply};
use crate::menus::{invoke, menu_rows, row};
const NAMES: &str = "view.show.artboardNames";
const EXTRAS: &str = "view.extras";
const ALL: &str = "view.show.all";
const BOARD: &str = "Cover board";
fn assert_menu_state(app: &PhotocraftApp, enabled: bool, checked: bool) {
let rows = menu_rows(app);
let item = row(&rows, NAMES).expect("View › Show has an Artboard Names item");
assert_eq!(item.enabled, enabled);
assert_eq!(item.kind, ItemKind::Check(checked));
}
#[test]
fn artboard_names_retains_its_check_when_the_last_document_closes() {
let mut app = PhotocraftApp::new(Session::new(), Default::default());
let ctx = app.ctx().clone();
let order: Vec<_> = menu_rows(&app).into_iter().filter(|item| item.path == ["View", "Show"]).map(|item| item.command.id).collect();
assert!(order.windows(3).any(|items| items == ["view.show.artboardGuides", NAMES, "view.show.count"]));
assert_menu_state(&app, false, true);
assert!(invoke(&mut app, &ctx, NAMES, json!({})).is_err());
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
assert_menu_state(&app, false, true);
assert!(app.session.execute(NAMES, json!({"on": false})).is_err());
app.run("file.close", json!({"save": "discard"})).unwrap();
app.run("file.new", json!({"width": 400, "height": 300, "artboard": true})).unwrap();
assert_menu_state(&app, true, true);
let doc = app.session.active().unwrap();
assert!(!doc.is_dirty());
let history = doc.history.generation();
assert_eq!(invoke(&mut app, &ctx, NAMES, json!({})).unwrap(), json!(false));
assert_menu_state(&app, true, false);
let doc = app.session.active().unwrap();
assert!(!doc.is_dirty());
assert_eq!(doc.history.generation(), history);
app.run("file.close", json!({})).unwrap();
assert!(app.session.documents().is_empty());
assert_menu_state(&app, false, false);
app.run("file.new", json!({"width": 400, "height": 300, "artboard": true})).unwrap();
assert_menu_state(&app, true, false);
app.run("file.close", json!({})).unwrap();
assert_eq!(invoke(&mut app, &ctx, ALL, json!({})).unwrap(), json!(true));
assert_menu_state(&app, false, true);
app.run("file.new", json!({"width": 400, "height": 300, "artboard": true})).unwrap();
assert_menu_state(&app, true, true);
}
#[test]
fn artboard_names_automation_and_extras_redraw_only_the_canvas_labels() {
let mut app = PhotocraftApp::new(Session::new(), Default::default());
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
app.run("layer.new.artboard", json!({"rect": [40, 50, 230, 180], "name": BOARD})).unwrap();
crate::tool_memory::select(&mut app, crate::state::Tool::Artboard);
app.sync_views();
let ctx = app.ctx().clone();
let mut h = Harness::builder().with_size(vec2(1000.0, 700.0)).with_context(ctx.clone()).build_ui_state(
|ui, app: &mut Box<PhotocraftApp>| {
if ui.ctx().fonts(|fonts| fonts.families().contains(&egui::FontFamily::Name("medium".into()))) {
egui::CentralPanel::default().show(ui, |ui| crate::canvas::testing::document_area(app, ui));
}
},
app,
);
PhotocraftApp::setup_context(&ctx, crate::theme::AppTheme::default());
h.run_steps(4);
let name_drawn = |h: &Harness<'_, Box<PhotocraftApp>>| crate::paint_test_support::drawn_text(h).iter().any(|text| text == BOARD);
let name_accessible = |h: &Harness<'_, Box<PhotocraftApp>>| h.query_by_role_and_label(Role::Button, BOARD).is_some();
let add_right_rect = |h: &Harness<'_, Box<PhotocraftApp>>| h.get_by_role_and_label(Role::Button, "Add right").rect();
assert!(name_drawn(&h) && name_accessible(&h), "the artboard name shows by default");
let add = add_right_rect(&h);
let idx = h.state().session.active_index().unwrap();
let visible = crate::canvas::artboard_ui::pages(h.state(), idx);
let set_names = |app: &mut PhotocraftApp, on: bool| {
let (req, _response) = ControlRequest::new("engine.execute", json!({"command": NAMES, "params": {"on": on}}));
let Reply::Done(result) = crate::control::handle(app, &ctx, &req) else { panic!("expected an immediate result") };
assert_eq!(result["ok"], true, "{result}");
assert_eq!(result["result"], Value::Bool(on));
};
set_names(h.state_mut(), false);
h.run_steps(3);
assert!(!name_drawn(&h) && !name_accessible(&h), "hiding a name invalidates the canvas without a document edit");
let hidden = crate::canvas::artboard_ui::pages(h.state(), idx);
assert_eq!(hidden.len(), visible.len());
for (hidden, visible) in hidden.iter().zip(visible.iter()) {
let mut visible = visible.clone();
visible.name = None;
assert_eq!(hidden, &visible, "the frame, border and fill are retained");
}
assert_eq!(add_right_rect(&h), add, "the add-artboard button stays");
invoke(h.state_mut(), &ctx, EXTRAS, json!({"on": false})).unwrap();
invoke(h.state_mut(), &ctx, EXTRAS, json!({"on": true})).unwrap();
h.run_steps(3);
assert!(!name_drawn(&h), "restoring Extras does not override the unchecked flag");
invoke(h.state_mut(), &ctx, EXTRAS, json!({"on": false})).unwrap();
set_names(h.state_mut(), true);
h.run_steps(3);
assert!(name_drawn(&h), "showing this overlay turns Extras on like other View › Show commands");
invoke(h.state_mut(), &ctx, EXTRAS, json!({"on": false})).unwrap();
h.run_steps(3);
assert!(!name_drawn(&h) && !name_accessible(&h), "Extras hides the name without unchecking it");
assert_menu_state(h.state(), true, true);
assert_eq!(add_right_rect(&h), add);
invoke(h.state_mut(), &ctx, EXTRAS, json!({"on": true})).unwrap();
h.run_steps(3);
assert!(name_drawn(&h) && name_accessible(&h), "restoring Extras brings the checked overlay back");
}
+1 -1
View File
@@ -325,7 +325,7 @@ pub(crate) fn canvas(app: &PhotocraftApp) -> u64 {
(
documents,
views,
(windows, ui.tool_options.revision(), tools, picker),
(windows, ui.tool_options.revision(), tools, picker, app.session.prefs().artboard_names_hidden),
sessions,
editing,
previews,
+6 -5
View File
@@ -2,21 +2,21 @@
Generated by `cargo xtask parity` from `crates/ui-egui/src/menu_catalog.rs` (Photoshop's menu tree) and the live command registry. Do not edit by hand.
**663 of 663 menu items live (100.0%).**
**666 of 666 menu items live (100.0%).**
| Menu | Live | Total | % |
|---|---:|---:|---:|
| File | 53 | 53 | 100% |
| Edit | 74 | 74 | 100% |
| Image | 61 | 61 | 100% |
| Layer | 163 | 163 | 100% |
| Layer | 164 | 164 | 100% |
| Type | 74 | 74 | 100% |
| Select | 25 | 25 | 100% |
| Filter | 75 | 75 | 100% |
| View | 76 | 76 | 100% |
| View | 78 | 78 | 100% |
| Window | 62 | 62 | 100% |
**Headless ([RFC-0052](https://github.com/storytold/craft-contrib/blob/main/rfcs/0052-headless-reach.md)): 516 yes, 48 no (window 48, os 0, engine-gap 0), 0 partial, 99 unknown.**
**Headless ([RFC-0052](https://github.com/storytold/craft-contrib/blob/main/rfcs/0052-headless-reach.md)): 518 yes, 48 no (window 48, os 0, engine-gap 0), 0 partial, 100 unknown.**
Live counts the desktop app's own panels, workspaces, tools and view handlers. Headless counts only the engine registry that `photocraft-cli` and the MCP server load: an item is `yes` when its id is an engine command. The rest are listed under [Not headless](#not-headless), with the hand mark from `HEADLESS` in `crates/ui-egui/src/menus/parity.rs`, `no` (`window`) for a desktop panel, workspace or tool, or `unknown`.
@@ -64,7 +64,7 @@ Live counts the desktop app's own panels, workspaces, tools and view handlers. H
* Select and Mask… (`select.selectAndMask`): headless: unknown
### View (57)
### View (58)
* Proof Setup › Custom… (`view.proofSetup.custom`): headless: unknown
* Proof Setup › Working CMYK (`view.proofSetup.workingCmyk`): headless: unknown
@@ -88,6 +88,7 @@ Live counts the desktop app's own panels, workspaces, tools and view handlers. H
* 100% (`view.actualPixels`): headless: unknown
* 200% (`view.twoHundredPercent`): headless: unknown
* Print Size (`view.printSize`): headless: unknown
* Actual Size (`view.actualSize`): headless: unknown
* Flip Horizontal (`view.flipHorizontal`): headless: unknown
* Screen Mode › Standard Screen Mode (`view.screenMode.standard`): headless: unknown
* Screen Mode › Full Screen Mode With Menu Bar (`view.screenMode.fullScreenWithMenuBar`): headless: unknown
+4 -4
View File
@@ -9,9 +9,9 @@ Generated by `cargo xtask scorecard` from `perf/budgets.toml`, `perf/baseline.js
| [Performance](#performance) | 3 | 22 | 59 | 93 scenarios: 3 within budget, 22 over budget or failing, 9 tracked only, 55 not run, 4 not measurable yet (baseline 2026-10-05) |
| [File compatibility](#file-compatibility) | 11 | 14 | 2 | io corpus: oracle ≥ 148/170, round trip ≥ 169/170; psd-tools corpus: oracle ≥ 249/309, round trip ≥ 308/309; photoshop oracles: oracle ≥ 190/258, round trip ≥ 258/258 |
| [Tools](#tools) | 36 | 9 | 0 | |
| [Workspace and UI](#workspace-and-ui) | 15 | 6 | 2 | settings that do nothing: 9 of 206 (target 0) |
| [Workspace and UI](#workspace-and-ui) | 15 | 6 | 2 | settings that do nothing: 9 of 207 (target 0) |
| [Type](#type) | 6 | 6 | 0 | |
| [Automation](#automation) | 6 | 4 | 2 | 663 of 663 menu items live (100.0%) |
| [Automation](#automation) | 6 | 4 | 2 | 666 of 666 menu items live (100.0%) |
| [Reliability](#reliability) | 5 | 2 | 0 | never-crash lints on 28 of 28 crates; panic_hunt present |
| [Distribution](#distribution) | 5 | 5 | 1 | |
| [Open bugs](#open-bugs) | 31 | 1 | 0 | |
@@ -217,7 +217,7 @@ Corpus floors (`crates/io/tests/it/corpus.rs`): the enforced minimums; the corpu
## Workspace and UI
**Settings that do nothing: 9 of 206** (target 0, #204). Counted by the prefs audit (`xtask/src/scorecard.rs`): a `Preferences` field counts as read when code outside the prefs model (`prefs.rs` except its `impl Session` blocks; tests excluded; the schema-driven dialog never names a field) accesses `section.field`, or `.section` and `.field` in the same file, or calls a section method that reads `self.field`. It is a heuristic lower bound: a generic name can look read when it isn't.
**Settings that do nothing: 9 of 207** (target 0, #204). Counted by the prefs audit (`xtask/src/scorecard.rs`): a `Preferences` field counts as read when code outside the prefs model (`prefs.rs` except its `impl Session` blocks; tests excluded; the schema-driven dialog never names a field) accesses `section.field`, or `.section` and `.field` in the same file, or calls a section method that reads `self.field`. It is a heuristic lower bound: a generic name can look read when it isn't.
Unread: `general.color_picker`, `workspace.auto_show_hidden_panels`, `workspace.enable_floating_document_window_docking`, `workspace.enable_narrow_options_bar`, `performance.legacy_compositing`, `plug_ins.show_extension_panels`, `plug_ins.allow_scripts_to_connect`, `type_.text_engine`, `enhanced_controls.scrubby_slider_acceleration`.
@@ -266,7 +266,7 @@ Unread: `general.color_picker`, `workspace.auto_show_hidden_panels`, `workspace.
## Automation
Menu wiring (`docs/parity-checklist.md`): 663 of 663 menu items live (100.0%). This counts dispatch, not behaviour.
Menu wiring (`docs/parity-checklist.md`): 666 of 666 menu items live (100.0%). This counts dispatch, not behaviour.
| Id | Target | Status | Issue | Note |
|---|---|---|---|---|