use counter for disabling layout updates

This commit is contained in:
Eduardo Bart 2012-04-09 18:44:33 -03:00
parent 685c730dda
commit 48d2027327
2 changed files with 19 additions and 9 deletions

View File

@ -28,6 +28,20 @@
void UILayout::update() void UILayout::update()
{ {
//logTraceCounter(); //logTraceCounter();
UIWidgetPtr parentWidget = getParentWidget();
if(!parentWidget || parentWidget->isDestroyed())
return;
/*
UIWidgetPtr parent = parentWidget;
do {
UILayoutPtr ownerLayout = parent->getLayout();
if(ownerLayout && ownerLayout->isUpdateDisabled())
return;
parent = parent->getParent();
} while(parent);
*/
if(m_updateDisabled) if(m_updateDisabled)
return; return;
@ -36,10 +50,6 @@ void UILayout::update()
return; return;
} }
UIWidgetPtr parentWidget = getParentWidget();
if(!parentWidget || parentWidget->isDestroyed())
return;
m_updating = true; m_updating = true;
internalUpdate(); internalUpdate();
parentWidget->onLayoutUpdate(); parentWidget->onLayoutUpdate();

View File

@ -30,7 +30,7 @@
class UILayout : public LuaObject class UILayout : public LuaObject
{ {
public: public:
UILayout(UIWidgetPtr parentWidget) : m_parentWidget(parentWidget) { } UILayout(UIWidgetPtr parentWidget) : m_parentWidget(parentWidget) { m_updateDisabled = 0; }
void update(); void update();
void updateLater(); void updateLater();
@ -38,13 +38,13 @@ public:
virtual void applyStyle(const OTMLNodePtr& styleNode) { } virtual void applyStyle(const OTMLNodePtr& styleNode) { }
virtual void addWidget(const UIWidgetPtr& widget) = 0; virtual void addWidget(const UIWidgetPtr& widget) = 0;
virtual void removeWidget(const UIWidgetPtr& widget) = 0; virtual void removeWidget(const UIWidgetPtr& widget) = 0;
void disableUpdates() { m_updateDisabled = true; } void disableUpdates() { m_updateDisabled++; }
void enableUpdates() { m_updateDisabled = false; } void enableUpdates() { m_updateDisabled = std::max(m_updateDisabled-1,0); }
void setParent(UIWidgetPtr parentWidget) { m_parentWidget = parentWidget; } void setParent(UIWidgetPtr parentWidget) { m_parentWidget = parentWidget; }
UIWidgetPtr getParentWidget() { return m_parentWidget.lock(); } UIWidgetPtr getParentWidget() { return m_parentWidget.lock(); }
bool isUpdateDisabled() { return m_updateDisabled; } bool isUpdateDisabled() { return m_updateDisabled > 0; }
bool isUpdating() { return m_updating; } bool isUpdating() { return m_updating; }
UILayoutPtr asUILayout() { return std::static_pointer_cast<UILayout>(shared_from_this()); } UILayoutPtr asUILayout() { return std::static_pointer_cast<UILayout>(shared_from_this()); }
@ -57,7 +57,7 @@ public:
protected: protected:
virtual bool internalUpdate() = 0; virtual bool internalUpdate() = 0;
Boolean<false> m_updateDisabled; int m_updateDisabled;
Boolean<false> m_updating; Boolean<false> m_updating;
Boolean<false> m_updateScheduled; Boolean<false> m_updateScheduled;
UIWidgetWeakPtr m_parentWidget; UIWidgetWeakPtr m_parentWidget;