i have 20 Labels (called for testing label1, label2… label20).
And i want to access these Labels by numbers.
As idea in a For-Loop, to write for every Label the name “MYLABEL”, instead of calling each label one by one in a line of code and set the name.
My idea is to do it in an OwnedArray of Labels. Could that work?
As i understood OwnedArrays, i can make an Array of Pointers, each Pointer points to a Specific label.
For example could i:
myOwnedArray[5].setName(“MYLABEL”);
and that would change the name of Label 6 to the given String?
OwnedArray<Label> labels;
for (auto i = 0; i < 20; ++i)
labels.add(new Label({}, "Label Number " + String(i)));
for (auto * label: labels)
addAndMakeVisible(label);
Awesome!!!
Just needed such an example to understand the working of the OwnedArray. Documentation has no real Examples, and i am very new to c++ and Juce, so examples help me alot!!
thought i need to create first 20 Labels.
And then add pointers to each of them from the array.
Thanks, gonna get back here if i stuck on further operations!!
It just saves one variable. But your version is surely easier to understand. And I am pretty sure, the produced binary will be identical.
Plus your first example shows nicely the new way how to iterate a container…
Just posted it as a gimmick…