annotate mde/gui/widget/TextWidget.d @ 119:d28aea50c6da

Basic edit cursor placement using the mouse. Moved textContent.d's contents into TextWidget.d.
author Diggory Hardy <diggory.hardy@gmail.com>
date Thu, 01 Jan 2009 14:52:09 +0000
parents b16a534f5302
children 5b37d0400732
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 (...); */
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
35 protected this (IWidgetManager mgr, widgetID id, WidgetData data) {
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
36 super (mgr, id, data);
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. */
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
73 this (IWidgetManager mgr, widgetID id, WidgetData 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
74 WDCheck (data, 2, 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
75 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
76 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
77 super (mgr, id, 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
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 {
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 90
diff changeset
87 this (IWidgetManager mgr, 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);
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
90 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
91 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
92 super (mgr, id,data);
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 {
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
109 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
110 content = c;
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
111 WDCMinCheck(data, 1,0, content);
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
112 adapter = mgr.renderer.getAdapter ();
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
113 adapter.text = content.toString(0);
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
114 super (mgr, id, data);
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
115 }
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
116
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
117 protected:
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
118 IContent content;
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 /// 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
122 class AStringContentWidget : ATextWidget
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
123 {
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
124 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
125 content = cast(AStringContent) c;
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
126 WDCMinCheck(data, 1,0, content);
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
127 adapter = mgr.renderer.getAdapter ();
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
128 adapter.text = content.toString(0);
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
129 super (mgr, id, data);
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
130 }
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 override bool isWSizable () { return true; }
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
133 override bool isHSizable () { return true; }
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
134
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
135 /** On click, request keyboard input. */
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
136 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
137 //adapter.index = content.editIndex;
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
138 content.editIndex = adapter.setIndex (cx - x);
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
139 mgr.requestRedraw;
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
140 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
141 }
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
142
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
143 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
144 adapter.text = content.keyStroke (s, i);
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
145 adapter.index = content.editIndex;
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
146 adapter.getDimensions (mw, mh); // NOTE: only passively change size: next resize will see new minimal size
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
147 mgr.requestRedraw;
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
148 }
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
149 override void keyFocusLost () {
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
150 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
151 adapter.index;
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 }
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 protected:
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
156 AStringContent content;
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
157 }