This follows up on another question about the sensitivity of Locators in a a LocatorPane.
I would like to be able to enable/disable individual locators in a LocatorPane. In the simplified version of the applet, pictured below, I would like to be able to disable the locators that set the slope of the red line, while allowing the locators that set the slope of the blue line to remain enabled.
Using individual Locator
s, rather than a LocatorPane
, is not an option. (There are some subtle issues that arise with individual locators. Essentially, multiple Locator
s can behave in a "flaky" fashion in complex applets, in ways that LocatorPane
does not.)
Code below:
Manipulate[m = 15;
LocatorPane[Dynamic[pts],
Dynamic[ Module[{x = pts[[1, 1]], y = pts[[2, 2]], x2 = pts[[3, 1]], y2 = pts[[4, 2]]},
Graphics[{
{Blue, Line[{-m*{x2, y2}, m*{x2, y2}}]},
Line[{{x2, 0}, {x2, y2}}], Line[{{x2, y2}, {0, y2}}],
{Red, Line[{-m*{x, y}, m*{x, y}}]},
Line[{{x, 0}, {x, y}}], Line[{{x, y}, {0, y}}]},
PlotRange -> m, Axes -> True, ImageSize -> {300, 300}]]],
{{{-m, 0}, {m, 0}, {1, 0}},
{{0, -m}, {0, m}, {0, 1}},
{{-m, 0}, {m, 0}, {1, 0}},
{{0, -m}, {0, m}, {0, 1}}},
Appearance -> {Automatic, Automatic, Automatic, Automatic}],
{{pts, {{6, 0}, {0, 9}, {3, 0}, {0, 7}}}, ControlType -> None}]
The visibility of the locators can be individually controlled by toggling the respective locator's Appearance
between None
and Automatic
. But even when the locator is invisible (i.e. Appearance -> None
) it continues enabled. For example, the red sliders will continue to set the slope of the red line.
A possible solution would be to obtain the Appearance
setting of the red sliders and make the assignment of x
and y
contingent on the Appearance setting.
Answer
A simple way to do this is to change the Dynamic so that it updates only the points you want to be editable. Here is a very simple demonstration
pts = {{6, 0}, {0, 9}, {3, 0}, {0, 7}};
updatable = Range@Length@pts;
Button["Fixate point 3", (updatable = {1, 2, 4})]
LocatorPane[Dynamic[pts, (pts[[updatable]] = #[[updatable]]) &],
Dynamic@Graphics[Point /@ pts, PlotRange -> {{-10, 10}, {-10, 10}}]]
Comments
Post a Comment