Browse Source

Relative Positioning Bug Fixed

Relative positioning did not work right when used with min extent and scroll bars. This fixes the problem.
Peter Robinson 3 years ago
parent
commit
f815811c90
2 changed files with 49 additions and 24 deletions
  1. 21 2
      engine/source/gui/containers/guiScrollCtrl.cc
  2. 28 22
      engine/source/gui/guiControl.cc

+ 21 - 2
engine/source/gui/containers/guiScrollCtrl.cc

@@ -95,8 +95,27 @@ void GuiScrollCtrl::initPersistFields()
 
 void GuiScrollCtrl::resize(const Point2I &newPos, const Point2I &newExt)
 {
-   Parent::resize(newPos, newExt);
-   computeSizes();
+	bool hasH = mHasHScrollBar;
+	bool hasV = mHasVScrollBar;
+	Parent::resize(newPos, newExt);
+	computeSizes();
+
+	if (hasH != mHasHScrollBar || hasV != mHasVScrollBar)
+	{
+		S32 deltaY = hasH != mHasHScrollBar ? (mHasHScrollBar ? mScrollBarThickness : -mScrollBarThickness) : 0;
+		S32 deltaX = hasV != mHasVScrollBar ? (mHasVScrollBar ? mScrollBarThickness : -mScrollBarThickness) : 0;
+
+		iterator i;
+		for (i = begin(); i != end(); i++)
+		{
+			GuiControl* ctrl = static_cast<GuiControl*>(*i);
+			ctrl->mRenderInsetRB = Point2I(ctrl->mRenderInsetRB.x + deltaX, ctrl->mRenderInsetRB.y + deltaY);
+			ctrl->parentResized(mBounds.extent - (ctrl->mRenderInsetLT + ctrl->mRenderInsetRB), mBounds.extent - (ctrl->mRenderInsetLT + ctrl->mRenderInsetRB));
+		}
+
+		Parent::resize(newPos, newExt);
+		computeSizes();
+	}
 }
 
 void GuiScrollCtrl::childResized(GuiControl *child)

+ 28 - 22
engine/source/gui/guiControl.cc

@@ -566,29 +566,35 @@ Point2I GuiControl::extentBattery(Point2I &newExtent)
 	}
 
 	Point2I result = Point2I(newExtent);
-	if (newExtent.x < mBounds.extent.x && newExtent.x < mMinExtent.x)
-	{
-		mStoredExtent.x += mBounds.extent.x > mMinExtent.x ? (mMinExtent.x - newExtent.x) : (mBounds.extent.x - newExtent.x);
-		result.x = mMinExtent.x;
-	}
-	else if (newExtent.x > mBounds.extent.x && mStoredExtent.x > 0)
-	{
-		S32 charge = getMin(newExtent.x - mBounds.extent.x, mStoredExtent.x);
-		mStoredExtent.x -= charge;
-		result.x = newExtent.x - charge;
-	}
+    if (mHorizSizing != horizResizeRelative)
+    {
+        if (newExtent.x < mBounds.extent.x && newExtent.x < mMinExtent.x)
+        {
+            mStoredExtent.x += mBounds.extent.x > mMinExtent.x ? (mMinExtent.x - newExtent.x) : (mBounds.extent.x - newExtent.x);
+            result.x = mMinExtent.x;
+        }
+        else if (newExtent.x > mBounds.extent.x && mStoredExtent.x > 0)
+        {
+            S32 charge = getMin(newExtent.x - mBounds.extent.x, mStoredExtent.x);
+            mStoredExtent.x -= charge;
+            result.x = newExtent.x - charge;
+        }
+    }
 
-	if (newExtent.y < mBounds.extent.y && newExtent.y < mMinExtent.y)
-	{
-		mStoredExtent.y += mBounds.extent.y > mMinExtent.y ? (mMinExtent.y - newExtent.y) : (mBounds.extent.y - newExtent.y);
-		result.y = mMinExtent.y;
-	}
-	else if (newExtent.y > mBounds.extent.y && mStoredExtent.y > 0)
-	{
-		S32 charge = getMin(newExtent.y - mBounds.extent.y, mStoredExtent.y);
-		mStoredExtent.y -= charge;
-		result.y = newExtent.y - charge;
-	}
+    if (mVertSizing != vertResizeRelative)
+    {
+        if (newExtent.y < mBounds.extent.y && newExtent.y < mMinExtent.y)
+        {
+            mStoredExtent.y += mBounds.extent.y > mMinExtent.y ? (mMinExtent.y - newExtent.y) : (mBounds.extent.y - newExtent.y);
+            result.y = mMinExtent.y;
+        }
+        else if (newExtent.y > mBounds.extent.y && mStoredExtent.y > 0)
+        {
+            S32 charge = getMin(newExtent.y - mBounds.extent.y, mStoredExtent.y);
+            mStoredExtent.y -= charge;
+            result.y = newExtent.y - charge;
+        }
+    }
 	return result;
 }