Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add drag threshold to improve click experience #4426

Merged
merged 6 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Fixed issue with CairoMakie rendering scene backgrounds at the wrong position [#4425](https://github.com/MakieOrg/Makie.jl/pull/4425)
- Fix incorrect inverse transformation in `position_on_plot` for lines, causing incorrect tooltip placement in DataInspector [#4402](https://github.com/MakieOrg/Makie.jl/pull/4402)
- Added threshold before a drag starts which improves false negative rates for clicks. `Button` can now trigger on click and not mouse-down which is the canonical behavior in other GUI systems [#4336](https://github.com/MakieOrg/Makie.jl/pull/4336).

## [0.21.12] - 2024-09-28

Expand Down
4 changes: 4 additions & 0 deletions src/makielayout/blocks/button.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ function initialize_block!(b::Button)

onmouseleftdown(mouseevents) do _
mousestate[] = :active
return Consume(true)
end

onmouseleftclick(mouseevents) do _
b.clicks[] = b.clicks[] + 1
return Consume(true)
end
Expand Down
5 changes: 4 additions & 1 deletion src/makielayout/mousestatemachine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ function _addmouseevents!(scene, is_mouse_over_relevant_area, priority)
mouse_downed_inside = Ref(false)
mouse_downed_button = Ref{Optional{Mouse.Button}}(nothing)
drag_ongoing = Ref(false)
mouse_downed_at = Ref(Point2d(0, 0)) # store the position of mouse down so drags only start after some threshold
drag_threshold = 2.0 # mouse needs to move this distance before a drag starts, otherwise it's easy to drag instead of click on trackpads
mouse_was_inside = Ref(false)
prev_t = Ref(0.0)
t_last_click = Ref(0.0)
Expand Down Expand Up @@ -231,7 +233,7 @@ function _addmouseevents!(scene, is_mouse_over_relevant_area, priority)
else
# mouse was downed inside but no drag is ongoing
# that means a drag started
if mouse_downed_inside[]
if mouse_downed_inside[] && norm(mouse_downed_at[] - px) >= drag_threshold
drag_ongoing[] = true
event = to_drag_start_event(mouse_downed_button[])
x = setindex!(mouseevent,
Expand Down Expand Up @@ -294,6 +296,7 @@ function _addmouseevents!(scene, is_mouse_over_relevant_area, priority)
mouse_downed_button[] = button

if mouse_was_inside[]
mouse_downed_at[] = px
event = to_down_event(mouse_downed_button[])
x = setindex!(mouseevent,
MouseEvent(event, t, data, px, prev_t[], prev_data[], prev_px[])
Expand Down
Loading