diff --git a/ASSETS.md b/ASSETS.md index 89eb4be74e..a21d7a9692 100644 --- a/ASSETS.md +++ b/ASSETS.md @@ -262,6 +262,8 @@ Generated-in-code art is original and has no file to list. This covers the defau | `assets/icons/dc-puppet.svg` | VectorCraft contributors | Original work, drawn for VectorCraft | MIT OR Apache-2.0 | | | `assets/icons/dc-quick-pen.svg` | VectorCraft contributors | Original work, drawn for VectorCraft (a line and a half circle with a dot at each point) | MIT OR Apache-2.0 | | | `assets/icons/dc-rearrange.svg` | VectorCraft contributors | Original work, drawn for VectorCraft | MIT OR Apache-2.0 | | +| `assets/icons/dc-recolor-arrow.svg` | VectorCraft contributors | Original work, drawn for VectorCraft (a right arrow, a Recolor Artwork row that is recolored) | MIT OR Apache-2.0 | | +| `assets/icons/dc-recolor-arrow-off.svg` | VectorCraft contributors | Original work, drawn for VectorCraft (a dashed line without a head, a Recolor Artwork row that is excluded) | MIT OR Apache-2.0 | | | `assets/icons/dc-rect-cut.svg` | VectorCraft contributors | Original work, drawn for VectorCraft | MIT OR Apache-2.0 | | | `assets/icons/dc-rect-grid.svg` | VectorCraft contributors | Original work, drawn for VectorCraft | MIT OR Apache-2.0 | | | `assets/icons/dc-reference-point.svg` | VectorCraft contributors | Original work, drawn for VectorCraft | MIT OR Apache-2.0 | | diff --git a/assets/icons/dc-recolor-arrow-off.svg b/assets/icons/dc-recolor-arrow-off.svg new file mode 100644 index 0000000000..9a972d3804 --- /dev/null +++ b/assets/icons/dc-recolor-arrow-off.svg @@ -0,0 +1 @@ + diff --git a/assets/icons/dc-recolor-arrow.svg b/assets/icons/dc-recolor-arrow.svg new file mode 100644 index 0000000000..41dd50e3be --- /dev/null +++ b/assets/icons/dc-recolor-arrow.svg @@ -0,0 +1 @@ + diff --git a/crates/ui-egui/src/dialogs/recolor.rs b/crates/ui-egui/src/dialogs/recolor.rs index fb8aea7c51..c6c9f72d3d 100644 --- a/crates/ui-egui/src/dialogs/recolor.rs +++ b/crates/ui-egui/src/dialogs/recolor.rs @@ -212,8 +212,6 @@ const ARROW: ColumnKey = ColumnKey::new("arrow"); const NEW: ColumnKey = ColumnKey::new("new"); const HEX: ColumnKey = ColumnKey::new("hex"); /// The arrow of a row that is recolored, and of one that is excluded (a dashed line without a head). -// PLAN: assumed icons `dc-recolor-arrow` and `dc-recolor-arrow-off` (VectorCraft's own solid and dashed arrows); -// the assets owner draws them and adds them to `assets/icons`, `icon_data.rs` and `ASSETS.md`. const ARROW_ON: &str = "dc-recolor-arrow"; const ARROW_OFF: &str = "dc-recolor-arrow-off"; diff --git a/crates/ui-egui/src/icon_data.rs b/crates/ui-egui/src/icon_data.rs index d58888e122..8c8962dd50 100644 --- a/crates/ui-egui/src/icon_data.rs +++ b/crates/ui-egui/src/icon_data.rs @@ -174,6 +174,8 @@ pub static ICONS: &[(&str, &[u8])] = &[ ("dc-puppet", include_bytes!("../../../assets/icons/dc-puppet.svg")), ("dc-quick-pen", include_bytes!("../../../assets/icons/dc-quick-pen.svg")), ("dc-rearrange", include_bytes!("../../../assets/icons/dc-rearrange.svg")), + ("dc-recolor-arrow", include_bytes!("../../../assets/icons/dc-recolor-arrow.svg")), + ("dc-recolor-arrow-off", include_bytes!("../../../assets/icons/dc-recolor-arrow-off.svg")), ("dc-rect-cut", include_bytes!("../../../assets/icons/dc-rect-cut.svg")), ("dc-rect-grid", include_bytes!("../../../assets/icons/dc-rect-grid.svg")), ("dc-reference-point", include_bytes!("../../../assets/icons/dc-reference-point.svg")), diff --git a/crates/ui-egui/src/icons.rs b/crates/ui-egui/src/icons.rs index c0ca9fdf0c..46b96ae2c1 100644 --- a/crates/ui-egui/src/icons.rs +++ b/crates/ui-egui/src/icons.rs @@ -131,6 +131,72 @@ mod tests { has_icon(&IconId::new(name)) } + /// The ways a source line writes an icon id as a literal; a `const` that holds one is read by `const_icon`. + const FORMS: [&str; 3] = ["IconId::new(\"", "icon(\"", "icon = \""]; + + /// The id a `const NAME: &str = ""` line declares, when `NAME` ends in `ICON` or `code` passes it to + /// `IconId::new(NAME)`. + fn const_icon<'a>(line: &'a str, code: &str) -> Option<&'a str> { + let rest = line.trim_start().trim_start_matches("pub ").trim_start_matches("pub(crate) ").strip_prefix("const ")?; + let (name, after) = rest.split_once(':')?; + if name.is_empty() || !name.chars().all(|c| c.is_ascii_uppercase() || c.is_ascii_digit() || c == '_') { + return None; + } + if !name.ends_with("ICON") && !code.contains(&format!("IconId::new({name})")) { + return None; + } + after.trim_start().strip_prefix("&str")?.split_once("= \"")?.1.split('"').next() + } + + /// An id that no set has draws nothing and raises no error at build time. Every icon id this crate's code + /// writes as a literal or a `const`, and every icon panel's and dock tab's icon, resolves in the catalog or the + /// app's set. Other ids built in match arms and tuple tables are not scanned. + #[test] + fn every_icon_id_literal_and_panel_icon_resolves() { + register_app_icons(&APP_ICONS); + let resolves = |id: &str| has_icon(&IconId::from(std::borrow::Cow::Owned(id.to_owned()))); + let (mut seen, mut unknown) = (0, Vec::new()); + let mut stack = vec![std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("src")]; + while let Some(dir) = stack.pop() { + let entries = std::fs::read_dir(&dir).unwrap_or_else(|e| panic!("{}: {e}", dir.display())); + for entry in entries { + let path = entry.unwrap_or_else(|e| panic!("{}: {e}", dir.display())).path(); + let name = path.file_name().and_then(|n| n.to_str()).unwrap_or(""); + if path.is_dir() { + if name != "tests" { + stack.push(path); + } + continue; + } + if !name.ends_with(".rs") || name.starts_with("tests") { + continue; + } + let text = std::fs::read_to_string(&path).unwrap_or_else(|e| panic!("{}: {e}", path.display())); + // Code up to the test module: a test harness's `icon("..")` names a panel, not an icon. + let code = text.find("#[cfg(test)]\nmod ").map_or(text.as_str(), |at| &text[..at]); + for (number, line) in code.lines().enumerate().filter(|(_, l)| !l.trim_start().starts_with("//")) { + let literal = |form: &&str| { + line.match_indices(*form).filter_map(|(at, form)| line[at + form.len()..].split('"').next()).collect::>() + }; + for id in FORMS.iter().flat_map(literal).chain(const_icon(line, code)) { + seen += 1; + if !resolves(id) { + unknown.push(format!("{}:{}: {id:?}", path.display(), number + 1)); + } + } + } + } + } + assert!(seen > 50, "the source scan found only {seen} icon ids"); + let tabs = crate::state::DockTab::ALL.map(crate::state::DockTab::info); + for (panel, _, icon) in crate::state::ICON_PANELS.iter().chain(tabs.iter()) { + if !resolves(icon) { + unknown.push(format!("panel {panel}: {icon:?}")); + } + } + assert!(unknown.is_empty(), "icon ids that no set has: {unknown:#?}"); + } + /// Appearance (effects) and Pathfinder both lived in the icon column; they used the same /// overlapping-squares motif (storytold/vectorcraft#2681). #[test]