Essentially, you have the solution, and the only thing left is to break the circularity. This can be done by triggering a change only when slider state is out of the ‘good’ set of states. And to make sure the changes bring you back into the ‘good’ set of states (otherwise a “doom loop” can occur, like you suggested).
So for the example in the post:
using Observables
obs_func = on(slider1.value) do val
abs(val+slider2.value[])>0.01 && Makie.set_close_to!(slider2, -val)
end
obs_func2 = on(slider2.value) do val
abs(slider1.value[]+val)>0.01 && Makie.set_close_to!(slider1, -val)
end
The code makes sure slider1
and slider2
sum to zero.
When I ran it, it worked quite smoothly.