Is it posible to make a 2D slider in Makie?

Is it possible to make a 2D slider ?? In the following code I would like to have a circle in a rectangle that I can drag around instead of 2 different sliders.
How would you do that ?

using GLMakie

fig = Figure()

sl_ang = Slider(fig[1, 1], range = -pi:0.01:pi, startvalue = 0)

sl_k = Slider(fig[2, 1], range = 0:0.01:5, startvalue = 1)


f(x,y,z,k,v) = sin(k*cos(v)*x)*sin(k*sin(v)*y)*sinh(k*z)

xs, ys, zs = [-10:0.1:10 for d in range(1,3)]



vol = lift(sl_ang.value, sl_k.value) do v,k
  [f(x,y,z,k,v) for x in xs, y in xs, z in zs]
end

ax = Axis3(fig[3,1])

volume!(xs,ys,zs,vol; colormap=:redsblues, colorrange=(-1000,1000),algorithm=:absorption)
display(fig)

Here’s an example of how one might construct an xy slider from available parts:

f = Figure()

sliderdomain = Observable(BBox(0, 1, 0, 1))
limits = lift(sliderdomain) do d
    mi = minimum(d)
    ma = maximum(d)
    (mi[1], ma[1], mi[2], ma[2])
end
sliderax = Axis(f[1, 1]; limits, width = 200, height = 200, tellheight = false)
hidedecorations!(sliderax)
deregister_interaction!(sliderax, :rectanglezoom)
deregister_interaction!(sliderax, :scrollzoom)
current_value = Observable(sliderdomain[].origin .+ 0.5 .* sliderdomain[].widths)
vlines!(sliderax, @lift($current_value[1]), color = :black)
hlines!(sliderax, @lift($current_value[2]), color = :black)
scatter!(sliderax, current_value, markersize = 15, color = :black)
me = addmouseevents!(sliderax.scene)
onmouseleftdrag(me) do event
    current_value[] = clamp.(event.data, minimum(sliderdomain[]), maximum(sliderdomain[]))
end
onmouseleftdown(me) do event
    current_value[] = clamp.(event.data, minimum(sliderdomain[]), maximum(sliderdomain[]))
end

color = @lift RGBf($current_value[1], 0, 0)
markersize = @lift $current_value[2] * 50

scatter(f[1, 2], randn(100, 3), color = color, markersize = markersize, axis = (; type = Axis3))

f

12 Likes

Thanks, exactly what I am looking for.