I'm implementing a two-sided slider to be able to set upper and lower bound in just one slider:
The problem is that it can get stuck when both locators are at the far left:
And I'm unable to grab the blue locator.
SetAttributes[TwoSidedSlider, HoldAll];
TwoSidedSlider[sliderMin_, sliderMax_, var1_, var2_,
maxIsInfinity_: False] := DynamicModule[
{pt = {{var1, 0}, {If[var2 == Infinity, sliderMax, var2], 0}}},
LocatorPane[
Dynamic[pt,
((* Update while dragging \*)
pt = #1;
var1 = #1[[1, 1]];
var2 =
If[maxIsInfinity && #1[[2, 1]] == sliderMax,
Infinity, #1[[2, 1]]];
) &
],
Graphics[{
Gray, Line[{{sliderMin, 0}, {Dynamic[pt[[1, 1]]], 0}}],(* min to lower \*)
Black,
Line[{{Dynamic[pt[[1, 1]]], 0}, {Dynamic[pt[[2, 1]]], 0}}], (* lower to upper \*)
Gray,
Line[{{Dynamic[pt[[2, 1]]], 0}, {sliderMax, 0}}] (* upper to max \*)
}, AspectRatio -> 1/5],
{ (* Locator Region and stepsize \*)
{{sliderMin, 0},
{Dynamic[pt[[2, 1]]], 0}, {1, 1}},
{{Dynamic[pt[[1, 1]]], 0},
{sliderMax, 0}, {1, 1}}
}
, Appearance -> {Style["[", Red, Larger, Bold],
Style["]", Blue, Larger, Bold]}]]
It is used something like this:
lower = 0; upper = Infinity;
{{Dynamic[lower], TwoSidedSlider[0, 5000, lower, upper, True],
Dynamic[upper]}} // TableForm
Any tips on how to get a two-sided slider or what causes this one to get stuck?
Experimental`
context interesting: Needs@"Experimental"; Experimental
IntervalSlider[Dynamic@z, {-10, 10}]. $\endgroup$Needs
. And the rest was just trial and error. It is also mentioned here. $\endgroup$