# HG changeset patch # User Diggory Hardy # Date 1234270629 0 # Node ID 66c58e5b0062b17739a710cd94aa1708a28845bb # Parent 2ac3e001278863e90ba47a330f169d804206e237 Added a BoolContent-based collapsible widget. diff -r 2ac3e0012788 -r 66c58e5b0062 data/conf/guiDemo.mtt --- 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 @@ {Working} - + @@ -34,6 +34,9 @@ + {Basic} diff -r 2ac3e0012788 -r 66c58e5b0062 mde/gui/WidgetDataSet.d --- 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)); } } diff -r 2ac3e0012788 -r 66c58e5b0062 mde/gui/WidgetManager.d --- 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"]; diff -r 2ac3e0012788 -r 66c58e5b0062 mde/gui/widget/AChildWidget.d --- 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. diff -r 2ac3e0012788 -r 66c58e5b0062 mde/gui/widget/Floating.d --- 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 () { diff -r 2ac3e0012788 -r 66c58e5b0062 mde/gui/widget/Ifaces.d --- 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 diff -r 2ac3e0012788 -r 66c58e5b0062 mde/gui/widget/ParentContent.d --- 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; +} diff -r 2ac3e0012788 -r 66c58e5b0062 mde/gui/widget/layout.d --- 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