Dynamic Linkage of LocatorPane and InputField
Consider the following refactoring of your code
First, the locator pane is used to set a point location constrained on a circle with unit radius (this part borrowed heavily from an example in the documentation for LocatorPane
). A degree value is then calculated from the coordinates of tha tpoint.
Secondly, the input field is used to read in a degree value, which is then used to update the position of the dynamic point pt
using the second argument of Dynamic
.
DynamicModule[
{pt = {0, 1.}},
Column[{
"Degrees:", Dynamic[(ArcTan @@ pt)/Degree],
LocatorPane[
Dynamic[pt],
Graphics[{
Circle[],
PointSize[Large],
Dynamic[Arrow[{{0, 0}, pt/Norm[pt]}]]
}],
Appearance -> None
],
InputField[
Dynamic[(ArcTan @@ pt)/Degree, (pt = N@{Cos[#1 Degree], Sin[#1 Degree]}) &],
FieldSize -> Tiny
]
}, Alignment -> Center
]
]
This keeps both fields in sync with each other:
An alternative way to use Experimental`AngularSlider
is to use a single dynamic variable and limit the angles to the range 0 to 360 using {0,360}
as the second argument of AngularSlider
:
DynamicModule[{z = 120},
Column[{Experimental`AngularSlider[Dynamic[z], {0, 360},
Experimental`BoundaryAction -> "Clip"],
InputField[Dynamic[z], ImageSize -> {100, 24}, BaseStyle -> 16]},
Alignment -> Center]]
To display angles in radians and degrees and allow the slider to move around the clock:
DynamicModule[{z = 120},
Panel @ Column[{Style["Degree", 16],
Overlay[{Experimental`AngularSlider[Dynamic[z,(z = Round[#, 1]) &], {0, 360},
Experimental`BoundaryAction -> "Wrap", ImageSize -> 200],
Graphics[{Text[Framed[Style[Dynamic[Round[z,1]] °, 16], FrameStyle -> None],
Scaled @ {3/4, 4/10}, {-1, 1}],
Text[Framed[Style[Dynamic[Round[z Degree, Pi/2^7] ], 16], FrameStyle -> None],
Scaled @ {3/4, 4/10}, {-1, -1}]}]}, All, 1],
InputField[Dynamic[z, (z = Round[#, 1]) &], ImageSize -> {100, 24}, BaseStyle -> 16]},
Alignment -> Center]]
If you want to play with various options of Experimental`AngularSlider
you can use
NotebookTools`AngularSliderTest[]
Here is a simplified demo linking an InputField[]
with Experimental`AngularSlider[]
:
DynamicModule[{x = 0., u = 0.},
Column[{Experimental`AngularSlider[Dynamic[x, (x = #; u = x/Degree) &]],
InputField[Dynamic[u, (u = #; x = u Degree) &], Number]}]]
Clicking on the AngularSlider[]
updates the value in the InputField[]
, and entering a (degree) value in the InputField[]
moves the slider to the specified angle.