comparison mde/gui/widget/TextWidget.d @ 65:891211f034f2

Changes to widgets: widgets may now get strings as creation data. Strings for TextWidgets can be set in files (in a temporary mannor).
author Diggory Hardy <diggory.hardy@gmail.com>
date Sun, 29 Jun 2008 15:40:37 +0100
parents 66d555da083e
children 159775502bb4
comparison
equal deleted inserted replaced
64:cc3763817b8a 65:891211f034f2
28 28
29 import tango.io.Stdout; 29 import tango.io.Stdout;
30 30
31 /// Adapter to ease use of ContentText 31 /// Adapter to ease use of ContentText
32 struct ContentAdapter(ContentT : IContent) { 32 struct ContentAdapter(ContentT : IContent) {
33 void set (int col) { 33 void set (char[] cID, int col) {
34 if (font is null) font = FontStyle.get("default"); 34 if (font is null) font = FontStyle.get("default");
35 35
36 content = new ContentT; 36 static if (is(ContentT == ContentText)) {
37 content = getContentText (cID);
38 } else static if (is(ContentT == ContentInt)) {
39 content = getContentInt (cID);
40 } else static assert (false, "Unsupported content type");
37 colour = Colour (cast(ubyte) (col >> 16u), 41 colour = Colour (cast(ubyte) (col >> 16u),
38 cast(ubyte) (col >> 8u), 42 cast(ubyte) (col >> 8u),
39 cast(ubyte) col ); 43 cast(ubyte) col );
40 } 44 }
41 45
56 } 60 }
57 61
58 /// Basic text widget 62 /// Basic text widget
59 class ContentWidget(ContentT : IContent) : Widget 63 class ContentWidget(ContentT : IContent) : Widget
60 { 64 {
65 /** Constructor for a widget containing [fixed] content.
66 *
67 * Widget uses the initialisation data:
68 * [widgetID, contentID, colour]
69 * where contentID is an ID for the string ID of the contained content
70 * and colour is an 8-bit-per-channel RGB colour of the form 0xRRGGBB. */
61 this (IWindow wind, int[] data) { 71 this (IWindow wind, int[] data) {
62 if (data.length != 2) throw new WidgetDataException; 72 if (data.length != 3) throw new WidgetDataException;
63 text.set (data[1]); 73 text.set (wind.getWidgetString(data[1]), data[2]);
64 text.getDimensions (mw, mh); 74 text.getDimensions (mw, mh);
65 super (wind,data); 75 super (wind,data);
66 } 76 }
67 77
68 void draw () { 78 void draw () {