//
//  buttonPanel.cpp
//  tweakathlon
//
//  Created by Robert Tubb on 11/02/2014.
//
//

#include "buttonPanel.h"
ButtonPanel::ButtonPanel(float ax,
                         float ay,
                         float awidth,
                         float aheight,
                         const UIProps& aprops,
                         vector<controllerType> elemList) :
UIElementContainer(ax,ay,awidth,aheight,aprops)
{
    //cout << "ButtonPanel auto layout contructor\n";
    
    generateControls(elemList);
    autoArrangeRow();
}
//---------------------------------------------------
ButtonPanel::ButtonPanel(float ax,
                         float ay,
                         float awidth,
                         float aheight,
                         const UIProps& aprops) :
UIElementContainer(ax,ay,awidth,aheight,aprops)
{
    //cout << "ButtonPanel - ctrls added later constructor\n";

}
//---------------------------------------------------
vector<UIElement*> ButtonPanel::generateControls(vector<controllerType> elemList){
    removeAllSubelements();
    vector<controllerType>::iterator i;
    
    // 10 cm is 520 pixels
    
    // calc positions
    int top  = y + myProps.spacerSize;
    
    int n=0;
    for(i=elemList.begin(); i<elemList.end();i++){
        if(*i == BUTTON){
            // add a slider
            Buttron * butt = new Buttron(0 , top , myProps.buttonWidth, myProps.buttonHeight,myProps);
            butt->setLabel("unassigned");
            subElements.push_back(butt);
            n++;

        }else{
            cout << "ERROR: button panel only handles buttons" << endl;
        }
    }
    return subElements;
}
