Mercurial > projects > mde
diff mde/gui/widget/TextWidget.d @ 90:b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Started on allowing alignment to be shared between instances of a layout widget in a dynamic list (to allow column alignment of list's rows).
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Wed, 01 Oct 2008 23:37:51 +0100 |
parents | 3dfd934100f7 |
children | 4d5d53e4f881 |
line wrap: on
line diff
--- a/mde/gui/widget/TextWidget.d Mon Sep 29 18:27:17 2008 +0100 +++ b/mde/gui/widget/TextWidget.d Wed Oct 01 23:37:51 2008 +0100 @@ -26,42 +26,8 @@ import mde.font.font; -import tango.io.Stdout; - -/// Adapter to ease use of ContentText -struct ContentAdapter(ContentT : IContent) { - void set (char[] cID, int col) { - if (font is null) font = FontStyle.get("default"); - - static if (is(ContentT == ContentText)) { - content = getContentText (cID); - } else static if (is(ContentT == ContentInt)) { - content = getContentInt (cID); - } else static assert (false, "Unsupported content type"); - 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); - } - - ContentT content; - TextBlock textCache; - Colour colour; - static FontStyle font; -} - /// Basic text widget -// FIXME (content, creation for different types) -class ContentWidget(ContentT : IContent) : Widget +class TextLabelWidget : Widget { /** Constructor for a widget containing [fixed] content. * @@ -71,26 +37,29 @@ * and colour is an 8-bit-per-channel RGB colour of the form 0xRRGGBB. */ this (IWidgetManager mgr, WidgetData data) { WDCheck (data, 2, 1); - text.set (data.strings[0], data.ints[1]); - text.getDimensions (mw, mh); + 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(); - text.draw (x,y); + font.textBlock (x,y, text, textCache, colour); } protected: - ContentAdapter!(ContentT) text; + char[] text; + Colour colour; + TextBlock textCache; + static FontStyle font; } -alias ContentWidget!(ContentText) TextWidget; -alias ContentWidget!(ContentInt) IntWidget; - -/// Adapter to ease use of ContentOptionWidget -struct ContentOptionAdapter { +/// Adapter to ease use of ContentLabelWidget +struct ContentLabelAdapter { void set (IContent c, int col) { if (font is null) font = FontStyle.get("default"); @@ -116,21 +85,21 @@ static FontStyle font; } -/// Basic text widget -class ContentOptionWidget : Widget +/// Basic widget displaying a label from a content. +class ContentLabelWidget : Widget { this (IWidgetManager mgr, WidgetData data, IContent c) { WDCheck (data, 2, 0); - content.set (c, data.ints[1]); - content.getDimensions (mw, mh); + adapter.set (c, data.ints[1]); + adapter.getDimensions (mw, mh); super (mgr,data); } void draw () { super.draw(); - content.draw (x,y); + adapter.draw (x,y); } protected: - ContentOptionAdapter content; + ContentLabelAdapter adapter; }