ui internal destroy
This commit is contained in:
parent
6a3ee47cc5
commit
bfa3903940
|
@ -32,22 +32,34 @@ UIWidget::UIWidget()
|
||||||
|
|
||||||
UIWidget::~UIWidget()
|
UIWidget::~UIWidget()
|
||||||
{
|
{
|
||||||
if(!m_destroyed)
|
if(!m_destroyed) {
|
||||||
logWarning("widget '", m_id, "' was destructed without being explicit destroyed");
|
logWarning("widget '", m_id, "' was destructed without being explicit destroyed");
|
||||||
|
internalDestroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIWidget::destroy()
|
void UIWidget::destroy()
|
||||||
{
|
{
|
||||||
// destroy only once
|
// destroy only once
|
||||||
if(!m_destroyed) {
|
if(!m_destroyed) {
|
||||||
|
internalDestroy();
|
||||||
|
|
||||||
|
// add destroy check event
|
||||||
|
g_dispatcher.addEvent(std::bind(&UIWidget::internalDestroyCheck, asUIWidget()));
|
||||||
|
} else
|
||||||
|
logWarning("attempt to destroy widget '", m_id, "' again");
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIWidget::internalDestroy()
|
||||||
|
{
|
||||||
// first release lua table, because it may contains references to children
|
// first release lua table, because it may contains references to children
|
||||||
releaseLuaFieldsTable();
|
releaseLuaFieldsTable();
|
||||||
|
|
||||||
// clear additional child references
|
// clear other references
|
||||||
m_lockedChildren.clear();
|
m_lockedChildren.clear();
|
||||||
m_focusedChild.reset();
|
|
||||||
m_anchors.clear();
|
m_anchors.clear();
|
||||||
m_anchoredWidgets.clear();
|
m_anchoredWidgets.clear();
|
||||||
|
m_focusedChild.reset();
|
||||||
|
|
||||||
// destroy children
|
// destroy children
|
||||||
while(m_children.size() > 0) {
|
while(m_children.size() > 0) {
|
||||||
|
@ -59,16 +71,10 @@ void UIWidget::destroy()
|
||||||
if(UIWidgetPtr parent = getParent())
|
if(UIWidgetPtr parent = getParent())
|
||||||
parent->removeChild(asUIWidget());
|
parent->removeChild(asUIWidget());
|
||||||
|
|
||||||
// by now this widget is destroyed
|
|
||||||
m_destroyed = true;
|
m_destroyed = true;
|
||||||
|
|
||||||
// add destroy check event
|
|
||||||
g_dispatcher.addEvent(std::bind(&UIWidget::destroyCheck, asUIWidget()));
|
|
||||||
} else
|
|
||||||
logWarning("attempt to destroy widget '", m_id, "' again");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIWidget::destroyCheck()
|
void UIWidget::internalDestroyCheck()
|
||||||
{
|
{
|
||||||
// collect lua garbage before checking
|
// collect lua garbage before checking
|
||||||
g_lua.collectGarbage();
|
g_lua.collectGarbage();
|
||||||
|
@ -128,7 +134,7 @@ void UIWidget::setParent(const UIWidgetPtr& parent)
|
||||||
|
|
||||||
// set new parent
|
// set new parent
|
||||||
if(parent) {
|
if(parent) {
|
||||||
m_parent = UIWidgetWeakPtr(parent);
|
m_parent = parent;
|
||||||
|
|
||||||
// add to parent if needed
|
// add to parent if needed
|
||||||
if(!parent->hasChild(self))
|
if(!parent->hasChild(self))
|
||||||
|
@ -141,9 +147,6 @@ void UIWidget::applyStyle(const std::string& styleName)
|
||||||
try {
|
try {
|
||||||
OTMLNodePtr styleNode = g_ui.getStyle(styleName);
|
OTMLNodePtr styleNode = g_ui.getStyle(styleName);
|
||||||
onStyleApply(styleNode);
|
onStyleApply(styleNode);
|
||||||
|
|
||||||
// forces layout recalculation
|
|
||||||
updateLayout();
|
|
||||||
} catch(std::exception& e) {
|
} catch(std::exception& e) {
|
||||||
logError("couldn't change widget '", m_id, "' style: ", e.what());
|
logError("couldn't change widget '", m_id, "' style: ", e.what());
|
||||||
}
|
}
|
||||||
|
@ -336,9 +339,7 @@ void UIWidget::focusChild(const UIWidgetPtr& child, UI::FocusReason reason)
|
||||||
{
|
{
|
||||||
assert(!m_destroyed);
|
assert(!m_destroyed);
|
||||||
|
|
||||||
if(!child)
|
if(child)
|
||||||
return;
|
|
||||||
|
|
||||||
assert(hasChild(child));
|
assert(hasChild(child));
|
||||||
|
|
||||||
if(child != m_focusedChild) {
|
if(child != m_focusedChild) {
|
||||||
|
@ -704,7 +705,7 @@ void UIWidget::internalUpdateChildrenLayout()
|
||||||
// update children layouts
|
// update children layouts
|
||||||
for(const UIWidgetWeakPtr& anchoredWidgetWeak : m_anchoredWidgets) {
|
for(const UIWidgetWeakPtr& anchoredWidgetWeak : m_anchoredWidgets) {
|
||||||
if(UIWidgetPtr anchoredWidget = anchoredWidgetWeak.lock())
|
if(UIWidgetPtr anchoredWidget = anchoredWidgetWeak.lock())
|
||||||
anchoredWidget->updateLayout();
|
anchoredWidget->internalUpdateLayout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -850,10 +851,10 @@ void UIWidget::onStyleApply(const OTMLNodePtr& styleNode)
|
||||||
addAnchor(edge, hookedWidgetId, hookedEdge);
|
addAnchor(edge, hookedWidgetId, hookedEdge);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(node->tag() == "onLoad") {
|
/*else if(node->tag() == "onLoad") {
|
||||||
g_lua.loadFunction(node->value<std::string>(), "@" + node->source() + "[" + node->tag() + "]");
|
g_lua.loadFunction(node->value<std::string>(), "@" + node->source() + "[" + node->tag() + "]");
|
||||||
luaSetField("onLoad");
|
luaSetField("onLoad");
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,6 +116,9 @@ public:
|
||||||
UIWidgetPtr asUIWidget() { return std::static_pointer_cast<UIWidget>(shared_from_this()); }
|
UIWidgetPtr asUIWidget() { return std::static_pointer_cast<UIWidget>(shared_from_this()); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void internalDestroy();
|
||||||
|
void internalDestroyCheck();
|
||||||
|
|
||||||
void internalUpdateLayout();
|
void internalUpdateLayout();
|
||||||
void internalUpdateChildrenLayout();
|
void internalUpdateChildrenLayout();
|
||||||
|
|
||||||
|
@ -154,9 +157,6 @@ protected:
|
||||||
|
|
||||||
friend class UIManager;
|
friend class UIManager;
|
||||||
|
|
||||||
private:
|
|
||||||
void destroyCheck();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool m_enabled;
|
bool m_enabled;
|
||||||
bool m_visible;
|
bool m_visible;
|
||||||
|
|
Loading…
Reference in New Issue