Mercurial > projects > mde
comparison 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 |
comparison
equal
deleted
inserted
replaced
137:9f035cd139c6 | 138:3468e9bfded1 |
---|---|
76 adapter = mgr.renderer.getAdapter (data.ints[1]); | 76 adapter = mgr.renderer.getAdapter (data.ints[1]); |
77 adapter.text = data.strings[0]; | 77 adapter.text = data.strings[0]; |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 /** Basic widget displaying a label from a content. | 81 /** Displays text from a content. |
82 * | 82 * |
83 * Can display value, name, description or possibly other field of a content, dependent on | 83 * Displays the value, name, description or possibly another field of a |
84 * data.ints[1]. */ | 84 * content, depending on data.ints[2]. */ |
85 class ContentLabelWidget : ATextWidget | 85 class DisplayContentWidget : ATextWidget |
86 { | 86 { |
87 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) { | 87 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) { |
88 content = c; | 88 content = cast(Content) c; |
89 WDCCheck (data, 3, 0, content); | 89 WDCMinCheck (data, 1, 0, content); |
90 super (mgr, parent, id); | 90 super (mgr, parent, id); |
91 index = data.ints[1]; | 91 |
92 adapter = mgr.renderer.getAdapter (data.ints[2]); | 92 if (data.ints.length >= 3) |
93 cIndex = data.ints[2]; // otherwise display '0', the value | |
94 if (cIndex == 0) | |
95 content.addCallback (&updateVal); | |
96 | |
97 adapter = mgr.renderer.getAdapter (); | |
93 } | 98 } |
94 | 99 |
95 override bool setup (uint n, uint flags) { | 100 override bool setup (uint n, uint flags) { |
96 if (!(flags & 3)) return false; // string or renderer (and possibly font) changed | 101 if (!(flags & 3)) return false; // string or renderer (and possibly font) changed |
97 adapter.text = content.toString(index); | 102 adapter.text = content.toString(cIndex); |
98 return super.setup (n, 3); // force redimensioning | 103 return super.setup (n, 3); // force redimensioning |
99 } | 104 } |
100 | 105 |
101 protected: | 106 protected: |
102 IContent content; | 107 void updateVal (Content) { // callback |
103 int index; | 108 adapter.text = content.toString(cIndex); |
104 } | 109 wdim omw = mw, omh = mh; |
105 | 110 adapter.getDimensions (mw, mh); |
106 /// Just displays the value of a content. Generic − any IContent. | 111 if (omw != mw) |
107 class DisplayContentWidget : ATextWidget | 112 parent.minWChange (this, mw); |
108 { | 113 if (omh != mh) |
109 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData, IContent c) { | 114 parent.minHChange (this, mh); |
110 content = c; | |
111 if (content is null) throw new ContentException (this); | |
112 super (mgr, parent, id); | |
113 | |
114 Content c2 = cast(Content) content; | |
115 if (c2) // add callback if possible | |
116 c2.addCallback (&update); | |
117 adapter = mgr.renderer.getAdapter (); | |
118 adapter.text = content.toString(0); | |
119 } | 115 } |
120 | 116 Content content; |
121 protected: | 117 int cIndex; |
122 void update (Content) { // callback | |
123 adapter.text = content.toString(0); | |
124 } | |
125 IContent content; | |
126 } | 118 } |
127 | 119 |
128 /// Text-box for editing a content's value. Generic − any AStringContent. | 120 /// Text-box for editing a content's value. Generic − any AStringContent. |
129 class AStringContentWidget : ATextWidget | 121 class AStringContentWidget : ATextWidget |
130 { | 122 { |