comparison mde/gui/widget/TextWidget.d @ 121:5b37d0400732

Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed. WidgetManager code redistributed between classes; WMScreen class moved to WMScreen.d. addContent function now calls makeWidget with another id.
author Diggory Hardy <diggory.hardy@gmail.com>
date Fri, 02 Jan 2009 18:07:10 +0000
parents d28aea50c6da
children d3b2cefd46c9
comparison
equal deleted inserted replaced
120:46c63cb1c74f 121:5b37d0400732
30 /** Base text widget. */ 30 /** Base text widget. */
31 class ATextWidget : AWidget 31 class ATextWidget : AWidget
32 { 32 {
33 /** Set the adapter first: 33 /** Set the adapter first:
34 * adapter = mgr.renderer.getAdapter (...); */ 34 * adapter = mgr.renderer.getAdapter (...); */
35 protected this (IWidgetManager mgr, widgetID id, WidgetData data) { 35 protected this (IWidgetManager mgr, IParentWidget parent, widgetID id) {
36 super (mgr, id, data); 36 super (mgr, parent, id);
37 } 37 }
38 38
39 /** Recalculates dims if the renderer changed. */ 39 /** Recalculates dims if the renderer changed. */
40 override bool setup (uint,uint flags) { 40 override bool setup (uint,uint flags) {
41 if (flags & 1) { 41 if (flags & 1) {
68 * 68 *
69 * Widget uses the initialisation data: 69 * Widget uses the initialisation data:
70 * [widgetID, contentID, colour] 70 * [widgetID, contentID, colour]
71 * where contentID is an ID for the string ID of the contained content 71 * where contentID is an ID for the string ID of the contained content
72 * and colour is an 8-bit-per-channel RGB colour of the form 0xRRGGBB. */ 72 * and colour is an 8-bit-per-channel RGB colour of the form 0xRRGGBB. */
73 this (IWidgetManager mgr, widgetID id, WidgetData data) { 73 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data) {
74 WDCheck (data, 2, 1); 74 WDCheck (data, 2, 1);
75 super (mgr, parent, id);
75 adapter = mgr.renderer.getAdapter (data.ints[1]); 76 adapter = mgr.renderer.getAdapter (data.ints[1]);
76 adapter.text = data.strings[0]; 77 adapter.text = data.strings[0];
77 super (mgr, id, data);
78 } 78 }
79 } 79 }
80 80
81 /** Basic widget displaying a label from a content. 81 /** Basic widget displaying a label from a content.
82 * 82 *
83 * Can display value, name, description or possibly other field of a content, dependent on 83 * Can display value, name, description or possibly other field of a content, dependent on
84 * data.ints[1]. */ 84 * data.ints[1]. */
85 class ContentLabelWidget : ATextWidget 85 class ContentLabelWidget : ATextWidget
86 { 86 {
87 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) { 87 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) {
88 content = c; 88 content = c;
89 WDCCheck (data, 3, 0, content); 89 WDCCheck (data, 3, 0, content);
90 super (mgr, parent, id);
90 index = data.ints[1]; 91 index = data.ints[1];
91 adapter = mgr.renderer.getAdapter (data.ints[2]); 92 adapter = mgr.renderer.getAdapter (data.ints[2]);
92 super (mgr, id,data);
93 } 93 }
94 94
95 override bool setup (uint n, uint flags) { 95 override bool setup (uint n, uint flags) {
96 if (!(flags & 3)) return false; // string or renderer (and possibly font) changed 96 if (!(flags & 3)) return false; // string or renderer (and possibly font) changed
97 adapter.text = content.toString(index); 97 adapter.text = content.toString(index);
104 } 104 }
105 105
106 /// Just displays the value of a content. Generic − any IContent. 106 /// Just displays the value of a content. Generic − any IContent.
107 class DisplayContentWidget : ATextWidget 107 class DisplayContentWidget : ATextWidget
108 { 108 {
109 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) { 109 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData, IContent c) {
110 content = c; 110 content = c;
111 WDCMinCheck(data, 1,0, content); 111 if (content is null) throw new ContentException (this);
112 adapter = mgr.renderer.getAdapter (); 112 super (mgr, parent, id);
113
114 adapter = mgr.renderer.getAdapter ();
113 adapter.text = content.toString(0); 115 adapter.text = content.toString(0);
114 super (mgr, id, data);
115 } 116 }
116 117
117 protected: 118 protected:
118 IContent content; 119 IContent content;
119 } 120 }
120 121
121 /// Text-box for editing a content's value. Generic − any AStringContent. 122 /// Text-box for editing a content's value. Generic − any AStringContent.
122 class AStringContentWidget : ATextWidget 123 class AStringContentWidget : ATextWidget
123 { 124 {
124 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) { 125 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData, IContent c) {
125 content = cast(AStringContent) c; 126 content = cast(AStringContent) c;
126 WDCMinCheck(data, 1,0, content); 127 if (content is null) throw new ContentException (this);
128 super (mgr, parent, id);
129
127 adapter = mgr.renderer.getAdapter (); 130 adapter = mgr.renderer.getAdapter ();
128 adapter.text = content.toString(0); 131 adapter.text = content.toString(0);
129 super (mgr, id, data);
130 } 132 }
131 133
132 override bool isWSizable () { return true; } 134 override bool isWSizable () { return true; }
133 override bool isHSizable () { return true; } 135 override bool isHSizable () { return true; }
134 136