Hey All,
I am trying to get a ListBox component going, but I can’t seem to get it to display. My list uses custom components in rows. Here is the code:
class LayerList : public Component,
public ListBoxModel
{
private:
ListBox* list;
Composition* composition;
int numRows;
public:
LayerList(Composition* c);
int getNumRows();
void paintListBoxItem(int rowNumber, Graphics &g, int width, int height, bool rowIsSelected);
Component* refreshComponentForRow (int rowNumber, bool isRowSelected, Component* existingComponentToUpdate);
};
LayerList::LayerList(Composition* c) {
composition = c;
list = new ListBox(T("Layers List"), this);
addAndMakeVisible(list);
//list->updateContent();
list->setMinimumContentWidth(260);
list->setRowHeight(50);
DBG("visible content width " + (String)list->getVisibleContentWidth()); //this returns 0... why?
}
int LayerList::getNumRows() {
return composition->getNumLayers();
}
void LayerList::paintListBoxItem(int rowNumber, Graphics &g, int width, int height, bool rowIsSelected) {
DBG("IN PAINT LIST BOX ITEM"); //this method never seems to get called
}
Component* LayerList::refreshComponentForRow (int rowNumber, bool isRowSelected, Component* existingComponentToUpdate) {
if(getNumRows() > 0) { //don't know if this check is really necessary
LayerLabelComponent* labelComp = (LayerLabelComponent*) existingComponentToUpdate; //my custom component
if(labelComp == 0) {
DBG("ADDED A LABEL COMP");
labelComp = new LayerLabelComponent();
}
DBG("UPDATED A LABEL COMP");
labelComp->setName(composition->getLayer(rowNumber)->getName());
DBG( (String)(composition->getLayer(rowNumber)->getName()));
list->repaintRow(rowNumber);
return labelComp;
} else {
jassert (existingComponentToUpdate == 0);
return 0;
}
}
My class LayerList gets added to a DocumentWindow as its content component somewhere further up the food chain. Anything that is glaringly wrong with the way I am doing things?
If I add a component to the LayerList, say a Button in the constructor (or my custom LayerLabelComponent), it will show up in my window, so it isn’t the way I am adding the component to the window.
Any help appreciated, and thanks.
c.