onLoad and onDestroy events

This commit is contained in:
Eduardo Bart
2011-04-23 00:28:23 -03:00
parent 02ada0b82e
commit a98f1d67db
16 changed files with 210 additions and 31 deletions

View File

@@ -27,10 +27,27 @@
#include <ui/uicontainer.h>
#include <core/dispatcher.h>
UIContainerPtr rootContainer(new UIContainer);
void UIContainer::internalOnDestroy()
{
// destroy children
for(auto it = m_children.begin(); it != m_children.end(); ++it) {
(*it)->setParent(UIContainerPtr());
(*it)->destroy();
}
m_children.clear();
// root container must not call internalDestroy
if(asUIContainer() != getRootContainer())
UIElement::internalOnDestroy();
}
UIContainerPtr& UIContainer::getRootContainer()
{
static UIContainerPtr rootContainer;
if(!rootContainer) {
rootContainer = UIContainerPtr(new UIContainer);
rootContainer->setId("root");
}
return rootContainer;
}
@@ -118,6 +135,13 @@ void UIContainer::pushChildToTop(const UIElementPtr& child)
}
}
void UIContainer::onLoad()
{
for(auto it = m_children.begin(); it != m_children.end(); ++it)
(*it)->onLoad();
UIElement::onLoad();
}
void UIContainer::render()
{
UIElement::render();