Mercurial > projects > mde
annotate mde/gui/widget/TextWidget.d @ 130:c5c38eaadb64
Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Ifaces.IParentWidget.SIZABILITY controlling parent sizability.
TextWidget no longer vertically resizable (since multi-line editing is not supported).
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Sat, 17 Jan 2009 16:11:26 +0000 |
parents | c9843fbaac88 |
children | 9cff74f68b84 |
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 |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
19 import mde.gui.widget.Widget; |
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. */ |
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
|
31 class ATextWidget : AWidget |
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 |
119
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
81 /** Basic widget displaying a label from a content. |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
82 * |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
83 * Can display value, name, description or possibly other field of a content, dependent on |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
84 * data.ints[1]. */ |
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
|
85 class ContentLabelWidget : 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) { |
112
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
111
diff
changeset
|
88 content = c; |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
111
diff
changeset
|
89 WDCCheck (data, 3, 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); |
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
|
91 index = data.ints[1]; |
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
|
92 adapter = mgr.renderer.getAdapter (data.ints[2]); |
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
|
93 } |
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
94 |
114
b16a534f5302
Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
112
diff
changeset
|
95 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
|
96 if (!(flags & 3)) return false; // string or renderer (and possibly font) changed |
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
|
97 adapter.text = content.toString(index); |
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
|
98 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
|
99 } |
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
|
100 |
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
|
101 protected: |
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
102 IContent content; |
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
103 int index; |
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
104 } |
119
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
105 |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
106 /// Just displays the value of a content. Generic − any IContent. |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
107 class DisplayContentWidget : ATextWidget |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
108 { |
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
|
109 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
|
110 content = 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
|
111 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
|
112 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
|
113 |
126
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
114 Content c2 = cast(Content) content; |
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
115 if (c2) // add callback if possible |
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
116 c2.addCallback (&update); |
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
|
117 adapter = mgr.renderer.getAdapter (); |
119
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
118 adapter.text = content.toString(0); |
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 |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
121 protected: |
126
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
122 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
|
123 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
|
124 } |
119
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
125 IContent content; |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
126 } |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
127 |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
128 /// 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
|
129 class AStringContentWidget : ATextWidget |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
130 { |
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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 |
126
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
136 content.addCallback (&update); |
119
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
137 adapter = mgr.renderer.getAdapter (); |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
138 adapter.text = content.toString(0); |
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 |
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
|
141 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
|
142 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
|
143 } |
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
|
144 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
|
145 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
|
146 } |
119
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 /** On click, request keyboard input. */ |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
149 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
|
150 //adapter.index = content.editIndex; |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
151 content.editIndex = adapter.setIndex (cx - x); |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
152 mgr.requestRedraw; |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
153 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
|
154 } |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
155 |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
156 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
|
157 adapter.text = content.keyStroke (s, i); |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
158 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
|
159 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
|
160 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
|
161 if (omw != mw) |
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
162 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
|
163 if (omh != mh) |
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
164 parent.minHChange (this, mh); |
119
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
165 mgr.requestRedraw; |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
166 } |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
167 override void keyFocusLost () { |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
168 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
|
169 adapter.index; |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
170 mgr.requestRedraw; |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
171 } |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
172 |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
173 protected: |
126
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
174 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
|
175 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
|
176 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
|
177 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
|
178 if (omw != mw) |
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
179 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
|
180 if (omh != mh) |
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
181 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
|
182 } |
119
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
183 AStringContent content; |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
114
diff
changeset
|
184 } |