changeset 125:3e648bc53bde

Added a simple switch/tab widget (depends on existing EnumContent).
author Diggory Hardy <diggory.hardy@gmail.com>
date Tue, 06 Jan 2009 16:54:04 +0000
parents a2ef6b549101
children c9843fbaac88
files data/conf/guiDemo.mtt mde/content/Items.d mde/gui/WidgetManager.d mde/gui/widget/Ifaces.d mde/gui/widget/miscContent.d mde/imde.d
diffstat 6 files changed, 96 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/data/conf/guiDemo.mtt	Mon Jan 05 12:43:27 2009 +0000
+++ b/data/conf/guiDemo.mtt	Tue Jan 06 16:54:04 2009 +0000
@@ -3,7 +3,7 @@
 <char[]|Design="Working">
 {Working}
 <WidgetData|root={0:[0x4100,0,3,1],1:["bar","float","bar"]}>
-<WidgetData|float={0:[0x4200,14],1:["optaC"]}>
+<WidgetData|float={0:[0x4200,14,14],1:["optaC","switchC"]}>
 <WidgetData|bar={0:[0x4100,14,1,3],1:["menu","blank","menu"]}>
 <WidgetData|menu={0:[0x2031],1:["imde.menu","menu0"]}>
 <WidgetData|menu0={0:[0x4011,0],1:["menu1"]}>
@@ -24,5 +24,10 @@
 <WidgetData|optVal={0:[0xE030,12],1:["optEnum"]}>
 <WidgetData|optEnum={0:[0x4100,0,1,2],1:["optVal","optName"]}>
 <WidgetData|optSep={0:[0x21, 0xff],1:[" = "]}>
+<WidgetData|switchC={0:[0x2031],1:["imde.sw","switchL"]}>
+<WidgetData|switchL={0:[0x4100,0,2,1],1:["optVal","switchT"]}>
+<WidgetData|switchT={0:[0x4210],1:["1","2"]}>
+<WidgetData|1={0:[0x21,0xcf],1:["one"]}>
+<WidgetData|2={0:[0x21,0xcf],1:["two  T  W  O"]}>
 {Basic}
 <WidgetData|root={0:[0x21,0x90D970],1:["A string!"]}>
--- a/mde/content/Items.d	Mon Jan 05 12:43:27 2009 +0000
+++ b/mde/content/Items.d	Tue Jan 06 16:54:04 2009 +0000
@@ -63,7 +63,10 @@
 		return imde.menu;
 	    else if (h == "quit" && item is null)
 		return imde.quit;
+            else if (h == "sw" && item is null)
+                return imde.sw;
 	}
+        logger.warn ("Bad content specifier: {}",h);
 	return new ErrorContent ("Error: bad content specifier",h);
     }
     
--- a/mde/gui/WidgetManager.d	Mon Jan 05 12:43:27 2009 +0000
+++ b/mde/gui/WidgetManager.d	Tue Jan 06 16:54:04 2009 +0000
@@ -407,6 +407,7 @@
     ContentList		= TAKES_CONTENT | SAFE_RECURSION | 0x110,
     
     FloatingArea	= TAKES_CONTENT | 0x200,
+    Switch		= TAKES_CONTENT | 0x210,
 }
 
 // Only used for binarySearch algorithm generation; must be ordered by numerical values.
@@ -426,6 +427,7 @@
 	"MenuButtonContent",
 	"GridLayout",
 	"FloatingArea",
+	"Switch",
 	"subMenuContent",
 	"ContentList",
 	"editContent",
--- a/mde/gui/widget/Ifaces.d	Mon Jan 05 12:43:27 2009 +0000
+++ b/mde/gui/widget/Ifaces.d	Tue Jan 06 16:54:04 2009 +0000
@@ -53,6 +53,8 @@
      *	widget	= The child widget calling the function
      *	mw	= New minimal width
      *	mh	= New minimal height */
