فهرست منبع

Merge pull request #1775 from reven86/next-clean

UI fixes (mostly related to parent container updating)
Sean Taylor 10 سال پیش
والد
کامیت
c3babfbb52
2فایلهای تغییر یافته به همراه27 افزوده شده و 18 حذف شده
  1. 17 10
      gameplay/src/Container.cpp
  2. 10 8
      gameplay/src/Control.cpp

+ 17 - 10
gameplay/src/Container.cpp

@@ -425,6 +425,8 @@ const Vector2& Container::getScrollPosition() const
 void Container::setScrollPosition(const Vector2& scrollPosition)
 void Container::setScrollPosition(const Vector2& scrollPosition)
 {
 {
     _scrollPosition = scrollPosition;
     _scrollPosition = scrollPosition;
+    setDirty(DIRTY_BOUNDS);
+    setChildrenDirty(DIRTY_BOUNDS, true);
 }
 }
 
 
 Animation* Container::getAnimation(const char* id) const
 Animation* Container::getAnimation(const char* id) const
@@ -542,9 +544,6 @@ void Container::updateState(State state)
 
 
 void Container::updateBounds()
 void Container::updateBounds()
 {
 {
-    // Compute total bounds of container
-    Control::updateBounds();
-
     // Handle automatically sizing based on our children
     // Handle automatically sizing based on our children
     if (_autoSize != AUTO_SIZE_NONE)
     if (_autoSize != AUTO_SIZE_NONE)
     {
     {
@@ -557,7 +556,7 @@ void Container::updateBounds()
                 Control* ctrl = _controls[i];
                 Control* ctrl = _controls[i];
                 if (ctrl->isVisible() && !ctrl->isWidthPercentage())
                 if (ctrl->isVisible() && !ctrl->isWidthPercentage())
                 {
                 {
-                    float w = ctrl->getWidth();
+                    float w = ctrl->getWidth() + ctrl->getMargin().right;
                     if (!ctrl->isXPercentage())
                     if (!ctrl->isXPercentage())
                         w += ctrl->getX();
                         w += ctrl->getX();
                     if (width < w)
                     if (width < w)
@@ -577,7 +576,7 @@ void Container::updateBounds()
                 Control* ctrl = _controls[i];
                 Control* ctrl = _controls[i];
                 if (ctrl->isVisible() && !ctrl->isHeightPercentage())
                 if (ctrl->isVisible() && !ctrl->isHeightPercentage())
                 {
                 {
-                    float h = ctrl->getHeight();
+                    float h = ctrl->getHeight() + ctrl->getMargin().bottom;
                     if (!ctrl->isYPercentage())
                     if (!ctrl->isYPercentage())
                         h += ctrl->getY();
                         h += ctrl->getY();
                     if (height < h)
                     if (height < h)
@@ -589,6 +588,9 @@ void Container::updateBounds()
         }
         }
     }
     }
 
 
+    // Compute total bounds of container
+    Control::updateBounds();
+
     // Update layout to position children correctly within us
     // Update layout to position children correctly within us
     GP_ASSERT(_layout);
     GP_ASSERT(_layout);
     _layout->update(this);
     _layout->update(this);
@@ -636,7 +638,7 @@ bool Container::updateChildBounds()
             if (changed)
             if (changed)
             {
             {
                 Control* parent = this;
                 Control* parent = this;
-                while (parent && parent->_autoSize != AUTO_SIZE_NONE)
+                while (parent && (parent->_autoSize != AUTO_SIZE_NONE || static_cast<Container *>(parent)->getLayout()->getType() != Layout::LAYOUT_ABSOLUTE))
                 {
                 {
                     parent->setDirty(DIRTY_BOUNDS);
                     parent->setDirty(DIRTY_BOUNDS);
                     parent = parent->_parent;
                     parent = parent->_parent;
@@ -1086,6 +1088,9 @@ void Container::updateScroll()
     {
     {
         Control* control = _controls[i];
         Control* control = _controls[i];
 
 
+        if (!control->isVisible())
+            continue;
+
         const Rectangle& bounds = control->getBounds();
         const Rectangle& bounds = control->getBounds();
         const Theme::Margin& margin = control->getMargin();
         const Theme::Margin& margin = control->getMargin();
 
 
@@ -1134,34 +1139,35 @@ void Container::updateScroll()
     }
     }
 
 
     // Stop scrolling when the far edge is reached.
     // Stop scrolling when the far edge is reached.
+    Vector2 lastScrollPosition(_scrollPosition);
+
     if (-_scrollPosition.x > _totalWidth - clipWidth)
     if (-_scrollPosition.x > _totalWidth - clipWidth)
     {
     {
         _scrollPosition.x = -(_totalWidth - clipWidth);
         _scrollPosition.x = -(_totalWidth - clipWidth);
         _scrollingVelocity.x = 0;
         _scrollingVelocity.x = 0;
-        dirty = true;
     }
     }
     
     
     if (-_scrollPosition.y > _totalHeight - clipHeight)
     if (-_scrollPosition.y > _totalHeight - clipHeight)
     {
     {
         _scrollPosition.y = -(_totalHeight - clipHeight);
         _scrollPosition.y = -(_totalHeight - clipHeight);
         _scrollingVelocity.y = 0;
         _scrollingVelocity.y = 0;
-        dirty = true;
     }
     }
 
 
     if (_scrollPosition.x > 0)
     if (_scrollPosition.x > 0)
     {
     {
         _scrollPosition.x = 0;
         _scrollPosition.x = 0;
         _scrollingVelocity.x = 0;
         _scrollingVelocity.x = 0;
-        dirty = true;
     }
     }
 
 
     if (_scrollPosition.y > 0)
     if (_scrollPosition.y > 0)
     {
     {
         _scrollPosition.y = 0;
         _scrollPosition.y = 0;
         _scrollingVelocity.y = 0;
         _scrollingVelocity.y = 0;
-        dirty = true;
     }
     }
 
 
+    if (_scrollPosition != lastScrollPosition)
+        dirty = true;
+
     float scrollWidth = 0;
     float scrollWidth = 0;
     if (clipWidth < _totalWidth)
     if (clipWidth < _totalWidth)
         scrollWidth = (clipWidth / _totalWidth) * clipWidth;
         scrollWidth = (clipWidth / _totalWidth) * clipWidth;
@@ -1291,6 +1297,7 @@ bool Container::touchEventScroll(Touch::TouchEvent evt, int x, int y, unsigned i
             _scrollingLastTime = gameTime;
             _scrollingLastTime = gameTime;
             setDirty(DIRTY_BOUNDS);
             setDirty(DIRTY_BOUNDS);
             setChildrenDirty(DIRTY_BOUNDS, true);
             setChildrenDirty(DIRTY_BOUNDS, true);
+            updateScroll();
             return false;
             return false;
         }
         }
         break;
         break;

+ 10 - 8
gameplay/src/Control.cpp

@@ -1132,15 +1132,15 @@ bool Control::updateBoundsInternal(const Vector2& offset)
         _dirtyBits &= ~DIRTY_STATE;
         _dirtyBits &= ~DIRTY_STATE;
     }
     }
 
 
-    // Clear our dirty bounds bit
-    bool dirtyBounds = (_dirtyBits & DIRTY_BOUNDS) != 0;
-    _dirtyBits &= ~DIRTY_BOUNDS;
-
     // If we are a container, always update child bounds first
     // If we are a container, always update child bounds first
     bool changed = false;
     bool changed = false;
     if (isContainer())
     if (isContainer())
         changed = static_cast<Container*>(this)->updateChildBounds();
         changed = static_cast<Container*>(this)->updateChildBounds();
 
 
+    // Clear our dirty bounds bit
+    bool dirtyBounds = (_dirtyBits & DIRTY_BOUNDS) != 0;
+    _dirtyBits &= ~DIRTY_BOUNDS;
+
     if (dirtyBounds)
     if (dirtyBounds)
     {
     {
         // Store old bounds so we can determine if they change
         // Store old bounds so we can determine if they change
@@ -1172,12 +1172,14 @@ void Control::updateBounds()
 
 
     const Rectangle parentAbsoluteBounds = _parent ? _parent->_viewportBounds : Rectangle(0, 0, game->getViewport().width, game->getViewport().height);
     const Rectangle parentAbsoluteBounds = _parent ? _parent->_viewportBounds : Rectangle(0, 0, game->getViewport().width, game->getViewport().height);
 
 
+    const Theme::Margin& margin = _style->getMargin();
+
     // Calculate local unclipped bounds.
     // Calculate local unclipped bounds.
     _bounds.set(_relativeBounds);
     _bounds.set(_relativeBounds);
     if (isXPercentage())
     if (isXPercentage())
-        _bounds.x *= parentAbsoluteBounds.width;
+        _bounds.x = _bounds.x * parentAbsoluteBounds.width + margin.left;
     if (isYPercentage())
     if (isYPercentage())
-        _bounds.y *= parentAbsoluteBounds.height;
+        _bounds.y = _bounds.y * parentAbsoluteBounds.height + margin.top;
     if (isWidthPercentage())
     if (isWidthPercentage())
         _bounds.width *= parentAbsoluteBounds.width;
         _bounds.width *= parentAbsoluteBounds.width;
     if (isHeightPercentage())
     if (isHeightPercentage())
@@ -1212,7 +1214,7 @@ void Control::updateBounds()
         }
         }
         else if ((_alignment & Control::ALIGN_VCENTER) == Control::ALIGN_VCENTER)
         else if ((_alignment & Control::ALIGN_VCENTER) == Control::ALIGN_VCENTER)
         {
         {
-            _bounds.y = clipHeight * 0.5f - _bounds.height * 0.5f;
+            _bounds.y = clipHeight * 0.5f - _bounds.height * 0.5f + (margin.top - margin.bottom) * 0.5f;
         }
         }
         else if ((_alignment & Control::ALIGN_TOP) == Control::ALIGN_TOP)
         else if ((_alignment & Control::ALIGN_TOP) == Control::ALIGN_TOP)
         {
         {
@@ -1226,7 +1228,7 @@ void Control::updateBounds()
         }
         }
         else if ((_alignment & Control::ALIGN_HCENTER) == Control::ALIGN_HCENTER)
         else if ((_alignment & Control::ALIGN_HCENTER) == Control::ALIGN_HCENTER)
         {
         {
-            _bounds.x = clipWidth * 0.5f - _bounds.width * 0.5f;
+            _bounds.x = clipWidth * 0.5f - _bounds.width * 0.5f + (margin.left - margin.right) * 0.5f;
         }
         }
         else if ((_alignment & Control::ALIGN_LEFT) == Control::ALIGN_LEFT)
         else if ((_alignment & Control::ALIGN_LEFT) == Control::ALIGN_LEFT)
         {
         {