From 977a52933d05c8d978d8a0b38baaeb459251439b Mon Sep 17 00:00:00 2001 From: bflatastic Date: Wed, 25 Nov 2026 21:07:01 +0700 Subject: [PATCH] Native panel window test: drop the art on the first graphic style's tile The test dropped the art 60 x 120 points into the Graphic Styles window. Since Thumbnail View's tiles are 40 points (df940cff4e) the tile row ends at 116 points, so that point lies in the empty room below the tiles, which takes no drop, and the panel made no style. The test now finds the first style's tile by its name in the window's access tree and drops the art there. The test host keeps each window's named access nodes for that. --- .../ui-egui/src/panel_docking/native_tests.rs | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/panel_docking/native_tests.rs b/crates/ui-egui/src/panel_docking/native_tests.rs index 4c33e45b1e..996afc5964 100644 --- a/crates/ui-egui/src/panel_docking/native_tests.rs +++ b/crates/ui-egui/src/panel_docking/native_tests.rs @@ -27,6 +27,8 @@ struct Window { frames: usize, /// The texts its last frame drew, with their rects in the window. texts: Vec<(String, Rect)>, + /// The named nodes of its last frame's access tree, with their rects in the window. + nodes: Vec<(String, Rect)>, } struct Host { @@ -77,6 +79,7 @@ impl Host { dropped: Vec::new(), frames: 0, texts: Vec::new(), + nodes: Vec::new(), }); let viewports = host.infos(); let (time, focused) = (host.time, host.focus == id); @@ -105,9 +108,16 @@ impl Host { } let mut shown = Vec::new(); full.shapes.iter().for_each(|c| texts(&c.shape, &mut shown)); + 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() + }); let mut host = host.borrow_mut(); if let Some(window) = host.windows.get_mut(&id) { window.texts = shown; + if !nodes.is_empty() { + window.nodes = nodes; + } } host.apply(&full); } @@ -317,6 +327,7 @@ fn button(pos: Pos2, pressed: bool) -> Event { #[test] fn art_dragged_from_the_canvas_onto_a_native_panel_window_drops_there() { let mut h = Harness::new(); + h.ctx.enable_accesskit(); let id = h.app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 50, "height": 40})).unwrap()["id"].as_u64().unwrap(); let id = vectorcraft_doc::NodeId(id); let viewport = h.float("graphicStyles"); @@ -327,8 +338,14 @@ fn art_dragged_from_the_canvas_onto_a_native_panel_window_drops_there() { let before = art(&h); let view = h.app.canvas_view().expect("the canvas was drawn"); let from = view.to_screen(vectorcraft_geom::Point::new(35.0, 30.0)); - let window = h.host.borrow().windows.get(&viewport).map(|w| w.rect).unwrap(); - let to = window.min + vec2(60.0, 120.0) - ORIGIN.to_vec2(); + // The first style's tile, found by its name: the panel takes art dropped onto a style or between styles. + let first = h.app.session.active().unwrap().doc.graphic_styles[0].name.clone(); + let to = { + let host = h.host.borrow(); + let window = &host.windows[&viewport]; + let tile = window.nodes.iter().find(|(name, _)| *name == first).map(|(_, r)| *r).expect("the first style's tile"); + window.rect.min + tile.center().to_vec2() - ORIGIN.to_vec2() + }; assert!(view.rect.contains(to), "the window lies over the canvas"); h.frame(vec![Event::PointerMoved(from), button(from, true)]); for k in 1..=8 {