1
$\begingroup$

Imagine I have a dynamic opener that changes the number of rows. For example,

opg = True;
Dynamic@Grid[{
   {Item[Row@{"Show slider ", Opener[Dynamic[opg]]}, 
     Alignment -> Center], SpanFromLeft},
   If[opg, {"Slider 1", Slider[1]}, Nothing]
   }, Frame -> All, ItemSize -> {{10, 10}}]

enter image description here

As you can see, whenever I click on the opener, the grid changes size to some default automatic size. Is it possible to keep the grid size based on the maximum default size its items can have? That is, I want the following behaviour

enter image description here

Using ItemSize I can get something pretty decent, but not quite what I'm asking

Dynamic@Grid[{
   {Item[Row@{"Show slider ", Opener[Dynamic[opg]]}, 
     Alignment -> Center], SpanFromLeft},
   If[opg, {"Slider 1", Slider[1]}, Nothing]
   }, Frame -> All, ItemSize -> {{15, 15}}]

enter image description here

However, I'd like to keep it automatic everywhere apart from the "Show slider" item, to avoid weird spacing in the other items. How would you do it?.

Two small notes:

  • Notice that the opener size changes based on the grid automatic resizing: enter image description here

  • The slider default size is not adjusted with ItemSize, if this is too small, the slider gets partially hidden:

enter image description here

$\endgroup$
3
  • $\begingroup$ Based on the last time I've looked into something like this, I don't think there is a clean way to do this. The issue with Grid is that there is no way (as far as I am aware) to have a "zero-height" row where you could hide the size-giving elements. So the only other option is to precompute (via Rasterize) the width of the columns, or to hide the elements in the header (which might actually work). One question is of course: Does it need to be Grid, or would something that looks similar also work? $\endgroup$
    – Lukas Lang
    Jul 8, 2021 at 12:58
  • $\begingroup$ Odd, I don't see this behavior in 12.3.1.0 running on macOS. The Grid stays the same width on my machine. $\endgroup$
    – Jagra
    Jul 8, 2021 at 13:29
  • $\begingroup$ @LukasLang what alternative to Grid were you thinking of? I guess it could also work, as long as it's list-based. $\endgroup$
    – sam wolfe
    Jul 8, 2021 at 13:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.