comparison mde/gui/widget/TextWidget.d @ 111:1655693702fc

Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run. Removed prefinalize and finalize and added setup as the new second initialization phase, which can be re-run.
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 06 Dec 2008 17:41:42 +0000
parents 6acd96f8685f
children fe061009029d
comparison
equal deleted inserted replaced
110:6acd96f8685f 111:1655693702fc
36 class ATextWidget : AWidget 36 class ATextWidget : AWidget
37 { 37 {
38 /** Set the adapter first: 38 /** Set the adapter first:
39 * adapter = mgr.renderer.getAdapter ("string", 0xRRGGBB); */ 39 * adapter = mgr.renderer.getAdapter ("string", 0xRRGGBB); */
40 this (IWidgetManager mgr, widgetID id, WidgetData data) { 40 this (IWidgetManager mgr, widgetID id, WidgetData data) {
41 adapter.getDimensions (mw, mh);
42 w = mw;
43 h = mh;
44 super (mgr, id, data); 41 super (mgr, id, data);
45 } 42 }
46 43
47 bool reloadStrings () { 44 /** Recalculates dims if the renderer changed. */
48 adapter.getDimensions (mw, mh); 45 bool setup (uint,uint flags) {
49 bool r = (mw != w || mh != h) ? true : false; 46 if (flags & 1) {
50 w = mw; 47 adapter.getDimensions (mw, mh);
51 h = mh; 48 if (mw != w || mh != h) {
52 return true; 49 w = mw;
50 h = mh;
51 return true;
52 }
53 }
54 return false;
53 } 55 }
54 56
55 void draw () { 57 void draw () {
56 super.draw(); 58 super.draw();
57 adapter.draw (x,y); 59 adapter.draw (x,y);
71 * [widgetID, contentID, colour] 73 * [widgetID, contentID, colour]
72 * where contentID is an ID for the string ID of the contained content 74 * where contentID is an ID for the string ID of the contained content
73 * and colour is an 8-bit-per-channel RGB colour of the form 0xRRGGBB. */ 75 * and colour is an 8-bit-per-channel RGB colour of the form 0xRRGGBB. */
74 this (IWidgetManager mgr, widgetID id, WidgetData data) { 76 this (IWidgetManager mgr, widgetID id, WidgetData data) {
75 WDCheck (data, 2, 1); 77 WDCheck (data, 2, 1);
76 adapter = mgr.renderer.getAdapter (data.strings[0], data.ints[1]); 78 adapter = mgr.renderer.getAdapter (data.ints[1]);
79 adapter.text = data.strings[0];
77 super (mgr, id, data); 80 super (mgr, id, data);
78 } 81 }
79 } 82 }
80 83
81 /// Basic widget displaying a label from a content. 84 /// Basic widget displaying a label from a content.
84 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) { 87 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
85 WDCheck (data, 3, 0); 88 WDCheck (data, 3, 0);
86 content = c; 89 content = c;
87 if (!content) throw new ContentException (); 90 if (!content) throw new ContentException ();
88 index = data.ints[1]; 91 index = data.ints[1];
89 adapter = mgr.renderer.getAdapter (content.toString(index), data.ints[2]); 92 adapter = mgr.renderer.getAdapter (data.ints[2]);
90 super (mgr, id,data); 93 super (mgr, id,data);
91 } 94 }
92 95
93 bool reloadStrings () { 96 bool setup (uint n, uint flags) {
97 if (!(flags & 3)) return false; // string or renderer (and possibly font) changed
94 adapter.text = content.toString(index); 98 adapter.text = content.toString(index);
95 return super.reloadStrings; 99 return super.setup (n, 3); // force redimensioning
96 } 100 }
97 101
98 protected: 102 protected:
99 IContent content; 103 IContent content;
100 int index; 104 int index;