diff mde/gui/widget/Window.d @ 45:0fd51d2c6c8a

Several changes to resising windows and layout widgets. This commit still has some bugs. Moved the implementable widgets from mde.gui.widget.Widget to miscWidgets, leaving base widgets in Widget. Rewrote some of GridLayoutWidget's implementation. Made many operations general to work for either columns or rows. Some optimisations were intended but ended up being removed due to problems. Allowed layout's to resize from either direction (only with window resizes). committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Thu, 22 May 2008 11:34:09 +0100
parents b3a6ca4516b4
children 03fa79a48c48
line wrap: on
line diff
--- a/mde/gui/widget/Window.d	Fri May 16 12:22:10 2008 +0100
+++ b/mde/gui/widget/Window.d	Thu May 22 11:34:09 2008 +0100
@@ -219,7 +219,7 @@
         ch = h;
     }
     
-    void setSize (int nw, int nh) {
+    void setSize (int nw, int nh, bool wB, bool hB) {
         getMinimalSize (w,h);
         if (nw > w) w = nw;     // expand if new size is larger, but don't go smaller
         if (nh > h) h = nh;
@@ -227,7 +227,7 @@
         xw = x+w;
         yh = y+h;
         
-        widget.setSize (w - border.l - border.r, h - border.t - border.b);
+        widget.setSize (w - border.l - border.r, h - border.t - border.b, wB, hB);
         
         gui_.requestRedraw ();  // obviously necessary whenever the window's size is changed
     }
@@ -303,32 +303,39 @@
         setPosition (cx-xDrag, cy-yDrag);
     }
     void resizeCallback (ushort cx, ushort cy) {
+        debug scope(failure)
+                logger.trace ("resizeCallback: failure");
+        
+        // This function is only called if some resize is going to happen.
+        // To improve efficiency, store parameters to resize to.
+        int xSize = w, ySize = h;	// new size
+        int xDiff, yDiff;		// difference to new position
+        bool xHigh, yHigh;		// resize from positive side
+        
         if (resizeType & RESIZE_TYPE.L) {
-            int mw, nw;
-            getMinimalSize (mw, nw);    // (only want mw)
-            nw = xDrag - cx;
-            if (nw < mw) nw = mw;       // clamp
-            mw = x + w - nw;            // reuse
-            setSize (nw, h);
-            setPosition (mw, y);
+            getMinimalSize (xDiff, xSize);	// (only want xDiff, temporarily used as mw)
+            xSize = xDrag - cx;
+            if (xSize < xDiff) xSize = xDiff;	// clamp
+            xDiff = w - xSize;			// now used as amount to move
         }
         else if (resizeType & RESIZE_TYPE.R) {
-            setSize (xDrag + cx, h);
-            setPosition (x, y);         // required to call after setSize.
+            xSize = xDrag + cx;
+            xHigh = true;
         }
         if (resizeType & RESIZE_TYPE.T) {
-            int mh, nh;
-            getMinimalSize (nh, mh);
-            nh = yDrag - cy;
-            if (nh < mh) nh = mh;
-            mh = y + h - nh;
-            setSize (w, nh);
-            setPosition (x, mh);
+            getMinimalSize (ySize, yDiff);
+            ySize = yDrag - cy;
+            if (ySize < yDiff) ySize = yDiff;
+            yDiff = h - ySize;
         }
         else if (resizeType & RESIZE_TYPE.B) {
-            setSize (w, yDrag + cy);
-            setPosition (x, y);
+            ySize = yDrag + cy;
+            yHigh = true;
         }
+        
+        setSize (xSize, ySize, xHigh, yHigh);
+        if (xDiff != 0 || yDiff != 0)
+            setPosition (x + xDiff, y + yDiff);
     }
     bool endCallback (ushort cx, ushort cy, ubyte b, bool state) {
         if (b == 1 && state == false) {