optimize widget destruction
This commit is contained in:
parent
353aa5215e
commit
5425d344ba
|
@ -7,9 +7,10 @@ function RadioGroup.create()
|
||||||
end
|
end
|
||||||
|
|
||||||
function RadioGroup:destroy()
|
function RadioGroup:destroy()
|
||||||
while #self.widgets ~= 0 do
|
for k,widget in pairs(self.widgets) do
|
||||||
self:removeWidget(self.widgets[1])
|
widget.onMousePress = nil
|
||||||
end
|
end
|
||||||
|
self.widgets = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
function RadioGroup:addWidget(widget)
|
function RadioGroup:addWidget(widget)
|
||||||
|
@ -25,6 +26,13 @@ function RadioGroup:removeWidget(widget)
|
||||||
table.removevalue(self.widgets, widget)
|
table.removevalue(self.widgets, widget)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function RadioGroup:destroy()
|
||||||
|
for k,widget in pairs(self.widgets) do
|
||||||
|
widget.onMousePress = nil
|
||||||
|
end
|
||||||
|
self.widgets = {}
|
||||||
|
end
|
||||||
|
|
||||||
function RadioGroup:selectWidget(selectedWidget)
|
function RadioGroup:selectWidget(selectedWidget)
|
||||||
if selectedWidget == self.selectedWidget then return end
|
if selectedWidget == self.selectedWidget then return end
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ function NPCTrade.init()
|
||||||
end
|
end
|
||||||
|
|
||||||
function NPCTrade.terminate()
|
function NPCTrade.terminate()
|
||||||
radioTabs:destroy()
|
--radioTabs:destroy()
|
||||||
radioTabs = nil
|
radioTabs = nil
|
||||||
npcWindow:destroy()
|
npcWindow:destroy()
|
||||||
npcWindow = nil
|
npcWindow = nil
|
||||||
|
@ -230,6 +230,9 @@ function NPCTrade.createItemsOnPanel()
|
||||||
offerSelected = nil
|
offerSelected = nil
|
||||||
itemsPanel:destroyChildren()
|
itemsPanel:destroyChildren()
|
||||||
|
|
||||||
|
if radioItems then
|
||||||
|
radioItems:destroy()
|
||||||
|
end
|
||||||
radioItems = RadioGroup.create()
|
radioItems = RadioGroup.create()
|
||||||
|
|
||||||
for i, v in pairs(cacheItems) do
|
for i, v in pairs(cacheItems) do
|
||||||
|
|
|
@ -74,6 +74,9 @@ bool UIGridLayout::internalUpdate()
|
||||||
{
|
{
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
UIWidgetPtr parentWidget = getParentWidget();
|
UIWidgetPtr parentWidget = getParentWidget();
|
||||||
|
if(!parentWidget)
|
||||||
|
return false;
|
||||||
|
|
||||||
UIWidgetList widgets = parentWidget->getChildren();
|
UIWidgetList widgets = parentWidget->getChildren();
|
||||||
|
|
||||||
Rect clippingRect = parentWidget->getClippingRect();
|
Rect clippingRect = parentWidget->getClippingRect();
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
void UILayout::update()
|
void UILayout::update()
|
||||||
{
|
{
|
||||||
|
//logTraceCounter();
|
||||||
if(m_updateDisabled)
|
if(m_updateDisabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -35,12 +36,13 @@ void UILayout::update()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UIWidgetPtr parentWidget = getParentWidget();
|
||||||
|
if(!parentWidget || parentWidget->isDestroyed())
|
||||||
|
return;
|
||||||
|
|
||||||
m_updating = true;
|
m_updating = true;
|
||||||
internalUpdate();
|
internalUpdate();
|
||||||
if(UIWidgetPtr parentWidget = getParentWidget()) {
|
parentWidget->onLayoutUpdate();
|
||||||
if(!parentWidget->isDestroyed())
|
|
||||||
parentWidget->onLayoutUpdate();
|
|
||||||
}
|
|
||||||
m_updating = false;
|
m_updating = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -659,21 +659,19 @@ void UIWidget::bindRectToParent()
|
||||||
setRect(boundRect);
|
setRect(boundRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIWidget::destroy()
|
void UIWidget::internalDestroy()
|
||||||
{
|
{
|
||||||
if(m_destroyed)
|
|
||||||
logWarning("attempt to destroy widget '", m_id, "' two times");
|
|
||||||
|
|
||||||
m_destroyed = true;
|
m_destroyed = true;
|
||||||
setVisible(false);
|
m_visible = false;
|
||||||
setEnabled(false);
|
m_enabled = false;
|
||||||
|
m_parent.reset();
|
||||||
// remove itself from parent
|
|
||||||
if(UIWidgetPtr parent = getParent())
|
|
||||||
parent->removeChild(asUIWidget());
|
|
||||||
|
|
||||||
destroyChildren();
|
|
||||||
m_focusedChild = nullptr;
|
m_focusedChild = nullptr;
|
||||||
|
m_layout = nullptr;
|
||||||
|
m_lockedChildren.clear();
|
||||||
|
|
||||||
|
for(const UIWidgetPtr& child : m_children)
|
||||||
|
child->internalDestroy();
|
||||||
|
m_children.clear();
|
||||||
|
|
||||||
callLuaField("onDestroy");
|
callLuaField("onDestroy");
|
||||||
|
|
||||||
|
@ -682,10 +680,31 @@ void UIWidget::destroy()
|
||||||
g_ui.onWidgetDestroy(asUIWidget());
|
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()
|
void UIWidget::destroyChildren()
|
||||||
{
|
{
|
||||||
|
UILayoutPtr layout = getLayout();
|
||||||
|
if(layout)
|
||||||
|
layout->disableUpdates();
|
||||||
|
|
||||||
while(!m_children.empty())
|
while(!m_children.empty())
|
||||||
getFirstChild()->destroy();
|
m_children[0]->destroy();
|
||||||
|
|
||||||
|
layout->enableUpdates();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIWidget::setId(const std::string& id)
|
void UIWidget::setId(const std::string& id)
|
||||||
|
|
|
@ -164,6 +164,7 @@ protected:
|
||||||
bool hasState(Fw::WidgetState state);
|
bool hasState(Fw::WidgetState state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void internalDestroy();
|
||||||
void updateState(Fw::WidgetState state);
|
void updateState(Fw::WidgetState state);
|
||||||
void updateStates();
|
void updateStates();
|
||||||
void updateChildrenIndexStates();
|
void updateChildrenIndexStates();
|
||||||
|
|
Loading…
Reference in New Issue