Mercurial > projects > mde
annotate mde/gui/widget/TextWidget.d @ 138:3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Sat, 07 Feb 2009 13:28:52 +0000 |
parents | 9cff74f68b84 |
children | 1048b5c7cab1 |
rev | line source |
---|---|
59
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
1 /* LICENSE BLOCK |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
2 Part of mde: a Modular D game-oriented Engine |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
3 Copyright © 2007-2008 Diggory Hardy |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
4 |
672b6b162a36
Added very basic (and currently useless) content support.
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 |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
6 of the GNU General Public License as published by the Free Software Foundation, either |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
7 version 2 of the License, or (at your option) any later version. |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
8 |
672b6b162a36
Added very basic (and currently useless) content support.
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; |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
11 See the GNU General Public License for more details. |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
12 |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
13 You should have received a copy of the GNU General Public License |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
15 |
119
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
16 /** Simple text widgets. */ |
59
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
17 module mde.gui.widget.TextWidget; |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
18 |
131
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
130
diff
changeset
|
19 import mde.gui.widget.AChildWidget; |
59
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
20 import mde.gui.exception; |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
21 import mde.gui.renderer.IRenderer; |
119
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
22 import mde.content.AStringContent; |
59
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
23 |
103
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
99
diff
changeset
|
24 import tango.util.log.Log : Log, Logger; |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
99
diff
changeset
|
25 private Logger logger; |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
99
diff
changeset
|
26 static this () { |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
99
diff
changeset
|
27 logger = Log.getLogger ("mde.gui.widget.TextWidget"); |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
93
diff
changeset
|
28 } |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
93
diff
changeset
|
29 |
119
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
30 /** Base text widget. */ |
131
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
130
diff
changeset
|
31 class ATextWidget : AChildWidget |
59
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
32 { |
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:
94
diff
changeset
|
33 /** Set the adapter first: |
119
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
34 * adapter = mgr.renderer.getAdapter (...); */ |
121
5b37d0400732
Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
35 protected this (IWidgetManager mgr, IParentWidget parent, widgetID id) { |
5b37d0400732
Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
36 super (mgr, parent, id); |
72
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
65
diff
changeset
|
37 } |
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
65
diff
changeset
|
38 |
111
1655693702fc
Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
110
diff
changeset
|
39 /** Recalculates dims if the renderer changed. */ |
114
b16a534f5302
Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
112
diff
changeset
|
40 override bool setup (uint,uint flags) { |
111
1655693702fc
Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
110
diff
changeset
|
41 if (flags & 1) { |
1655693702fc
Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
110
diff
changeset
|
42 adapter.getDimensions (mw, mh); |
1655693702fc
Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
110
diff
changeset
|
43 if (mw != w || mh != h) { |
1655693702fc
Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
110
diff
changeset
|
44 w = mw; |
1655693702fc
Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
110
diff
changeset
|
45 h = mh; |
1655693702fc
Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
110
diff
changeset
|
46 return true; |
1655693702fc
Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
110
diff
changeset
|
47 } |
1655693702fc
Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
110
diff
changeset
|
48 } |
1655693702fc
Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
110
diff
changeset
|
49 return false; |
110
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
50 } |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
51 |
114
b16a534f5302
Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
112
diff
changeset
|
52 override void draw () { |
72
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
65
diff
changeset
|
53 super.draw(); |
90
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
54 adapter.draw (x,y); |
72
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
65
diff
changeset
|
55 } |
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
65
diff
changeset
|
56 |
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
65
diff
changeset
|
57 protected: |
93
08a4ae11454b
Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
58 IRenderer.TextAdapter adapter; |
72
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
65
diff
changeset
|
59 } |
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
|
60 |
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:
94
diff
changeset
|
61 |
119
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
62 /** Basic text widget |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
63 * |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
64 * Displays data.strings[0] directly (no translation). */ |
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:
94
diff
changeset
|
65 class TextLabelWidget : ATextWidget |
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:
94
diff
changeset
|
66 { |
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:
94
diff
changeset
|
67 /** Constructor for a widget containing [fixed] content. |
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:
94
diff
changeset
|
68 * |
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:
94
diff
changeset
|
69 * Widget uses the initialisation data: |
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:
94
diff
changeset
|
70 * [widgetID, contentID, colour] |
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:
94
diff
changeset
|
71 * where contentID is an ID for the string ID of the contained content |
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:
94
diff
changeset
|
72 * and colour is an 8-bit-per-channel RGB colour of the form 0xRRGGBB. */ |
121
5b37d0400732
Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
73 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data) { |
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:
94
diff
changeset
|
74 WDCheck (data, 2, 1); |
121
5b37d0400732
Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
75 super (mgr, parent, id); |
111
1655693702fc
Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
110
diff
changeset
|
76 adapter = mgr.renderer.getAdapter (data.ints[1]); |
1655693702fc
Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
110
diff
changeset
|
77 adapter.text = data.strings[0]; |
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:
94
diff
changeset
|
78 } |
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:
94
diff
changeset
|
79 } |
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:
94
diff
changeset
|
80 |
138
3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
81 /** Displays text from a content. |
119
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
82 * |
138
3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
83 * Displays the value, name, description or possibly another field of a |
3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
84 * content, depending on data.ints[2]. */ |
3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
85 class DisplayContentWidget : ATextWidget |
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
|
86 { |
121
5b37d0400732
Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
87 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) { |
138
3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
88 content = cast(Content) c; |
3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
89 WDCMinCheck (data, 1, 0, content); |
121
5b37d0400732
Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
90 super (mgr, parent, id); |
138
3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
91 |
3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
92 if (data.ints.length >= 3) |
3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
93 cIndex = data.ints[2]; // otherwise display '0', the value |
3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
94 if (cIndex == 0) |
3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
95 content.addCallback (&updateVal); |
3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
96 |
3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
97 adapter = mgr.renderer.getAdapter (); |
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
|
98 } |
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
99 |
114
b16a534f5302
Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
112
diff
changeset
|
100 override bool setup (uint n, uint flags) { |
111
1655693702fc
Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
110
diff
changeset
|
101 if (!(flags & 3)) return false; // string or renderer (and possibly font) changed |
138
3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
102 adapter.text = content.toString(cIndex); |
3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
103 return super.setup (n, 3); // force redimensioning |
110
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
104 } |
6acd96f8685f
Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
105 |
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
|
106 protected: |
138
3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
107 void updateVal (Content) { // callback |
3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
108 adapter.text = content.toString(cIndex); |
3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
109 wdim omw = mw, omh = mh; |
3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
110 adapter.getDimensions (mw, mh); |
3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
111 if (omw != mw) |
3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
112 parent.minWChange (this, mw); |
3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
113 if (omh != mh) |
3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
114 parent.minHChange (this, mh); |
119
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
115 } |
138
3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
116 Content content; |
3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
117 int cIndex; |
119
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
118 } |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
119 |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
120 /// Text-box for editing a content's value. Generic − any AStringContent. |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
121 class AStringContentWidget : ATextWidget |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
122 { |
121
5b37d0400732
Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
123 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData, IContent c) { |
119
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
124 content = cast(AStringContent) c; |
121
5b37d0400732
Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
125 if (content is null) throw new ContentException (this); |
5b37d0400732
Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
126 super (mgr, parent, id); |
5b37d0400732
Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
127 |
126
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
128 content.addCallback (&update); |
119
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
129 adapter = mgr.renderer.getAdapter (); |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
130 adapter.text = content.toString(0); |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
131 } |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
132 |
130
c5c38eaadb64
Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
133 override bool isWSizable () { |
c5c38eaadb64
Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
134 return true; |
c5c38eaadb64
Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
135 } |
c5c38eaadb64
Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
136 override bool isHSizable () { |
c5c38eaadb64
Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
137 return false; |
c5c38eaadb64
Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
138 } |
119
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
139 |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
140 /** On click, request keyboard input. */ |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
141 override int clickEvent (wdabs cx, wdabs, ubyte, bool) { |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
142 //adapter.index = content.editIndex; |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
143 content.editIndex = adapter.setIndex (cx - x); |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
144 mgr.requestRedraw; |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
145 return 1; // get keyboard input via keyEvent |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
146 } |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
147 |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
148 override void keyEvent (ushort s, char[] i) { |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
149 adapter.text = content.keyStroke (s, i); |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
150 adapter.index = content.editIndex; |
126
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
151 wdim omw = mw, omh = mh; |
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
152 adapter.getDimensions (mw, mh); |
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
153 if (omw != mw) |
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
154 parent.minWChange (this, mw); |
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
155 if (omh != mh) |
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
156 parent.minHChange (this, mh); |
119
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
157 mgr.requestRedraw; |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
158 } |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
159 override void keyFocusLost () { |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
160 adapter.text = content.endEdit; // update other users of content relying on callbacks |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
161 adapter.index; |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
162 mgr.requestRedraw; |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
163 } |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
164 |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
165 protected: |
126
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
166 void update (Content) { // callback |
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
167 adapter.text = content.toString(0); |
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
168 wdim omw = mw, omh = mh; |
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
169 adapter.getDimensions (mw, mh); |
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
170 if (omw != mw) |
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
171 parent.minWChange (this, mw); |
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
172 if (omh != mh) |
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
173 parent.minHChange (this, mh); |
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
174 } |
119
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
175 AStringContent content; |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
176 } |