Consider the following
Manipulate[a,
Dynamic@Grid[{
{"Control 1", Control[{{a, 0, ""}, {1, 0}}]},
If[a == 1, {"Subcontrol 1", Control[{{aa, 0, ""}, {1, 0}}]},
Unevaluated[Sequence[]]],
{"Control 2", Control[{{b, 0, ""}, {1, 0}}]}
},
Spacings -> {Automatic, {2 -> 1}},
Dividers -> {False, {2 -> Manipulate`Dump`$delimitercolor}},
Alignment -> {{Right, Left}, Automatic}],
ControlPlacement -> Left]
My goal is to include a dynamic delimiter between the two controls. Since Delimiter doesn't seem to work within a Grid, an alternative is to use Spacings and Dividers with the right colouring, as previously discussed here.
This solution, however, doesn't account for possible dynamic changes in the Control section. For example, if Control 1 is checked, we get
As one can see, the divider doesn't change position. A solution would be to make the slight change
Spacings -> {Automatic, {2 + a -> 1}},
Dividers -> {False, {2 + a -> Manipulate`Dump`$delimitercolor}}
In this manner, the spacings and dividers change accordingly to Control 1 and I get what I want
However, my code has a great amount of controls of all type, all interconnected and conditioned by Ifs. This would yield a more complex and long manipulation of both Spacings and Dividers. I'm afraid this might slow down the Manipulate interactivity and I feel there must be an easier solution to divider (or delimiter, in my case) positioning.
For example, Spacings could be reasonably replaced by something like {"",""} or {Spacer[x],Spacer[x]} in the Control section. Since I want to keep the Grid layout, getting the right Delimiter look seems somewhat trickier without Dividers.
Any ideas?
Answer
In the meantime, I believe I have found an answer. Might not be the best one, but I'm sharing it anyway.
One thing we could do is to track the position of the specific section I want to delimit. One can do that using Position. In my case, I want to track Control 2. Thus, defining the Grid as grid and Control 2 as ctr2, the following code does what I want
Manipulate[a,
Dynamic@Grid[gri = {
{"Control 1", Control[{{a, 0, ""}, {1, 0}}]},
If[a == 1, {"Subcontrol 1", Control[{{aa, 0, ""}, {1, 0}}]},
Unevaluated[Sequence[]]],
ctr2 = {"Control 2", Control[{{b, 0, ""}, {1, 0}}]}
},
Spacings -> {Automatic, {Position[gri, ctr2][[1, 1]] -> 1}},
Dividers -> {False, {Position[gri, ctr2][[1, 1]] ->
Manipulate`Dump`$delimitercolor}},
Alignment -> {{Right, Left}, Automatic}],
ControlPlacement -> Left]
Any improvements/suggestions are welcome.




Comments
Post a Comment