comparison mde/gui/widget/Widget.d @ 112:fe061009029d

EnumContent; log level can be selected from a popup list. New EnumContent, with code to load translations in Items. Editable as an AStringContent. Hacked OptionsMisc to use an EnumContent. Implemented a EnumContentWidget providing a pop-up list to select from (still needs improving). Moved IContent to its own module. ContentExceptions thrown via WDCCheck now. Fixed a small bug with reloading translations.
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 13 Dec 2008 12:54:43 +0000
parents 1655693702fc
children 9824bee909fd
comparison
equal deleted inserted replaced
111:1655693702fc 112:fe061009029d
24 * interfaces. 24 * interfaces.
25 *************************************************************************************************/ 25 *************************************************************************************************/
26 module mde.gui.widget.Widget; 26 module mde.gui.widget.Widget;
27 27
28 public import mde.gui.widget.Ifaces; 28 public import mde.gui.widget.Ifaces;
29 import mde.content.IContent;
29 import mde.gui.exception; 30 import mde.gui.exception;
30 31
31 debug { 32 debug {
32 import tango.util.log.Log : Log, Logger; 33 import tango.util.log.Log : Log, Logger;
33 private Logger logger; 34 private Logger logger;
128 mgr.renderer.drawWidgetBack (x,y, w,h); 129 mgr.renderer.drawWidgetBack (x,y, w,h);
129 } 130 }
130 131
131 protected: 132 protected:
132 /********************************************************************************************** 133 /**********************************************************************************************
133 * Widgets may use WDCheck as a utility to check what data holds. Its use is encouraged, so 134 * Widgets may use W*Check as a utility to check for existance of data. Its use is encouraged,
134 * that the checks can easily be updated should WidgetData be changed. WDMinCheck is similar, 135 * so that the checks can easily be updated should WidgetData be changed.
135 * but allows more data than required; it is used by some generic content widgets. 136 *
137 * Variants:
138 * WDCheck checks the exact length of integer and string data.
139 * WDCCheck checks data as WDCheck and that the content passed is valid.
140 * WDCMinCheck does the same as WDCCheck, but allows more data than required (used by some
141 * generic widgets).
136 * 142 *
137 * Params: 143 * Params:
138 * data = the WidgetData to check lengths of 144 * data = the WidgetData to check lengths of
139 * n_ints = number of integers wanted 145 * n_ints = number of integers wanted
140 * n_strings= number of strings (default 0 since not all widgets use strings) 146 * n_strings= number of strings (default 0 since not all widgets use strings)
143 if (data.ints.length != n_ints || 149 if (data.ints.length != n_ints ||
144 data.strings.length != n_strings) 150 data.strings.length != n_strings)
145 throw new WidgetDataException (this); 151 throw new WidgetDataException (this);
146 } 152 }
147 /** ditto */ 153 /** ditto */
148 void WDMinCheck (WidgetData data, size_t n_ints, size_t n_strings = 0) { 154 void WDCCheck (WidgetData data, size_t n_ints, size_t n_strings, IContent c) {
155 if (data.ints.length != n_ints ||
156 data.strings.length != n_strings)
157 throw new WidgetDataException (this);
158 if (c is null)
159 throw new ContentException (this);
160 }
161 /** ditto */
162 void WDCMinCheck (WidgetData data, size_t n_ints, size_t n_strings, IContent c) {
149 if (data.ints.length < n_ints || 163 if (data.ints.length < n_ints ||
150 data.strings.length < n_strings) 164 data.strings.length < n_strings)
151 throw new WidgetDataException (this); 165 throw new WidgetDataException (this);
166 if (c is null)
167 throw new ContentException (this);
152 } 168 }
153 169
154 widgetID id; // The widget's ID, used for saving data 170 widgetID id; // The widget's ID, used for saving data
155 IWidgetManager mgr; // the enclosing window 171 IWidgetManager mgr; // the enclosing window
156 wdim x, y; // position 172 wdim x, y; // position