diff mde/gui/widget/TextWidget.d @ 93:08a4ae11454b

Widgets now save dimensions without preventing structural changes in the base config file from applying. Widget dimensional data separated from other data in files, hence above change. Moved TextAdapter from TextWidget to IRenderer.
author Diggory Hardy <diggory.hardy@gmail.com>
date Tue, 21 Oct 2008 11:35:15 +0100
parents 4d5d53e4f881
children 9520cc0448e5
line wrap: on
line diff
--- a/mde/gui/widget/TextWidget.d	Tue Oct 21 09:57:19 2008 +0100
+++ b/mde/gui/widget/TextWidget.d	Tue Oct 21 11:35:15 2008 +0100
@@ -24,34 +24,6 @@
 import mde.gui.renderer.IRenderer;
 import mde.gui.content.Content;
 
-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
 {
@@ -63,7 +35,7 @@
      * and colour is an 8-bit-per-channel RGB colour of the form 0xRRGGBB. */
     this (IWidgetManager mgr, widgetID id, WidgetData data) {
         WDCheck (data, 2, 1);
-        adapter.set (data.strings[0], data.ints[1]);
+        adapter = mgr.renderer.getAdapter (data.strings[0], data.ints[1]);
         adapter.getDimensions (mw, mh);
         super (mgr, id, data);
     }
@@ -74,7 +46,7 @@
     }
     
 protected:
-    TextAdapter adapter;
+    IRenderer.TextAdapter adapter;
 }
 
 /// Basic widget displaying a label from a content.
@@ -84,7 +56,7 @@
         WDCheck (data, 3, 0);
         content = c;
         index = data.ints[1];
-        adapter.set (content.toString(index), data.ints[2]);
+        adapter = mgr.renderer.getAdapter (content.toString(index), data.ints[2]);
         adapter.getDimensions (mw, mh);
         super (mgr, id,data);
     }
@@ -95,7 +67,7 @@
     }
     
 protected:
-    TextAdapter adapter;
+    IRenderer.TextAdapter adapter;
     IContent content;
     int index;
 }