comparison mde/gui/widget/TextWidget.d @ 95:2a364c7d82c9

Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes. Fixed a minor bug where layouts with the same id but without shared alignments would be messed up. Tracked down the "nothing trawn until a resize" bug (see jobs.txt). If widgets throw during creation they're now replaced by debug widgets. Function pointers are converted to delegates using a safer method.
author Diggory Hardy <diggory.hardy@gmail.com>
date Thu, 06 Nov 2008 11:07:18 +0000
parents 9520cc0448e5
children dbf332403c6e
comparison
equal deleted inserted replaced
94:9520cc0448e5 95:2a364c7d82c9
30 static this () { 30 static this () {
31 logger = Log.getLogger ("mde.gui.widget.TextWidget"); 31 logger = Log.getLogger ("mde.gui.widget.TextWidget");
32 } 32 }
33 } 33 }
34 34
35 /// Basic text widget 35 /** Base text widget.
36 class TextLabelWidget : Widget 36 *
37 * Little use currently except to ease future additions. */
38 class ATextWidget : AWidget
37 { 39 {
38 /** Constructor for a widget containing [fixed] content. 40 /** Set the adapter first:
39 * 41 * adapter = mgr.renderer.getAdapter ("string", 0xRRGGBB); */
40 * Widget uses the initialisation data:
41 * [widgetID, contentID, colour]
42 * where contentID is an ID for the string ID of the contained content
43 * and colour is an 8-bit-per-channel RGB colour of the form 0xRRGGBB. */
44 this (IWidgetManager mgr, widgetID id, WidgetData data) { 42 this (IWidgetManager mgr, widgetID id, WidgetData data) {
45 WDCheck (data, 2, 1);
46 adapter = mgr.renderer.getAdapter (data.strings[0], data.ints[1]);
47 adapter.getDimensions (mw, mh); 43 adapter.getDimensions (mw, mh);
48 super (mgr, id, data); 44 super (mgr, id, data);
49 } 45 }
50 46
51 void draw () { 47 void draw () {
55 51
56 protected: 52 protected:
57 IRenderer.TextAdapter adapter; 53 IRenderer.TextAdapter adapter;
58 } 54 }
59 55
56
57 /// Basic text widget
58 class TextLabelWidget : ATextWidget
59 {
60 /** Constructor for a widget containing [fixed] content.
61 *
62 * Widget uses the initialisation data:
63 * [widgetID, contentID, colour]
64 * where contentID is an ID for the string ID of the contained content
65 * and colour is an 8-bit-per-channel RGB colour of the form 0xRRGGBB. */
66 this (IWidgetManager mgr, widgetID id, WidgetData data) {
67 WDCheck (data, 2, 1);
68 adapter = mgr.renderer.getAdapter (data.strings[0], data.ints[1]);
69 super (mgr, id, data);
70 }
71 }
72
60 /// Basic widget displaying a label from a content. 73 /// Basic widget displaying a label from a content.
61 class ContentLabelWidget : Widget 74 class ContentLabelWidget : ATextWidget
62 { 75 {
63 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) { 76 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
64 debug assert (c, "content is null (code error)"); 77 debug assert (c, "content is null (code error)");
65 WDCheck (data, 3, 0); 78 WDCheck (data, 3, 0);
66 content = c; 79 content = c;
80 if (!content) throw new ContentException ();
67 index = data.ints[1]; 81 index = data.ints[1];
68 adapter = mgr.renderer.getAdapter (content.toString(index), data.ints[2]); 82 adapter = mgr.renderer.getAdapter (content.toString(index), data.ints[2]);
69 adapter.getDimensions (mw, mh);
70 super (mgr, id,data); 83 super (mgr, id,data);
71 } 84 }
72 85
73 void draw () {
74 super.draw();
75 adapter.draw (x,y);
76 }
77
78 protected: 86 protected:
79 IRenderer.TextAdapter adapter;
80 IContent content; 87 IContent content;
81 int index; 88 int index;
82 } 89 }