Mercurial > projects > mde
diff mde/gui/widget/TextWidget.d @ 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 | 9cff74f68b84 |
children | 1048b5c7cab1 |
line wrap: on
line diff
--- 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.