I want to create a custom ui control with interacting elements.
For simplicity, assume there are going to be three Slider
s, where each successive Slider
's max value depends on the current value of the preceding Slider
.
{
Slider[Dynamic[x, (y=f[y, # - 1]; x = #)&], {3, 10, 1}],
Slider[Dynamic[y, (z=f[z, # - 1]; y = #)&], {2, Dynamic[x-1], 1}],
Slider[Dynamic[z], {1, Dynamic[y-1], 1}]
} // Column
where f
, is an auxiliary function that limits the value of the first argument, if it exceeds the value of the second argument:
f[x_, max_] := Which[
x > max, max,
True, x
]
After a certain amount of experimentation, I realized that the second argument of Dynamic
needs to include all the expressions that involve changing variables, otherwise the outcome is not user friendly.
For example, this is how I'd modify the second argument of Dynamic
in the first Slider
:
...(y=f[y,#-1];z=f[z,y-1];y=#)&... (* first slider mod *)
Notice how the mod includes z
, now. Similar modifications should be made in the second Slider
.
However, notice that including at the second argument of Dynamic
all the expressions that are needed to change the respective variables, becomes cumbersome for anything larger than an ensamble of three Sliders
s.
Also, it seems that automating the construction of such a composite ui element becomes progressively difficult as the dependence relations between variables get more elaborate (and the f
functions get more complicated).
So, my question is, is there another way to construct a composite ui element, like the one above, where each successive element responds to the values of previous elements?
The response I'm more interested here, is for the max value of dependent sliders to change in an expected manner, when the value of a preceding master sliders changes.