({{, (RefLink[TrackingFunction, paclet:ref/TrackingFunction]) 
is an option for (RefLink[Manipulate, paclet:ref/Manipulate]) controls that specifies functions to use during interactive changing or editing.}})

OpenersNotesSection(Spacer1)Details

(RefLink[TrackingFunction, paclet:ref/TrackingFunction]) gives access to the second argument of (RefLink[Dynamic, paclet:ref/Dynamic]) in the underlying control.

The (RefLink[Manipulate, paclet:ref/Manipulate]) argument {u,…,TrackingFunction->f} represents a control that continually evaluates f[val,u] during interactive changing or editing of val.

The default setting of (RefLink[TrackingFunction, paclet:ref/TrackingFunction]) is equivalent to (u=#)&.

(RefLink[TrackingFunction, paclet:ref/TrackingFunction]) can be set to a function or a list of up to three functions.

For interactive mouse operations, (RefLink[TrackingFunction, paclet:ref/TrackingFunction])->{fstart,f,fend} typically evaluates fstart[val,u] once when the mouse is pressed, then evaluates f[val,u] whenever the mouse is moved, and then evaluates fend[val,u] once the mouse is released.

OpenersPrimaryExamplesSection(Spacer1)Examples  (3)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

(RefLink[TrackingFunction, paclet:ref/TrackingFunction]) can be used to set more than one variable at a time:

Manipulate[{x,y},{x,0,1,TrackingFunction->(x=#;y=(1-#);&)},{y,0,1}]

(RefLink[TrackingFunction, paclet:ref/TrackingFunction]) can be used to enforce restrictions on a control:

Manipulate[x,{{x,2},0,100,1,TrackingFunction->(If[PrimeQ[#],x=#]&)}]

Two-dimensional controls like (RefLink[Locator, paclet:ref/Locator]) can be restricted to regions:

Manipulate[Graphics[Circle[],PlotRange ->2],{{pt,{0,0}},Locator,TrackingFunction->(pt=#/Max[Norm[#],1];&)}]

(RefLink[Locator, paclet:ref/Locator]) tracking functions can make use of (RefLink[CurrentValue, paclet:ref/CurrentValue])["CurrentLocatorPaneThumb"] to enforce different restrictions on different points:

Manipulate[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]]}]&)}]

OpenersExampleSection2(Spacer1)Possible Issues  (1)

The (RefLink[TrackingFunction, paclet:ref/TrackingFunction]) is only active when interacting with the control. Changing the variable in other ways will not pass through the (RefLink[TrackingFunction, paclet:ref/TrackingFunction]):

Manipulate[x,{{x,2},0,100,1,TrackingFunction->(If[PrimeQ[#],x=#]&)},Button["+1",x++]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Manipulate, paclet:ref/Manipulate])  ▪  (RefLink[Control, paclet:ref/Control])  ▪  (RefLink[Dynamic, paclet:ref/Dynamic])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Options & Styling for Interactive Manipulation, paclet:guide/OptionsAndStylingForInteractiveManipulation])}})}})