Documentation Request for setFixedAspectRatio() and setResizeLimit()


#1

Howdy. It’s not written in the documentation that if you setConstrainer(nullptr) that you’ll need to first call setResizeLimits() before you can call setFixedAspectRatio. I figured this out via some crashes in my program and looking at the code for ResizableWindow::setResizeLimits() that the constrainer is assigned to the defaultConstrainer if the current constrainer is nullptr.

SOOOOOOOO,

it would be nice if the documentation for setConstrainer included a comment along the lines of
"if you set this to nullptr and later need to setFixedAspectRatio or set some other constraints and don’t want to create your own ComponentBoundsConstrainer to enable constraining, you’ll need to call ResizableWindow::setResizeLimits() to assign the ResizableWindow::defaultConstrainer (which is private) as the current constrainer returned via ResizableWindow::getConstrainer(). only then will you be able to access a constrainer for your resizableWindow instance and can modify the constrainer parameters, like the aspect ratio or min/max sizes."

either that, or give us:

void ResizableWindow::restoreDefaultConstrainer() { setConstrainer(&defaultConstrainer); }

#2

How are you calling setFixedAspectRatio? This is a method of the ComponentBoundsConstrainer class? So you need to have obtained a pointer to this class by calling getConstrainer (on an AudioProcessorEditor or a Window class) or similar. If you set the constrainer to a nullptr via setConstrainer (nullptr) then of course you will get a crash if you then do getConstrainer()->setFixedAspectRatio().


#3

You missed my point @fabian . If we are using the default constrainer, then call setConstrainer(nullptr) for whatever reason, and then we want to re-enable constraining for our resizableWindow without creating our own componentBoundsConstrainer, we have to call setResizeLimits. It is not written in the documentation that THIS METHOD is how you reassign the default constrainer to be used by the resizableWindow. THAT is what I am requesting.

Please add “if you wish to re-enable the default constrainer to your resizableWindow after setting the current constrainer to nullptr, simply call resizableWindow:: setResizeLimits ()” to the documentation.


#4

was this ever added?


#5

No. I don’t think Fabian missed the point completely - if you call setConstrainer (nullptr) then you’ve explicitly opted out of using any constrainer. The fact that setResizeLimits enables the default constrainer in the absence of a previously set constrainer is more a side-effect than anything else.


#6

When I made this post, I spent a lot of time being stuck on that missing bit of knowledge. Chalk it up to not knowing how to read the original source to get answers when the documentation is lacking specifics for usage, but I think a lot of new users learning to use the Constrainer would benefit from adding that comment to the documentation.


#7

We’re still not seeing eye to eye. Calling setResizeLimits is not a good way to restore the default constrainer - you’d almost certainly need a comment in your code to say “this restores the default constrainer (which we previously set to nullptr) as a side effect” to remember what’s going on.

If you want to keep the default constrainer, do not call setConstrainer (nullptr).