+    //FIXME: set rules for setting size: i.e. can widget rely on parent (ulimately mgr) setting
+    // a new size?
     void minSizeChange (IChildWidget widget, wdim mw, wdim mh);
 }
 
--- a/mde/gui/widget/miscContent.d	Mon Jan 05 12:43:27 2009 +0000
+++ b/mde/gui/widget/miscContent.d	Tue Jan 06 16:54:04 2009 +0000
@@ -14,7 +14,7 @@
 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 /*************************************************************************************************
- * A function to return content widgets and some miscellaneous content widgets.
+ * A function to return content widgets and some miscellaneous content display/editing widgets.
  *************************************************************************************************/
 module mde.gui.widget.miscContent;
 
@@ -132,3 +132,80 @@
     EventContent content;
     int index;
 }
+
+/** A "tab" widget: it doesn't display the tabs, but shows one of a number of widgets dependant on
+ * an EnumContent. */
+class SwitchWidget : AParentWidget
+{
+    this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) {
+        super (mgr, parent, id);
+        content = cast(EnumContent) c;
+        if (content is null || (subWidgets.length = content.list.length) == 0)
+            throw new ContentException (this);
+        WDCheck (data, 1, subWidgets.length);
+        
+        foreach (i,sc; content.list)
+            subWidgets[i] = mgr.makeWidget (this, data.strings[i], sc);
+        currentW = subWidgets[content()];
+        
+        content.addCallback (&switchWidget);
+    }
+    
+    override bool setup (uint n, uint flags) {
+        bool r = super.setup (n, flags);
+        if (r) {
+            mw = currentW.minWidth;
+            mh = currentW.minHeight;
+            w = currentW.width;
+            h = currentW.height;
+        }
+        return r;
+    }
+    
+    override void minSizeChange (IChildWidget widget, wdim nmw, wdim nmh) {
+        mw = nmw;
+        mh = nmh;
+        parent.minSizeChange (this, nmw, nmh);
+    }
+    
+    override bool isWSizable () {
+        return currentW.isWSizable;
+    }
+    override bool isHSizable () {
+        return currentW.isHSizable;
+    }
+    
+    override void setWidth (wdim nw, int dir) {
+	w = (nw >= mw ? nw : mw);
+        currentW.setWidth (w, dir);
+    }
+    override void setHeight (wdim nh, int dir) {
+        h = (nh >= mh ? nh : mh);
+        currentW.setHeight (h, dir);
+    }
+    
+    override void setPosition (wdim nx, wdim ny) {
+        x = nx;
+        y = ny;
+        currentW.setPosition (nx,ny);
+    }
+    
+    override void draw () {
+        currentW.draw;
+    }
+    
+protected:
+    // callback on content
+    void switchWidget (Content) {
+        currentW = subWidgets[content()];
+        mw = currentW.minWidth;
+        mh = currentW.minHeight;
+        parent.minSizeChange (this, mw, mh);
+        w = currentW.width;
+        h = currentW.height;
+        currentW.setPosition (x,y);
+    }
+    
+    IChildWidget currentW;
+    EnumContent content;
+}
--- a/mde/imde.d	Mon Jan 05 12:43:27 2009 +0000
+++ b/mde/imde.d	Tue Jan 06 16:54:04 2009 +0000
@@ -20,6 +20,7 @@
 import mde.input.Input;
 import mde.scheduler.Scheduler;
 import mde.content.miscContent;
+import mde.content.AStringContent;	//FIXME: for sw
 
 static this () {
     // Make these available to all importing modules' static CTORs, as well as during init.
@@ -36,11 +37,15 @@
                                            new EventContent("b"),
                                            new EventContent("c")])
                             ]);
+    
+    sw = new EnumContent ("switch", ["one", "two"]);
 }
 
 ContentList menu;	/// Root menu for imde
 EventContent quit;	/// A content triggering mde to halt
 
+EnumContent sw;
+
 Scheduler mainSchedule; /// The schedule used by the main loop.
 
 /** Some enums used by per request scheduled functions. */