comparison 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
comparison
equal deleted inserted replaced
118:9ac208b53582 119:d28aea50c6da
11 See the GNU General Public License for more details. 11 See the GNU General Public License for more details.
12 12
13 You should have received a copy of the GNU General Public License 13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
15 15
16 /** Basic text widget and supporting code for widgets containing text. 16 /** Simple text widgets. */
17 *
18 * All content widgets have one (at least for basic content widgets) Content, from
19 * mde.gui.content.Items . */
20 module mde.gui.widget.TextWidget; 17 module mde.gui.widget.TextWidget;
21 18
22 import mde.gui.widget.Widget; 19 import mde.gui.widget.Widget;
23 import mde.gui.exception; 20 import mde.gui.exception;
24 import mde.gui.renderer.IRenderer; 21 import mde.gui.renderer.IRenderer;
25 import mde.content.Content; 22 import mde.content.AStringContent;
26 23
27 import tango.util.log.Log : Log, Logger; 24 import tango.util.log.Log : Log, Logger;
28 private Logger logger; 25 private Logger logger;
29 static this () { 26 static this () {
30 logger = Log.getLogger ("mde.gui.widget.TextWidget"); 27 logger = Log.getLogger ("mde.gui.widget.TextWidget");
31 } 28 }
32 29
33 /** Base text widget. 30 /** Base text widget. */
34 *
35 * Little use currently except to ease future additions. */
36 class ATextWidget : AWidget 31 class ATextWidget : AWidget
37 { 32 {
38 /** Set the adapter first: 33 /** Set the adapter first:
39 * adapter = mgr.renderer.getAdapter ("string", 0xRRGGBB); */ 34 * adapter = mgr.renderer.getAdapter (...); */
40 this (IWidgetManager mgr, widgetID id, WidgetData data) { 35 protected this (IWidgetManager mgr, widgetID id, WidgetData data) {
41 super (mgr, id, data); 36 super (mgr, id, data);
42 } 37 }
43 38
44 /** Recalculates dims if the renderer changed. */ 39 /** Recalculates dims if the renderer changed. */
45 override bool setup (uint,uint flags) { 40 override bool setup (uint,uint flags) {
62 protected: 57 protected:
63 IRenderer.TextAdapter adapter; 58 IRenderer.TextAdapter adapter;
64 } 59 }
65 60
66 61
67 /// Basic text widget 62 /** Basic text widget
63 *
64 * Displays data.strings[0] directly (no translation). */
68 class TextLabelWidget : ATextWidget 65 class TextLabelWidget : ATextWidget
69 { 66 {
70 /** Constructor for a widget containing [fixed] content. 67 /** Constructor for a widget containing [fixed] content.
71 * 68 *
72 * Widget uses the initialisation data: 69 * Widget uses the initialisation data:
79 adapter.text = data.strings[0]; 76 adapter.text = data.strings[0];
80 super (mgr, id, data); 77 super (mgr, id, data);
81 } 78 }
82 } 79 }
83 80
84 /// Basic widget displaying a label from a content. 81 /** Basic widget displaying a label from a content.
82 *
83 * Can display value, name, description or possibly other field of a content, dependent on
84 * data.ints[1]. */
85 class ContentLabelWidget : ATextWidget 85 class ContentLabelWidget : ATextWidget
86 { 86 {
87 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) { 87 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
88 content = c; 88 content = c;
89 WDCCheck (data, 3, 0, content); 89 WDCCheck (data, 3, 0, content);
100 100
101 protected: 101 protected:
102 IContent content; 102 IContent content;
103 int index; 103 int index;
104 } 104 }
105
106 /// Just displays the value of a content. Generic − any IContent.
107 class DisplayContentWidget : ATextWidget
108 {
109 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
110 content = c;
111 WDCMinCheck(data, 1,0, content);
112 adapter = mgr.renderer.getAdapter ();
113 adapter.text = content.toString(0);
114 super (mgr, id, data);
115 }
116
117 protected:
118 IContent content;
119 }
120
121 /// Text-box for editing a content's value. Generic − any AStringContent.
122 class AStringContentWidget : ATextWidget
123 {
124 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
125 content = cast(AStringContent) c;
126 WDCMinCheck(data, 1,0, content);
127 adapter = mgr.renderer.getAdapter ();
128 adapter.text = content.toString(0);
129 super (mgr, id, data);
130 }
131
132 override bool isWSizable () { return true; }
133 override bool isHSizable () { return true; }
134
135 /** On click, request keyboard input. */
136 override int clickEvent (wdabs cx, wdabs, ubyte, bool) {
137 //adapter.index = content.editIndex;
138 content.editIndex = adapter.setIndex (cx - x);
139 mgr.requestRedraw;
140 return 1; // get keyboard input via keyEvent
141 }
142
143 override void keyEvent (ushort s, char[] i) {
144 adapter.text = content.keyStroke (s, i);
145 adapter.index = content.editIndex;
146 adapter.getDimensions (mw, mh); // NOTE: only passively change size: next resize will see new minimal size
147 mgr.requestRedraw;
148 }
149 override void keyFocusLost () {
150 adapter.text = content.endEdit; // update other users of content relying on callbacks
151 adapter.index;
152 mgr.requestRedraw;
153 }
154
155 protected:
156 AStringContent content;
157 }