Mercurial > projects > mde
diff mde/gui/widget/createWidget.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 | 56c0ddd90193 |
children | 4d5d53e4f881 |
line wrap: on
line diff
--- a/mde/gui/widget/createWidget.d Mon Sep 29 18:27:17 2008 +0100 +++ b/mde/gui/widget/createWidget.d Wed Oct 01 23:37:51 2008 +0100 @@ -13,11 +13,15 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/// GUI Widget module. +/** This module contains code to create a widget based on an enumeration value passed at runtime. + * + * It could be a part of the WidgetLoader.makeWidget function, but having it here makes things + * tidier. */ module mde.gui.widget.createWidget; import mde.gui.widget.Ifaces; import mde.gui.exception : WidgetDataException; +import mde.gui.content.Content; //NOTE - maybe move IContent to a separate module // Widgets to create: import mde.gui.widget.layout; @@ -38,11 +42,11 @@ * Widget created of type data.ints[0] (see enum WIDGET_TYPES), with one of the following CTORs: * --- * this (IWidgetManager mgr, WidgetData data); - * // Called if (data.ints[0] & WIDGET_TYPES.TAKES_PARENT): - * this (IWidgetManager mgr, WidgetData data, IParentWidget parent); + * // Called if (data.ints[0] & WIDGET_TYPES.TAKES_CONTENT): + * this (IWidgetManager mgr, WidgetData data, IContent content); * --- *************************************************************************************************/ -IChildWidget createWidget (IWidgetManager mgr, WidgetData data, IParentWidget parent) +IChildWidget createWidget (IWidgetManager mgr, WidgetData data, IContent content) in { assert (mgr !is null, "createWidget: mgr is null"); } body { @@ -73,8 +77,8 @@ private: /// Widget types. enum WIDGET_TYPE : int { - TAKES_PARENT = 0x4000, // CTOR takes reference to its parent - PARENT = 0x8000, // widget can have children + TAKES_CONTENT = 0x4000, // Flag indicates widget's this should be passed an IContent reference. + PARENT = 0x8000, // widget can have children; not used by code (except in data files) // Use widget names rather than usual capitals convention Unnamed = 0x0, // Only for use by widgets not created with createWidget @@ -87,11 +91,11 @@ // buttons: 0x10 Button = 0x10, - // content: 0x20 - Text = 0x21, - Int = 0x22, + // labels: 0x20 + ContentLabel = TAKES_CONTENT | 0x20, + TextLabel = 0x21, - GridLayout = PARENT | 0x100, + GridLayout = TAKES_CONTENT | PARENT | 0x100, TrialContentLayout = PARENT | 0x110, FloatingArea = PARENT | 0x200, @@ -105,11 +109,11 @@ "SizableBlank", "Debug", "Button", - "Text", - "Int", - "GridLayout", + "TextLabel", + "ContentLabel", "TrialContentLayout", - "FloatingArea"]; + "FloatingArea", + "GridLayout"]; /* Generates a binary search algorithm. */ char[] binarySearch (char[] var, char[][] consts) { @@ -124,8 +128,8 @@ foreach (c; consts) { ret ~= "if (" ~ var ~ " == WIDGET_TYPE." ~ c ~ ") {\n" ~ " debug (mdeWidgets) logger.trace (\"Creating new "~c~"Widget.\");\n" ~ - " static if (WIDGET_TYPE."~c~" & WIDGET_TYPE.TAKES_PARENT)\n" ~ - " return new " ~ c ~ "Widget (mgr, data, parent);\n" ~ + " static if (WIDGET_TYPE."~c~" & WIDGET_TYPE.TAKES_CONTENT)\n" ~ + " return new " ~ c ~ "Widget (mgr, data, content);\n" ~ " else\n" ~ " return new " ~ c ~ "Widget (mgr, data);\n" ~ "} else "; @@ -134,3 +138,16 @@ return ret; } } + +debug { // check items in WIDGETS are listed in order + char[] WIDGETS_check () { + char[] ret; + for (int i = WIDGETS.length-2; i > 0; --i) { + ret ~= "WIDGET_TYPE."~WIDGETS[i] ~" >= WIDGET_TYPE."~ WIDGETS[i+1]; + if (i>1) ret ~= " || "; + } + return ret; + } + mixin ("static if ("~WIDGETS_check~") + static assert (false, \"WIDGETS is not in order!\");"); +} \ No newline at end of file