From 3f74e38feaf9149fe0bbd572bc486ec4a61b4ae3 Mon Sep 17 00:00:00 2001 From: skylar taylor-barrick Date: Thu, 22 Oct 2026 13:10:20 -0600 Subject: [PATCH] #871: test that the Artboard tool names its active artboard once With the Artboard tool the active artboard's name was drawn twice: by the canvas, as for every artboard, and by the tool, a little higher. The test draws a frame with two artboards and checks that each name is painted once and that the active artboard's sits where the other's does. It fails without the canvas skipping the tool-labelled artboard (two labels for the active one) and without the tool's label position (8 points to the right and 11 higher than the other name). --- crates/ui-egui/src/canvas.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index e943a0524..7fcbcd742 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -4132,6 +4132,37 @@ mod tests { assert_eq!(edges(&mut app), active(2), "Artboard 3 is the active one of the two selected"); } + // Regression test for #824: with the Artboard tool, the active artboard's name was drawn twice, + // once by the canvas as for every artboard and once, a little higher and in blue, by the tool. + // Now each artboard is named once, and the active one's name sits where the others' do. + #[test] + fn the_artboard_tool_names_its_active_artboard_once() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.session.execute("file.new", &json!({"width": 200, "height": 100, "artboards": 2})).unwrap(); + app.select_tool("artboard"); + let ctx = egui::Context::default(); + frame(&mut app, &ctx, vec![]); + let drawn = shapes(&mut app, &ctx); + let xf = Xf::new(app.canvas_rect.unwrap(), app.view().unwrap()); + // Each name drawn: how far its left edge is right of the artboard's corner, and its bottom above it. + let named = |name: &str, board: usize| -> Vec<(f32, f32)> { + let r = app.session.active().unwrap().doc.artboards[board].rect; + let corner = xf.to_screen(Point::new(r.x0, r.y0)); + drawn + .iter() + .filter_map(|s| match s { + Shape::Text(t) if t.galley.text() == name => Some((t.pos.x - corner.x, corner.y - (t.pos.y + t.galley.size().y))), + _ => None, + }) + .collect() + }; + let (active, other) = (named("01 - Artboard 1", 0), named("02 - Artboard 2", 1)); + assert_eq!(other.len(), 1, "the other artboard is named once: {other:?}"); + assert_eq!(active.len(), 1, "the active artboard is named once: {active:?}"); + assert!((active[0].0 - other[0].0).abs() < 0.6, "flush with the artboard's left edge like the other name: {active:?} vs {other:?}"); + assert!((active[0].1 - other[0].1).abs() < 2.0, "on the artboard's top edge like the other name: {active:?} vs {other:?}"); + } + /// Enable Touch Gestures (#585): a two-finger tap undoes and a three-finger one redoes, and the /// first finger's press (the pointer egui makes of it) draws nothing. Off, a tap does nothing. #[test]