1
$\begingroup$

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]

enter image description here

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

enter image description here

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

enter image description here

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?

$\endgroup$
4
  • $\begingroup$ Do the controls HAVE to appear and disappear? Wouldn't it be preferable to simply have them there all the time in an inactive state, only to be activated when the corresponding master control is active? That would also seem to be better UI design as well; I for one hate to hunt around for moving buttons in user interfaces. $\endgroup$
    – MarcoB
    Jan 6, 2020 at 17:17
  • $\begingroup$ The problem is that there are too many controls in my program, thus some of them expand or collapse sections. It's not ideal, but having all at all times would yield a huge interface, and I want to keep it as clean as possible. I don't like moving buttons/sections constantly as well, but do you have suggestions for better/alternative expanding/collapsing designs? $\endgroup$
    – sam wolfe
    Jan 6, 2020 at 18:02
  • $\begingroup$ Sam, Why not just have them become inactive with a tooltip that describes how to get them to activate? Or some design of that sort, where you could click the inactive box and have other boxes become highlighted or indicated that would be potential combinations to activate the aforementioned clicked inactive box? $\endgroup$ Jan 8, 2020 at 6:23
  • $\begingroup$ @CATrevillian That would be great too. I'm actually tempted to change my main code to that, and avoid the many If expressions I'm using. Do you have any suggestions on how to do that? Anyway, I believe I have found a solution for this specific problem, I posted it as an answer. $\endgroup$
    – sam wolfe
    Jan 8, 2020 at 17:02

1 Answer 1

0
$\begingroup$

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]

enter image description here

Any improvements/suggestions are welcome.

$\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.