From d8b303c5814744dd2dc9d201756692e32581f5d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduard=20M=C3=BCller?= Date: Wed, 27 May 2026 12:53:50 +0200 Subject: [PATCH] Apply slint view scale factors before sending events to PluginView --- plugin-canvas-slint/src/window_adapter.rs | 8 +++++++- plugin-canvas/src/event.rs | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/plugin-canvas-slint/src/window_adapter.rs b/plugin-canvas-slint/src/window_adapter.rs index b301c74..4c57d3e 100644 --- a/plugin-canvas-slint/src/window_adapter.rs +++ b/plugin-canvas-slint/src/window_adapter.rs @@ -137,7 +137,13 @@ impl PluginCanvasWindowAdapter { pub fn on_event(&self, event: &plugin_canvas::Event) -> EventResponse { let view_response = if let Some(view) = self.view.borrow().as_ref() { - view.on_event(event) + view.on_event(&event.clone().with_mapped_position(|position| { + let position = self.convert_logical_position(position); + plugin_canvas::LogicalPosition { + x: position.x as f64, + y: position.y as f64, + } + })) } else { EventResponse::Ignored }; diff --git a/plugin-canvas/src/event.rs b/plugin-canvas/src/event.rs index 53e29e1..eccf3f3 100644 --- a/plugin-canvas/src/event.rs +++ b/plugin-canvas/src/event.rs @@ -65,6 +65,25 @@ pub enum Event { }, } +impl Event { + pub fn with_mapped_position(mut self, map: F) -> Self + where + F: Fn(&LogicalPosition) -> LogicalPosition, + { + match &mut self { + Event::DragDropped { position, .. } => *position = map(position), + Event::DragEntered { position, .. } => *position = map(position), + Event::DragMoved { position, .. } => *position = map(position), + Event::MouseButtonDown { position, .. } => *position = map(position), + Event::MouseButtonUp { position, .. } => *position = map(position), + Event::MouseMoved { position, .. } => *position = map(position), + Event::MouseWheel { position, .. } => *position = map(position), + _ => {} + } + self + } +} + #[derive(Clone, Copy, Debug, PartialEq)] pub enum EventResponse { Handled,