Hi, I’m using an AudioDeviceSelectorComponent for obvious reasons but it would be nice if I had some way of knowing how much space it needs to display all of its controls especially as these disappear/reappear depending on the device selected. As far as I can see there are two ways (possibly 3) ways of doing this.
The first is how I currently have it and is the ‘quick and dirty’ method by simply letting the component control its own size by calling something like this at the end of resized()
[code] if (midiOutputSelector != nullptr)
midiOutputSelector->setBounds (lx, y, w, h);
y += h + space;
This means we can just call selectorComp.setBounds(x, y, w, selectorComp.getHeight()); in our own resized method. However I can see how this could break other peoples code (and probably some of my own) so probably not a good idea for the library.
Another possibility is to keep a member variable which is updated inside resized called something like “minHeightRequiredToDisplayAllComponents” and provide a accessor for it. Then we would need some callback to tell us that the size has changed so we could respond accordingly.
Now, during writing this I realised that we can register with the AudioDeviceManager’s ChangeBroadcaster to be informed when a device changes but the problem then is that our own callback gets called before the AudioDeviceSelectorComponent’s so it doesn’t have a chance to update its size. This can be worked around by inheriting from AsycUpdater and triggering an async update during the change callback and repainting during the handleAsyncUpdate callback to make sure the AudioDeviceSelectorComponent has a chance to update its size. As you can probably tell, long winded.
A better solution would be for the AudioDeviceSelectorComponent to either directly inherit from changeBroadcaster and emit change messages when its size changes or for it to implement its own listener interface like so many other (admittedly more generic) UI widgets.
What do you think? Has anyone else implemented a possibly more elegant solution? I’m open to ideas.