changeset 109:2a1428ec5344

Optional, visible spacing in grid layouts.
author Diggory Hardy <diggory.hardy@gmail.com>
date Thu, 04 Dec 2008 10:32:20 +0000
parents c9fc2d303178
children 6acd96f8685f
files data/conf/gui.mtt mde/gui/renderer/IRenderer.d mde/gui/renderer/SimpleRenderer.d mde/gui/widget/layout.d
diffstat 4 files changed, 33 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/data/conf/gui.mtt	Wed Dec 03 19:37:32 2008 +0000
+++ b/data/conf/gui.mtt	Thu Dec 04 10:32:20 2008 +0000
@@ -7,8 +7,8 @@
 <WidgetData|menu={0:[0xC011],1:["quit","Menu"]}>
 <WidgetData|square={0:[0x1,6,6]}>
 <WidgetData|blank={0:[0x2]}>
-<WidgetData|opts={0:[0x2031,0xC100,0,2,1],1:["Options","optName","optSecs"]}>
-<WidgetData|optSecs={0:[0x6030,0],1:["optSec"]}>
+<WidgetData|opts={0:[0x2031,0xC100,4,2,1],1:["Options","optName","optSecs"]}>
+<WidgetData|optSecs={0:[0x6030,4],1:["optSec"]}>
 <WidgetData|optSec={0:[0xC100,0,2,1],1:["optName","optVars"]}>
 <WidgetData|optVars={0:[0x6030,0],1:["optDBox"]}>
 <WidgetData|optDBox={0:[0xC100,1,2,1],1:["optBox","optDesc"]}>
--- a/mde/gui/renderer/IRenderer.d	Wed Dec 03 19:37:32 2008 +0000
+++ b/mde/gui/renderer/IRenderer.d	Thu Dec 04 10:32:20 2008 +0000
@@ -142,6 +142,14 @@
     /** Draw a window border plus background. */
     void drawWindow (Border* border, wdim x, wdim y, wdim w, wdim h);
     
+    /** Draw vertical and horizontal spacers.
+     *
+     * x,y and w,h are the position and size of the grid containing spacers.
+     * 
+     * For each col in cols, spacers should be drawn in the rectangle
+     * [x+col-layoutSpacing,x+col)*[y,y+h), and similarly for rows. */
+    void drawSpacers (wdabs x, wdabs y, wdsize w, wdsize h, wdims cols, wdims rows);
+    
     /** Draws a widget background. Usually doesn't do anything since backgrounds are transparent.
      *
      * It used to be required for all widgets to do this, but I lapsed since mostly it's unused. */
--- a/mde/gui/renderer/SimpleRenderer.d	Wed Dec 03 19:37:32 2008 +0000
+++ b/mde/gui/renderer/SimpleRenderer.d	Thu Dec 04 10:32:20 2008 +0000
@@ -54,7 +54,7 @@
     }
     
     wdim layoutSpacing () {
-        return 0;
+        return 5;
     }
     
     
@@ -97,6 +97,22 @@
         glRecti(x+border.x1, y+h-border.y2, x+w-border.x2, y+border.y1);
     }
 
+    void drawSpacers (wdabs x, wdabs y, wdsize w, wdsize h, wdims cols, wdims rows) {
+        glColor3f (.2f, .2f, .2f);
+        glBegin (GL_LINES);
+        wdabs t = x - cast(wdim) 3;
+        foreach (col; cols) {
+            glVertex2i (t + col, y);
+            glVertex2i (t + col, y + h);
+        }
+        t = y - cast(wdim) 3;
+        foreach (row; rows) {
+            glVertex2i (x, t + row);
+            glVertex2i (x + w, t + row);
+        }
+        glEnd ();
+    }
+    
     void drawWidgetBack (wdim x, wdim y, wdim w, wdim h) {
         debug {
             glColor3f (0f, .2f, .2f);
--- a/mde/gui/widget/layout.d	Wed Dec 03 19:37:32 2008 +0000
+++ b/mde/gui/widget/layout.d	Thu Dec 04 10:32:20 2008 +0000
@@ -170,6 +170,7 @@
         else
             row = (new AlignColumns (rows));
         row.addSetCallback (&setRowHeight);
+        useSpacing = (data.ints[1] & 4) != 0;
     }
     
     /** Prior to finalizing but after sub-widgets are finalized, some information needs to be
@@ -276,6 +277,9 @@
         
         foreach (widget; subWidgets)
             widget.draw ();
+        
+        if (useSpacing)
+            mgr.renderer.drawSpacers (x,y, w,h, col.pos[1..$], row.pos[1..$]);
     }
     
 package:
@@ -288,7 +292,7 @@
     void genCachedConstructionData () {
         // Will only change if renderer changes:
         // NOTE shared AlignColumns get this set by all sharing GridWidgets
-        col.spacing = row.spacing = mgr.renderer.layoutSpacing;
+        col.spacing = row.spacing = useSpacing ? mgr.renderer.layoutSpacing : 0;
         
         // Calculate the minimal column and row sizes:
         // AlignColumns (row, col) takes care of initializing minWidth.
@@ -366,6 +370,7 @@
     
     myIt cols, rows;	// number of cells in grid
     wdim[] initWidths;  // see this / setInitialSize
+    bool useSpacing;	// true if spacing should be applied
     
     /* All widgets in the grid, by row. Order:  [ 0 1 ]
      *                                          [ 2 3 ] */