Attached labels and resizing components


I’m using JUCE v1.52.84, and StretchableLayoutManager to resize a couple of sliders with labels.

First, I realized while laying the components out by hand that the labels aren’t included in the components’ setBounds, so I had to leave some space for them.

However, now that I’m trying to use a StretchableLayoutManager to lay them out, the labels just get covered by adjacent components.

It’s so nice to be able to just attach a label to a component, but I would love for it to be considered when the component is resized by the layout manager.

Any suggestions on how this might be facilitated?


The future for this kind of thing will be by using markers instead - I’ll probably deprecate the StretchableLayoutManager class at some point (I’ve always hated that class…)

The new jucer will make it easy to set up markers, but all the code to create and use them manually is already available.

The way you can do it is by giving your parent class a MarkerList object (overriding Component::getMarkers() to return it). Then you’d create some named vertical markers for all the X positions that you want to move about. Then you can set the positions of your child components using Component::setBounds (const RelativeRectangle&), using expressions that involve the names of markers. Then, whenever you change the position of a marker, all the components whose positions are based on it will magically follow it. No need for any messing about in resized() or anything.

Since the positions of markers are expressions too, you can set up all kinds of complicated layouts, where some markers may depend on the position of other ones or the parent component, etc, and you can use min()/max() to limit their size.

Haven’t got time to explain it all in more detail, but hopefully that might have whetted your appetite!

What a teaser! :wink:

Well, not really, because all the functionality is already there for you to use, I’ve just not written any examples or docs on how to use it yet!

So… What a spoiler :?:

Yes… I guess “spoiler” is a better word for it!