lapce / floem

A native Rust UI library with fine-grained reactivity
https://lap.dev/floem/
MIT License
3.06k stars 133 forks source link

fix drag jitter #674

Closed jrmoulton closed 1 week ago

jrmoulton commented 2 weeks ago

this fixes some jitter when dragging views. because the view could have moved between the time that it is painted, the computed offset can be outdated. This causes lots of jitter in the draggable example.

I feel like there should be a simpler way of doing this but I couldn't figure out another way

dzhou121 commented 2 weeks ago

Do you mean the pointer could have moved between the time that it is painted? But if we don't receive the pointermove event, there's no information the pointer has been moved.

Do I understand this issue correctly?

jrmoulton commented 2 weeks ago

https://github.com/user-attachments/assets/8e01fe36-bd85-420c-b9eb-6f176ab26c5a

Screenshot 2024-11-07 at 10 36 59 AM

The pointer move event is registered on the view, it is dragging so it computes an offset relative to the view and then requests a paint. but if the same events causes the view to move (as it does in this dragging example) when it does eventually paint the offset that was relative to the view is now incorrect

dzhou121 commented 2 weeks ago

Thanks for the clarification.

Because the dragged view should be always follows the pointer, maybe we can simply it by storing the offset of the view relative to the pointer at drag start, and then at paint time, we know where it should be according to the pointer position. i.e. we don't use the relative value with the original view which could have moved as well, but use the relative value to the pointer and it should always be right.

jrmoulton commented 1 week ago

https://github.com/user-attachments/assets/77b7fd25-190e-4cd5-9bc3-c6360da6ed56