diff --git a/assets/icons/dc-free-distort.svg b/assets/icons/dc-free-distort.svg index 9013cf97ae..3a6ea4451d 100644 --- a/assets/icons/dc-free-distort.svg +++ b/assets/icons/dc-free-distort.svg @@ -1,4 +1,4 @@ - + diff --git a/crates/ui-egui/src/addons/shapes.rs b/crates/ui-egui/src/addons/shapes.rs index e5fde5725e..65fed545ca 100644 --- a/crates/ui-egui/src/addons/shapes.rs +++ b/crates/ui-egui/src/addons/shapes.rs @@ -709,7 +709,7 @@ mod cancel_tests { #[cfg(test)] mod tests { use craft::behavior::IconId; - use craft::ui::primitives::{has_icon, register_app_icons}; + use craft::ui::primitives::has_icon; use super::icon_for_shape; @@ -717,7 +717,7 @@ mod tests { /// would show the placeholder instead of the toolbar's icon. #[test] fn every_shape_button_shows_its_tools_icon() { - register_app_icons(&crate::icons::APP_ICONS); + crate::icons::register(); for id in ["box3d", "rectangle", "ellipse", "polygon", "star", "spiral"] { let tool = vectorcraft_tools::tool_info(id).unwrap_or_else(|| panic!("{id} is a tool")); assert_eq!(icon_for_shape(id), crate::icons::tool_icon(tool.icon), "{id}"); diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index 34bad16a79..9849b7e02e 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -67,7 +67,7 @@ impl VectorcraftApp { /// once, gives Data Recovery the host's store and makes a view for each open document. pub fn new(mut session: Session, mut services: Services) -> Self { // Every entry point (desktop, web, tests) makes the app before its first pass. - craft::ui::primitives::register_app_icons(&super::icons::APP_ICONS); + super::icons::register(); craft::ui::primitives::register_app_icons(&super::cursors::CURSOR_ICONS); // The font menus and the first file opened need the installed fonts: catalog them now. vectorcraft_text::FontDb::global().scan_in_background(); diff --git a/crates/ui-egui/src/cursors/tests.rs b/crates/ui-egui/src/cursors/tests.rs index 183bda8b47..2f6821f8a9 100644 --- a/crates/ui-egui/src/cursors/tests.rs +++ b/crates/ui-egui/src/cursors/tests.rs @@ -17,7 +17,7 @@ fn every_tool_cursors_hotspot_is_on_its_glyph() { use craft::ui::primitives::{painted_image, register_app_icons}; use craft::ui::runtime::env::Env; use craft::ui::style::rgba_color; - register_app_icons(&crate::icons::APP_ICONS); + crate::icons::register(); register_app_icons(&CURSOR_ICONS); let mut missed = Vec::new(); crate::testing::ui_context() diff --git a/crates/ui-egui/src/icon_data.rs b/crates/ui-egui/src/icon_data.rs index 96719fa0c9..eb2a544af8 100644 --- a/crates/ui-egui/src/icon_data.rs +++ b/crates/ui-egui/src/icon_data.rs @@ -4,31 +4,8 @@ /// The Selection and Direct Selection arrows' fill, painted black or white under their outline. pub const DC_ARROW_FILL: &[u8] = include_bytes!("../../../assets/icons/dc-arrow-fill.svg"); +/// VectorCraft's own `dc-*` icons, drawn with 1.5-unit strokes in a 24-unit view box. pub static ICONS: &[(&str, &[u8])] = &[ - ("align-center-horizontal", include_bytes!("../../../assets/icons/align-center-horizontal.svg")), - ("align-center-vertical", include_bytes!("../../../assets/icons/align-center-vertical.svg")), - ("align-end-horizontal", include_bytes!("../../../assets/icons/align-end-horizontal.svg")), - ("align-end-vertical", include_bytes!("../../../assets/icons/align-end-vertical.svg")), - ("align-horizontal-justify-center", include_bytes!("../../../assets/icons/align-horizontal-justify-center.svg")), - ("align-horizontal-justify-end", include_bytes!("../../../assets/icons/align-horizontal-justify-end.svg")), - ("align-horizontal-justify-start", include_bytes!("../../../assets/icons/align-horizontal-justify-start.svg")), - ("align-start-horizontal", include_bytes!("../../../assets/icons/align-start-horizontal.svg")), - ("align-start-vertical", include_bytes!("../../../assets/icons/align-start-vertical.svg")), - ("align-vertical-justify-center", include_bytes!("../../../assets/icons/align-vertical-justify-center.svg")), - ("align-vertical-justify-end", include_bytes!("../../../assets/icons/align-vertical-justify-end.svg")), - ("align-vertical-justify-start", include_bytes!("../../../assets/icons/align-vertical-justify-start.svg")), - ("arrow-left-right", include_bytes!("../../../assets/icons/arrow-left-right.svg")), - ("arrow-up-down", include_bytes!("../../../assets/icons/arrow-up-down.svg")), - ("chart-column", include_bytes!("../../../assets/icons/chart-column.svg")), - ("chevron-down", include_bytes!("../../../assets/icons/chevron-down.svg")), - ("chevron-left", include_bytes!("../../../assets/icons/chevron-left.svg")), - ("chevron-right", include_bytes!("../../../assets/icons/chevron-right.svg")), - ("chevrons-left", include_bytes!("../../../assets/icons/chevrons-left.svg")), - ("chevrons-right", include_bytes!("../../../assets/icons/chevrons-right.svg")), - // PLAN: circle-off.svg is plugins-w11's file; the row waits for it. - ("circle-off", include_bytes!("../../../assets/icons/circle-off.svg")), - ("clipboard-paste", include_bytes!("../../../assets/icons/clipboard-paste.svg")), - ("combine", include_bytes!("../../../assets/icons/combine.svg")), ("dc-actions", include_bytes!("../../../assets/icons/dc-actions.svg")), ("dc-al-bottom", include_bytes!("../../../assets/icons/dc-al-bottom.svg")), ("dc-al-center", include_bytes!("../../../assets/icons/dc-al-center.svg")), @@ -244,6 +221,34 @@ pub static ICONS: &[(&str, &[u8])] = &[ ("dc-wrinkle", include_bytes!("../../../assets/icons/dc-wrinkle.svg")), ("dc-zoom-large", include_bytes!("../../../assets/icons/dc-zoom-large.svg")), ("dc-zoom-small", include_bytes!("../../../assets/icons/dc-zoom-small.svg")), +]; + +/// Lucide icons the built-in catalog lacks, drawn with Lucide's 2-unit strokes in a 24-unit view box. +pub static LUCIDE_ICONS: &[(&str, &[u8])] = &[ + ("align-center-horizontal", include_bytes!("../../../assets/icons/align-center-horizontal.svg")), + ("align-center-vertical", include_bytes!("../../../assets/icons/align-center-vertical.svg")), + ("align-end-horizontal", include_bytes!("../../../assets/icons/align-end-horizontal.svg")), + ("align-end-vertical", include_bytes!("../../../assets/icons/align-end-vertical.svg")), + ("align-horizontal-justify-center", include_bytes!("../../../assets/icons/align-horizontal-justify-center.svg")), + ("align-horizontal-justify-end", include_bytes!("../../../assets/icons/align-horizontal-justify-end.svg")), + ("align-horizontal-justify-start", include_bytes!("../../../assets/icons/align-horizontal-justify-start.svg")), + ("align-start-horizontal", include_bytes!("../../../assets/icons/align-start-horizontal.svg")), + ("align-start-vertical", include_bytes!("../../../assets/icons/align-start-vertical.svg")), + ("align-vertical-justify-center", include_bytes!("../../../assets/icons/align-vertical-justify-center.svg")), + ("align-vertical-justify-end", include_bytes!("../../../assets/icons/align-vertical-justify-end.svg")), + ("align-vertical-justify-start", include_bytes!("../../../assets/icons/align-vertical-justify-start.svg")), + ("arrow-left-right", include_bytes!("../../../assets/icons/arrow-left-right.svg")), + ("arrow-up-down", include_bytes!("../../../assets/icons/arrow-up-down.svg")), + ("chart-column", include_bytes!("../../../assets/icons/chart-column.svg")), + ("chevron-down", include_bytes!("../../../assets/icons/chevron-down.svg")), + ("chevron-left", include_bytes!("../../../assets/icons/chevron-left.svg")), + ("chevron-right", include_bytes!("../../../assets/icons/chevron-right.svg")), + ("chevrons-left", include_bytes!("../../../assets/icons/chevrons-left.svg")), + ("chevrons-right", include_bytes!("../../../assets/icons/chevrons-right.svg")), + // PLAN: circle-off.svg is plugins-w11's file; the row waits for it. + ("circle-off", include_bytes!("../../../assets/icons/circle-off.svg")), + ("clipboard-paste", include_bytes!("../../../assets/icons/clipboard-paste.svg")), + ("combine", include_bytes!("../../../assets/icons/combine.svg")), ("ellipsis", include_bytes!("../../../assets/icons/ellipsis.svg")), ("eye-off", include_bytes!("../../../assets/icons/eye-off.svg")), ("file-plus", include_bytes!("../../../assets/icons/file-plus.svg")), diff --git a/crates/ui-egui/src/icons.rs b/crates/ui-egui/src/icons.rs index 30b6edfb49..a544de7e90 100644 --- a/crates/ui-egui/src/icons.rs +++ b/crates/ui-egui/src/icons.rs @@ -2,14 +2,24 @@ use craft::ui::primitives::{AppIcons, icon_names}; -use crate::icon_data::{DC_ARROW_FILL, ICONS}; +use crate::icon_data::{DC_ARROW_FILL, ICONS, LUCIDE_ICONS}; /// The fills of the Selection and Direct Selection arrows: black and white whatever the theme, as users /// know them, under an outline in the theme's colour. const FILLS: &[(&str, &[u8], [u8; 4])] = &[("dc-selection", DC_ARROW_FILL, [0, 0, 0, 255]), ("dc-direct", DC_ARROW_FILL, [255, 255, 255, 255])]; -/// The app's icons, for `register_app_icons`. -pub static APP_ICONS: AppIcons = AppIcons::new("vectorcraft", Some(1.6), ICONS).with_fills(FILLS); +/// The app's own icons, for `register_app_icons`. The stroke width is the documents' own, so the framework redraws +/// their strokes at the width it draws the catalog's. +pub static APP_ICONS: AppIcons = AppIcons::new("vectorcraft", Some(1.5), ICONS).with_fills(FILLS); + +/// The Lucide icons the catalog lacks, with Lucide's own stroke width. +pub static LUCIDE_APP_ICONS: AppIcons = AppIcons::new("vectorcraft-lucide", Some(2.0), LUCIDE_ICONS); + +/// Registers both of the app's icon sets beside the framework's catalog. +pub fn register() { + craft::ui::primitives::register_app_icons(&APP_ICONS); + craft::ui::primitives::register_app_icons(&LUCIDE_APP_ICONS); +} /// Map tool-catalogue icon names to the names of icons that resolve. pub fn tool_icon(name: &str) -> &'static str { @@ -114,23 +124,63 @@ pub fn tool_icon(name: &str) -> &'static str { "tool-print-tiling" => "dc-print-tiling", "tool-zoom" => "zoom_in", // A name that is already an icon maps to itself, as the `'static` name of the set that has it. - other => icon_names().iter().copied().chain(APP_ICONS.icons.iter().map(|(n, _)| *n)).find(|n| *n == other).unwrap_or("rect_dashed"), + other => icon_names() + .iter() + .copied() + .chain(APP_ICONS.icons.iter().chain(LUCIDE_APP_ICONS.icons).map(|(n, _)| *n)) + .find(|n| *n == other) + .unwrap_or("rect_dashed"), } } #[cfg(test)] mod tests { - use craft::ui::primitives::{has_icon, register_app_icons}; + use craft::ui::primitives::has_icon; // PLAN: assumed the `craft` facade is a dependency of vectorcraft-ui-egui (Cargo.toml is not in this set's files; craft-ui does not re-export IconId) use craft::behavior::IconId; use super::*; fn resolves(name: &'static str) -> bool { - register_app_icons(&APP_ICONS); + register(); has_icon(&IconId::new(name)) } + /// The SVG document of the app icon `name`, from either set. + fn app_svg(name: &str) -> String { + let (_, bytes) = ICONS.iter().chain(LUCIDE_ICONS).find(|(n, _)| *n == name).unwrap_or_else(|| panic!("{name} isn't an app icon")); + String::from_utf8_lossy(bytes).into_owned() + } + + /// The `stroke-width` the document's root `` element sets, the width of every stroke that sets none of its + /// own; `None` for a document drawn with fills. + fn root_stroke_width(svg: &str) -> Option { + let root = svg.split("').next()?; + Some(root.split("stroke-width=\"").nth(1)?.split('"').next()?.parse().unwrap_or(f32::NAN)) + } + + // Regression test: the tool rail's icons drew uneven outlines. The app set declared a 1.6-unit stroke while its own icons drew 1.5 and + // its Lucide copies drew 2, so the framework drew them 6% thinner and 25% heavier than the catalog's icons. + /// The framework scales every stroke in a set by the drawn width over the set's declared width, so an icon's + /// outline matches the catalog's only when its root stroke width equals its set's declared width. Details with + /// a width of their own keep their ratio to the outline. + #[test] + fn every_app_icon_draws_its_outline_at_the_catalog_width() { + let mut off = Vec::new(); + for set in [&APP_ICONS, &LUCIDE_APP_ICONS] { + let declared = set.stroke_width.unwrap_or_else(|| panic!("{} declares its stroke width", set.name)); + for (name, bytes) in set.icons { + let Some(width) = root_stroke_width(&String::from_utf8_lossy(bytes)) else { continue }; + // The outline's drawn width relative to the catalog's. + let relative = width / declared; + if !(0.99..=1.01).contains(&relative) { + off.push(format!("{name} in {}: {width} draws at {relative:.3} of the catalog width", set.name)); + } + } + } + assert!(off.is_empty(), "app icons whose outlines do not draw at the catalog width: {off:#?}"); + } + /// 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 = \""]; @@ -153,7 +203,7 @@ mod tests { /// 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); + register(); 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")]; @@ -212,10 +262,7 @@ mod tests { // as opaque as the line, so the line vanished where it crossed the bar. #[test] fn the_cap_icons_mark_the_path_end_in_one_place_over_a_lighter_stroke() { - let svg = |name: &str| { - let (_, bytes) = crate::icon_data::ICONS.iter().find(|(n, _)| *n == name).unwrap_or_else(|| panic!("{name} isn't an icon")); - String::from_utf8_lossy(bytes).into_owned() - }; + let svg = app_svg; // The end-of-path line is the icon's last shape, a vertical line `M{x} …V…`. let end_line = |icon: &str| -> String { let last = icon.rsplit(">(); let pen = shapes(&svg("tool-pen")); @@ -331,7 +373,7 @@ mod tests { assert!(resolves(name), "{} maps to {name}, which no icon set has", tool.icon); } let catalog = icon_names(); - for (name, _) in APP_ICONS.icons { + for (name, _) in APP_ICONS.icons.iter().chain(LUCIDE_APP_ICONS.icons) { assert!(!catalog.contains(name), "{name} is in the catalog: the app's copy is refused"); } } diff --git a/crates/ui-egui/src/panels/layers/tests.rs b/crates/ui-egui/src/panels/layers/tests.rs index 6155d4f6e7..ef54366ba5 100644 --- a/crates/ui-egui/src/panels/layers/tests.rs +++ b/crates/ui-egui/src/panels/layers/tests.rs @@ -341,7 +341,7 @@ fn rows_list_by_depth_and_ruler_guide_nodes_get_no_object_row() { /// guide kind's ruler, and both glyphs are in the app's icon set. #[test] fn horizontal_and_vertical_guide_rows_show_their_own_drawn_glyphs() { - use craft::ui::primitives::{has_icon, register_app_icons}; + use craft::ui::primitives::has_icon; let mut app = VectorcraftApp::new(Session::new(), Default::default()); app.session.execute("file.new", &json!({"width": 100, "height": 100})).unwrap(); @@ -355,7 +355,7 @@ fn horizontal_and_vertical_guide_rows_show_their_own_drawn_glyphs() { }; let (across, down) = (icon_of(false), icon_of(true)); assert_ne!(across, down, "the two kinds of guide rows look alike"); - register_app_icons(&crate::icons::APP_ICONS); + crate::icons::register(); for icon in [&across, &down] { assert!(has_icon(icon), "{icon:?} is in no icon set, so the row draws nothing"); } diff --git a/crates/ui-egui/src/tests/cut.rs b/crates/ui-egui/src/tests/cut.rs index 4732a6347b..995f87564a 100644 --- a/crates/ui-egui/src/tests/cut.rs +++ b/crates/ui-egui/src/tests/cut.rs @@ -11,7 +11,7 @@ fn the_cut_tools_have_their_own_icons_and_toolbar_slot() { let info = vectorcraft_tools::tool_info(tool).unwrap(); assert_eq!(icons::tool_icon(info.icon), icon); // The app registers its icons at start; a test run alone in its process must too. - craft::ui::primitives::register_app_icons(&icons::APP_ICONS); + icons::register(); assert!(craft::ui::primitives::has_icon(&IconId::new(icon)), "{icon}"); assert!(crate::toolbar::BASIC.iter().flat_map(|(_, slots)| slots.iter()).any(|s| s.contains(&tool) && s.contains(&"knife"))); }