Simple label properties: how to set?

With all the utility of openFrameworks, power of openGL, and expert contributions (ofxGUI, ofxUI) I have yet to find an example or tutorial on this:
Set the location, size, color, text of a simple, explanatory label. No interaction; no event-triggered callbacks. Just a short string which could be modified each update/draw cycle.
I am not alone: How to change the color of text of a Label Button in ofxUI?

In advance, thanks for your thoughts.


create a canvas for example “canvas”
then add a label

canvas->addLabel("labelName", "Your text here");

when you need to update the label text

ofxUILabel *label = (ofxUILabel *)canvas->getWidget("labelName");
label->setLabel("new text here");

Oh, yes!
I was stumped last night on how to access the named label that had been created by the addLabel() function. I was unable to spot the getWidget() tool and probably wouldn’t have recognized its usefulness anyway.
Many thanks SMarty.

Or you can avoid the getWidget() by declaring a class member to handle the label.
In .h:

ofxUILabel *label;

Assign it somewhere in .cpp:

label = canvas->addLabel("labelName", "Your text here");

And later, in update

label->setLabel("new text here");

lilive: thanks for this tip.
I had a vague thought about your approach but didn’t see the mechanism that makes it work: the pointer to ofxUILabel returned by addLabel doesn’t get “swallowed up” by canvas but exists as an rvalue to be passed to the label variable.