# HG changeset patch # User Diggory Hardy # Date 1231260844 0 # Node ID 3e648bc53bde557502e6173df1f74c354f14f4fe # Parent a2ef6b549101f0e595e7aa1f5fc98f1bce3315c2 Added a simple switch/tab widget (depends on existing EnumContent). diff -r a2ef6b549101 -r 3e648bc53bde data/conf/guiDemo.mtt --- 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 @@ {Working} - + @@ -24,5 +24,10 @@ + + + + {Basic} diff -r a2ef6b549101 -r 3e648bc53bde mde/content/Items.d --- 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); } diff -r a2ef6b549101 -r 3e648bc53bde mde/gui/WidgetManager.d --- 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", diff -r a2ef6b549101 -r 3e648bc53bde mde/gui/widget/Ifaces.d --- 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); } diff -r a2ef6b549101 -r 3e648bc53bde mde/gui/widget/miscContent.d --- 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 . */ /************************************************************************************************* - * 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; +} diff -r a2ef6b549101 -r 3e648bc53bde mde/imde.d --- 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. */