From 9595a8910826d552c4f60c798658f2dbc8a77faf Mon Sep 17 00:00:00 2001 From: Asger Nyman Christiansen Date: Mon, 26 Feb 2024 12:38:46 +0100 Subject: [PATCH] Fix egui integration after event positions are defined in physical pixels --- src/gui/egui_gui.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/gui/egui_gui.rs b/src/gui/egui_gui.rs index cd5d2b42..98a45d3c 100644 --- a/src/gui/egui_gui.rs +++ b/src/gui/egui_gui.rs @@ -123,8 +123,9 @@ impl GUI { if !handled { Some(egui::Event::PointerButton { pos: egui::Pos2 { - x: position.x, - y: position.y, + x: position.x / device_pixel_ratio as f32, + y: (viewport.height as f32 - position.y) + / device_pixel_ratio as f32, }, button: button.into(), pressed: true, @@ -143,8 +144,9 @@ impl GUI { if !handled { Some(egui::Event::PointerButton { pos: egui::Pos2 { - x: position.x, - y: position.y, + x: position.x / device_pixel_ratio as f32, + y: (viewport.height as f32 - position.y) + / device_pixel_ratio as f32, }, button: button.into(), pressed: false, @@ -159,8 +161,9 @@ impl GUI { } => { if !handled { Some(egui::Event::PointerMoved(egui::Pos2 { - x: position.x, - y: position.y, + x: position.x / device_pixel_ratio as f32, + y: (viewport.height as f32 - position.y) + / device_pixel_ratio as f32, })) } else { None