Beispiel #1
0
void Container::update()
{
    if(needsWidgetResize) //If a resize is needed, resize/update all contained widgets
    {
        containerView.reset(sf::FloatRect(getPosition().x, getPosition().y, getSize().x, getSize().y));
        scrollBar->setYOffset(0.f);
        needsWidgetResize = false;
        for(unsigned int a = 0; a < widgets.size(); a++)
        {
            if(widgets[a])
            {
                //Update widget's data
                widgets[a]->recalculateBezel();
                widgets[a]->centerText();
            }
        }
        //Reposition/Rezise the widgets to fit properly
        repositionWidgets();
    }


    //Pass update call to sub-widgets
    for(auto iter = widgets.rbegin(); iter != widgets.rend(); iter++)
    {
        if((*iter)->isEnabled())
        {
            (*iter)->update();
        }
    }
    scrollBar->update();
}
Beispiel #2
0
void Container::allowAutomaticResizing(bool shouldAllow)
{
    if(allowAutoResizing != shouldAllow) //Only if current allocation is different from given
    {
        allowAutoResizing = shouldAllow;
        repositionWidgets();
    }
}
Beispiel #3
0
void Container::setAllocation(const Allocation& alloc)
{
    if(allocation != alloc) //Only update if the given allocation is different to the new one. No point in repositioning widgets otherwise.
    {
        allocation = alloc;
        repositionWidgets(); //Reposition widgets to fit new allocation
    }
}
void Container::removeWidget(ofPtr<Widget> widget){
	for(int i=0; i<(int)widgets.size(); i++){
		if(widgets[i] == widget){
			widget->disableEvents();
			widgets.erase(widgets.begin()+i);
			repositionWidgets();
			return;
		}
	}
}
void Container::removeDrawable(ofPtr<ofBaseDraws> drawable){
	for(int i=0; i<(int)widgets.size(); i++){
		std::tr1::shared_ptr<DrawableContainer> drw = std::tr1::dynamic_pointer_cast<DrawableContainer >(widgets[i]);
		if(drw && drw->getDrawable()==drawable){
			drw->disableEvents();
			widgets.erase(widgets.begin()+i);
			repositionWidgets();
			return;
		}
	}
}
Beispiel #6
0
void Container::setSize(const sf::Vector2f& newarea)
{
    if(getSize() != newarea) //If given is different from current
    {
        WidgetBase::setSize(newarea);
        repositionWidgets(); //Reposition things to take up the new space
        recalculateView();
        scrollBar->recalculateScrollBar();
        needsWidgetResize = true;
        update();
    }
}
Beispiel #7
0
void Container::init(const sf::Font &defaultFont, unsigned int defaultCharacterSize, const sf::Color &defaultLabelColor, sf::Vector2i winSize)
{
    WidgetBase::init(defaultFont, defaultCharacterSize, defaultLabelColor, winSize); //Call default function
    isInitialised = true;
    //Init scrollbar
    scrollBar->init(defaultFont, defaultCharacterSize, defaultLabelColor, winSize);

    //Now update widgets
    for(unsigned int a = 0; a < widgets.size(); a++)
    {
        widgets[a]->init(defaultFont, defaultCharacterSize, defaultLabelColor, winSize);
    }
    repositionWidgets();
}
void Container::addWidget(ofPtr<Widget> widget){
	widgets.push_back(widget);
	repositionWidgets();
	if(eventsEnabled) widget->enableEvents();
}