Layout Question - stacking views

If I want a vertical column of views, with them all laid out one after the other, what’s the easiest way to do that? Simply add each one and call MoveBy to position it based on the Bounds() of the last child in the list already?

Started with a BGroupLayout but of course that stretches things, I want views all stacked and contained within a scroll view should they get too tall for the container.

So then add a spacer to the end of the layout, to compress them down to the minimum size?

You should be able to just make a GroupView the target of a ScrollView and it should all work out from there.

Use a vertical BGroupLayout and then AddGlue() at the end to prevent stretching. AddGlue() does the opposite of what its name implies. It should be called AddSpring() but I digress. The point is that AddGlue() is what you are looking for.

1 Like

I had tried a spacer but it could squash the text views I was using. I’m now using a BStringView per line (which is fine because this is for pre-formatted content though I may play some more) and the adding in a glue element worked perfectly with those.

Appreciate the input both!

Alternatively,if you prefer working with BTextView,you could ->SetExplicitMinSize() on your BTextView to make sure it doesn’t get too small.

I strongly agree that AddGlue() is misnamed.

Agree, it feels like Spring is a mutch better fit so that it gives the idea of expanding to fill the space. I didn’t see the information on glue or struts at all until I went looking through after reading jscipione’s post.

in addition to support for BBox this kind of stuff could be added, I don’t see why we can’t have an .AddSpring() alias to .AddGlue :slight_smile:

You mean, in a better way than #define AddSpring AddGlue ?

:face_with_peeking_eye:

1 Like

In Swing it’s called glue as well; it seems to originate in TeX. Qt calls it a spacer, and the method addStretch().