Consider the following code
Manipulate[a,
Dynamic@Grid[{
{"Slider", Control[{{a, 0, ""}, 0, 1, .1}]},
{"Checkbox", Control[{{b, 1, ""}, {1, 0}}]}
}, Alignment -> {{Right, Left}, Automatic}],
Delimiter,
Button["Button 1"],
Button["Button 2"],
ControlPlacement -> Left]
which gives
Now, if we were to include an If
statement for one of the buttons, we would need to use Dynamic
. For example, we could use
Manipulate[a,
Dynamic@Grid[{
{"Slider", Control[{{a, 0, ""}, 0, 1, .1}]},
{"Checkbox", Control[{{b, 1, ""}, {1, 0}}]}
}, Alignment -> {{Right, Left}, Automatic}],
Delimiter,
Button["Button 1"],
Dynamic[If[a == 0, Button["Button 2"], Button["Button 3"]]],
ControlPlacement -> Left]
which yields
As one can see, the button alignment changes when I do this. I want to fix this, to keep the same appearance as in the first example. One attempt at trying to solve this was to consider a Dynamic@Grid
. That is,
Manipulate[a,
Dynamic@Grid[{
{"Slider", Control[{{a, 0, ""}, 0, 1, .1}]},
{"Checkbox", Control[{{b, 1, ""}, {1, 0}}]}
}, Alignment -> {{Right, Left}, Automatic}],
Delimiter,
Dynamic@Grid[{
{Button["Button 1"]},
If[a == 0, {Button["Button 2"]}, {Button["Button 3"]}]
}],
ControlPlacement -> Left]
This, however, makes it a bit worse:
I could change the ItemSize
within the Grid
to get something similar to what I want, but I would have to do it manually. For instance,
Manipulate[a,
Dynamic@Grid[{
{"Slider", Control[{{a, 0, ""}, 0, 1, .1}]},
{"Checkbox", Control[{{b, 1, ""}, {1, 0}}]}
}, Alignment -> {{Right, Left}, Automatic}],
Delimiter,
Dynamic@Grid[{
{Button["Button 1"]},
If[a == 0, {Button["Button 2"]}, {Button["Button 3"]}]
}, ItemSize -> 30],
ControlPlacement -> Left]
leads to
Still, the alignment with the slider is not perfect, and I'd have to manually adjust it. I wonder if it's possible to do this in a more "automatic" way, without relying on manually fixing the ItemSize
. I could include all controls in a Grid
, but the problem with that is that the Delimiter
doesn't seem to format if I use a Grid
, and I want to keep it in my Manipulate
. Any ideas how to solve this?
Furthermore, how would I deal with the case
Manipulate[a,
Dynamic@Grid[{
{"Slider", Control[{{a, 0, ""}, 0, 1, .1}]},
{"Checkbox", Control[{{b, 1, ""}, {1, 0}}]}
}, Alignment -> {{Right, Left}, Automatic}],
Delimiter,
Dynamic@Column[{
{Button["Button 1"], Button["Button 2"]} // Row,
{Button["Button 3"], Button["Button 4"]} // Row
}, ItemSize -> 15],
ControlPlacement -> Left]
that is,
Any suggestions are appreciated.