Problem
Consider the following code:
DynamicModule[{a = {0, Pi}, b = 4},
{Slider[Dynamic@b, {a}], Dynamic@b}
]
I want a Slider
which sets b
to the exact values in a
(0 and Pi
). However b
is set to 3.14159
instead of Pi
.
The same problem exists also for Manipulator
and Manipulate
:
Manipulate[b,
{b, {0, Pi}, ControlType -> Slider}
]
Is there a better way to do this than the following workaround?
Workaround
My current workaround is to use a third variable c
and Nearest
:
DynamicModule[{a = {0, Pi}, b, c},
{Slider[Dynamic@b, {a}], Dynamic@b, Dynamic[c = First@Nearest[a, b]]}
]
this sets c
correctly to 0 or Pi
but it is a bit cumbersome.
Manipulate[var, {{var, Pi}, 0, Pi, Pi/16, Appearance -> "Labeled"}]
$\endgroup$