diff --git a/assets/icons/dc-al-bottom.svg b/assets/icons/dc-al-bottom.svg index 73ca1c4b02..45b61c2338 100644 --- a/assets/icons/dc-al-bottom.svg +++ b/assets/icons/dc-al-bottom.svg @@ -1 +1 @@ - + diff --git a/assets/icons/dc-al-center.svg b/assets/icons/dc-al-center.svg index 2e8e9e978f..9b1d61bd3f 100644 --- a/assets/icons/dc-al-center.svg +++ b/assets/icons/dc-al-center.svg @@ -1 +1 @@ - + diff --git a/assets/icons/dc-al-hcenter.svg b/assets/icons/dc-al-hcenter.svg index ae7c705f0a..f5561a859e 100644 --- a/assets/icons/dc-al-hcenter.svg +++ b/assets/icons/dc-al-hcenter.svg @@ -1 +1 @@ - + diff --git a/assets/icons/dc-al-left.svg b/assets/icons/dc-al-left.svg index e8088d1386..0d0c93d70f 100644 --- a/assets/icons/dc-al-left.svg +++ b/assets/icons/dc-al-left.svg @@ -1 +1 @@ - + diff --git a/assets/icons/dc-al-right.svg b/assets/icons/dc-al-right.svg index 6f5407ccf0..c3b38820a8 100644 --- a/assets/icons/dc-al-right.svg +++ b/assets/icons/dc-al-right.svg @@ -1 +1 @@ - + diff --git a/assets/icons/dc-al-top.svg b/assets/icons/dc-al-top.svg index 9a32bc30cf..1ba453a482 100644 --- a/assets/icons/dc-al-top.svg +++ b/assets/icons/dc-al-top.svg @@ -1 +1 @@ - + diff --git a/assets/icons/dc-al-vcenter.svg b/assets/icons/dc-al-vcenter.svg index 29e42fb45c..cc900e5bc1 100644 --- a/assets/icons/dc-al-vcenter.svg +++ b/assets/icons/dc-al-vcenter.svg @@ -1 +1 @@ - + diff --git a/assets/icons/dc-alignto-artboard.svg b/assets/icons/dc-alignto-artboard.svg index a04ffb9970..9e539b8050 100644 --- a/assets/icons/dc-alignto-artboard.svg +++ b/assets/icons/dc-alignto-artboard.svg @@ -1 +1 @@ - + diff --git a/assets/icons/dc-alignto-key.svg b/assets/icons/dc-alignto-key.svg index 5dd9f88b88..ee6c886f3a 100644 --- a/assets/icons/dc-alignto-key.svg +++ b/assets/icons/dc-alignto-key.svg @@ -1 +1 @@ - + diff --git a/assets/icons/dc-alignto-selection.svg b/assets/icons/dc-alignto-selection.svg index d145c91c0f..22767bb02d 100644 --- a/assets/icons/dc-alignto-selection.svg +++ b/assets/icons/dc-alignto-selection.svg @@ -1 +1 @@ - + diff --git a/assets/icons/dc-dist-bottom.svg b/assets/icons/dc-dist-bottom.svg index 06f9e16c0a..cdd41fbbc5 100644 --- a/assets/icons/dc-dist-bottom.svg +++ b/assets/icons/dc-dist-bottom.svg @@ -1 +1 @@ - + diff --git a/assets/icons/dc-dist-hcenter.svg b/assets/icons/dc-dist-hcenter.svg index 30cabd1ad7..83ebc04416 100644 --- a/assets/icons/dc-dist-hcenter.svg +++ b/assets/icons/dc-dist-hcenter.svg @@ -1 +1 @@ - + diff --git a/assets/icons/dc-dist-hspace.svg b/assets/icons/dc-dist-hspace.svg index bc7a749459..b26492efc5 100644 --- a/assets/icons/dc-dist-hspace.svg +++ b/assets/icons/dc-dist-hspace.svg @@ -1 +1 @@ - + diff --git a/assets/icons/dc-dist-left.svg b/assets/icons/dc-dist-left.svg index efc53ab8e6..2b381ea7a9 100644 --- a/assets/icons/dc-dist-left.svg +++ b/assets/icons/dc-dist-left.svg @@ -1 +1 @@ - + diff --git a/assets/icons/dc-dist-right.svg b/assets/icons/dc-dist-right.svg index 1dc5566767..9461ef385e 100644 --- a/assets/icons/dc-dist-right.svg +++ b/assets/icons/dc-dist-right.svg @@ -1 +1 @@ - + diff --git a/assets/icons/dc-dist-top.svg b/assets/icons/dc-dist-top.svg index f0560524ed..8e070c2028 100644 --- a/assets/icons/dc-dist-top.svg +++ b/assets/icons/dc-dist-top.svg @@ -1 +1 @@ - + diff --git a/assets/icons/dc-dist-vcenter.svg b/assets/icons/dc-dist-vcenter.svg index 4b0b5e76a1..bb5266c039 100644 --- a/assets/icons/dc-dist-vcenter.svg +++ b/assets/icons/dc-dist-vcenter.svg @@ -1 +1 @@ - + diff --git a/assets/icons/dc-dist-vspace.svg b/assets/icons/dc-dist-vspace.svg index 8a2429cb98..0adda19d8a 100644 --- a/assets/icons/dc-dist-vspace.svg +++ b/assets/icons/dc-dist-vspace.svg @@ -1 +1 @@ - + diff --git a/assets/icons/dc-pf-crop.svg b/assets/icons/dc-pf-crop.svg index 70f9dfc9a2..ba8af6315e 100644 --- a/assets/icons/dc-pf-crop.svg +++ b/assets/icons/dc-pf-crop.svg @@ -1 +1 @@ - + diff --git a/assets/icons/dc-pf-divide.svg b/assets/icons/dc-pf-divide.svg index 9c4299adff..e1719c8226 100644 --- a/assets/icons/dc-pf-divide.svg +++ b/assets/icons/dc-pf-divide.svg @@ -1 +1 @@ - + diff --git a/assets/icons/dc-pf-exclude.svg b/assets/icons/dc-pf-exclude.svg index c535d82d9c..8e6a236f0a 100644 --- a/assets/icons/dc-pf-exclude.svg +++ b/assets/icons/dc-pf-exclude.svg @@ -1 +1 @@ - + diff --git a/assets/icons/dc-pf-intersect.svg b/assets/icons/dc-pf-intersect.svg index fec68213c1..f186706ad9 100644 --- a/assets/icons/dc-pf-intersect.svg +++ b/assets/icons/dc-pf-intersect.svg @@ -1 +1 @@ - + diff --git a/assets/icons/dc-pf-merge.svg b/assets/icons/dc-pf-merge.svg index bbf2641547..adf641c87f 100644 --- a/assets/icons/dc-pf-merge.svg +++ b/assets/icons/dc-pf-merge.svg @@ -1 +1 @@ - + diff --git a/assets/icons/dc-pf-minus-back.svg b/assets/icons/dc-pf-minus-back.svg index 487a240cab..8c47aed2e1 100644 --- a/assets/icons/dc-pf-minus-back.svg +++ b/assets/icons/dc-pf-minus-back.svg @@ -1 +1 @@ - + diff --git a/assets/icons/dc-pf-minus-front.svg b/assets/icons/dc-pf-minus-front.svg index 6d077acca6..2363e726b9 100644 --- a/assets/icons/dc-pf-minus-front.svg +++ b/assets/icons/dc-pf-minus-front.svg @@ -1 +1 @@ - + diff --git a/assets/icons/dc-pf-outline.svg b/assets/icons/dc-pf-outline.svg index cd0b691f5b..9fc55c5022 100644 --- a/assets/icons/dc-pf-outline.svg +++ b/assets/icons/dc-pf-outline.svg @@ -1 +1 @@ - + diff --git a/assets/icons/dc-pf-trim.svg b/assets/icons/dc-pf-trim.svg index 8b448fc44c..714e6cdaef 100644 --- a/assets/icons/dc-pf-trim.svg +++ b/assets/icons/dc-pf-trim.svg @@ -1 +1 @@ - + diff --git a/assets/icons/dc-pf-unite.svg b/assets/icons/dc-pf-unite.svg index a3eefb76a1..89a5dbdc87 100644 --- a/assets/icons/dc-pf-unite.svg +++ b/assets/icons/dc-pf-unite.svg @@ -1 +1 @@ - + diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs index d9edd18bb2..1071d14108 100644 --- a/crates/ui-egui/src/panels.rs +++ b/crates/ui-egui/src/panels.rs @@ -1007,6 +1007,8 @@ mod tests_effectedit; #[cfg(test)] mod tests_freeform; #[cfg(test)] +mod tests_icon_buttons; +#[cfg(test)] mod tests_links; #[cfg(test)] mod tests_maskview; diff --git a/crates/ui-egui/src/panels/tests_icon_buttons.rs b/crates/ui-egui/src/panels/tests_icon_buttons.rs new file mode 100644 index 0000000000..b7a1ee607e --- /dev/null +++ b/crates/ui-egui/src/panels/tests_icon_buttons.rs @@ -0,0 +1,61 @@ +//! Headless frames of the Align and Pathfinder panels' icon buttons: each icon fills its glyph square as the app's +//! Lucide icons do. + +use egui::{ImageData, Rect, Shape, TextureId}; +use serde_json::json; + +use super::tests_appearance::{app_with_rect, run}; +use super::*; +use crate::tests::panel_harness::Panel; + +/// The share of its square a Lucide icon's art may span: the Lucide grid keeps 2 of its 24 units clear on each side. +const LUCIDE_ART: f32 = 20.0 / 24.0; + +/// The longer side of the inked pixels of the icon drawn inside `rect`, as a share of the icon's image side. +fn ink_share(shapes: &[Shape], images: &[(TextureId, ImageData)], rect: Rect) -> f32 { + let mut shares = shapes.iter().filter_map(|shape| match shape { + Shape::Mesh(mesh) if mesh.texture_id != TextureId::default() && rect.contains_rect(mesh.calc_bounds()) => { + let image = images.iter().find(|(id, _)| *id == mesh.texture_id).map(|(_, image)| image); + let Some(ImageData::Color(image)) = image else { panic!("no image for the icon's texture in this frame") }; + let [w, h] = image.size; + let inked = |x: usize, y: usize| image.pixels[y * w + x].a() > 0; + let cols: Vec = (0..w).filter(|&x| (0..h).any(|y| inked(x, y))).collect(); + let rows: Vec = (0..h).filter(|&y| (0..w).any(|x| inked(x, y))).collect(); + let span = |v: &[usize]| v.first().zip(v.last()).map_or(0, |(a, b)| b - a + 1); + Some(span(&cols).max(span(&rows)) as f32 / w.max(h) as f32) + } + _ => None, + }); + shares.next().unwrap_or_else(|| panic!("no icon drawn in {rect:?}")) +} + +/// Two selected rectangles, so every button is on. +fn two_rects() -> VectorcraftApp { + let mut app = app_with_rect(); + run(&mut app, "shape.rectangle", json!({"x": 50, "y": 50, "width": 100, "height": 100})); + run(&mut app, "select.all", json!({})); + app +} + +fn assert_full_size(draw: fn(&mut VectorcraftApp, &mut egui::Ui), names: &[&str]) { + let mut panel = Panel::new(two_rects(), draw); + // A new pixel density draws every icon again, so the frame carries their images. + let (shapes, images) = panel.paint_at(2.0); + for name in names { + let share = ink_share(&shapes, &images, panel.rect(name)); + assert!(share >= LUCIDE_ART, "{name}: the icon spans {share} of its square, less than a Lucide icon's {LUCIDE_ART}"); + } +} + +#[test] +fn the_align_panel_icons_fill_their_square() { + let mut names: Vec<&str> = align::ALIGN.iter().chain(&align::DISTRIBUTE).map(|r| r.1).collect(); + names.extend(["Vertical Distribute Space", "Horizontal Distribute Space"]); + assert_full_size(align::show, &names); +} + +#[test] +fn the_pathfinder_panel_icons_fill_their_square() { + let names: Vec<&str> = pathfinder::SHAPE_MODES.iter().chain(&pathfinder::PATHFINDERS).map(|r| r.1).collect(); + assert_full_size(pathfinder::show, &names); +} diff --git a/crates/ui-egui/src/tests/panel_harness.rs b/crates/ui-egui/src/tests/panel_harness.rs index 574da463f5..c48710edc3 100644 --- a/crates/ui-egui/src/tests/panel_harness.rs +++ b/crates/ui-egui/src/tests/panel_harness.rs @@ -291,6 +291,27 @@ impl Panel { self.look(name).rect } + /// One frame with no input at `pixels_per_point`; the shapes it painted, nested shapes flattened, and the images of + /// the textures it made. + pub(crate) fn paint_at(&mut self, pixels_per_point: f32) -> (Vec, Vec<(egui::TextureId, egui::ImageData)>) { + self.fixture.pixels_per_point(pixels_per_point).record_paint(); + self.take_input(); + self.fixture.frame(Vec::new()); + let Some(mut paint) = self.fixture.take_paint() else { return (Vec::new(), Vec::new()) }; + let images = paint.textures_delta.set.iter().flat_map(|(id, deltas)| deltas.iter().map(move |delta| (*id, delta.image.clone()))).collect(); + // The test reads the images; no renderer applies them. + paint.textures_delta.clear(); + let mut shapes = Vec::new(); + let mut open: Vec = paint.shapes.into_iter().map(|clipped| clipped.shape).collect(); + while let Some(shape) = open.pop() { + match shape { + egui::Shape::Vec(nested) => open.extend(nested), + shape => shapes.push(shape), + } + } + (shapes, images) + } + /// Where the control of `role` named `name` is, where nodes of other roles share the name. pub(crate) fn rect_role(&self, name: &str, role: craft::ui::contract::Role) -> Rect { self.look_role(name, role).rect