Skip to content

Commit

Permalink
fix: translate the wayland event position for content inside a scroll…
Browse files Browse the repository at this point in the history
…able
  • Loading branch information
wash2 committed Dec 4, 2023
1 parent 419c052 commit 33b2fd9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
17 changes: 17 additions & 0 deletions core/src/event/wayland/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
_ => {}
}
}
}
10 changes: 9 additions & 1 deletion widget/src/scrollable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ pub fn layout<Renderer>(
/// accordingly.
pub fn update<Message>(
state: &mut State,
event: Event,
#[allow(unused_mut)] mut event: Event,
layout: Layout<'_>,
cursor: mouse::Cursor,
clipboard: &mut dyn Clipboard,
Expand Down Expand Up @@ -699,6 +699,14 @@ pub fn update<Message>(

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,
Expand Down

0 comments on commit 33b2fd9

Please sign in to comment.