optimize widget destruction

This commit is contained in:
Eduardo Bart
2012-04-09 17:52:39 -03:00
parent 353aa5215e
commit 5425d344ba
6 changed files with 57 additions and 21 deletions

View File

@@ -74,6 +74,9 @@ bool UIGridLayout::internalUpdate()
{
bool changed = false;
UIWidgetPtr parentWidget = getParentWidget();
if(!parentWidget)
return false;
UIWidgetList widgets = parentWidget->getChildren();
Rect clippingRect = parentWidget->getClippingRect();

View File

@@ -27,6 +27,7 @@
void UILayout::update()
{
//logTraceCounter();
if(m_updateDisabled)
return;
@@ -35,12 +36,13 @@ void UILayout::update()
return;
}
UIWidgetPtr parentWidget = getParentWidget();
if(!parentWidget || parentWidget->isDestroyed())
return;
m_updating = true;
internalUpdate();
if(UIWidgetPtr parentWidget = getParentWidget()) {
if(!parentWidget->isDestroyed())
parentWidget->onLayoutUpdate();
}
parentWidget->onLayoutUpdate();
m_updating = false;
}

View File

@@ -659,21 +659,19 @@ void UIWidget::bindRectToParent()
setRect(boundRect);
}
void UIWidget::destroy()
void UIWidget::internalDestroy()
{
if(m_destroyed)
logWarning("attempt to destroy widget '", m_id, "' two times");
m_destroyed = true;
setVisible(false);
setEnabled(false);
// remove itself from parent
if(UIWidgetPtr parent = getParent())
parent->removeChild(asUIWidget());
destroyChildren();
m_visible = false;
m_enabled = false;
m_parent.reset();
m_focusedChild = nullptr;
m_layout = nullptr;
m_lockedChildren.clear();
for(const UIWidgetPtr& child : m_children)
child->internalDestroy();
m_children.clear();
callLuaField("onDestroy");
@@ -682,10 +680,31 @@ void UIWidget::destroy()
g_ui.onWidgetDestroy(asUIWidget());
}
void UIWidget::destroy()
{
if(m_destroyed)
logWarning("attempt to destroy widget '", m_id, "' two times");
// hold itself reference
UIWidgetPtr self = asUIWidget();
m_destroyed = true;
// remove itself from parent
if(UIWidgetPtr parent = getParent())
parent->removeChild(self);
internalDestroy();
}
void UIWidget::destroyChildren()
{
UILayoutPtr layout = getLayout();
if(layout)
layout->disableUpdates();
while(!m_children.empty())
getFirstChild()->destroy();
m_children[0]->destroy();
layout->enableUpdates();
}
void UIWidget::setId(const std::string& id)

View File

@@ -164,6 +164,7 @@ protected:
bool hasState(Fw::WidgetState state);
private:
void internalDestroy();
void updateState(Fw::WidgetState state);
void updateStates();
void updateChildrenIndexStates();