From fa1c0a8dc4d84ffa1050996e54cf88589f96ce29 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 29 Nov 2026 06:01:24 -0800 Subject: [PATCH] Tests: read retained paint chunks in every ui-egui shape walk The pinned egui replays a region that did not change as one Shape::PaintChunk of clipped shapes. Test helpers that walked out.shapes by hand stopped at the chunk, so text, meshes, rects and lines painted inside it were missed. - Add painted_shapes and flat_painted_shapes next to text_shapes in tests/labels.rs. They open Shape::Vec and Shape::PaintChunk in paint order and compose each shape's transform and clip the same way. - Route every remaining hand-written text and shape walk in the ui-egui tests through text_shapes or these helpers, keeping each test's assertions and its first-painted or last-painted order. - panel_readout_copy: the Link Info Name check called the removed text_shape helper and did not compile; it now reads visible_paint. Format the file. --- crates/ui-egui/src/canvas/panes/tests.rs | 28 +++++----------- crates/ui-egui/src/canvas/tests.rs | 13 ++------ crates/ui-egui/src/chrome/tests.rs | 12 +------ crates/ui-egui/src/dialogs/new_document.rs | 13 +++----- crates/ui-egui/src/dialogs/tests_screens.rs | 30 +++++++---------- .../src/dialogs/tracing_presets/tests.rs | 19 ++++------- crates/ui-egui/src/doc_windows/tests.rs | 12 ++----- crates/ui-egui/src/export_progress.rs | 8 ++--- crates/ui-egui/src/menus/tests.rs | 16 +++------ crates/ui-egui/src/opening/tests.rs | 8 ++--- .../ui-egui/src/panel_docking/native_tests.rs | 13 +++----- crates/ui-egui/src/panel_docking/tests.rs | 9 +++-- crates/ui-egui/src/panels/tests_appearance.rs | 16 +++------ .../src/panels/tests_brush_libraries.rs | 11 +------ .../src/panels/tests_style_libraries.rs | 11 +------ .../src/panels/tests_symbol_libraries.rs | 11 +------ crates/ui-egui/src/placing/tests.rs | 8 ++--- crates/ui-egui/src/prefs_dialog/tests.rs | 2 +- crates/ui-egui/src/tests/background.rs | 11 +------ crates/ui-egui/src/tests/dialog_layout.rs | 14 +++----- crates/ui-egui/src/tests/document_drag.rs | 13 +++----- crates/ui-egui/src/tests/labels.rs | 33 +++++++++++++++++++ crates/ui-egui/src/tests/panel_harness.rs | 10 ++---- crates/ui-egui/src/tests/picks.rs | 14 +++----- crates/ui-egui/src/tests/removeanchors.rs | 6 ++-- crates/ui-egui/src/tests/retype_runs.rs | 8 ++--- crates/ui-egui/src/tests/ruler_origin.rs | 14 +++----- crates/ui-egui/src/tests/script_run.rs | 12 ++----- crates/ui-egui/src/tests/scrub.rs | 12 +++---- crates/ui-egui/src/toolbar/tests.rs | 28 +++++----------- crates/ui-egui/tests/panel_readout_copy.rs | 22 +++++-------- 31 files changed, 147 insertions(+), 290 deletions(-) diff --git a/crates/ui-egui/src/canvas/panes/tests.rs b/crates/ui-egui/src/canvas/panes/tests.rs index 4464e67326..d5c13920ef 100644 --- a/crates/ui-egui/src/canvas/panes/tests.rs +++ b/crates/ui-egui/src/canvas/panes/tests.rs @@ -38,20 +38,12 @@ fn frame(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec /// [`frame`] on a window `size` points large. fn frame_in(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec, size: egui::Vec2) -> Vec { - fn flat(s: Shape, out: &mut Vec) { - match s { - Shape::Vec(v) => v.into_iter().for_each(|s| flat(s, out)), - s => out.push(s), - } - } let raw = egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(Pos2::ZERO, size)), max_texture_side: Some(8192), events, ..Default::default() }; let mut out = ctx.run_ui(raw, |ui| app.canvas_area(ui)); // A pane's picture is uploaded once, maybe in this frame: [`wait_ready`] finds it later. note_uploads(&mut out.textures_delta); - let mut shapes = vec![]; - out.shapes.into_iter().for_each(|c| flat(c.shape, &mut shapes)); - shapes + crate::tests_labels::flat_painted_shapes(&out.shapes) } /// A texture's picture: its pixels and size. @@ -627,15 +619,10 @@ fn art_carried_through_a_tab_drops_into_a_third_documents_pane() { // A tab's title starts with its document's name (an inactive tab shows the name alone). let names: Vec = app.session.documents().iter().map(|d| d.title()).collect(); let titles = |out: egui::FullOutput| -> Vec { - let mut t: Vec<_> = out - .shapes - .iter() - .filter_map(|s| match &s.shape { - Shape::Text(t) if names.iter().any(|n| t.galley.text().starts_with(n.as_str())) => { - Some(egui::Rect::from_min_size(t.pos, t.galley.size())) - } - _ => None, - }) + let mut t: Vec<_> = crate::tests_labels::text_shapes(&out) + .into_iter() + .filter(|(t, _)| names.iter().any(|n| t.galley.text().starts_with(n.as_str()))) + .map(|(t, transform)| transform * egui::Rect::from_min_size(t.pos, t.galley.size())) .collect(); t.sort_by(|a, b| a.left().total_cmp(&b.left())); t @@ -1002,14 +989,15 @@ fn other_panes_draw_through_their_documents_profiles() { let fills = |out: &egui::FullOutput, rgb: [u8; 3]| { fn any(s: &Shape, f: &dyn Fn(Color32) -> bool) -> bool { match s { - Shape::Vec(v) => v.iter().any(|s| any(s, f)), Shape::Path(p) => f(p.fill), Shape::Rect(r) => f(r.fill), Shape::Mesh(m) if m.texture_id == egui::TextureId::default() => m.vertices.iter().any(|v| f(v.color)), _ => false, } } - out.shapes.iter().any(|c| any(&c.shape, &|c: Color32| c.a() == 255 && near([c.r(), c.g(), c.b()], rgb))) + crate::tests_labels::painted_shapes(&out.shapes) + .into_iter() + .any(|(s, ..)| any(s, &|c: Color32| c.a() == 255 && near([c.r(), c.g(), c.b()], rgb))) }; let ctx = crate::testing::ui_context(); let raw = || egui::RawInput { diff --git a/crates/ui-egui/src/canvas/tests.rs b/crates/ui-egui/src/canvas/tests.rs index 8b7cabc0cb..ae6956a288 100644 --- a/crates/ui-egui/src/canvas/tests.rs +++ b/crates/ui-egui/src/canvas/tests.rs @@ -956,17 +956,10 @@ fn shapes(app: &mut VectorcraftApp, ctx: &egui::Context) -> Vec { shapes } -/// The shapes of a frame's output, `Shape::Vec`s flattened: the canvas's picture slot holds the art's. +/// The shapes of a frame's output, `Shape::Vec`s and retained paint chunks flattened: the canvas's +/// picture slot holds the art's. fn flat_shapes(clipped: Vec) -> Vec { - fn flat(s: Shape, out: &mut Vec) { - match s { - Shape::Vec(v) => v.into_iter().for_each(|s| flat(s, out)), - s => out.push(s), - } - } - let mut v = vec![]; - clipped.into_iter().for_each(|c| flat(c.shape, &mut v)); - v + crate::tests_labels::flat_painted_shapes(&clipped) } /// One headless canvas frame → the shapes drawn ([`flat_shapes`]) and the textures uploaded by it diff --git a/crates/ui-egui/src/chrome/tests.rs b/crates/ui-egui/src/chrome/tests.rs index 8fe7f3e43f..67cc29b63f 100644 --- a/crates/ui-egui/src/chrome/tests.rs +++ b/crates/ui-egui/src/chrome/tests.rs @@ -3292,13 +3292,6 @@ struct StyleFace { /// The Style field of the settled bar. `textures` holds the textures the frames uploaded since the fixture began /// recording; the uploads of these frames are applied to it. fn style_face(bar: &mut Shown, textures: &mut std::collections::HashMap) -> StyleFace { - fn flat(shape: egui::Shape, out: &mut Vec) { - if let egui::Shape::Vec(shapes) = shape { - shapes.into_iter().for_each(|s| flat(s, out)); - } else { - out.push(shape); - } - } let field = bar.settle().named("Graphic Styles").rect; let mut paint = bar.fixture.take_paint().expect("the fixture records what it paints"); for (id, delta) in paint.textures_delta.set.iter().flat_map(|(id, deltas)| deltas.iter().map(move |delta| (id, delta))) { @@ -3320,10 +3313,7 @@ fn style_face(bar: &mut Shown, textures: &mut std::collections::HashMap) { - match s { - egui::Shape::Text(t) => out.push((t.galley.text().to_string(), t.visual_bounding_rect().center())), - egui::Shape::Vec(v) => v.iter().for_each(|s| texts(s, out)), - _ => {} - } - } let mut app = app(); open(&mut app); let out = laid_out(&mut app); + let drawn: Vec<(String, egui::Pos2)> = crate::tests_labels::text_shapes(&out) + .into_iter() + .map(|(t, transform)| (t.galley.text().to_string(), (transform * t.visual_bounding_rect()).center())) + .collect(); let nodes = out.platform_output.accesskit_update.map(|u| u.nodes).unwrap_or_default(); let bounds = |label: &str, role: egui::accesskit::Role| { let (_, n) = nodes.iter().find(|(_, n)| n.label() == Some(label) && n.role() == role).unwrap_or_else(|| panic!("no {role:?} {label}")); @@ -1104,8 +1101,6 @@ mod tests { // Artboards follows Landscape on its line, or wraps below it when the column has no room for it. assert!(landscape.x1 <= artboards.x0 || landscape.y1 <= artboards.y0, "Landscape {landscape:?} stays clear of Artboards {artboards:?}"); let group = bounds("Orientation", egui::accesskit::Role::RadioGroup); - let mut drawn = Vec::new(); - out.shapes.iter().for_each(|s| texts(&s.shape, &mut drawn)); let inside: Vec<_> = drawn .iter() .filter(|(_, at)| (group.x0..=group.x1).contains(&f64::from(at.x)) && (group.y0..=group.y1).contains(&f64::from(at.y))) diff --git a/crates/ui-egui/src/dialogs/tests_screens.rs b/crates/ui-egui/src/dialogs/tests_screens.rs index b4ae88d15a..8d5ebb9789 100644 --- a/crates/ui-egui/src/dialogs/tests_screens.rs +++ b/crates/ui-egui/src/dialogs/tests_screens.rs @@ -295,18 +295,15 @@ fn checked_artboards_read_as_a_range() { /// The rect the frame `shapes` paint `texture` over; `None` when none paints it. fn painted(shapes: &[egui::epaint::ClippedShape], texture: egui::TextureId) -> Option { - fn walk(shape: &egui::Shape, texture: egui::TextureId, out: &mut Option) { - match shape { - egui::Shape::Vec(all) => all.iter().for_each(|s| walk(s, texture, out)), - egui::Shape::Mesh(mesh) if mesh.texture_id == texture => { - let at = mesh.calc_bounds(); - *out = Some(out.map_or(at, |r| r.union(at))); - } - _ => {} + let mut out: Option = None; + for (shape, transform, _) in crate::tests_labels::painted_shapes(shapes) { + if let egui::Shape::Mesh(mesh) = shape + && mesh.texture_id == texture + { + let at = transform * mesh.calc_bounds(); + out = Some(out.map_or(at, |r| r.union(at))); } } - let mut out = None; - shapes.iter().for_each(|clipped| walk(&clipped.shape, texture, &mut out)); out } @@ -943,14 +940,11 @@ fn a_preset_export_reopens_on_its_rows() { } fn screen_text_at(out: &egui::FullOutput, label: &str) -> egui::Pos2 { - fn find(shape: &egui::Shape, label: &str) -> Option { - match shape { - egui::Shape::Text(t) if t.galley.text().trim() == label => Some(t.visual_bounding_rect().center()), - egui::Shape::Vec(v) => v.iter().find_map(|s| find(s, label)), - _ => None, - } - } - out.shapes.iter().find_map(|s| find(&s.shape, label)).unwrap_or_else(|| panic!("missing {label}: {}", crate::tests_labels::shapes_text(out))) + crate::tests_labels::text_shapes(out) + .into_iter() + .find(|(t, _)| t.galley.text().trim() == label) + .map(|(t, transform)| (transform * t.visual_bounding_rect()).center()) + .unwrap_or_else(|| panic!("missing {label}: {}", crate::tests_labels::shapes_text(out))) } /// First-directory entries of the big-endian TIFF chosen below: tag, type, count, inline value. diff --git a/crates/ui-egui/src/dialogs/tracing_presets/tests.rs b/crates/ui-egui/src/dialogs/tracing_presets/tests.rs index bfb3edf947..2cecc9332e 100644 --- a/crates/ui-egui/src/dialogs/tracing_presets/tests.rs +++ b/crates/ui-egui/src/dialogs/tracing_presets/tests.rs @@ -72,16 +72,6 @@ fn frame_texts(app: &VectorcraftApp, ctx: &egui::Context) -> Vec { /// The texts the dialogs paint with where each is drawn and its font, once they have faded in. fn frame_runs(app: &VectorcraftApp, ctx: &egui::Context) -> Vec<(String, egui::Rect, Option)> { - fn walk(s: &egui::Shape, out: &mut Vec<(String, egui::Rect, Option)>) { - match s { - egui::Shape::Text(t) => { - let font = t.galley.job.sections.first().map(|section| section.format.font_id.clone()); - out.push((t.galley.text().to_string(), t.galley.rect.translate(t.pos.to_vec2()), font)); - } - egui::Shape::Vec(v) => v.iter().for_each(|s| walk(s, out)), - _ => {} - } - } let dialogs = app.dialogs().expect("a window"); let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1200.0, 1200.0)); let mut texts = vec![]; @@ -89,8 +79,13 @@ fn frame_runs(app: &VectorcraftApp, ctx: &egui::Context) -> Vec<(String, egui::R let raw = egui::RawInput { screen_rect: Some(screen), time: Some(f64::from(k) * 0.25), ..Default::default() }; let mut out = ctx.run_ui(raw, |ui| dialogs.with(|host| host.run(ui))); out.textures_delta.clear(); - texts.clear(); - out.shapes.iter().for_each(|c| walk(&c.shape, &mut texts)); + texts = crate::tests_labels::text_shapes(&out) + .into_iter() + .map(|(t, transform)| { + let font = t.galley.job.sections.first().map(|section| section.format.font_id.clone()); + (t.galley.text().to_string(), transform * t.galley.rect.translate(t.pos.to_vec2()), font) + }) + .collect(); } texts } diff --git a/crates/ui-egui/src/doc_windows/tests.rs b/crates/ui-egui/src/doc_windows/tests.rs index 5033868701..4e7905cb9f 100644 --- a/crates/ui-egui/src/doc_windows/tests.rs +++ b/crates/ui-egui/src/doc_windows/tests.rs @@ -15,18 +15,10 @@ fn app_with(n: usize) -> VectorcraftApp { /// One headless frame of the canvas panel's body (the tabs and the canvas or panes) on a /// 1200 × 800 window, then the floating document windows, which egui draws inside the window, run -/// as the hosts run a frame → the shapes it drew, `Shape::Vec`s flattened. +/// as the hosts run a frame → the shapes it drew, `Shape::Vec`s and retained paint chunks flattened. fn frame(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec) -> Vec { - fn flat(s: Shape, out: &mut Vec) { - match s { - Shape::Vec(v) => v.into_iter().for_each(|s| flat(s, out)), - s => out.push(s), - } - } let out = run_frame(app, ctx, events); - let mut shapes = vec![]; - out.shapes.into_iter().for_each(|c| flat(c.shape, &mut shapes)); - shapes + crate::tests_labels::flat_painted_shapes(&out.shapes) } /// One headless frame of the canvas panel's body and the floating document windows on a 1200 × diff --git a/crates/ui-egui/src/export_progress.rs b/crates/ui-egui/src/export_progress.rs index 8ec6e39b37..81bf88811c 100644 --- a/crates/ui-egui/src/export_progress.rs +++ b/crates/ui-egui/src/export_progress.rs @@ -132,11 +132,9 @@ mod tests { let mut out = ctx.run_ui(egui::RawInput::default(), |ui| super::show(app, ui)); out.textures_delta.clear(); let mut texts = String::new(); - for shape in out.shapes { - if let egui::epaint::Shape::Text(t) = shape.shape { - texts.push_str(t.galley.text()); - texts.push('\n'); - } + for (t, _) in crate::tests_labels::text_shapes(&out) { + texts.push_str(t.galley.text()); + texts.push('\n'); } texts } diff --git a/crates/ui-egui/src/menus/tests.rs b/crates/ui-egui/src/menus/tests.rs index 120c80aadd..b21b2e8ccf 100644 --- a/crates/ui-egui/src/menus/tests.rs +++ b/crates/ui-egui/src/menus/tests.rs @@ -288,18 +288,10 @@ fn discover_says_why_a_tool_cannot_be_marked() { } fn texts(ctx: &egui::Context, app: &mut VectorcraftApp, events: Vec) -> Vec<(String, egui::Rect)> { let out = pass(ctx, app, events); - fn collect(s: &egui::Shape, out: &mut Vec<(String, egui::Rect)>) { - match s { - egui::Shape::Text(t) => out.push((t.galley.text().to_string(), t.visual_bounding_rect())), - egui::Shape::Vec(v) => v.iter().for_each(|s| collect(s, out)), - _ => {} - } - } - let mut texts = vec![]; - for c in &out.shapes { - collect(&c.shape, &mut texts); - } - texts + crate::tests_labels::text_shapes(&out) + .into_iter() + .map(|(t, transform)| (t.galley.text().to_string(), transform * t.visual_bounding_rect())) + .collect() } fn click(ctx: &egui::Context, app: &mut VectorcraftApp, label: &str) { texts(ctx, app, vec![]); diff --git a/crates/ui-egui/src/opening/tests.rs b/crates/ui-egui/src/opening/tests.rs index 68386b4c5d..cdb55375db 100644 --- a/crates/ui-egui/src/opening/tests.rs +++ b/crates/ui-egui/src/opening/tests.rs @@ -522,11 +522,9 @@ fn progress(app: &mut VectorcraftApp, ctx: &egui::Context) -> String { let mut out = ctx.run_ui(egui::RawInput::default(), |ui| crate::export_progress::show(app, ui)); out.textures_delta.clear(); let mut texts = String::new(); - for shape in out.shapes { - if let egui::epaint::Shape::Text(t) = shape.shape { - texts.push_str(t.galley.text()); - texts.push('\n'); - } + for (t, _) in crate::tests_labels::text_shapes(&out) { + texts.push_str(t.galley.text()); + texts.push('\n'); } texts } diff --git a/crates/ui-egui/src/panel_docking/native_tests.rs b/crates/ui-egui/src/panel_docking/native_tests.rs index eebf3d6a77..3ceb28ad9f 100644 --- a/crates/ui-egui/src/panel_docking/native_tests.rs +++ b/crates/ui-egui/src/panel_docking/native_tests.rs @@ -113,15 +113,10 @@ impl Host { }; let mut full = ctx.run_ui(input, |ui| (viewport.viewport_ui_cb)(ui)); full.textures_delta.clear(); - fn texts(s: &egui::Shape, out: &mut Vec<(String, Rect)>) { - match s { - egui::Shape::Text(t) => out.push((t.galley.text().to_string(), t.visual_bounding_rect())), - egui::Shape::Vec(v) => v.iter().for_each(|s| texts(s, out)), - _ => {} - } - } - let mut shown = Vec::new(); - full.shapes.iter().for_each(|c| texts(&c.shape, &mut shown)); + let shown: Vec<(String, Rect)> = crate::tests_labels::text_shapes(&full) + .into_iter() + .map(|(t, transform)| (t.galley.text().to_string(), transform * t.visual_bounding_rect())) + .collect(); let nodes = full.platform_output.accesskit_update.as_ref().map_or_else(Vec::new, |update| { let rect = |b: egui::accesskit::Rect| Rect::from_min_max(pos2(b.x0 as f32, b.y0 as f32), pos2(b.x1 as f32, b.y1 as f32)); update.nodes.iter().filter_map(|(_, node)| Some((node.label()?.to_string(), rect(node.bounds()?)))).collect() diff --git a/crates/ui-egui/src/panel_docking/tests.rs b/crates/ui-egui/src/panel_docking/tests.rs index f132c35145..3476f5c2b0 100644 --- a/crates/ui-egui/src/panel_docking/tests.rs +++ b/crates/ui-egui/src/panel_docking/tests.rs @@ -1080,11 +1080,10 @@ fn footer_strip_shows_no_rows(h: &mut Harness, case: &str) { egui::Shape::Mesh(m) => m.vertices.iter().all(|v| v.color.a() == 0), _ => false, }; - let showing: Vec = h - .shapes - .iter() - .filter(|c| !transparent(&c.shape)) - .map(|c| (c.shape.visual_bounding_rect(), c.clip_rect)) + let showing: Vec = crate::tests_labels::painted_shapes(&h.shapes) + .into_iter() + .filter(|(shape, ..)| !transparent(shape)) + .map(|(shape, transform, clip)| (transform * shape.visual_bounding_rect(), clip)) .filter(|(bounds, clip)| { let seen = clip.intersect(*bounds).intersect(strip); bounds.height() < 60.0 && bounds.top() < footer.top() && seen.is_positive() && seen.height() > 0.5 diff --git a/crates/ui-egui/src/panels/tests_appearance.rs b/crates/ui-egui/src/panels/tests_appearance.rs index a98ddb02d3..66ca13b1ee 100644 --- a/crates/ui-egui/src/panels/tests_appearance.rs +++ b/crates/ui-egui/src/panels/tests_appearance.rs @@ -43,18 +43,10 @@ pub(super) fn frame_raw( ) -> Vec<(String, egui::Rect)> { let mut out = ctx.run_ui(raw, |ui| f(app, ui)); out.textures_delta.clear(); - fn collect(s: &egui::Shape, out: &mut Vec<(String, egui::Rect)>) { - match s { - egui::Shape::Text(t) => out.push((t.galley.text().to_string(), t.visual_bounding_rect())), - egui::Shape::Vec(v) => v.iter().for_each(|s| collect(s, out)), - _ => {} - } - } - let mut texts = vec![]; - for c in &out.shapes { - collect(&c.shape, &mut texts); - } - texts + crate::tests_labels::text_shapes(&out) + .into_iter() + .map(|(t, transform)| (t.galley.text().to_string(), transform * t.visual_bounding_rect())) + .collect() } /// Click at `pos` over three frames of `f` (hover, press, release). diff --git a/crates/ui-egui/src/panels/tests_brush_libraries.rs b/crates/ui-egui/src/panels/tests_brush_libraries.rs index de00122189..06458f8e4a 100644 --- a/crates/ui-egui/src/panels/tests_brush_libraries.rs +++ b/crates/ui-egui/src/panels/tests_brush_libraries.rs @@ -20,20 +20,11 @@ fn app() -> VectorcraftApp { /// One frame of `draw` with `events`; the texts it painted. fn frame(ctx: &egui::Context, events: Vec, time: f64, mut draw: impl FnMut(&mut egui::Ui)) -> Vec { - fn texts(s: &egui::Shape, out: &mut Vec) { - match s { - egui::Shape::Text(t) => out.push(t.galley.text().to_string()), - egui::Shape::Vec(v) => v.iter().for_each(|s| texts(s, out)), - _ => {} - } - } let screen_rect = Some(Rect::from_min_size(Pos2::ZERO, vec2(1200.0, 800.0))); let input = egui::RawInput { events, time: Some(time), screen_rect, ..Default::default() }; let mut out = ctx.run_ui(input, &mut draw); out.textures_delta.clear(); - let mut v = vec![]; - out.shapes.iter().for_each(|c| texts(&c.shape, &mut v)); - v + crate::tests_labels::text_shapes(&out).into_iter().map(|(t, _)| t.galley.text().to_string()).collect() } fn undo_len(app: &VectorcraftApp) -> usize { diff --git a/crates/ui-egui/src/panels/tests_style_libraries.rs b/crates/ui-egui/src/panels/tests_style_libraries.rs index 5f7eea0e7b..e3eee634d5 100644 --- a/crates/ui-egui/src/panels/tests_style_libraries.rs +++ b/crates/ui-egui/src/panels/tests_style_libraries.rs @@ -25,21 +25,12 @@ fn app() -> VectorcraftApp { /// One frame of `draw` with `events` and `modifiers` held; the texts it painted. fn frame(ctx: &egui::Context, events: Vec, modifiers: Modifiers, time: f64, mut draw: impl FnMut(&mut egui::Ui)) -> Vec { - fn texts(s: &egui::Shape, out: &mut Vec) { - match s { - egui::Shape::Text(t) => out.push(t.galley.text().to_string()), - egui::Shape::Vec(v) => v.iter().for_each(|s| texts(s, out)), - _ => {} - } - } let screen_rect = Some(Rect::from_min_size(Pos2::ZERO, vec2(1200.0, 800.0))); let events = std::iter::once(Event::ModifiersChanged(modifiers)).chain(events).collect(); let input = egui::RawInput { events, time: Some(time), screen_rect, ..Default::default() }; let mut out = ctx.run_ui(input, &mut draw); out.textures_delta.clear(); - let mut v = vec![]; - out.shapes.iter().for_each(|c| texts(&c.shape, &mut v)); - v + crate::tests_labels::text_shapes(&out).into_iter().map(|(t, _)| t.galley.text().to_string()).collect() } fn undo_len(app: &VectorcraftApp) -> usize { diff --git a/crates/ui-egui/src/panels/tests_symbol_libraries.rs b/crates/ui-egui/src/panels/tests_symbol_libraries.rs index c5ca39e7ec..a0f42855b1 100644 --- a/crates/ui-egui/src/panels/tests_symbol_libraries.rs +++ b/crates/ui-egui/src/panels/tests_symbol_libraries.rs @@ -21,20 +21,11 @@ fn app() -> VectorcraftApp { /// One frame of `draw` with `events`; the texts it painted. fn frame(ctx: &egui::Context, events: Vec, time: f64, mut draw: impl FnMut(&mut egui::Ui)) -> Vec { - fn texts(s: &egui::Shape, out: &mut Vec) { - match s { - egui::Shape::Text(t) => out.push(t.galley.text().to_string()), - egui::Shape::Vec(v) => v.iter().for_each(|s| texts(s, out)), - _ => {} - } - } let screen_rect = Some(Rect::from_min_size(Pos2::ZERO, vec2(1200.0, 800.0))); let input = egui::RawInput { events, time: Some(time), screen_rect, ..Default::default() }; let mut out = ctx.run_ui(input, &mut draw); out.textures_delta.clear(); - let mut v = vec![]; - out.shapes.iter().for_each(|c| texts(&c.shape, &mut v)); - v + crate::tests_labels::text_shapes(&out).into_iter().map(|(t, _)| t.galley.text().to_string()).collect() } fn undo_len(app: &VectorcraftApp) -> usize { diff --git a/crates/ui-egui/src/placing/tests.rs b/crates/ui-egui/src/placing/tests.rs index 385b1b3803..fb75d86663 100644 --- a/crates/ui-egui/src/placing/tests.rs +++ b/crates/ui-egui/src/placing/tests.rs @@ -1951,11 +1951,9 @@ fn progress(app: &mut VectorcraftApp, ctx: &egui::Context) -> String { let mut out = ctx.run_ui(egui::RawInput::default(), |ui| crate::export_progress::show(app, ui)); out.textures_delta.clear(); let mut texts = String::new(); - for shape in out.shapes { - if let egui::epaint::Shape::Text(t) = shape.shape { - texts.push_str(t.galley.text()); - texts.push('\n'); - } + for (t, _) in crate::tests_labels::text_shapes(&out) { + texts.push_str(t.galley.text()); + texts.push('\n'); } texts } diff --git a/crates/ui-egui/src/prefs_dialog/tests.rs b/crates/ui-egui/src/prefs_dialog/tests.rs index 25c2d367f1..fc61192b84 100644 --- a/crates/ui-egui/src/prefs_dialog/tests.rs +++ b/crates/ui-egui/src/prefs_dialog/tests.rs @@ -1265,7 +1265,7 @@ fn access_frame(a: &mut VectorcraftApp, events: Vec) -> (Vec<(Strin script_access::show(a, &mut w.script_access, ui); a.prefs = Some(w); }); - (crate::tests_removeanchors::shapes_text(&out.shapes.iter().map(|c| c.shape.clone()).collect::>()), out) + (crate::tests_removeanchors::shapes_text(&crate::tests_labels::flat_painted_shapes(&out.shapes)), out) } /// The texts of General › Script File Access after the frames it lays itself out in. diff --git a/crates/ui-egui/src/tests/background.rs b/crates/ui-egui/src/tests/background.rs index a314413f8b..fe90152db4 100644 --- a/crates/ui-egui/src/tests/background.rs +++ b/crates/ui-egui/src/tests/background.rs @@ -362,19 +362,10 @@ fn quitting_waits_for_background_saves() { /// The status bar's texts in one headless frame. pub(super) fn status_bar_texts(app: &mut VectorcraftApp) -> Vec { - fn texts(s: &egui::Shape, out: &mut Vec) { - match s { - egui::Shape::Text(t) => out.push(t.galley.text().to_string()), - egui::Shape::Vec(v) => v.iter().for_each(|s| texts(s, out)), - _ => {} - } - } let ctx = crate::testing::ui_context(); let mut out = ctx.run_ui(egui::RawInput::default(), |ui| crate::chrome::status_bar(app, ui)); out.textures_delta.clear(); - let mut v = vec![]; - out.shapes.iter().for_each(|c| texts(&c.shape, &mut v)); - v + crate::tests_labels::text_shapes(&out).into_iter().map(|(t, _)| t.galley.text().to_string()).collect() } #[test] diff --git a/crates/ui-egui/src/tests/dialog_layout.rs b/crates/ui-egui/src/tests/dialog_layout.rs index 0caa8e7007..121e9a0350 100644 --- a/crates/ui-egui/src/tests/dialog_layout.rs +++ b/crates/ui-egui/src/tests/dialog_layout.rs @@ -48,21 +48,15 @@ fn step(h: &mut Window) { /// The texts the window paints with `command` run, each with where it was drawn, a field label's colon left off. fn texts(command: &str, params: Value) -> Vec<(String, Rect)> { - fn collect(s: &egui::Shape, out: &mut Vec<(String, Rect)>) { - match s { - egui::Shape::Text(t) => out.push((t.galley.text().trim().trim_end_matches(':').to_owned(), t.visual_bounding_rect())), - egui::Shape::Vec(v) => v.iter().for_each(|s| collect(s, out)), - _ => {} - } - } let mut h = window(); crate::menus::invoke(h.state_mut(), command, params); for _ in 0..6 { step(&mut h); } - let mut out = vec![]; - h.output().shapes.iter().for_each(|c| collect(&c.shape, &mut out)); - out + crate::tests_labels::text_shapes(h.output()) + .into_iter() + .map(|(t, transform)| (t.galley.text().trim().trim_end_matches(':').to_owned(), transform * t.visual_bounding_rect())) + .collect() } /// Where each painted `label` was drawn, top to bottom. diff --git a/crates/ui-egui/src/tests/document_drag.rs b/crates/ui-egui/src/tests/document_drag.rs index a18cb222a5..08744212f1 100644 --- a/crates/ui-egui/src/tests/document_drag.rs +++ b/crates/ui-egui/src/tests/document_drag.rs @@ -37,15 +37,10 @@ fn frame(app: &mut VectorcraftApp, ctx: &egui::Context, time: f64, events: Vec = app.session.documents().iter().map(|d| d.title()).collect(); - let mut titles: Vec<_> = out - .shapes - .iter() - .filter_map(|s| match &s.shape { - egui::Shape::Text(t) if names.iter().any(|n| t.galley.text().starts_with(n.as_str())) => { - Some(egui::Rect::from_min_size(t.pos, t.galley.size())) - } - _ => None, - }) + let mut titles: Vec<_> = crate::tests_labels::text_shapes(&out) + .into_iter() + .filter(|(t, _)| names.iter().any(|n| t.galley.text().starts_with(n.as_str()))) + .map(|(t, transform)| transform * egui::Rect::from_min_size(t.pos, t.galley.size())) .collect(); titles.sort_by(|a, b| a.left().total_cmp(&b.left())); titles diff --git a/crates/ui-egui/src/tests/labels.rs b/crates/ui-egui/src/tests/labels.rs index ea2a08be62..e9c07abee0 100644 --- a/crates/ui-egui/src/tests/labels.rs +++ b/crates/ui-egui/src/tests/labels.rs @@ -46,6 +46,39 @@ pub(crate) fn text_shapes(out: &egui::FullOutput) -> Vec<(&egui::epaint::TextSha text } +/// Every painted shape other than `Shape::Vec` and `Shape::PaintChunk` (whose members it lists +/// instead), in paint order, with its composed window transform and the clip rectangle it is drawn in. +pub(crate) fn painted_shapes(clipped: &[egui::epaint::ClippedShape]) -> Vec<(&Shape, egui::emath::TSTransform, egui::Rect)> { + use egui::emath::TSTransform; + + fn collect<'a>(shape: &'a Shape, transform: TSTransform, clip: egui::Rect, out: &mut Vec<(&'a Shape, TSTransform, egui::Rect)>) { + match shape { + Shape::Vec(shapes) => shapes.iter().for_each(|shape| collect(shape, transform, clip, out)), + Shape::PaintChunk(shapes) => shapes.iter().for_each(|clipped| { + collect(&clipped.shape, transform * clipped.transform_after_tessellation, clip.intersect(transform * clipped.clip_rect), out); + }), + shape => out.push((shape, transform, clip)), + } + } + let mut shapes = Vec::new(); + for clipped in clipped { + collect(&clipped.shape, clipped.transform_after_tessellation, clipped.clip_rect, &mut shapes); + } + shapes +} + +/// [`painted_shapes`] as owned shapes, each moved by its transform. +pub(crate) fn flat_painted_shapes(clipped: &[egui::epaint::ClippedShape]) -> Vec { + painted_shapes(clipped) + .into_iter() + .map(|(shape, transform, _)| { + let mut shape = shape.clone(); + shape.transform(transform); + shape + }) + .collect() +} + /// Every string a frame painted, one per line. pub(crate) fn shapes_text(out: &egui::FullOutput) -> String { let mut text = String::new(); diff --git a/crates/ui-egui/src/tests/panel_harness.rs b/crates/ui-egui/src/tests/panel_harness.rs index 9252b1cec6..0c7d427a68 100644 --- a/crates/ui-egui/src/tests/panel_harness.rs +++ b/crates/ui-egui/src/tests/panel_harness.rs @@ -397,14 +397,8 @@ impl Panel { 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), - } - } + // Last painted first. + let shapes = crate::tests_labels::flat_painted_shapes(&paint.shapes).into_iter().rev().collect(); (shapes, images) } diff --git a/crates/ui-egui/src/tests/picks.rs b/crates/ui-egui/src/tests/picks.rs index 755aefbc45..851d438904 100644 --- a/crates/ui-egui/src/tests/picks.rs +++ b/crates/ui-egui/src/tests/picks.rs @@ -261,19 +261,13 @@ fn frame( events: Vec, draw: &impl Fn(&mut VectorcraftApp, &mut egui::Ui), ) -> Vec<(String, Rect)> { - fn texts(s: &egui::Shape, out: &mut Vec<(String, Rect)>) { - match s { - egui::Shape::Text(t) => out.push((t.galley.text().to_string(), t.visual_bounding_rect())), - egui::Shape::Vec(v) => v.iter().for_each(|s| texts(s, out)), - _ => {} - } - } let raw = egui::RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(SCREEN.0, SCREEN.1))), events, ..Default::default() }; // With the app's frame input, as the window's frames have it: its host carries the file service a dialog picks with. let out = crate::testing::part_frame(app, ctx, raw, |app, ui| draw(app, ui)); - let mut v = vec![]; - out.shapes.iter().for_each(|c| texts(&c.shape, &mut v)); - v + crate::tests_labels::text_shapes(&out) + .into_iter() + .map(|(t, transform)| (t.galley.text().to_string(), transform * t.visual_bounding_rect())) + .collect() } /// Where text `label` was drawn (menu items pad theirs). diff --git a/crates/ui-egui/src/tests/removeanchors.rs b/crates/ui-egui/src/tests/removeanchors.rs index 90c977f58f..64f6fc4eea 100644 --- a/crates/ui-egui/src/tests/removeanchors.rs +++ b/crates/ui-egui/src/tests/removeanchors.rs @@ -59,7 +59,7 @@ pub(crate) const CONTROL_ROOM: egui::Vec2 = vec2(2200.0, 900.0); pub(crate) fn control_frame(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec) -> Vec<(String, Rect)> { let raw = egui::RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, CONTROL_ROOM)), events, ..Default::default() }; let out = crate::testing::part_frame(app, ctx, raw, chrome::control_bar); - shapes_text(&out.shapes.iter().map(|c| c.shape.clone()).collect::>()) + shapes_text(&crate::tests_labels::flat_painted_shapes(&out.shapes)) } pub(crate) fn click_control(app: &mut VectorcraftApp, ctx: &egui::Context, at: Pos2) { @@ -74,7 +74,7 @@ fn canvas_frame(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec>()) + shapes_text(&crate::tests_labels::flat_painted_shapes(&out.shapes)) } fn click_canvas(app: &mut VectorcraftApp, ctx: &egui::Context, at: Pos2, button: PointerButton) -> Vec<(String, Rect)> { @@ -92,7 +92,7 @@ pub(crate) fn properties_frame(app: &mut VectorcraftApp, width: f32) -> Vec<(Str crate::panels::properties::show(app, ui); }); out.textures_delta.clear(); - shapes_text(&out.shapes.iter().map(|c| c.shape.clone()).collect::>()) + shapes_text(&crate::tests_labels::flat_painted_shapes(&out.shapes)) } pub(crate) fn has(texts: &[(String, Rect)], label: &str) -> bool { diff --git a/crates/ui-egui/src/tests/retype_runs.rs b/crates/ui-egui/src/tests/retype_runs.rs index 8f27f1c572..aa10397dbd 100644 --- a/crates/ui-egui/src/tests/retype_runs.rs +++ b/crates/ui-egui/src/tests/retype_runs.rs @@ -39,11 +39,9 @@ fn has_type(app: &VectorcraftApp) -> bool { fn progress(app: &mut VectorcraftApp, ctx: &egui::Context, time: f64) -> String { let out = crate::testing::part_frame(app, ctx, egui::RawInput { time: Some(time), ..Default::default() }, export_progress::show); let mut texts = String::new(); - for shape in out.shapes { - if let egui::epaint::Shape::Text(t) = shape.shape { - texts.push_str(t.galley.text()); - texts.push('\n'); - } + for (t, _) in crate::tests_labels::text_shapes(&out) { + texts.push_str(t.galley.text()); + texts.push('\n'); } texts } diff --git a/crates/ui-egui/src/tests/ruler_origin.rs b/crates/ui-egui/src/tests/ruler_origin.rs index d731d7db76..d016e09d26 100644 --- a/crates/ui-egui/src/tests/ruler_origin.rs +++ b/crates/ui-egui/src/tests/ruler_origin.rs @@ -30,16 +30,10 @@ fn frame(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec, draw ..Default::default() }; let out = crate::testing::part_frame(app, ctx, raw, draw); - fn walk(s: &egui::Shape, v: &mut Vec<(String, Rect)>) { - match s { - egui::Shape::Text(t) => v.push((t.galley.text().to_string(), Rect::from_min_size(t.pos, t.galley.size()))), - egui::Shape::Vec(s) => s.iter().for_each(|s| walk(s, v)), - _ => {} - } - } - let mut texts = vec![]; - out.shapes.iter().for_each(|c| walk(&c.shape, &mut texts)); - texts + crate::tests_labels::text_shapes(&out) + .into_iter() + .map(|(t, transform)| (t.galley.text().to_string(), transform * Rect::from_min_size(t.pos, t.galley.size()))) + .collect() } /// How many fields show `v` points: painted as one run, or as its number with the unit as the next run on its row. diff --git a/crates/ui-egui/src/tests/script_run.rs b/crates/ui-egui/src/tests/script_run.rs index 9cb5757c6b..106bd96575 100644 --- a/crates/ui-egui/src/tests/script_run.rs +++ b/crates/ui-egui/src/tests/script_run.rs @@ -626,13 +626,6 @@ fn a_scripts_file_dialog_keeps_at_most_2048_picked_files() { /// The texts the open warning draws, after a few frames of the whole app. fn dialog_texts(app: &mut VectorcraftApp) -> Vec { - fn texts(s: &egui::Shape, out: &mut Vec) { - match s { - egui::Shape::Text(t) => out.push(t.galley.text().to_string()), - egui::Shape::Vec(v) => v.iter().for_each(|s| texts(s, out)), - _ => {} - } - } let ctx = app.ui_ctx.clone().unwrap(); let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1600.0, 4000.0)); let mut out = None; @@ -640,9 +633,8 @@ fn dialog_texts(app: &mut VectorcraftApp) -> Vec { let raw = egui::RawInput { time: Some(0.1 * f64::from(i)), screen_rect: Some(screen), ..Default::default() }; out = Some(crate::testing::app_frame(app, &ctx, raw)); } - let mut v = vec![]; - out.unwrap().shapes.iter().for_each(|c| texts(&c.shape, &mut v)); - v + let out = out.unwrap(); + crate::tests_labels::text_shapes(&out).into_iter().map(|(t, _)| t.galley.text().to_string()).collect() } /// The warning before a run lists the files the script writes, read without running it. diff --git a/crates/ui-egui/src/tests/scrub.rs b/crates/ui-egui/src/tests/scrub.rs index 39142a71e5..78cc74f86f 100644 --- a/crates/ui-egui/src/tests/scrub.rs +++ b/crates/ui-egui/src/tests/scrub.rs @@ -18,14 +18,10 @@ pub(super) fn window(app: &mut VectorcraftApp, ui: &mut egui::Ui) { fn app_frame(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec, text: &str) -> Option { let screen_rect = Some(Rect::from_min_size(Pos2::ZERO, vec2(1600.0, 900.0))); let out = crate::testing::app_frame(app, ctx, egui::RawInput { events, screen_rect, ..Default::default() }); - fn find(shape: &egui::Shape, text: &str) -> Option { - match shape { - egui::Shape::Text(t) if t.galley.text() == text => Some(t.galley.rect.translate(t.pos.to_vec2())), - egui::Shape::Vec(v) => v.iter().find_map(|s| find(s, text)), - _ => None, - } - } - out.shapes.iter().find_map(|s| find(&s.shape, text)) + crate::tests_labels::text_shapes(&out) + .into_iter() + .find(|(t, _)| t.galley.text() == text) + .map(|(t, transform)| transform * t.galley.rect.translate(t.pos.to_vec2())) } fn app_with_rect() -> (VectorcraftApp, egui::Context) { diff --git a/crates/ui-egui/src/toolbar/tests.rs b/crates/ui-egui/src/toolbar/tests.rs index 2495ec4d03..9ce6cca2e6 100644 --- a/crates/ui-egui/src/toolbar/tests.rs +++ b/crates/ui-egui/src/toolbar/tests.rs @@ -321,14 +321,7 @@ fn the_controls_under_the_tools_share_a_line_under_a_rule() { let proxy = named_rect(&nodes, "Fill and Stroke"); let screen_rect = Some(egui::Rect::from_min_size(Pos2::ZERO, egui::vec2(1200.0, 2000.0))); let out = crate::testing::app_frame(&mut app, &ctx, egui::RawInput { time: Some(1.0), screen_rect, ..Default::default() }); - let mut flat = Vec::new(); - let mut stack: Vec = out.shapes.into_iter().map(|clipped| clipped.shape).collect(); - while let Some(shape) = stack.pop() { - match shape { - egui::Shape::Vec(inner) => stack.extend(inner), - shape => flat.push(shape), - } - } + let flat = crate::tests_labels::flat_painted_shapes(&out.shapes); // A rule is a thin horizontal line or bar across most of the rail's width, between the tools and the controls. let between = |y: f32| y > last.bottom() && y < proxy.top(); let across = |left: f32, right: f32| right - left >= last.width() * 0.75 && left < last.right() && right > last.left(); @@ -595,20 +588,15 @@ fn a_short_tools_rail_shows_its_scroll_bar_at_rest() { let rail = nodes.iter().find(|n| n.role() == Role::Toolbar && n.label() == Some("Tools")).and_then(bounds).expect("the rail is drawn"); let screen_rect = Some(egui::Rect::from_min_size(Pos2::ZERO, egui::vec2(1200.0, height))); let out = crate::testing::app_frame(app, &ctx, egui::RawInput { time: Some(t0 + 0.2), screen_rect, ..Default::default() }); - let mut stack: Vec = out.shapes.into_iter().map(|clipped| clipped.shape).collect(); let mut found = 0; - while let Some(shape) = stack.pop() { - match shape { - egui::Shape::Vec(inner) => stack.extend(inner), - egui::Shape::Rect(r) => { - let b = r.rect; - let narrow = b.width() > 0.0 && b.width() <= rail.width() * 0.25 && b.height() >= b.width() * 3.0; - let at_end = rail.expand(0.5).contains_rect(b) && b.center().x > rail.center().x; - if narrow && at_end { - found += 1; - } + for shape in crate::tests_labels::flat_painted_shapes(&out.shapes) { + if let egui::Shape::Rect(r) = shape { + let b = r.rect; + let narrow = b.width() > 0.0 && b.width() <= rail.width() * 0.25 && b.height() >= b.width() * 3.0; + let at_end = rail.expand(0.5).contains_rect(b) && b.center().x > rail.center().x; + if narrow && at_end { + found += 1; } - _ => {} } } found diff --git a/crates/ui-egui/tests/panel_readout_copy.rs b/crates/ui-egui/tests/panel_readout_copy.rs index 7c65f085e6..47c72fcb30 100644 --- a/crates/ui-egui/tests/panel_readout_copy.rs +++ b/crates/ui-egui/tests/panel_readout_copy.rs @@ -353,12 +353,11 @@ fn copy_long_link_value(a: &mut App) { assert_eq!(names.len(), 1, "one actual full-name copy readout"); assert_eq!(names[0].1.description(), Some("Copy")); let area = location_node_rect(&names[0].1); - let (value, clipped) = out - .shapes - .iter() - .find_map(|s| { - let t = text_shape(&s.shape, &name)?; - let r = t.galley.rect.translate(t.pos.to_vec2()).intersect(s.clip_rect).intersect(area); + let (value, clipped) = visible_paint(&out) + .into_iter() + .filter(|(t, ..)| t.galley.text() == name) + .find_map(|(t, bounds, _)| { + let r = bounds.intersect(area); r.is_positive().then_some((r, t.galley.elided || r.width() < t.galley.rect.width())) }) .expect("the actual selected image's Link Info Name value"); @@ -636,9 +635,9 @@ fn location_node_rect(node: &egui::accesskit::Node) -> Rect { } fn shortened_location(out: &egui::FullOutput, rect: Rect, full: &str) -> bool { - visible_paint(out) - .into_iter() - .any(|(shape, bounds, center)| rect.contains(center) && bounds.contains(center) && shape.galley.text().contains('…') && shape.galley.text() != full) + visible_paint(out).into_iter().any(|(shape, bounds, center)| { + rect.contains(center) && bounds.contains(center) && shape.galley.text().contains('…') && shape.galley.text() != full + }) } #[test] @@ -725,10 +724,7 @@ fn panel_readout_long_location_fits_and_copies_by_pointer_accessibility_and_keyb let (location_id, node) = locations[0]; let location_rect = location_node_rect(node); assert!(body.contains_rect(location_rect), "{locale}: the fitted Location remains inside the panel"); - assert!( - shortened_location(&out, location_rect, location), - "{locale}: the long path must actually be shortened on screen" - ); + assert!(shortened_location(&out, location_rect, location), "{locale}: the long path must actually be shortened on screen"); let buttons: Vec<_> = nodes.iter().filter(|(_, n)| n.role() == Role::Button && n.label() == Some(vectorcraft_ui_egui::i18n::t("Copy Location"))).collect(); assert_eq!(buttons.len(), 1, "{locale}: one named native Copy Location button");