Mercurial > projects > mde
annotate 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 |
rev | line source |
---|---|
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
1 /* LICENSE BLOCK |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
2 Part of mde: a Modular D game-oriented Engine |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
3 Copyright © 2007-2008 Diggory Hardy |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
4 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify it under the terms |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
6 of the GNU General Public License as published by the Free Software Foundation, either |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
7 version 2 of the License, or (at your option) any later version. |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
8 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
11 See the GNU General Public License for more details. |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
12 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
13 You should have received a copy of the GNU General Public License |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
15 |
90
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
16 /** This module contains code to create a widget based on an enumeration value passed at runtime. |
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
17 * |
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
18 * It could be a part of the WidgetLoader.makeWidget function, but having it here makes things |
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
19 * tidier. */ |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
20 module mde.gui.widget.createWidget; |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
21 |
45
0fd51d2c6c8a
Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
22 import mde.gui.widget.Ifaces; |
0fd51d2c6c8a
Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
23 import mde.gui.exception : WidgetDataException; |
90
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
24 import mde.gui.content.Content; //NOTE - maybe move IContent to a separate module |
45
0fd51d2c6c8a
Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
25 |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
26 // Widgets to create: |
77
3dfd934100f7
Continuing widget data changes started in last commit: all previous widgets work again now (but lacking saving).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
27 import mde.gui.widget.layout; |
45
0fd51d2c6c8a
Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
44
diff
changeset
|
28 import mde.gui.widget.miscWidgets; |
77
3dfd934100f7
Continuing widget data changes started in last commit: all previous widgets work again now (but lacking saving).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
29 import mde.gui.widget.TextWidget; |
95
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
30 import mde.gui.widget.miscContent; |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
31 import mde.gui.widget.Floating; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
32 import tango.util.log.Log : Log, Logger; |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
33 |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
34 private Logger logger; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
35 static this () { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
36 logger = Log.getLogger ("mde.gui.widget.createWidget"); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
37 } |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
38 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
39 /** Create a widget. |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
40 * |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
41 * Usually called by the widget manager's makeWidget function. |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
42 * |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
43 * Widget created of type data.ints[0] (see enum WIDGET_TYPES), with one of the following CTORs: |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
44 * --- |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
45 * this (IWidgetManager mgr, WidgetData data); |
90
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
46 * // Called if (data.ints[0] & WIDGET_TYPES.TAKES_CONTENT): |
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
47 * this (IWidgetManager mgr, WidgetData data, IContent content); |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
48 * --- |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
49 *************************************************************************************************/ |
91
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
50 IChildWidget createWidget (IWidgetManager mgr, widgetID id, WidgetData data, IContent content) |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
51 in { |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
72
diff
changeset
|
52 assert (mgr !is null, "createWidget: mgr is null"); |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
53 } body { |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
54 if (data.ints.length < 1) { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
55 logger.error ("No int data; creating a debug widget"); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
56 data.ints = [WIDGET_TYPE.Debug]; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
57 } |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
72
diff
changeset
|
58 int type = data.ints[0]; // type is first element of data |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
59 |
95
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
60 try { |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
61 //pragma (msg, binarySearch ("type", WIDGETS)); |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
62 mixin (binarySearch ("type", WIDGETS)); // creates widget by type: new XWidget (mgr, data [, parent]); |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
63 // Not returned a new widget or thrown: |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
64 logger.error ("Bad widget type: {}; creating a debug widget instead",type); |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
65 } catch (Exception e) { |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
66 logger.error ("Error creating widget: {}; creating a debug widget instead.", e.msg); |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
67 } |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
68 |
91
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
69 return new DebugWidget (mgr, id, data); |
37
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
70 } |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
71 |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
72 /+ for converting to a char[] name (unused) |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
73 static this() { |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
74 WIDGET_NAMES = [ |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
75 FixedBlank : "FixedBlank", |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
76 SizableBlank : "SizableBlank", |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
77 Button : "Button", |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
78 GridLayout : "GridLayout" |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
79 ]; |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
80 }+/ |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
81 |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
82 private: |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
83 /// Widget types. |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
84 enum WIDGET_TYPE : int { |
95
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
85 FUNCTION = 0x2000, // Function called instead of widget created (no "Widget" appended to fct name) |
90
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
86 TAKES_CONTENT = 0x4000, // Flag indicates widget's this should be passed an IContent reference. |
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
87 PARENT = 0x8000, // widget can have children; not used by code (except in data files) |
37
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
88 |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
89 // Use widget names rather than usual capitals convention |
77
3dfd934100f7
Continuing widget data changes started in last commit: all previous widgets work again now (but lacking saving).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
90 Unnamed = 0x0, // Only for use by widgets not created with createWidget |
37
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
91 |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
92 // blank: 0x1 |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
93 FixedBlank = 0x1, |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
94 SizableBlank = 0x2, |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
95 Debug = 0xF, |
37
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
96 |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
97 // buttons: 0x10 |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
98 Button = 0x10, |
37
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
99 |
90
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
100 // labels: 0x20 |
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
101 ContentLabel = TAKES_CONTENT | 0x20, |
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
102 TextLabel = 0x21, |
61
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
59
diff
changeset
|
103 |
95
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
104 // content editables: 0x30 |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
105 editContent = FUNCTION | TAKES_CONTENT | 0x30, |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
106 BoolContent = TAKES_CONTENT | 0x31, |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
107 |
90
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
108 GridLayout = TAKES_CONTENT | PARENT | 0x100, |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
109 TrialContentLayout = PARENT | 0x110, |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
110 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
111 FloatingArea = PARENT | 0x200, |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
112 } |
37
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
113 |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
114 //const char[][int] WIDGET_NAMES; |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
115 |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
116 // Only used for binarySearch algorithm generation; must be ordered by numerical values. |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
117 const char[][] WIDGETS = [ |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
118 "FixedBlank", |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
119 "SizableBlank", |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
120 "Debug", |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
121 "Button", |
90
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
122 "TextLabel", |
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
123 "ContentLabel", |
95
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
124 "BoolContent", |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
125 "editContent", |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
126 "TrialContentLayout", |
90
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
127 "FloatingArea", |
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
128 "GridLayout"]; |
37
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
129 |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
130 /* Generates a binary search algorithm. */ |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
72
diff
changeset
|
131 char[] binarySearch (char[] var, char[][] consts) { |
37
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
132 if (consts.length > 3) { |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
72
diff
changeset
|
133 return "if (" ~ var ~ " <= WIDGET_TYPE." ~ consts[$/2 - 1] ~ ") {\n" ~ |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
72
diff
changeset
|
134 binarySearch (var, consts[0 .. $/2]) ~ |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
72
diff
changeset
|
135 "} else {\n" ~ |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
72
diff
changeset
|
136 binarySearch (var, consts[$/2 .. $]) ~ |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
72
diff
changeset
|
137 "}\n"; |
37
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
138 } else { |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
139 char[] ret; |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
140 foreach (c; consts) { |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
141 ret ~= "if (" ~ var ~ " == WIDGET_TYPE." ~ c ~ ") {\n" ~ |
85
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
142 " debug (mdeWidgets) logger.trace (\"Creating new "~c~"Widget.\");\n" ~ |
95
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
143 " static if (WIDGET_TYPE."~c~" & WIDGET_TYPE.FUNCTION)\n" ~ |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
144 " return " ~ c ~ " (mgr, id, data, content);\n" ~ |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
145 " else static if (WIDGET_TYPE."~c~" & WIDGET_TYPE.TAKES_CONTENT)\n" ~ |
91
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
146 " return new " ~ c ~ "Widget (mgr, id, data, content);\n" ~ |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
147 " else\n" ~ |
91
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
148 " return new " ~ c ~ "Widget (mgr, id, data);\n" ~ |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
72
diff
changeset
|
149 "} else "; |
37
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
150 } |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
151 ret = ret[0..$-6] ~ '\n'; // remove last else |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
152 return ret; |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
153 } |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
154 } |
90
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
155 |
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
156 debug { // check items in WIDGETS are listed in order |
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
157 char[] WIDGETS_check () { |
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
158 char[] ret; |
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
159 for (int i = WIDGETS.length-2; i > 0; --i) { |
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
160 ret ~= "WIDGET_TYPE."~WIDGETS[i] ~" >= WIDGET_TYPE."~ WIDGETS[i+1]; |
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
161 if (i>1) ret ~= " || "; |
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
162 } |
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
163 return ret; |
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
164 } |
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
165 mixin ("static if ("~WIDGETS_check~") |
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
166 static assert (false, \"WIDGETS is not in order!\");"); |
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
167 } |