Making components graphics without introjucer? what is the juce way of doing this? std::vector?

I would like to add several buttons to my project, but i don't know how many! so i don't want to define them in introjucer.

i tried in my window component constructor to add this, but the i can't see anything on the screen. Am i missing something? can you gimme some hints on  the best way to do this? any example i could look for? what is the juce way of doing this? is it with vectors?

should i pre make the components vs run time making them makes a huge deal on cpu?

I came from scripting languages, so any help to understand this and subjacent concepts would be really appreciated.

 

-------- begin -----

    std::vector<ImageButton*>::iterator myPadsIterator;
    std::vector<ImageButton*> myPads;
   
    myPads.push_back(new ImageButton ("new button"));
    myPads.push_back(new ImageButton ("new button"));
    myPads.push_back(new ImageButton ("new button"));
    
    for(myPadsIterator=myPads.begin(); myPadsIterator != myPads.end(); myPadsIterator++) {
        
        addAndMakeVisible (*myPadsIterator);
        (*myPadsIterator)->addListener (this);
        
        (*myPadsIterator)->setImages (false, true, true,
                            ImageCache::getFromMemory (pad_notlit_png, pad_notlit_pngSize), 0.932f, Colour (0x00ffffff),
                            Image(), 1.000f, Colour (0x00000000),
                            ImageCache::getFromMemory (pad_lit_png, pad_lit_pngSize), 1.000f, Colour (0x00000000));
        
    }     

-------- end -----

 

 

 

 

 

Personally I'd use an OwnedArray instead of std::vector<class*>.

 

As for the visibility of your objects, you appear to be making all your icons transparent.  Also, are you ever giving them a size and position?  

...also, code style:

//Comments
int thisIsCode = 0;

Thank you! it helped me :)

Now leads me to this question: is the OwnedArray the equivelent injuce  for std::Vector?

other thing: in terms of performance CPU and Memory it's better to create buttons on runtime or like using the Introjucer to create them?

Which should be my best decision for 32 / 100 /2000 buttons? do them in introjucer or do them in runtime?

I am trying to get some concepts which i still don't know. Thank you in advance for any help

 

 

 

 

There won't be any performance difference, as the Introjucer just generates C++ code.

nice,  makes sense. =) thank you

I would say it's always best to generate objects dynamically if you don't know on startup how many you will need. Creating 1000s of object and only using as many of them as the user wants is not such a great approach. OwnedArray works like a standard vector more or less. It may even have some extra functionality :) 

Now leads me to this question: is the OwnedArray the equivelent injuce  for std::Vector?

JUCE has two array classes.  Array and OwnedArray.  Array is closer in behaviour to std::vector<>.

 

Read: http://www.parashift.com/c++-faq-lite/container-of-smart-ptr.html which gives a good overview of the risks involved in using a vector to store object pointers, and touches on why creating a vector of class type is not always possible or desirable.

tl;dr: std::vector<Component> will not behave well for a multitude of reasons, and std::vector<Component*> risks leaking component instances.  OwnedArray<Component*> side-steps those issues.