scrollbar: Keep the original thumb position when mouse down to dragging (#234)

![2024-09-10 23 18
50](https://github.com/user-attachments/assets/58c480a3-9c92-4c7c-8e7a-b37c2ffc3526)

fix #224
This commit is contained in:
xda 2024-09-11 09:37:07 +08:00 committed by GitHub
parent fbbb985e84
commit 4f8c4ccd5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -522,19 +522,25 @@ impl Element for Scrollbar {
// We need to keep the thumb bar still at the origin down position
let drag_pos = state.get().drag_pos;
let percentage = if is_vertical {
let percentage = (if is_vertical {
(event.position.y - drag_pos.y - bounds.origin.y)
/ (bounds.size.height - thumb_length)
} else {
(event.position.x - drag_pos.x - bounds.origin.x)
/ (bounds.size.width - thumb_length)
}
.min(1.);
/ (bounds.size.width - thumb_length - margin_end)
})
.clamp(0., 1.);
let offset = if is_vertical {
point(scroll_handle.offset().x, -scroll_area_size * percentage)
point(
scroll_handle.offset().x,
-(scroll_area_size - container_size) * percentage,
)
} else {
point(-scroll_area_size * percentage, scroll_handle.offset().y)
point(
-(scroll_area_size - container_size) * percentage,
scroll_handle.offset().y,
)
};
scroll_handle.set_offset(offset);