From 48d20273278587a98222546892908d3bc2886d43 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Mon, 9 Apr 2012 18:44:33 -0300 Subject: [PATCH] use counter for disabling layout updates --- src/framework/ui/uilayout.cpp | 18 ++++++++++++++---- src/framework/ui/uilayout.h | 10 +++++----- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/framework/ui/uilayout.cpp b/src/framework/ui/uilayout.cpp index 2c700740..a909541f 100644 --- a/src/framework/ui/uilayout.cpp +++ b/src/framework/ui/uilayout.cpp @@ -28,6 +28,20 @@ void UILayout::update() { //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) return; @@ -36,10 +50,6 @@ void UILayout::update() return; } - UIWidgetPtr parentWidget = getParentWidget(); - if(!parentWidget || parentWidget->isDestroyed()) - return; - m_updating = true; internalUpdate(); parentWidget->onLayoutUpdate(); diff --git a/src/framework/ui/uilayout.h b/src/framework/ui/uilayout.h index 5960018b..b985116b 100644 --- a/src/framework/ui/uilayout.h +++ b/src/framework/ui/uilayout.h @@ -30,7 +30,7 @@ class UILayout : public LuaObject { public: - UILayout(UIWidgetPtr parentWidget) : m_parentWidget(parentWidget) { } + UILayout(UIWidgetPtr parentWidget) : m_parentWidget(parentWidget) { m_updateDisabled = 0; } void update(); void updateLater(); @@ -38,13 +38,13 @@ public: virtual void applyStyle(const OTMLNodePtr& styleNode) { } virtual void addWidget(const UIWidgetPtr& widget) = 0; virtual void removeWidget(const UIWidgetPtr& widget) = 0; - void disableUpdates() { m_updateDisabled = true; } - void enableUpdates() { m_updateDisabled = false; } + void disableUpdates() { m_updateDisabled++; } + void enableUpdates() { m_updateDisabled = std::max(m_updateDisabled-1,0); } void setParent(UIWidgetPtr parentWidget) { m_parentWidget = parentWidget; } UIWidgetPtr getParentWidget() { return m_parentWidget.lock(); } - bool isUpdateDisabled() { return m_updateDisabled; } + bool isUpdateDisabled() { return m_updateDisabled > 0; } bool isUpdating() { return m_updating; } UILayoutPtr asUILayout() { return std::static_pointer_cast(shared_from_this()); } @@ -57,7 +57,7 @@ public: protected: virtual bool internalUpdate() = 0; - Boolean m_updateDisabled; + int m_updateDisabled; Boolean m_updating; Boolean m_updateScheduled; UIWidgetWeakPtr m_parentWidget;