Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion plugin-canvas-slint/src/window_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
19 changes: 19 additions & 0 deletions plugin-canvas/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,25 @@ pub enum Event {
},
}

impl Event {
pub fn with_mapped_position<F>(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,
Expand Down
Loading