Browse Source

UI: control's addition/removing/hiding makes parents dirty, autoSize doesn't count invisible controls

Andrew Karpushin 11 years ago
parent
commit
83f73cf659
2 changed files with 13 additions and 2 deletions
  1. 5 2
      gameplay/src/Container.cpp
  2. 8 0
      gameplay/src/Control.cpp

+ 5 - 2
gameplay/src/Container.cpp

@@ -240,6 +240,7 @@ unsigned int Container::addControl(Control* control)
 	control->_parent = this;
 
 	sortControls();
+    setDirty(Control::DIRTY_BOUNDS);
 
 	return (unsigned int)( _controls.size() - 1 );
 }
@@ -259,6 +260,7 @@ void Container::insertControl(Control* control, unsigned int index)
         _controls.insert(it, control);
         control->addRef();
         control->_parent = this;
+        setDirty(Control::DIRTY_BOUNDS);
     }
 }
 
@@ -270,6 +272,7 @@ void Container::removeControl(unsigned int index)
     Control* control = *it;
     _controls.erase(it);
     control->_parent = NULL;
+    setDirty(Control::DIRTY_BOUNDS);
 
     if (_activeControl == control)
         _activeControl = NULL;
@@ -551,7 +554,7 @@ void Container::updateBounds()
             for (size_t i = 0, count = _controls.size(); i < count; ++i)
             {
                 Control* ctrl = _controls[i];
-                if (!ctrl->isXPercentage() && !ctrl->isWidthPercentage())
+                if (ctrl->isVisible() && !ctrl->isXPercentage() && !ctrl->isWidthPercentage())
                 {
                     float w = ctrl->getX() + ctrl->getWidth();
                     if (width < w)
@@ -569,7 +572,7 @@ void Container::updateBounds()
             for (size_t i = 0, count = _controls.size(); i < count; ++i)
             {
                 Control* ctrl = _controls[i];
-                if (!ctrl->isYPercentage() && !ctrl->isHeightPercentage())
+                if (ctrl->isVisible() && !ctrl->isYPercentage() && !ctrl->isHeightPercentage())
                 {
                     float h = ctrl->getY() + ctrl->getHeight();
                     if (height < h)

+ 8 - 0
gameplay/src/Control.cpp

@@ -509,6 +509,14 @@ void Control::setVisible(bool visible)
             Form::controlDisabled(this);
 
         setDirty(DIRTY_BOUNDS);
+
+        // force to update parent boundaries when child is hidden
+        Control* parent = _parent;
+        while (parent && (parent->_autoSize != AUTO_SIZE_NONE || static_cast<Container *>(parent)->getLayout()->getType() != Layout::LAYOUT_ABSOLUTE))
+        {
+            parent->setDirty(DIRTY_BOUNDS);
+            parent = parent->_parent;
+        }
     }
 }