rezaali/ofxUI — pull request #173 by mitchmindtree (2014-02-02 09:46:15+00:00)
Title: Added copy constructor and assignment operator for handling of heap allocation, added missing ofxUIDropDownList constructors, added ofxUIEnvelopeEditor

In relation to the issue with ofxUI's stack vs heap business - I've worked out a solution that allows a user to create a vector of ofxUICanvas that handles all of the heap allocated memory correctly (should also be able to make a vector of ofxUIWidgets, though I haven't personally tested this yet). I've done this by implementing copy constructors and assignment operators to correctly handle the heap allocation during the copying/assignment process. I've been using it in my node UI framework and it's working like a charm :-D
NOTE: if you want to do the following,

ofxUICanvas canvas;
int numOfSuperCanvases = 10;
vector superCanvases;
superCanvases.reserve(numOfSuperCanvases);
for (int i=0; i < numOfSuperCanvases; i++) {
superCanvases.push_back(ofxUISuperCanvas(constructorStuff));
canvas.addWidgetDown(&superCanvases.at(i));
}

remember that your program will try to delete the vector of ofxUISuperCanvases twice (Once when being destructed on the stack, and again in "canvas'" explicit destructor). To get around this, I've added a method -

ofxUICanvas::clearWidgets();

which just clears each of the vectors of ofxUIWidget*'s (without freeing the memory) to ensure that ofxUICanvas doesn't try to free their memory a second time. So, make sure that you call this method in the destructor of the class that you're instantiating your ofxUICanvas in, like so -

~MyClass() {
canvas.clearEmbeddedWidgets();
canvas.clearWidgets();
}

Also, I've filled in a few constructors that were missing for the ofxUIDropDownList.

And finally, I've changed the ofxUIEnvelopeEditor over to the new .h / .cpp format. There's a few things in it that need some polishing/tweaking but it is certainly usable as is! [Here's an older video of my current project, in which you can see an example of the ofxUIEnvelopeEditor](https://www.youtube.com/watch?v=BK0f3CicNR4). In this example I'm using it to control the amplitude and frequency of oscillators within a basic audio synth (but you can't hear it sorry).

Anyway, hopefully someone else finds all of this as handy as I do! Thanks again for the awesome addon Reza :-)