diff dwt/layout/RowLayout.d @ 213:36f5cb12e1a2

Update to SWT 3.4M7
author Frank Benoit <benoit@tionex.de>
date Sat, 17 May 2008 17:34:28 +0200
parents ab60f3309436
children fd9c62a2998e
line wrap: on
line diff
--- a/dwt/layout/RowLayout.d	Mon May 05 00:12:38 2008 +0200
+++ b/dwt/layout/RowLayout.d	Sat May 17 17:34:28 2008 +0200
@@ -138,6 +138,17 @@
     public bool fill = false;
 
     /**
+     * center specifies whether the controls in a row should be
+     * centered vertically in each cell for horizontal layouts,
+     * or centered horizontally in each cell for vertical layouts.
+     *
+     * The default value is false.
+     * 
+     * @since 3.4
+     */
+    public bool center = false;
+    
+    /**
      * justify specifies whether the controls in a row should be
      * fully justified, with any extra space placed between the controls.
      *
@@ -268,7 +279,7 @@
     int [] wraps = null;
     bool wrapped = false;
     Rectangle [] bounds = null;
-    if (move && (justify || fill)) {
+    if (move && (justify || fill || center)) {
         bounds = new Rectangle [count];
         wraps = new int [count];
     }
@@ -282,17 +293,17 @@
         }
         if (wrap && (i !is 0) && (x + childWidth > width)) {
             wrapped = true;
-            if (move && (justify || fill)) wraps [i - 1] = maxHeight;
+            if (move && (justify || fill || center)) wraps [i - 1] = maxHeight;
             x = marginLeft + marginWidth;
             y += spacing + maxHeight;
             if (pack) maxHeight = 0;
         }
-        if (pack || fill) {
+        if (pack || fill || center) {
             maxHeight = Math.max (maxHeight, childHeight);
         }
         if (move) {
             int childX = x + clientX, childY = y + clientY;
-            if (justify || fill) {
+            if (justify || fill || center) {
                 bounds [i] = new Rectangle (childX, childY, childWidth, childHeight);
             } else {
                 child.setBounds (childX, childY, childWidth, childHeight);
@@ -303,13 +314,13 @@
     }
     maxX = Math.max (clientX + marginLeft + marginWidth, maxX - spacing);
     if (!wrapped) maxX += marginRight + marginWidth;
-    if (move && (justify || fill)) {
+    if (move && (justify || fill || center)) {
         int space = 0, margin = 0;
         if (!wrapped) {
             space = Math.max (0, (width - maxX) / (count + 1));
             margin = Math.max (0, ((width - maxX) % (count + 1)) / 2);
         } else {
-            if (fill || justify) {
+            if (fill || justify || center) {
                 int last = 0;
                 if (count > 0) wraps [count - 1] = maxHeight;
                 for (int i=0; i<count; i++) {
@@ -325,7 +336,13 @@
                         }
                         for (int j=last; j<=i; j++) {
                             if (justify) bounds [j].x += (space * (j - last + 1)) + margin;
-                            if (fill) bounds [j].height = wraps [i];
+                            if (fill) {
+                                bounds [j].height = wraps [i];
+                            } else {
+                                if (center) {
+                                    bounds [j].y += Math.max (0, (wraps [i] - bounds [j].height) / 2);
+                                }
+                            }
                         }
                         last = i + 1;
                     }
@@ -335,7 +352,13 @@
         for (int i=0; i<count; i++) {
             if (!wrapped) {
                 if (justify) bounds [i].x += (space * (i + 1)) + margin;
-                if (fill) bounds [i].height = maxHeight;
+                if (fill) {
+                    bounds [i].height = maxHeight;
+                } else {
+                    if (center) {
+                        bounds [i].y += Math.max (0, (maxHeight - bounds [i].height) / 2);
+                    }
+                }
             }
             children [i].setBounds (bounds [i]);
         }
@@ -375,7 +398,7 @@
     int [] wraps = null;
     bool wrapped = false;
     Rectangle [] bounds = null;
-    if (move && (justify || fill)) {
+    if (move && (justify || fill || center)) {
         bounds = new Rectangle [count];
         wraps = new int [count];
     }
@@ -389,17 +412,17 @@
         }
         if (wrap && (i !is 0) && (y + childHeight > height)) {
             wrapped = true;
-            if (move && (justify || fill)) wraps [i - 1] = maxWidth;
+            if (move && (justify || fill || center)) wraps [i - 1] = maxWidth;
             x += spacing + maxWidth;
             y = marginTop + marginHeight;
             if (pack) maxWidth = 0;
         }
-        if (pack || fill) {
+        if (pack || fill || center) {
             maxWidth = Math.max (maxWidth, childWidth);
         }
         if (move) {
             int childX = x + clientX, childY = y + clientY;
-            if (justify || fill) {
+            if (justify || fill || center) {
                 bounds [i] = new Rectangle (childX, childY, childWidth, childHeight);
             } else {
                 child.setBounds (childX, childY, childWidth, childHeight);
@@ -410,13 +433,13 @@
     }
     maxY = Math.max (clientY + marginTop + marginHeight, maxY - spacing);
     if (!wrapped) maxY += marginBottom + marginHeight;
-    if (move && (justify || fill)) {
+    if (move && (justify || fill || center)) {
         int space = 0, margin = 0;
         if (!wrapped) {
             space = Math.max (0, (height - maxY) / (count + 1));
             margin = Math.max (0, ((height - maxY) % (count + 1)) / 2);
         } else {
-            if (fill || justify) {
+            if (fill || justify || center) {
                 int last = 0;
                 if (count > 0) wraps [count - 1] = maxWidth;
                 for (int i=0; i<count; i++) {
@@ -432,7 +455,13 @@
                         }
                         for (int j=last; j<=i; j++) {
                             if (justify) bounds [j].y += (space * (j - last + 1)) + margin;
-                            if (fill) bounds [j].width = wraps [i];
+                            if (fill) {
+                                bounds [j].width = wraps [i];
+                            } else {
+                                if (center) {
+                                    bounds [j].x += Math.max (0, (wraps [i] - bounds [j].width) / 2);
+                                }
+                            }
                         }
                         last = i + 1;
                     }
@@ -442,7 +471,14 @@
         for (int i=0; i<count; i++) {
             if (!wrapped) {
                 if (justify) bounds [i].y += (space * (i + 1)) + margin;
-                if (fill) bounds [i].width = maxWidth;
+                if (fill) {
+                    bounds [i].width = maxWidth;
+                } else {
+                    if (center) {
+                        bounds [i].x += Math.max (0, (maxWidth - bounds [i].width) / 2);
+                    }
+                }
+
             }
             children [i].setBounds (bounds [i]);
         }