Mercurial > projects > mde
changeset 144:66c58e5b0062
Added a BoolContent-based collapsible widget.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Tue, 10 Feb 2009 12:57:09 +0000 |
parents | 2ac3e0012788 |
children | 1048b5c7cab1 |
files | data/conf/guiDemo.mtt mde/gui/WidgetDataSet.d mde/gui/WidgetManager.d mde/gui/widget/AChildWidget.d mde/gui/widget/Floating.d mde/gui/widget/Ifaces.d mde/gui/widget/ParentContent.d mde/gui/widget/layout.d |
diffstat | 8 files changed, 117 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/data/conf/guiDemo.mtt Mon Feb 09 23:27:41 2009 +0000 +++ b/data/conf/guiDemo.mtt Tue Feb 10 12:57:09 2009 +0000 @@ -3,7 +3,7 @@ <char[]|Design="Working"> {Working} <WidgetData|root={0:[0x4100,0,2,1],1:["bar","float"]}> -<WidgetData|float={0:[0x4200,14,14],1:["options","slider"]}> +<WidgetData|float={0:[0x4200,14,14],1:["options","sliderCB"]}> <WidgetData|bar={0:[0x4100,14,1,3],1:["menuContent","blank","allContent"]}> <WidgetData|blank={0:[0x2]}> @@ -34,6 +34,9 @@ <WidgetData|optEnum={0:[0x4100,1,1,2],1:["optName","optVal"]}> <WidgetData|optSep={0:[0x21, 0xff],1:[" = "]}> +<BoolContent|gui.collapse=> +<WidgetData|sliderCB={0:[0x2031],1:["gui.collapse","sliderC"]}> +<WidgetData|sliderC={0:[0x4214],1:["slider"]}> <WidgetData|slider={0:[0x2031],1:["MiscOptions.pollInterval","sliderW"]}> <WidgetData|sliderW={0:[0x4044]}> {Basic}
--- a/mde/gui/WidgetDataSet.d Mon Feb 09 23:27:41 2009 +0000 +++ b/mde/gui/WidgetDataSet.d Tue Feb 10 12:57:09 2009 +0000 @@ -54,8 +54,9 @@ widgetData[id] = deserialize!(WidgetData) (dt); } else if (tp == "WDims" && (id in dimData) is null) { dimData[id] = cast(wdims) deserialize!(int[]) (dt); + } else if (tp == "BoolContent" && (id in Content.allContent) is null) { + new BoolContent (id); } else if (tp == "EnumContent" && (id in Content.allContent) is null) { - // Add dynamic content. new EnumContent (id, deserialize!(char[][]) (dt)); } }
--- a/mde/gui/WidgetManager.d Mon Feb 09 23:27:41 2009 +0000 +++ b/mde/gui/WidgetManager.d Tue Feb 10 12:57:09 2009 +0000 @@ -509,6 +509,7 @@ FloatingArea = TAKES_CONTENT | 0x200, Switch = TAKES_CONTENT | 0x210, + Collapsible = TAKES_CONTENT | 0x214, } // Only used for binarySearch algorithm generation; must be ordered by numerical values. @@ -528,6 +529,7 @@ "ContentList", "FloatingArea", "Switch", + "Collapsible", "editContent", "popupListContent"];
--- a/mde/gui/widget/AChildWidget.d Mon Feb 09 23:27:41 2009 +0000 +++ b/mde/gui/widget/AChildWidget.d Tue Feb 10 12:57:09 2009 +0000 @@ -50,8 +50,8 @@ } // Widgets need to do their initialization either in this() or setup(). - override bool setup (uint,uint) { - return false; + override bool setup (uint n,uint) { + return n == 0; } // Don't save any data: fine for many widgets.
--- a/mde/gui/widget/Floating.d Mon Feb 09 23:27:41 2009 +0000 +++ b/mde/gui/widget/Floating.d Tue Feb 10 12:57:09 2009 +0000 @@ -63,7 +63,7 @@ debug (mdeWidgets) logger.trace ("FloatingAreaWidget.setup"); foreach (i, ref d; sWData) with (d) { auto widg = subWidgets[i]; - if (!widg.setup (n, flags) && n != 0 && !(flags & 1)) + if (!widg.setup (n, flags) && !(flags & 1)) continue; // no changes; skip the rest d.border = mgr.renderer.getBorder (borderType, widg.isWSizable, widg.isHSizable); @@ -74,7 +74,7 @@ widg.setWidth (w - border.x1 - border.x2, -1); widg.setHeight (h - border.y1 - border.y2, -1); } - return false; // floating area size is not changed + return n == 0; // floating area size is not changed } override bool saveChanges () {
--- a/mde/gui/widget/Ifaces.d Mon Feb 09 23:27:41 2009 +0000 +++ b/mde/gui/widget/Ifaces.d Tue Feb 10 12:57:09 2009 +0000 @@ -273,8 +273,9 @@ //BEGIN Load and save /** 2nd stage of initialization for widgets; also called on some changes. * - * Widgets should call recursively on their children, redo anything indicated by flags, and - * adjust their size and other cached data dependant on any thing which may have changed. + * Widgets should call recursively on their children, redo anything + * indicated by flags, and adjust their size and other cached data + * dependant on any thing which may have changed. * Widgets may rely on setPosition being called afterwards. * * Params: @@ -284,9 +285,8 @@ * These flags are always true on first run. * * Returns: - * The method should return true if the dimensions (may) have been changed. This may not be - * the case on the first run (when n == 0)!. - */ + * The method must return true on initial setup and if its dimensions + * (may) have changed. */ bool setup (uint n, uint flags); /** When this is called, if the widget has any changed data to save it should call
--- a/mde/gui/widget/ParentContent.d Mon Feb 09 23:27:41 2009 +0000 +++ b/mde/gui/widget/ParentContent.d Tue Feb 10 12:57:09 2009 +0000 @@ -227,3 +227,102 @@ bool isWS, isHS; // no infrastructure for changing sizability, so need to fix it. } + +/** A collapsible widget: shows/hides a child dependant on a BoolContent. + * + * Sizability is set once. Min-size is changed (but cannot force size to 0). + * + * Uses its content as a switch, which means content cannot be passed through. + * A builtin button would improve this. */ +class CollapsibleWidget : AParentWidget +{ + this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) { + super (mgr, parent, id); + content = cast(BoolContent) c; + WDCCheck (data, 1, 1, content); + + subWidgets = [mgr.makeWidget (this, data.strings[0])]; + + content.addCallback (&collapse); + } + + override bool setup (uint n, uint flags) { + bool r = super.setup (n, flags); + if (r) { + collapsed = content(); + if (!collapsed) { + mw = subWidgets[0].minWidth; + mh = subWidgets[0].minHeight; + w = subWidgets[0].width; + h = subWidgets[0].height; + } + } + return r; + } + + override void minWChange (IChildWidget widget, wdim nmw) { + debug assert (widget is subWidgets[0]); + mw = nmw; + parent.minWChange (this, nmw); + } + override void minHChange (IChildWidget widget, wdim nmh) { + debug assert (widget is subWidgets[0]); + mh = nmh; + parent.minHChange (this, nmh); + } + + // Doesn't change: + override bool isWSizable () { + return subWidgets[0].isWSizable; + } + override bool isHSizable () { + return subWidgets[0].isHSizable; + } + + override void setWidth (wdim nw, int dir) { + w = (nw >= mw ? nw : mw); + if (!collapsed) subWidgets[0].setWidth (w, dir); + } + override void setHeight (wdim nh, int dir) { + h = (nh >= mh ? nh : mh); + if (!collapsed) subWidgets[0].setHeight (h, dir); + } + + override void setPosition (wdim nx, wdim ny) { + x = nx; + y = ny; + if (!collapsed) subWidgets[0].setPosition (nx,ny); + } + + override IChildWidget getWidget (wdim cx, wdim cy) { + if (!collapsed) + return subWidgets[0].getWidget (cx, cy); + else return this; + } + + override void draw () { + if (!collapsed) subWidgets[0].draw; + } + +protected: + // callback on content + void collapse (Content) { + collapsed = content(); + if (collapsed) { + mw = mh = 0; + } else { + mw = subWidgets[0].minWidth; + mh = subWidgets[0].minHeight; + } + parent.minWChange (this, mw); + parent.minHChange (this, mh); + if (collapsed) return; + // set incase parent didn't: + subWidgets[0].setWidth (w, -1); + subWidgets[0].setHeight (h, -1); + subWidgets[0].setPosition (x,y); + } + + bool collapsed = false; + BoolContent content; +}
--- a/mde/gui/widget/layout.d Mon Feb 09 23:27:41 2009 +0000 +++ b/mde/gui/widget/layout.d Tue Feb 10 12:57:09 2009 +0000 @@ -220,7 +220,7 @@ widget.setWidth (col.width[i % cols], -1); widget.setHeight (row.width[i / cols], -1); } - return (ow != w || oh != h); + return (ow != w || oh != h || n == 0); } //END Creation & saving