comparison mde/gui/widget/layout.d @ 103:42e241e7be3e

ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget. Some tidy-up. Some name changes, to increase uniformity. Bug-fix: floating widgets of fixed size could previously be made larger than intended from config dimdata.
author Diggory Hardy <diggory.hardy@gmail.com>
date Tue, 25 Nov 2008 18:01:44 +0000
parents 5de5810e3516
children 08651e8a8c51
comparison
equal deleted inserted replaced
102:ba035eba07b4 103:42e241e7be3e
17 module mde.gui.widget.layout; 17 module mde.gui.widget.layout;
18 18
19 import mde.gui.widget.Widget; 19 import mde.gui.widget.Widget;
20 import mde.gui.exception; 20 import mde.gui.exception;
21 21
22 import mde.gui.widget.TextWidget;
23 import mde.gui.content.options;
24 import mde.gui.content.Content; 22 import mde.gui.content.Content;
25 23
26 import tango.util.container.HashMap; 24 import tango.util.container.HashMap;
27 25
28 debug { 26 debug {
91 protected: 89 protected:
92 } 90 }
93 91
94 92
95 /************************************************************************************************* 93 /*************************************************************************************************
96 * Trial layout of sub-widgets of one type only. 94 * Iterates on an ContentList to produce a list of widgets, each of which is created with widgetID
95 * data.strings[0]. If an IContent is passed, this is cast to a ContentList, otherwise
96 * content.Items is used to get an IContent. It is an error if the content fails to cast to
97 * ContentList.
97 *************************************************************************************************/ 98 *************************************************************************************************/
98 class TrialContentLayoutWidget : GridWidget 99 class ContentListWidget : GridWidget
99 { 100 {
100 this (IWidgetManager mgr, widgetID id, WidgetData data) { 101 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent content) {
101 debug scope (failure) 102 debug scope (failure)
102 logger.warn ("TrialContentLayoutWidget: failure"); 103 logger.warn ("TrialContentLayoutWidget: failure");
103 WDCheck (data, 2, 2); 104 WDCheck (data, 2, 1);
104 105
105 OptionList optsList = new OptionList(data.strings[1]); 106 cList = cast(ContentList) content;
107 if (cList is null)
108 throw new ContentException;
109
106 cols = 1; 110 cols = 1;
107 if ((rows = optsList.list.length) > 0) { 111 if ((rows = cList.list.length) > 0) {
108 // Get all sub-widgets
109 subWidgets.length = rows; 112 subWidgets.length = rows;
110 foreach (i, c; optsList.list) { 113 foreach (i, c; cList.list) {
111 subWidgets[i] = mgr.makeWidget (data.strings[0], c); 114 subWidgets[i] = mgr.makeWidget (data.strings[0], c);
112 } 115 }
113 } else { 116 } else {
114 rows = 1; 117 rows = 1;
115 subWidgets = [mgr.makeWidget (data.strings[0], new TextContent (data.strings[1], "Invalid Options section"))]; 118 subWidgets = [mgr.makeWidget (data.strings[0], new ErrorContent ("<empty list>"))];
116 } 119 }
117 super (mgr, id, data); 120 super (mgr, id, data);
118 } 121 }
119 122
120 bool saveChanges () { 123 bool saveChanges () {
123 return false; 126 return false;
124 return subWidgets[0].saveChanges; 127 return subWidgets[0].saveChanges;
125 } 128 }
126 129
127 private: 130 private:
128 OptionList optsList; 131 ContentList cList;
129 } 132 }
130 133
131 134
132 /************************************************************************************************* 135 /*************************************************************************************************
133 * Backend for grid-based (includes column/row) layout widgets. 136 * Backend for grid-based (includes column/row) layout widgets.