iced-rs / iced

A cross-platform GUI library for Rust, inspired by Elm
https://iced.rs
MIT License
24.08k stars 1.12k forks source link

Glitch Panning Image in Scrollable #1488

Open rs017991 opened 1 year ago

rs017991 commented 1 year ago

Is there an existing issue for this?

Is this issue related to iced?

What happened?

When you have an Image Viewer within a Scrollable, panning on the zoomed-in image causes it to jump wildly upwards.

This does not happen if the scroll bar is all the way at the top; the further you scroll down, the more pronounced the jump is.

You can reproduce this by running this slightly-tweaked example: (I've encountered this in both 0.4.0 and master, but the reproduction is against master): https://github.com/iced-rs/iced/compare/master...rs017991:iced:image_scrolling_reprod

I'm pretty sure I've tracked down the cause of this:

  1. When passing events, Scrollable converts cursor_position into its own coordinate system, yet it passes the event itself through untouched
  2. As a result, Viewer ends up calculating its delta based on two different coordinate systems: origin is based on the converted cursor_position, whereas position comes from the untouched CursorMoved event.

You could fix Viewer by changing this line to point at cursor_position instead of position: https://github.com/iced-rs/iced/blob/82217947aa80287282ed6deb02d238a31303e0d6/native/src/widget/image/viewer.rs#L250

However, a more thorough fix may be to have Scrollable tweak the CursorMoved event (as well as any others that include coordinate data).

What is the expected behavior?

Panning behaves the same as when it is not in a Scrollable

Version

master

Operative System

Windows

Do you have any log output?

No response

rs017991 commented 2 months ago

I've retested and confirmed that this issue still exists as of Iced 0.12.

See also my reproduction, rebased onto 0.12: https://github.com/iced-rs/iced/compare/0.12...rs017991:iced:image_scrolling_reprod-0.12