4
$\begingroup$

I am trying to write a Demonstration, which I believe means I must write it as a Manipulate, not a DynamicModule. My question is essentially the same as "Dynamic lists as function arguments", but I cannot figure out how to get the answer given there to work inside a Manipulate.

Below is a minimal non-working example that indicates what I am trying to accomplish. Basically, I want to use a HorizontalGauge with a list of two values as a Control object in a manipulate. I first tried using an IntervalSlider, but I need to do some computing with the values of the interval's endpoints and as far as I can tell, the TrackingFunction option does not work with IntervalSlider. At least the function I provided never seemed to get called, whereas functions I provided to Slider the same way work fine.

h[Dynamic[point_], opt___] :=
 Dynamic[HorizontalGauge[Dynamic[point][[1]]]]

Manipulate[
 {pt},
 {{pt, {0.6, 0.7}}, 0, 1, (h[##]) &}
 ]

The above displays correctly, but does not allow me to move the markers. My intention for taking Part 1 of Dynamic[point] is to get past the Dynamic Head to the list itself. I've tried With[{point=pt},...] and many other arrangements of the Dynamic calls with no luck. I can't believe this fairly common task is so difficult, so I assume I'm missing something obvious.

$\endgroup$

2 Answers 2

2
$\begingroup$

In version 10.1 this sort of works, but the sliders are sticky; I have to click once to move them rather than click-and-drag. I recall having this problem before (with Slider, not HorizontalGauge) but I cannot recall the cause or solution. How does this behave in whatever version you are using?

ClearAll[h]
h[d_, opt___] := Dynamic[HorizontalGauge[d, opt]]

Manipulate[{pt}, {{pt, {0.6, 0.7}}, 0, 5, (h[##] &)}]
$\endgroup$
3
  • $\begingroup$ In version 12.0.0.0 on MacOS 10.13.6 I get what sounds like the same behavior. When I click in the gauge, the nearest marker moves to the position I clicked and the value of pt is updated. Dragging does nothing. Thanks, I can make this work in a pinch. Can you explain why the argument of h is not inside a Dynamic? Do you think it might be worth fiddling with mouse events to try getting click-and-drag to work? $\endgroup$ Commented Jan 8, 2020 at 1:11
  • $\begingroup$ Huh, this exhibits the same behavior, too: h[Dynamic[point_], opt___] := Dynamic[HorizontalGauge[Dynamic[point]]] I just hadn't tried clicking outside the markers. $\endgroup$ Commented Jan 8, 2020 at 1:32
  • $\begingroup$ @Stephen (1) According to the specification of Manipulate: "The form {u, umin, umax, func} can also be used; what is evaluated is then func[Dynamic[u], {umin, umax}]." Since it is already passed in a Dynamic head thought perhaps nesting a second one was a source of trouble. (2) I feel like this should just work and wondered if it was a version-specific bug. I don't know how to get it working, and the fact that you're trying to do this for a Demonstration adds restrictions that make alternatives difficult. $\endgroup$
    – Mr.Wizard
    Commented Jan 8, 2020 at 12:39
0
$\begingroup$

I couldn't get the HorizontalGauge to work and resorted to using IntervalSlider for this problem after fixing the bug in my TrackingFunction. (Or rather, stumbling across a TrackingFunction that worked.) In my opinion, there's something fishy about passing List arguments in Manipulate

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.