Attempting to implement @Nasser's answer for How to avoid an expensive subset of a Manipulate computation when dependent variables have not changed?, using a Manipulate
that includes a TabView
, I wrote the following
Manipulate[tick;
TabView[{
"not continuous slider: b" -> Grid[{
{"b",
Manipulator[
Dynamic[b, {activeTab = 1 ; b = #; f = preCalculateStuff[b];
tick = Not[tick]} &], {0, 1, 0.01},
ContinuousAction -> False], Dynamic[b]}}]
, "Plot; continous slider: t" -> Grid[{
{"t",
Manipulator[
Dynamic[t, {activeTab = 2 ; t = #; tick = Not[tick]} &], {0,
1, 0.01}], Dynamic[t]},
{Row[{"f=", f, " b=", b, " t=", t}]},
{Plot[(f t) Sin[t + r], {r, 0, 2 Pi}, ImagePadding -> 30,
ImageSize -> 400, Frame -> True]}
}, Spacings -> {.5, .5}]
}, activeTab, Alignment -> Center]
, {{tick, False}, None}
, {{b, .4}, None}
, {{t, .7}, None}
, {{f, .5*.4}, None}
, {{activeTab, 1}, None}
, TrackedSymbols :> {tick}
, Initialization :> (preCalculateStuff[b_] :=
Module[{},(*heavy computation goes here*)0.5 b])]
This displays fine:
I had an issue with TabView
resetting to the first Tab after any Manipulator change, but solved that by adding the activeTab variable.
Without a TabView
(i.e. just a Grid
) this works fine, but when I use the TabView
:
- the slider that does not include
ContinuousAction -> False
will only slide by a small amount at a time. - either slider automatically goes into "Pause" state if the
Play
arrow of the control is used.
Nasser's sample that uses Grid
handles Play without this pausing issue, so I'm thinking that the trouble is with something like a temporary change of Tab focus happening somewhere under the covers.
EDIT: Note that one of my end goals was to have a fairly large set of control variables all in one tab (ones associated with preCalculateStuff), without cluttering up the rest. This is attempt to conform to the size restrictions imposed on wolfram demonstrations submissions.
Here's an example of a TabView with the Manipulates distributed between them. This works fine, but doesn't use the Tick method that allows the change of the variables to act as callbacks as in Nasser's code:
Manipulate[
pts1 = p;
pltrng = {{-1, 1}, {-1, 1}};
pnts = LocatorPane[ Dynamic[p, {(pts1 = p; p = #) &, (p = #) &}],
Dynamic@Graphics[Point[p], PlotRange -> pltrng], LocatorAutoCreate -> True ];
slider = Grid[{ { "q", Manipulator[ Dynamic[q, {q = #} &] , {0, 1, 0.01} ], Dynamic[q] },
{ "r", Manipulator[ Dynamic[r, {r = #} &] , {0, 1, 0.01} , ContinuousAction -> False ], Dynamic[r] } }] ;
tbl = Dynamic[ Grid[ { { (Table[
With[{i = i}, {i, Dynamic[pts1[[i]]]}], {i, Length@pts1}] // TableForm) , Dynamic[q] } } ]];
ln = Dynamic@Graphics[{Red, Thick, Line[pts1]}, PlotRange -> pltrng];
TabView[{ "table" -> tbl , "locators" -> pnts , "line" -> ln , "slider" -> slider }, Alignment -> Center]
, {{p, {{-.5, -0.5}, {-.25, .5}, {.6, 0.6}}}, None}
, {{q, 0.5}, None}
, {{r, 0.5}, None}
]
(This is based on: https://mathematica.stackexchange.com/a/5515/10)
Note that one of my end goals was to have a fairly large set of control variables all in one tab (ones associated with preCalculateStuff), without cluttering up the rest.
you can definitely do that. Here is demo with multiple tabs, each tab has in it many more controls that show up when selected. This is allow more controls to be put on the same screen area. demonstrations.wolfram.com/… This has three layers to have even more controls demonstrations.wolfram.com/… $\endgroup$