diff 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
line wrap: on
line diff
--- a/mde/gui/widget/TextWidget.d	Sun Dec 28 10:55:15 2008 +0000
+++ b/mde/gui/widget/TextWidget.d	Thu Jan 01 14:52:09 2009 +0000
@@ -13,16 +13,13 @@
 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
-/** Basic text widget and supporting code for widgets containing text.
- *
- * All content widgets have one (at least for basic content widgets) Content, from
- * mde.gui.content.Items . */
+/** Simple text widgets. */
 module mde.gui.widget.TextWidget;
 
 import mde.gui.widget.Widget;
 import mde.gui.exception;
 import mde.gui.renderer.IRenderer;
-import mde.content.Content;
+import mde.content.AStringContent;
 
 import tango.util.log.Log : Log, Logger;
 private Logger logger;
@@ -30,14 +27,12 @@
     logger = Log.getLogger ("mde.gui.widget.TextWidget");
 }
 
-/** Base text widget.
- *
- * Little use currently except to ease future additions. */
+/** Base text widget. */
 class ATextWidget : AWidget
 {
     /** Set the adapter first:
-     * adapter = mgr.renderer.getAdapter ("string", 0xRRGGBB); */
-    this (IWidgetManager mgr, widgetID id, WidgetData data) {
+     * adapter = mgr.renderer.getAdapter (...); */
+    protected this (IWidgetManager mgr, widgetID id, WidgetData data) {
         super (mgr, id, data);
     }
     
@@ -64,7 +59,9 @@
 }
 
 
-/// Basic text widget
+/** Basic text widget
+ *
+ * Displays data.strings[0] directly (no translation). */
 class TextLabelWidget : ATextWidget
 {
     /** Constructor for a widget containing [fixed] content.
@@ -81,7 +78,10 @@
     }
 }
 
-/// Basic widget displaying a label from a content.
+/** Basic widget displaying a label from a content.
+ *
+ * Can display value, name, description or possibly other field of a content, dependent on
+ * data.ints[1]. */
 class ContentLabelWidget : ATextWidget
 {
     this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
@@ -102,3 +102,56 @@
     IContent content;
     int index;
 }
+
+/// Just displays the value of a content. Generic − any IContent.
+class DisplayContentWidget : ATextWidget
+{
+    this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
+	content = c;
+	WDCMinCheck(data, 1,0, content);
+	adapter = mgr.renderer.getAdapter ();
+	adapter.text = content.toString(0);
+	super (mgr, id, data);
+    }
+    
+protected:
+    IContent content;
+}
+
+/// Text-box for editing a content's value. Generic − any AStringContent.
+class AStringContentWidget : ATextWidget
+{
+    this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
+	content = cast(AStringContent) c;
+	WDCMinCheck(data, 1,0, content);
+        adapter = mgr.renderer.getAdapter ();
+	adapter.text = content.toString(0);
+	super (mgr, id, data);
+    }
+    
+    override bool isWSizable () {    return true;    }
+    override bool isHSizable () {    return true;    }
+    
+    /** On click, request keyboard input. */
+    override int clickEvent (wdabs cx, wdabs, ubyte, bool) {
+	//adapter.index = content.editIndex;
+        content.editIndex = adapter.setIndex (cx - x);
+	mgr.requestRedraw;
+	return 1;	// get keyboard input via keyEvent
+    }
+    
+    override void keyEvent (ushort s, char[] i) {
+	adapter.text = content.keyStroke (s, i);
+	adapter.index = content.editIndex;
+	adapter.getDimensions (mw, mh);	// NOTE: only passively change size: next resize will see new minimal size
+	mgr.requestRedraw;
+    }
+    override void keyFocusLost () {
+	adapter.text = content.endEdit;	// update other users of content relying on callbacks
+	adapter.index;
+	mgr.requestRedraw;
+    }
+    
+protected:
+    AStringContent content;
+}