This post helped me out somewhat but it is missing a piece that I really need for something that I am working on that's more complex than what I've shown below. I want to disable a Locator
when its corresponding tab is not selected, I've achieved this using the method in the link, however it is slow (not with this simple code), ContinuousAction->False
doesn't affect it, and when I click anywhere within the plot range the Locator
does not move there and I haven't been able to change this.
clip[pt : {x_, y_}, {xMin_, yMin_}, {xMax_, yMax_}] := {Clip[
x, {xMin, xMax}], Clip[y, {yMin, yMax}]}
Manipulate[
Switch[ctrl,
1, Show[
Graphics[{
{Thick, Line[{{-3, 0}, {point1[[1]], point1[[2]]}}]},
Locator[Dynamic[point1, (point1 = clip[#, {-3, -2}, {3, 2}]) &],
Enabled -> True]
}, PlotRange -> {{-3, 3}, {-2, 2}}]
],
2, Show[
Graphics[{
{Thick, Red, Line[{{3, 0}, {point2[[1]], point2[[2]]}}]},
Locator[Dynamic[point2, (point2 = clip[#, {-3, -2}, {3, 2}]) &],
Enabled -> True]
},
PlotRange -> {{-3, 3}, {-2, 2}}]
]
],
{{ctrl, 1, ""}, {1 -> "black", 2 -> "red"}, SetterBar},
{{point1, {0, 1}}, None},
{{point2, {0, -1}}, None}]
I'm not sure if it's possible, or if there is a completely different way of going about enabling/disabling individual locators (that isn't super messy). I just want to do that and also be able to use options like ContinuousAction->False
and be able to click anywhere within the plot range and have the locator "jump" there.
What I've provided above is more or less what I learned from the other post, below is a short example of what I originally had.
Manipulate[
Switch[ctrl,
1, Show[
Graphics[{Thick, Line[{{-3, 0}, {point1[[1]], point1[[2]]}}]},
PlotRange -> {{-3, 3}, {-2, 2}}]
],
2, Show[
Graphics[{Thick, Red, Line[{{3, 0}, {point2[[1]], point2[[2]]}}]},
PlotRange -> {{-3, 3}, {-2, 2}}]
]
],
{{ctrl, 1, ""}, {1 -> "black", 2 -> "red"}, SetterBar},
{{point1, {0, 1}}, Locator},
{{point2, {0, -1}}, Locator}]