I'm trying to use Dynamic
and If
inside Manipulate
to alternate controls depending on a check box control. For example,
Manipulate[a,
Control[{{a, 0}, {0, 1}}],
Dynamic[If[a == 0, Control[{{abc, 0}, {0, 1}}], Control[{{abcdef, 0}, {0, 1}}]]],
ControlPlacement -> Left]
Which gives
and
However, I would like both check boxes to automatic align whenever a
is selected or not, as happens in the default case
Manipulate[a,
Control[{{a, 0}, {0, 1}}],
Control[{{abc, 0}, {0, 1}}],
Control[{{abcdef, 0}, {0, 1}}],
ControlPlacement -> Left]
Giving
The same thing happens if I use other control types, such as sliders. Any idea how to fix this?
Edit 1: In the check box case, the answer was already provided by user chuy, below. I am, however, also interested in the case where I have both sliders and boxes. Following the answer, I could write
Manipulate[a,
Column[{Control[{a, 0, 1, 0.1}],
Dynamic[If[a < 1, Control[{{abc, 0}, {0, 1}}],
Control[{{abcdef, 0}, {0, 1}}]]]}, Alignment -> Right],
ControlPlacement -> Left]
which gives
This is already pretty good, but I wonder if it's possible to get an alignment as in the following case
Manipulate[a, Control[{a, 0, 1, 0.1}], Control[{{abc, 0}, {0, 1}}],
ControlPlacement -> Left]
that is,
together, again, with Dynamic
and If
. In this case, the solution provided doesn't seem to work, even with Alignment
set to Center
or Right
. I can probably play around with Spacer
and Row
to get what I want, but is there any shorter solution?
Edit 2: Regarding spacing, as discussed in the comment section of m_goldberg's answer, I have, for example and considering an extra slider after the check box,
Manipulate[a,
Dynamic@Grid[{{"a", Control[{{a, 0, ""}, 0, 1, 0.1}]},
If[a < 1, {"abc", Control[{{abc, 0, ""}, {0, 1}}]}, {"",
SpanFromLeft}], {"b", Control[{{b, 0, ""}, 0, 1, 0.1}]}},
Alignment -> {{Right, Left}, Automatic}], ControlPlacement -> Left]
that is,
When a=1
, we get
There is clearly some spacing between the sliders due to {"", SpanFromLeft}
, which I want to avoid. My goal is to get the natural spacing, as seen in
Manipulate[a,
Dynamic@Grid[{{"a", Control[{{a, 1, ""}, 0, 1, 0.1}]}, {"b",
Control[{{b, 0, ""}, 0, 1, 0.1}]}},
Alignment -> {{Right, Left}, Automatic}], ControlPlacement -> Left]
that is,
Any ideas?
Note: I recognise I might be deviating a bit from the original question (which was already answered with different approaches), so I will stop editing it after I solve this last problem. Either way, thanks for all the answers!