Mercurial > projects > mde
diff mde/gui/widget/createWidget.d @ 80:ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Moved contents of mde/gui/WidgetData.d elsewhere; new gui/WidgetDataSet.d and gui/types.d modules.
Changes to widget/createWidget.d
Partially implemented FloatingAreaWidget to provide an area for floating "window" widgets.
New DebugWidget and some uses of it (e.g. bad widget data).
Decoupled OptionChanges from Options.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 07 Aug 2008 11:25:27 +0100 |
parents | 3dfd934100f7 |
children | 56c0ddd90193 |
line wrap: on
line diff
--- a/mde/gui/widget/createWidget.d Tue Aug 05 11:51:51 2008 +0100 +++ b/mde/gui/widget/createWidget.d Thu Aug 07 11:25:27 2008 +0100 @@ -23,18 +23,41 @@ import mde.gui.widget.layout; import mde.gui.widget.miscWidgets; import mde.gui.widget.TextWidget; +import mde.gui.widget.Floating; +import tango.util.log.Log : Log, Logger; -/** Create a widget of type data[0] (see enum WIDGET_TYPES) under manager mgr, with initialisation -* data [1..$]. */ -IChildWidget createWidget (IWidgetManager mgr, WidgetData data) +private Logger logger; +static this () { + logger = Log.getLogger ("mde.gui.widget.createWidget"); +} + +/** Create a widget. + * + * Usually called by the widget manager's makeWidget function. + * + * 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); + * --- + *************************************************************************************************/ +IChildWidget createWidget (IWidgetManager mgr, WidgetData data, IParentWidget parent) in { assert (mgr !is null, "createWidget: mgr is null"); } body { - if (data.ints.length < 1) throw new WidgetDataException ("No widget data"); + if (data.ints.length < 1) { + logger.error ("No int data; creating a debug widget"); + data.ints = [WIDGET_TYPE.Debug]; + } int type = data.ints[0]; // type is first element of data + //pragma (msg, binarySearch ("type", WIDGETS)); mixin (binarySearch ("type", WIDGETS)); // creates widget by type as new *Widget (mgr, data); - throw new WidgetDataException ("Bad widget type"); + + // Not returned a new widget... + logger.error ("Bad widget type: {}; creating a debug widget instead.",type); + return new DebugWidget (mgr, data); } /+ for converting to a char[] name (unused) @@ -50,27 +73,28 @@ private: /// Widget types. enum WIDGET_TYPE : int { - WSIZABLE = 0x1000, // horizontally resizable - HSIZABLE = 0x2000, // vertically resizable - INTERACTIBLE = 0x4000, // any specific interaction - LAYOUT = 0x8000, // is a layout widget (i.e. has sub-widgets)? + TAKES_PARENT = 0x4000, // CTOR takes reference to its parent + PARENT = 0x8000, // widget can have children // Use widget names rather than usual capitals convention Unnamed = 0x0, // Only for use by widgets not created with createWidget // blank: 0x1 FixedBlank = 0x1, - SizableBlank = WSIZABLE | HSIZABLE | 0x1, + SizableBlank = 0x2, + Debug = 0xF, // buttons: 0x10 - Button = INTERACTIBLE | 0x10, + Button = 0x10, // content: 0x20 Text = 0x21, Int = 0x22, - GridLayout = LAYOUT | WSIZABLE | HSIZABLE | 0x4, - TrialContentLayout = LAYOUT | WSIZABLE | HSIZABLE | 0x5 + GridLayout = PARENT | 0x100, + TrialContentLayout = PARENT | 0x110, + + FloatingArea = PARENT | 0x200, } //const char[][int] WIDGET_NAMES; @@ -78,12 +102,14 @@ // Only used for binarySearch algorithm generation; must be ordered by numerical values. const char[][] WIDGETS = [ "FixedBlank", + "SizableBlank", + "Debug", + "Button", "Text", "Int", - "SizableBlank", - "Button", "GridLayout", - "TrialContentLayout"]; + "TrialContentLayout", + "FloatingArea"]; /* Generates a binary search algorithm. */ char[] binarySearch (char[] var, char[][] consts) { @@ -96,8 +122,12 @@ } else { char[] ret; foreach (c; consts) { - ret ~= "if (" ~ var ~ " == WIDGET_TYPE." ~ c ~ ") {\n" ~ - "return new " ~ c ~ "Widget (mgr, data);\n" ~ + ret ~= "if (" ~ var ~ " == WIDGET_TYPE." ~ c ~ ") {\n" ~ + " debug 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" ~ + " else\n" ~ + " return new " ~ c ~ "Widget (mgr, data);\n" ~ "} else "; } ret = ret[0..$-6] ~ '\n'; // remove last else