Mercurial > projects > mde
changeset 138:3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Sat, 07 Feb 2009 13:28:52 +0000 |
parents | 9f035cd139c6 |
children | 29a524e7c858 |
files | data/conf/guiDemo.mtt mde/gui/WidgetManager.d mde/gui/widget/PopupMenu.d mde/gui/widget/TextWidget.d mde/gui/widget/contentFunctions.d mde/gui/widget/layout.d |
diffstat | 6 files changed, 57 insertions(+), 49 deletions(-) [+] |
line wrap: on
line diff
--- a/data/conf/guiDemo.mtt Sat Feb 07 12:46:03 2009 +0000 +++ b/data/conf/guiDemo.mtt Sat Feb 07 13:28:52 2009 +0000 @@ -9,8 +9,7 @@ <WidgetData|menuContent={0:[0x2031],1:["menus","menus"]}> <WidgetData|menus={0:[0x4110,12] ,1:["menuPopup"]}> -<WidgetData|menuPopup={0:[0x6033,0],1:["menuList"]}> -<WidgetData|menuList={0:[0x6030,0] ,1:["menuPopup"]}> +<WidgetData|menuPopup={0:[0x6033,0,1],1:["menuPopup"]}> <EnumContent|gui.switch=["misc","video","font"]> <WidgetData|options={0:[0x2031],1:["gui.switch","switchL"]}> @@ -23,12 +22,12 @@ <WidgetData|optFont={0:[0x2031],1:["Font","optSec"]}> !{use optBox for no description, optDBox for descriptions under entries} -<WidgetData|optSec={0:[0x4110,0],1:["optBox"]}> +<WidgetData|optSec={0:[0x4110,0],1:["optDBox"]}> <WidgetData|optDBox={0:[0x4100,1,2,1],1:["optBox","optDesc"]}> <WidgetData|optBox={0:[0x4100,1,1,3],1:["optName","optSep","optVal"]}> -<WidgetData|optName={0:[0x4020, 1, 0xffffff]}> -<WidgetData|optDesc={0:[0x4020, 2, 0x999999]}> -<WidgetData|optVal={0:[0x6030,12],1:["optEnum"]}> +<WidgetData|optName={0:[0x4040, 0,1]}> +<WidgetData|optDesc={0:[0x4040, 0,2]}> +<WidgetData|optVal={0:[0x6030,12,0],1:["optEnum"]}> <WidgetData|optEnum={0:[0x4100,0,1,2],1:["optVal","optName"]}> <WidgetData|optSep={0:[0x21, 0xff],1:[" = "]}> {Basic}
--- a/mde/gui/WidgetManager.d Sat Feb 07 12:46:03 2009 +0000 +++ b/mde/gui/WidgetManager.d Sat Feb 07 13:28:52 2009 +0000 @@ -490,7 +490,6 @@ PopupMenu = TAKES_CONTENT | 0x11, // labels: 0x20 - ContentLabel = TAKES_CONTENT | 0x20, TextLabel = 0x21, // content functions: 0x30 @@ -519,7 +518,6 @@ "addContent", "Debug", "PopupMenu", - "ContentLabel", "DisplayContent", "BoolContent", "AStringContent",
--- a/mde/gui/widget/PopupMenu.d Sat Feb 07 12:46:03 2009 +0000 +++ b/mde/gui/widget/PopupMenu.d Sat Feb 07 13:28:52 2009 +0000 @@ -20,6 +20,7 @@ import mde.gui.widget.AParentWidget; +import mde.gui.widget.layout; import mde.content.Content; import mde.gui.exception; @@ -33,19 +34,27 @@ /****************************************************************************** * Widget which pops up a menu based on a content. + * + * Is a button displaying a content string, just like DisplayContentWidget. + * + * Popped up widget is a ContentListWidget created from the same creation data. *****************************************************************************/ class PopupMenuWidget : APopupParentWidget { this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) { - content = c; - WDCMinCheck (data, 1,1, content); + content = cast(Content)c; + WDCMinCheck (data, 3,1, content); super (mgr, parent, id); - popup = mgr.makeWidget (this, data.strings[0], content); + //popup = mgr.makeWidget (this, data.strings[0], content); + popup = new ContentListWidget (mgr, this, id, data, c); subWidgets = [popup]; - adapter = mgr.renderer.getAdapter; - adapter.text = content.toString (1); + cIndex = data.ints[2]; + if (cIndex == 0) + content.addCallback (&updateVal); + adapter = mgr.renderer.getAdapter; + adapter.text = content.toString (cIndex); adapter.getDimensions (mw, mh); w = mw; h = mh; @@ -92,7 +101,17 @@ } protected: + void updateVal (Content) { // callback + adapter.text = content.toString(cIndex); + wdim omw = mw, omh = mh; + adapter.getDimensions (mw, mh); + if (omw != mw) + parent.minWChange (this, mw); + if (omh != mh) + parent.minHChange (this, mh); + } bool pushed = false; IRenderer.TextAdapter adapter; - IContent content; + Content content; + int cIndex; }
--- a/mde/gui/widget/TextWidget.d Sat Feb 07 12:46:03 2009 +0000 +++ b/mde/gui/widget/TextWidget.d Sat Feb 07 13:28:52 2009 +0000 @@ -78,51 +78,43 @@ } } -/** Basic widget displaying a label from a content. +/** Displays text from a content. * - * Can display value, name, description or possibly other field of a content, dependent on - * data.ints[1]. */ -class ContentLabelWidget : ATextWidget + * Displays the value, name, description or possibly another field of a + * content, depending on data.ints[2]. */ +class DisplayContentWidget : ATextWidget { this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) { - content = c; - WDCCheck (data, 3, 0, content); + content = cast(Content) c; + WDCMinCheck (data, 1, 0, content); super (mgr, parent, id); - index = data.ints[1]; - adapter = mgr.renderer.getAdapter (data.ints[2]); + + if (data.ints.length >= 3) + cIndex = data.ints[2]; // otherwise display '0', the value + if (cIndex == 0) + content.addCallback (&updateVal); + + adapter = mgr.renderer.getAdapter (); } override bool setup (uint n, uint flags) { if (!(flags & 3)) return false; // string or renderer (and possibly font) changed - adapter.text = content.toString(index); - return super.setup (n, 3); // force redimensioning + adapter.text = content.toString(cIndex); + return super.setup (n, 3); // force redimensioning } protected: - IContent content; - int index; -} - -/// Just displays the value of a content. Generic − any IContent. -class DisplayContentWidget : ATextWidget -{ - this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData, IContent c) { - content = c; - if (content is null) throw new ContentException (this); - super (mgr, parent, id); - - Content c2 = cast(Content) content; - if (c2) // add callback if possible - c2.addCallback (&update); - adapter = mgr.renderer.getAdapter (); - adapter.text = content.toString(0); + void updateVal (Content) { // callback + adapter.text = content.toString(cIndex); + wdim omw = mw, omh = mh; + adapter.getDimensions (mw, mh); + if (omw != mw) + parent.minWChange (this, mw); + if (omh != mh) + parent.minHChange (this, mh); } - -protected: - void update (Content) { // callback - adapter.text = content.toString(0); - } - IContent content; + Content content; + int cIndex; } /// Text-box for editing a content's value. Generic − any AStringContent.
--- a/mde/gui/widget/contentFunctions.d Sat Feb 07 12:46:03 2009 +0000 +++ b/mde/gui/widget/contentFunctions.d Sat Feb 07 13:28:52 2009 +0000 @@ -49,7 +49,7 @@ if (c is null) throw new ContentException; if (cast(AStringContent) c) { if (cast(EnumContent) c) // can be PopupMenuWidget or ContentListWidget - return new ContentListWidget(mgr,parent,id,data,c); + return new PopupMenuWidget(mgr,parent,id,data,c); if (cast(BoolContent) c) return new BoolContentWidget(mgr,parent,id,data,c); return new AStringContentWidget(mgr,parent,id,data,c);
--- a/mde/gui/widget/layout.d Sat Feb 07 12:46:03 2009 +0000 +++ b/mde/gui/widget/layout.d Sat Feb 07 13:28:52 2009 +0000 @@ -95,7 +95,7 @@ { this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent content) { cList = cast(IContentList) content; - WDCCheck (data, 2, 1, cList); + WDCMinCheck (data, 2, 1, cList); cols = 1; rows = cList.list.length; subWidgets.length = rows;