Group Abstract Group Abstract

Message Boards Message Boards

Find which Locator is active in a Manipulate or LocatorPane?

Posted 8 years ago
POSTED BY: W. Craig Carter
2 Replies

Thank you Lou, TrackingFunction is very useful. For other readers, there is a small problem with Lou's code, but it was enough to get me started--so double thanks Lou. Here is some code adapted from the doc page on TrackingFunction

Manipulate[
 Row@{
     Dynamic@CurrentValue["CurrentLocatorPaneThumb"], 
        Graphics[Line[pts], PlotRange -> 2]
 },
{{pts, {{-1, -1}, {1, 1}}}, Locator, TrackingFunction -> 
   (If[ CurrentValue["CurrentLocatorPaneThumb"] === 1, 
        pts[[1]] = {#[[1, 1]],  pts[[1, 2]]},
        pts[[2]] = {pts[[2, 1]], #[[2, 2]]}] &)
 }

]

POSTED BY: W. Craig Carter

In LocatorPane, you can use CurrentValue["CurrentLocatorPaneThumb"] to get the index of the currently active thumb.

DynamicModule[{active = False, pts = {{1, 1}/2, {-1, 1}/2}},
 Row[
  {active,
   LocatorPane[
    Dynamic[pts,
     With[{t=CurrentValue["CurrentLocatorPaneThumb"]},
      If[t===1, pts[[1]]={0,1}*#[[1]], pts[[t]]=#[[t]]]
      ]&
     ],
    Graphics[{Yellow, Disk[{0, 2]},
     PlotRange -> 2
     ]
    ]
   }
  ]
 ]

There is an example of this in the documentation for TrackingFunction, which is the way Dynamic's second argument is exposed to users of Manipulate, but I'll look into adding it to the LocatorPane reference page too.

POSTED BY: Lou D'Andria
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard