Attached labels and resizing components


#1

Hi,

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?

Regards,
Cameron


#2

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!


#3

What a teaser! :wink:


#4

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!


#5

So… What a spoiler :?:


#6

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