Adjusting AudioDeviceSelectorComponent height to include all its controls


#1

When the user interacts with an AudioDeviceSelectorComponent, it may happen that controls for devices with large number of inputs/outputs/midi fall well under the bottom margin of the AudioDeviceSelectorComponent's initial bounds, effectively making those controls unreachable.

It seems to me that there is no place where the height of the component gets updated accordingly, what do you think about adding a setSize() at the end of the AudioDeviceSelectorComponent::updateAllControls() method that sets the height so that all the controls are visible?

 


#2

On a second thought, I imagine that setting the size on all updates may not suit the needs of all developers and would also change the current behaviour, so here is a more reasonable proposal:

1) add a AudioDeviceSelectorComponent::getTotalContentHeight() that returns the height that would be needed to show all the contained component (the returned value could be implemented as a member updated upon each resized() call)

2) add an empty virtual callback that gets called every time such total height changes, or at the end of each updateAllControls() call

This way, developers that want to adjust the AudioDeviceSelectorComponent height to fit all controls, can subclass it and implement the virtual call to update the component's size accordingly using the value returned by getTotalContentHeight()

This is a very general approach that will allow users to customize the desired behaviour upon layout changes. Another quick-and-dirty solution could be to add a boolan settable member (false by default to retain current behaviour) that decides whether to adjust or not the height of the component to fit the total height of its content


#3

Surely you could implement this without doing anything specific to the AudioDeviceSelector class? A simple ComponentListener could watch the component for changes to its children, and then to resize the parent to fit them.


#4

Yes, I could follow the ComponentListener route, but that's quite far from the "Very easy to use - just create one of these and show it to the user." description that comes with the AudioDeviceSelectorComponent in the documentation.

I thought that my addition would have been in the direction of making it even easier to use for both developers and users. I don't think I'm the only one that would find this change convenient.

Using a ComponentListener means having to loop inside the selector's children every time I detect a change in their layout, only to find the bottomest coordinate of their bounds. This sounds silly to me as that same information gets calculated as the 'y' value at the end of each resized() method.

Storing that value in a member of the class and making it accessible with the getContentTotalHeight() method shouldn't be a lot of work on your side and will save a lot of it on ours. Plus, it will make the AudioDeviceSelectorComponent more similar to the PropertyPanel component, meaning that even the Selector is somehow a panel where you can change properties, containing a set of controls having a variable height.