ResizableWindow::setSizeConstrained() ?


#1

I would love a function ResizableWindow::setSizeConstrained() that called resizeStart() / resizeEnd() on the attached ComponentBoundsConstrainer, and applied the relevant limits to the passed in bounds.

The reason is that I have built a hierarchy of resizable Component objects that each individually know their own minimum/maximum sizes. My main application window has user-configurable panels, so when the app first comes up I want to basically do setSizeConstrained (0, 0) so that the window gets compacted down to its minimum size, without knowing in advance what that size is (because I don’t know without going through my ComponentBoundsConstrainer-derived class hierarchy).


#2

Obviously I could write this myself and use it in my own subclass…and here it is. Just saying, its a handy function.

[code]void ResizableWindow::setSizeConstrained (int width, int height)
{
ComponentBoundsConstrainer* constrainer = getConstrainer();
constrainer->resizeStart ();
constrainer->resizeEnd ();

width = jlimit (constrainer->getMinimumWidth(),
constrainer->getMaximumWidth(),
width);

height = jlimit (constrainer->getMinimumHeight(),
constrainer->getMaximumHeight(),
height);

setSize (width, height);
}[/code]