annotate mde/content/AStringContent.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 1b1e2297e2fc
children d3b2cefd46c9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
1 /* LICENSE BLOCK
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
2 Part of mde: a Modular D game-oriented Engine
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
3 Copyright © 2007-2008 Diggory Hardy
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
4
08651e8a8c51 Quit button, big changes to content system.
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
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
6 of the GNU General Public License as published by the Free Software Foundation, either
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
7 version 2 of the License, or (at your option) any later version.
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
8
08651e8a8c51 Quit button, big changes to content system.
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;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
11 See the GNU General Public License for more details.
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
12
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
13 You should have received a copy of the GNU General Public License
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
15
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
16 /** The content system − string-based editable content.
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
17 */
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
18 module mde.content.AStringContent;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
19 public import mde.content.Content;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
20
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
21 //FIXME: efficient conversions? Need to dup result when formatting a string anyway?
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
22 import Int = tango.text.convert.Integer;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
23 import Float = tango.text.convert.Float;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
24 import derelict.sdl.keysym;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
25
115
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
26 import tango.util.log.Log : Log, Logger;
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
27 private Logger logger;
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
28 static this () {
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
29 logger = Log.getLogger ("mde.content.AStringContent");
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
30 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
31
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
32 // Used by Options
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
33 template ContentN(T) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
34 static if (is(T == bool)) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
35 const char[] ContentN = "BoolContent";
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
36 } else static if (is(T == int)) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
37 const char[] ContentN = "IntContent";
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
38 } else static if (is(T == double)) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
39 const char[] ContentN = "DoubleContent";
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
40 } else static if (is(T == char[])) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
41 const char[] ContentN = "StringContent";
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
42 } else
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
43 static assert (false, "No Content of type "~T.stringof);
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
44 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
45
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
46 /** Base class for content containing a simple value editable as text. All content types used by
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
47 * Options extend this class.
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
48 *
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
49 * All derived classes should have the following functions:
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
50 * ---
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
51 * char[] endEdit (); // Should convert sv and assign to self, then call endEvent
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
52 * // Used by Options:
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
53 * BoolContent changeCb (void delegate (char[] symbol,T value) cb); // The callback used by Options
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
54 * void assignNoCb (T val); // assign val, but without calling callbacks
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
55 * ---
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
56 * On any assignation (by this, assignNoCb, opAssign) the value should be converted to a string and
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
57 * assigned to sv, and pos should be clamped to [0,sv.length] (i.e. enforce pos <= sv.length). */
115
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
58 abstract class AStringContent : Content
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
59 {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
60 protected this (char[] symbol) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
61 super (symbol);
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
62 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
63
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
64 /// Get the text.
115
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
65 override char[] toString (uint i) {
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
66 return i == 0 ? sv
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
67 : i == 1 ? name_
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
68 : i == 2 ? desc_
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
69 : null;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
70 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
71
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
72 /** Acts on a keystroke and returns the new value.
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
73 *
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
74 * Supports one-line editing: left/right, home/end, backspace/delete. */
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
75 char[] keyStroke (ushort sym, char[] i) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
76 debug assert (i.length, "StringContent.keyStroke: no value (??)"); // impossible?
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
77 char k = *i;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
78 if (k > 0x20) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
79 if (k == 0x7f) { // delete
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
80 size_t p = pos;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
81 if (p < sv.length) ++p;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
82 while (p < sv.length && (sv[p] & 0x80) && !(sv[p] & 0x40))
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
83 ++p;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
84 sv = sv[0..pos] ~ sv[p..$];
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
85 } else { // insert character
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
86 char[] tail = sv[pos..$];
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
87 sv.length = sv.length + i.length;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
88 size_t npos = pos+i.length;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
89 if (tail) sv[npos..$] = tail.dup; // cannot assign with overlapping ranges
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
90 sv[pos..npos] = i;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
91 pos = npos;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
92 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
93 } else { // use sym; many keys output 0
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
94 if (sym == SDLK_BACKSPACE) { // backspace; k == 0x8
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
95 char[] tail = sv[pos..$];
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
96 if (pos) --pos;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
97 while (pos && (sv[pos] & 0x80) && !(sv[pos] & 0x40))
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
98 --pos;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
99 sv = sv[0..pos] ~ tail;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
100 } else if (sym == SDLK_LEFT) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
101 if (pos) --pos;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
102 while (pos && (sv[pos] & 0x80) && !(sv[pos] & 0x40))
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
103 --pos;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
104 } else if (sym == SDLK_RIGHT) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
105 if (pos < sv.length) ++pos;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
106 while (pos < sv.length && (sv[pos] & 0x80) && !(sv[pos] & 0x40))
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
107 ++pos;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
108 } else if (sym == SDLK_HOME || sym == SDLK_UP) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
109 pos = 0;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
110 } else if (sym == SDLK_END || sym == SDLK_DOWN) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
111 pos = sv.length;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
112 } else
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
113 debug logger.trace ("Unhandled symbol: {}", sym);
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
114 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
115 return sv;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
116 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
117
119
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
118 /** Get the character the edit cursor is in front of.
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
119 *
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
120 * NOTE: unused. */
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
121 size_t editIndex () {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
122 size_t i = 0;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
123 for (size_t p = 0; p < pos; ++p)
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
124 if (!(sv[p] & 0x80) || sv[p] & 0x40)
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
125 ++i;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
126 return i;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
127 }
119
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
128 /** Set the edit position in front of i'th character.
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
129 *
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
130 * Assumes at least i characters are present; if not this will work but not be optimal. */
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
131 void editIndex (size_t i) {
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
132 pos = 0;
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
133 for (; i > 0; --i) { // NOTE: could be slightly optimised
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
134 if (pos < sv.length) ++pos;
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
135 while (pos < sv.length && (sv[pos] & 0x80) && !(sv[pos] & 0x40))
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
136 ++pos;
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
137 }
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
138 }
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
139
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
140 /** Call after editing a string; return new string (may be changed/reverted). */
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
141 char[] endEdit ();
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
142
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
143 protected:
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
144 char[] sv; // string of value; updated on assignment for displaying and editing
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
145 size_t pos; // editing position; used by keyStroke
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
146 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
147
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
148 class BoolContent : AStringContent
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
149 {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
150 /** Create a content with _symbol name symbol. */
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
151 this (char[] symbol, bool val = false) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
152 assignNoCb (val);
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
153 super (symbol);
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
154 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
155
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
156 void assignNoCb (bool val) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
157 v = val;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
158 sv = v ? "true" : "false";
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
159 if (pos > sv.length) pos = sv.length;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
160 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
161 void opAssign (bool val) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
162 assignNoCb (val);
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
163 endEvent;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
164 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
165 bool opCall () {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
166 return v;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
167 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
168 alias opCall opCast;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
169
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
170 override char[] endEdit () {
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
171 v = sv && (sv[0] == 't' || sv[0] == 'T' || sv[0] == '1');
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
172 endEvent;
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
173 return sv;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
174 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
175
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
176 protected:
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
177 bool v;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
178 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
179
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
180 /** Text content. */
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
181 class StringContent : AStringContent
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
182 {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
183 this (char[] symbol, char[] val = null) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
184 v = val;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
185 super (symbol);
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
186 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
187
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
188 void assignNoCb (char[] val) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
189 v = val;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
190 if (pos > sv.length) pos = sv.length;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
191 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
192 void opAssign (char[] val) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
193 assignNoCb (val);
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
194 endEvent;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
195 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
196 char[] opCall () {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
197 return v;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
198 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
199 alias opCall opCast;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
200
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
201 override char[] endEdit () {
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
202 endEvent;
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
203 return sv;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
204 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
205
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
206 protected:
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
207 alias sv v; // don't need separate v and sv in this case
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
208 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
209
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
210 /** Integer content. */
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
211 class IntContent : AStringContent
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
212 {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
213 /** Create a content with _symbol name symbol. */
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
214 this (char[] symbol, int val = 0) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
215 assignNoCb (val);
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
216 super (symbol);
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
217 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
218
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
219 void assignNoCb (int val) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
220 v = val;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
221 sv = Int.toString (v);
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
222 if (pos > sv.length) pos = sv.length;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
223 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
224 void opAssign (int val) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
225 assignNoCb (val);
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
226 endEvent;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
227 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
228 int opCall () {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
229 return v;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
230 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
231 alias opCall opCast;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
232
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
233 override char[] endEdit () {
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
234 v = Int.toInt (sv);
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
235 endEvent;
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
236 return sv;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
237 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
238
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
239 protected:
115
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
240 int v = 0; // must be a valid value for EnumContent (i.e. 0)
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
241 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
242
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
243 /** Double content. */
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
244 class DoubleContent : AStringContent
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
245 {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
246 /** Create a content with _symbol name symbol. */
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
247 this (char[] symbol, double val = 0) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
248 assignNoCb (val);
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
249 super (symbol);
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
250 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
251
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
252 void assignNoCb (double val) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
253 v = val;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
254 sv = Float.toString (v);
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
255 if (pos > sv.length) pos = sv.length;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
256 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
257 void opAssign (double val) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
258 assignNoCb (val);
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
259 endEvent;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
260 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
261 double opCall () {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
262 return v;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
263 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
264 alias opCall opCast;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
265
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
266 override char[] endEdit () {
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
267 v = Float.toFloat (sv);
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
268 endEvent;
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
269 return sv;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
270 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
271
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
272 protected:
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
273 double v;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
274 }
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
275
115
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
276 /** A content representing an enumeration.
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
277 *
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
278 * Extends IntContent for Options support. */
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
279 // maybe avoid problems by adding a special callback to BoolContent subclass?
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
280 class EnumContent : IntContent, IContentList
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
281 {
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
282 /** CTOR.
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
283 *
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
284 * Params:
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
285 * enumSymbols = Symbol names for each
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
286 * val = which value is active; must be in [0,length-1]
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
287 */
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
288 this (char[] symbol, char[][] enumSymbols, int val = 0) {
115
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
289 enums.length = enumSymbols.length;
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
290 foreach (i, ref e; enums) {
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
291 e = new BoolContent (enumSymbols[i], false);
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
292 e.addCallback (&enumAssignCb);
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
293 }
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
294 super (symbol, val);
115
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
295 //NOTE: if val is 0, no enumeration should be set; however it seems to work!
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
296 }
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
297
115
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
298 override void assignNoCb (int val) {
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
299 if (val == v) return;
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
300 if (val >= enums.length || val < 0) {
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
301 logger.error ("EnumContent "~name_~" assigned invalid value; keeping value: "~sv);
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
302 return;
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
303 }
115
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
304 enums[v] = false;
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
305 enums[val] = true;
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
306 v = val;
115
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
307 svAssign;
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
308 }
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
309 void svAssign () {
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
310 sv = enums[v].name_;
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
311 if (pos > sv.length) pos = sv.length;
115
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
312 endEvent;
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
313 }
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
314
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
315 override char[] endEdit () {
115
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
316 foreach (i,e; enums)
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
317 if (sv == e.name_) {
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
318 v = i;
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
319 goto break1;
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
320 }
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
321
115
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
322 sv = enums[v].name_; // sv was edited; revert
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
323 logger.error ("EnumContent "~name_~" assigned invalid value; keeping value: "~sv);
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
324 if (pos > sv.length) pos = sv.length;
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
325
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
326 break1:
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
327 endEvent;
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
328 return sv;
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
329 }
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
330
115
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
331 override Content[] list () {
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
332 return enums;
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
333 }
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
334
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
335 protected:
115
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
336 void enumAssignCb (Content c) {
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
337 if (enums[v] is c) { // No other is set so persist value
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
338 enums[v].assignNoCb (true);
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
339 }
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
340 foreach (i,e; enums)
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
341 if (c is e) {
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
342 enums[v].assignNoCb = false; // NOTE: opAssign causes sigsegv (due to recursive calling?)
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
343 v = i;
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
344 svAssign;
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
345 return;
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
346 }
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
347 debug logger.error ("EnumContent.enumAssignCb: invalid value (code error)");
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
348 }
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
349
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
350 BoolContent[] enums; // NOTE: an array isn't always fastest
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
351 }