diff mde/gui/widget/TextWidget.d @ 91:4d5d53e4f881

Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too. Some debugging improvements. When multiple .mtt files are read for merging, files with invalid headers are ignored and no error is thrown so long as at least one file os valid.
author Diggory Hardy <diggory.hardy@gmail.com>
date Thu, 16 Oct 2008 17:43:48 +0100
parents b525ff28774b
children 08a4ae11454b
line wrap: on
line diff
--- a/mde/gui/widget/TextWidget.d	Wed Oct 01 23:37:51 2008 +0100
+++ b/mde/gui/widget/TextWidget.d	Thu Oct 16 17:43:48 2008 +0100
@@ -26,6 +26,32 @@
 
 import mde.font.font;
 
+/// Adapter to ease use of ContentLabelWidget
+struct TextAdapter {
+    void set (char[] c, int col) {
+        //FIXME tie font to renderer or so
+        if (font is null) font = FontStyle.get("default");
+        
+        content = c;
+        colour = Colour (col);
+    }
+    
+    void getDimensions (out wdsize w, out wdsize h) {
+        font.updateBlock (content, textCache);
+        w = cast(wdim) textCache.w;
+        h = cast(wdim) textCache.h;
+    }
+    
+    void draw (wdabs x, wdabs y) {
+        font.textBlock (x,y, content, textCache, colour);
+    }
+    
+    char[] content;
+    TextBlock textCache;
+    Colour colour;
+    static FontStyle font;
+}
+
 /// Basic text widget
 class TextLabelWidget : Widget
 {
@@ -35,64 +61,11 @@
      * [widgetID, contentID, colour]
      * where contentID is an ID for the string ID of the contained content
      * and colour is an 8-bit-per-channel RGB colour of the form 0xRRGGBB. */
-    this (IWidgetManager mgr, WidgetData data) {
+    this (IWidgetManager mgr, widgetID id, WidgetData data) {
         WDCheck (data, 2, 1);
-        if (font is null) font = FontStyle.get("default");
-        font.updateBlock (data.strings[0], textCache);
-        mw = cast(wdim) textCache.w;
-        mh = cast(wdim) textCache.h;
-        colour = Colour (data.ints[1]);
-        super (mgr,data);
-    }
-    
-    void draw () {
-        super.draw();
-        font.textBlock (x,y, text, textCache, colour);
-    }
-    
-protected:
-    char[] text;
-    Colour colour;
-    TextBlock textCache;
-    static FontStyle font;
-}
-
-
-/// Adapter to ease use of ContentLabelWidget
-struct ContentLabelAdapter {
-    void set (IContent c, int col) {
-        if (font is null) font = FontStyle.get("default");
-        
-        content = c;
-        colour = Colour (cast(ubyte) (col >> 16u),
-                         cast(ubyte) (col >> 8u),
-                         cast(ubyte) col );
-    }
-    
-    void getDimensions (out wdsize w, out wdsize h) {
-        font.updateBlock (content.toString, textCache);
-        w = cast(wdim) textCache.w;
-        h = cast(wdim) textCache.h;
-    }
-    
-    void draw (wdabs x, wdabs y) {
-        font.textBlock (x,y, content.toString, textCache, colour);
-    }
-    
-    IContent content;
-    TextBlock textCache;
-    Colour colour;
-    static FontStyle font;
-}
-
-/// Basic widget displaying a label from a content.
-class ContentLabelWidget : Widget
-{
-    this (IWidgetManager mgr, WidgetData data, IContent c) {
-        WDCheck (data, 2, 0);
-        adapter.set (c, data.ints[1]);
+        adapter.set (data.strings[0], data.ints[1]);
         adapter.getDimensions (mw, mh);
-        super (mgr,data);
+        super (mgr, id, data);
     }
     
     void draw () {
@@ -101,5 +74,28 @@
     }
     
 protected:
-    ContentLabelAdapter adapter;
+    TextAdapter adapter;
 }
+
+/// Basic widget displaying a label from a content.
+class ContentLabelWidget : Widget
+{
+    this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
+        WDCheck (data, 3, 0);
+        content = c;
+        index = data.ints[1];
+        adapter.set (content.toString(index), data.ints[2]);
+        adapter.getDimensions (mw, mh);
+        super (mgr, id,data);
+    }
+    
+    void draw () {
+        super.draw();
+        adapter.draw (x,y);
+    }
+    
+protected:
+    TextAdapter adapter;
+    IContent content;
+    int index;
+}