From 33b2fd967ada2d2c86eb1b57eb4997719774499e Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Mon, 4 Dec 2023 13:32:34 -0500 Subject: [PATCH] fix: translate the wayland event position for content inside a scrollable --- core/src/event/wayland/mod.rs | 17 +++++++++++++++++ widget/src/scrollable.rs | 10 +++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/core/src/event/wayland/mod.rs b/core/src/event/wayland/mod.rs index bf3ddcb1b0..f7bfd5bac7 100644 --- a/core/src/event/wayland/mod.rs +++ b/core/src/event/wayland/mod.rs @@ -43,3 +43,20 @@ pub enum Event { /// Frame events Frame(Instant, WlSurface, Id), } + +impl Event { + /// Translate the event by some vector + pub fn translate(&mut self, vector: crate::vector::Vector) { + match self { + Event::DndOffer(DndOfferEvent::Enter { x, y, .. }) => { + *x += vector.x as f64; + *y += vector.y as f64; + } + Event::DndOffer(DndOfferEvent::Motion { x, y }) => { + *x += vector.x as f64; + *y += vector.y as f64; + } + _ => {} + } + } +} diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index 7b520476ad..3525b01952 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -657,7 +657,7 @@ pub fn layout( /// accordingly. pub fn update( state: &mut State, - event: Event, + #[allow(unused_mut)] mut event: Event, layout: Layout<'_>, cursor: mouse::Cursor, clipboard: &mut dyn Clipboard, @@ -699,6 +699,14 @@ pub fn update( let translation = state.translation(direction, bounds, content_bounds); + #[cfg(feature = "wayland")] + if let Event::PlatformSpecific( + iced_runtime::core::event::PlatformSpecific::Wayland(e), + ) = &mut event + { + e.translate(translation); + } + update_content( event.clone(), content,