Mercurial > projects > mde
comparison mde/gui/widget/createWidget.d @ 95:2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Fixed a minor bug where layouts with the same id but without shared alignments would be messed up.
Tracked down the "nothing trawn until a resize" bug (see jobs.txt).
If widgets throw during creation they're now replaced by debug widgets.
Function pointers are converted to delegates using a safer method.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 06 Nov 2008 11:07:18 +0000 |
parents | 4d5d53e4f881 |
children | 49e7cfed4b34 |
comparison
equal
deleted
inserted
replaced
94:9520cc0448e5 | 95:2a364c7d82c9 |
---|---|
25 | 25 |
26 // Widgets to create: | 26 // Widgets to create: |
27 import mde.gui.widget.layout; | 27 import mde.gui.widget.layout; |
28 import mde.gui.widget.miscWidgets; | 28 import mde.gui.widget.miscWidgets; |
29 import mde.gui.widget.TextWidget; | 29 import mde.gui.widget.TextWidget; |
30 import mde.gui.widget.miscContent; | |
30 import mde.gui.widget.Floating; | 31 import mde.gui.widget.Floating; |
31 import tango.util.log.Log : Log, Logger; | 32 import tango.util.log.Log : Log, Logger; |
32 | 33 |
33 private Logger logger; | 34 private Logger logger; |
34 static this () { | 35 static this () { |
54 logger.error ("No int data; creating a debug widget"); | 55 logger.error ("No int data; creating a debug widget"); |
55 data.ints = [WIDGET_TYPE.Debug]; | 56 data.ints = [WIDGET_TYPE.Debug]; |
56 } | 57 } |
57 int type = data.ints[0]; // type is first element of data | 58 int type = data.ints[0]; // type is first element of data |
58 | 59 |
59 //pragma (msg, binarySearch ("type", WIDGETS)); | 60 try { |
60 mixin (binarySearch ("type", WIDGETS)); // creates widget by type: new XWidget (mgr, data [, parent]); | 61 //pragma (msg, binarySearch ("type", WIDGETS)); |
62 mixin (binarySearch ("type", WIDGETS)); // creates widget by type: new XWidget (mgr, data [, parent]); | |
63 // Not returned a new widget or thrown: | |
64 logger.error ("Bad widget type: {}; creating a debug widget instead",type); | |
65 } catch (Exception e) { | |
66 logger.error ("Error creating widget: {}; creating a debug widget instead.", e.msg); | |
67 } | |
61 | 68 |
62 // Not returned a new widget... | |
63 logger.error ("Bad widget type: {}; creating a debug widget instead.",type); | |
64 return new DebugWidget (mgr, id, data); | 69 return new DebugWidget (mgr, id, data); |
65 } | 70 } |
66 | 71 |
67 /+ for converting to a char[] name (unused) | 72 /+ for converting to a char[] name (unused) |
68 static this() { | 73 static this() { |
75 }+/ | 80 }+/ |
76 | 81 |
77 private: | 82 private: |
78 /// Widget types. | 83 /// Widget types. |
79 enum WIDGET_TYPE : int { | 84 enum WIDGET_TYPE : int { |
85 FUNCTION = 0x2000, // Function called instead of widget created (no "Widget" appended to fct name) | |
80 TAKES_CONTENT = 0x4000, // Flag indicates widget's this should be passed an IContent reference. | 86 TAKES_CONTENT = 0x4000, // Flag indicates widget's this should be passed an IContent reference. |
81 PARENT = 0x8000, // widget can have children; not used by code (except in data files) | 87 PARENT = 0x8000, // widget can have children; not used by code (except in data files) |
82 | 88 |
83 // Use widget names rather than usual capitals convention | 89 // Use widget names rather than usual capitals convention |
84 Unnamed = 0x0, // Only for use by widgets not created with createWidget | 90 Unnamed = 0x0, // Only for use by widgets not created with createWidget |
93 | 99 |
94 // labels: 0x20 | 100 // labels: 0x20 |
95 ContentLabel = TAKES_CONTENT | 0x20, | 101 ContentLabel = TAKES_CONTENT | 0x20, |
96 TextLabel = 0x21, | 102 TextLabel = 0x21, |
97 | 103 |
104 // content editables: 0x30 | |
105 editContent = FUNCTION | TAKES_CONTENT | 0x30, | |
106 BoolContent = TAKES_CONTENT | 0x31, | |
107 | |
98 GridLayout = TAKES_CONTENT | PARENT | 0x100, | 108 GridLayout = TAKES_CONTENT | PARENT | 0x100, |
99 TrialContentLayout = PARENT | 0x110, | 109 TrialContentLayout = PARENT | 0x110, |
100 | 110 |
101 FloatingArea = PARENT | 0x200, | 111 FloatingArea = PARENT | 0x200, |
102 } | 112 } |
109 "SizableBlank", | 119 "SizableBlank", |
110 "Debug", | 120 "Debug", |
111 "Button", | 121 "Button", |
112 "TextLabel", | 122 "TextLabel", |
113 "ContentLabel", | 123 "ContentLabel", |
124 "BoolContent", | |
125 "editContent", | |
114 "TrialContentLayout", | 126 "TrialContentLayout", |
115 "FloatingArea", | 127 "FloatingArea", |
116 "GridLayout"]; | 128 "GridLayout"]; |
117 | 129 |
118 /* Generates a binary search algorithm. */ | 130 /* Generates a binary search algorithm. */ |
126 } else { | 138 } else { |
127 char[] ret; | 139 char[] ret; |
128 foreach (c; consts) { | 140 foreach (c; consts) { |
129 ret ~= "if (" ~ var ~ " == WIDGET_TYPE." ~ c ~ ") {\n" ~ | 141 ret ~= "if (" ~ var ~ " == WIDGET_TYPE." ~ c ~ ") {\n" ~ |
130 " debug (mdeWidgets) logger.trace (\"Creating new "~c~"Widget.\");\n" ~ | 142 " debug (mdeWidgets) logger.trace (\"Creating new "~c~"Widget.\");\n" ~ |
131 " static if (WIDGET_TYPE."~c~" & WIDGET_TYPE.TAKES_CONTENT)\n" ~ | 143 " static if (WIDGET_TYPE."~c~" & WIDGET_TYPE.FUNCTION)\n" ~ |
144 " return " ~ c ~ " (mgr, id, data, content);\n" ~ | |
145 " else static if (WIDGET_TYPE."~c~" & WIDGET_TYPE.TAKES_CONTENT)\n" ~ | |
132 " return new " ~ c ~ "Widget (mgr, id, data, content);\n" ~ | 146 " return new " ~ c ~ "Widget (mgr, id, data, content);\n" ~ |
133 " else\n" ~ | 147 " else\n" ~ |
134 " return new " ~ c ~ "Widget (mgr, id, data);\n" ~ | 148 " return new " ~ c ~ "Widget (mgr, id, data);\n" ~ |
135 "} else "; | 149 "} else "; |
136 } | 150 } |