diff mde/gui/widget/TextWidget.d @ 72:159775502bb4

The first dynamically generated widget lists, based on Options, are here!
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 05 Jul 2008 18:27:46 +0100
parents 891211f034f2
children 25cb7420dc91
line wrap: on
line diff
--- a/mde/gui/widget/TextWidget.d	Sat Jul 05 15:36:39 2008 +0100
+++ b/mde/gui/widget/TextWidget.d	Sat Jul 05 18:27:46 2008 +0100
@@ -86,3 +86,50 @@
 
 alias ContentWidget!(ContentText) TextWidget;
 alias ContentWidget!(ContentInt) IntWidget;
+
+
+/// Adapter to ease use of ContentOptionWidget
+struct ContentOptionAdapter {
+    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 text widget
+class ContentOptionWidget : Widget
+{
+    this (IWindow wind, int[] data, IContent c) {
+        if (data.length != 2) throw new WidgetDataException;
+        content.set (c, data[1]);
+        content.getDimensions (mw, mh);
+        super (wind,data);
+    }
+    
+    void draw () {
+        super.draw();
+        content.draw (x,y);
+    }
+    
+protected:
+    ContentOptionAdapter content;
+}