Forward Mouse input to Makie

Open
#162 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
julia
Domain
desktop

Research direction

Start by reading the referenced GtkMakie.jl src/events.jl implementation and the MouseArea workaround in this issue, then inspect how QML.jl exposes the Makie viewport and scene.events callbacks. Done means mouse and keyboard input reaches Makie reliably, including movement, buttons, wheel events, and coordinates, so interactions such as spinning 3D plots work without the workaround.

Written by the indexing model from the issue text.

Description

enhancement

It would be useful to forward mouse (and keyboard) input to Makie. E.g. to be able to spin 3d plots using the mouse.

The proper way to do this would probably to adapt the code at https://github.com/jwahlstrand/GtkMakie.jl/blob/main/src/events.jl

At the moment, I have a workaround, by putting a MouseArea over the Makie viewport.
Here's an example of how it can be done, it might be useful to someone in the meantime. 🙂

MouseArea {
	anchors.fill: parent
	acceptedButtons: Qt.AllButtons

	onPressed: mouse=>Julia.mouse_press_callback(mouse.x,height-mouse.y-1,mouse.button)
	onReleased: mouse=>Julia.mouse_release_callback(mouse.x,height-mouse.y-1,mouse.button)
	onPositionChanged: mouse=>Julia.mouse_position_callback(mouse.x,height-mouse.y-1)
	onWheel: wheel=>Julia.mouse_wheel_callback(wheel.x, wheel.y, wheel.angleDelta.x, wheel.angleDelta.y)
}

and in the callbacks we update the Observables in scene.events:

function mouse_button_qt2makie(button)
	button == 1 && return Makie.Mouse.left
	button == 2 && return Makie.Mouse.right
	button == 4 && return Makie.Mouse.middle
	Makie.Mouse.none
end

function mouse_press_callback(mouseX, mouseY, button)
	scene.events.mouseposition[] = (mouseX,mouseY)
	b = mouse_button_qt2makie(button)
	if b != Makie.Mouse.none
		scene.events.mousebutton[] = Makie.MouseButtonEvent(b, Makie.Mouse.press)
	end
end
function mouse_release_callback(mouseX, mouseY, button)
	scene.events.mouseposition[] = (mouseX,mouseY)
	b = mouse_button_qt2makie(button)
	if b != Makie.Mouse.none
		scene.events.mousebutton[] = Makie.MouseButtonEvent(b, Makie.Mouse.release)
	end
end
function mouse_position_callback(mouseX, mouseY)
	scene.events.mouseposition[] = (mouseX,mouseY)
end
function mouse_wheel_callback(mouseX, mouseY, angleDeltaX, angleDeltaY)
	scene.events.mouseposition[] = (mouseX,mouseY)
	scene.events.scroll[] = (angleDeltaX/120,angleDeltaY/120)
end
Dominant language
Julia
Stars
437
Forks
39
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from JuliaGraphics/QML.jl

All issues in JuliaGraphics/QML.jl

Similar issues

More Julia issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.