From 726a496eb5df4805c10fc8009fd2243a7fddd5c5 Mon Sep 17 00:00:00 2001 From: Lucas Meurer Date: Tue, 21 Jul 2026 11:33:50 +0200 Subject: [PATCH] Properly handle pixels_per_point in kittest --- crates/egui_kittest/src/lib.rs | 2 +- crates/egui_kittest/src/node.rs | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/crates/egui_kittest/src/lib.rs b/crates/egui_kittest/src/lib.rs index fa264d5b4..7333769ed 100644 --- a/crates/egui_kittest/src/lib.rs +++ b/crates/egui_kittest/src/lib.rs @@ -735,7 +735,7 @@ impl<'a, State> Harness<'a, State> { /// The root node of the test harness. pub fn root(&self) -> Node<'_> { - Node::new(self.kittest.root(), &self.queued_events) + Node::new(self.kittest.root(), &self.queued_events, self.ctx.pixels_per_point()) } /// Spawn a real native eframe window running this harness's app, reusing its [`egui::Context`]. diff --git a/crates/egui_kittest/src/node.rs b/crates/egui_kittest/src/node.rs index eb7c654fd..ec0925d05 100644 --- a/crates/egui_kittest/src/node.rs +++ b/crates/egui_kittest/src/node.rs @@ -19,6 +19,7 @@ pub type EventQueue = Mutex>; pub struct Node<'tree> { pub(crate) accesskit_node: AccessKitNode<'tree>, pub(crate) queue: &'tree EventQueue, + pub(crate) pixels_per_point: f32, } impl Debug for Node<'_> { @@ -33,16 +34,17 @@ impl<'tree> NodeT<'tree> for Node<'tree> { } fn new_related(&self, child_node: AccessKitNode<'tree>) -> Self { - Self::new(child_node, self.queue) + Self::new(child_node, self.queue, self.pixels_per_point) } } impl<'tree> Node<'tree> { /// Construct a new accesskit node - pub fn new(accesskit_node: AccessKitNode<'tree>, queue: &'tree EventQueue) -> Self { + pub fn new(accesskit_node: AccessKitNode<'tree>, queue: &'tree EventQueue, pixels_per_point: f32) -> Self { Self { queue, accesskit_node, + pixels_per_point, } } @@ -113,14 +115,17 @@ impl<'tree> Node<'tree> { )); } + /// This returns the rect in logical ui coordinates while the underlying [`accesskit::Node`] has it + /// in physical screen coordinates. pub fn rect(&self) -> egui::Rect { let rect = self .accesskit_node .bounding_box() .expect("Every egui node should have a rect"); + let ppp = self.pixels_per_point; egui::Rect { - min: Pos2::new(rect.x0 as f32, rect.y0 as f32), - max: Pos2::new(rect.x1 as f32, rect.y1 as f32), + min: Pos2::new(rect.x0 as f32 / ppp, rect.y0 as f32 / ppp), + max: Pos2::new(rect.x1 as f32 / ppp, rect.y1 as f32 / ppp), } }