Mercurial > projects > mde
annotate mde/content/AStringContent.d @ 124:a2ef6b549101
Dynamic minimal size changing is now fully supported.
Support for reducing minimal size in layouts.
Editing numbers as text now always converts new number back to string at end of edit.
Floating point number display format changed.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Mon, 05 Jan 2009 12:43:27 +0000 |
parents | d3b2cefd46c9 |
children | c9843fbaac88 |
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; |
123
d3b2cefd46c9
minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
78 if (k >= 0x20) { |
105
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 |
123
d3b2cefd46c9
minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
94 if (sym >= SDLK_RSHIFT && (sym <= SDLK_COMPOSE || sym == SDLK_MENU)) { |
d3b2cefd46c9
minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
95 } // all modifier keys and contect menu key; should be ignored |
d3b2cefd46c9
minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
96 else if (sym == SDLK_BACKSPACE) { // backspace; k == 0x8 |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
97 char[] tail = sv[pos..$]; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
98 if (pos) --pos; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
99 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
|
100 --pos; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
101 sv = sv[0..pos] ~ tail; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
102 } else if (sym == SDLK_LEFT) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
103 if (pos) --pos; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
104 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
|
105 --pos; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
106 } else if (sym == SDLK_RIGHT) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
107 if (pos < sv.length) ++pos; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
108 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
|
109 ++pos; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
110 } 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
|
111 pos = 0; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
112 } 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
|
113 pos = sv.length; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
114 } else |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
115 debug logger.trace ("Unhandled symbol: {}", sym); |
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 return sv; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
118 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
119 |
119
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
115
diff
changeset
|
120 /** 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
|
121 * |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
115
diff
changeset
|
122 * NOTE: unused. */ |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
123 size_t editIndex () { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
124 size_t i = 0; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
125 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
|
126 if (!(sv[p] & 0x80) || sv[p] & 0x40) |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
127 ++i; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
128 return i; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
129 } |
119
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
115
diff
changeset
|
130 /** 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
|
131 * |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
115
diff
changeset
|
132 * 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
|
133 void editIndex (size_t i) { |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
115
diff
changeset
|
134 pos = 0; |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
115
diff
changeset
|
135 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
|
136 if (pos < sv.length) ++pos; |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
115
diff
changeset
|
137 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
|
138 ++pos; |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
115
diff
changeset
|
139 } |
d28aea50c6da
Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
115
diff
changeset
|
140 } |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
141 |
112
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
142 /** 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
|
143 char[] endEdit (); |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
144 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
145 protected: |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
146 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
|
147 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
|
148 } |
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 class BoolContent : AStringContent |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
151 { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
152 /** Create a content with _symbol name symbol. */ |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
153 this (char[] symbol, bool val = false) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
154 assignNoCb (val); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
155 super (symbol); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
156 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
157 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
158 void assignNoCb (bool val) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
159 v = val; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
160 sv = v ? "true" : "false"; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
161 if (pos > sv.length) pos = sv.length; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
162 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
163 void opAssign (bool val) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
164 assignNoCb (val); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
165 endEvent; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
166 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
167 bool opCall () { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
168 return v; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
169 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
170 alias opCall opCast; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
171 |
112
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
172 override char[] endEdit () { |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
173 v = sv && (sv[0] == 't' || sv[0] == 'T' || sv[0] == '1'); |
124
a2ef6b549101
Dynamic minimal size changing is now fully supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
174 sv = v ? "true" : "false"; |
a2ef6b549101
Dynamic minimal size changing is now fully supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
175 endEvent; |
112
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
176 return sv; |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
177 } |
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 protected: |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
180 bool v; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
181 } |
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 /** Text content. */ |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
184 class StringContent : AStringContent |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
185 { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
186 this (char[] symbol, char[] val = null) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
187 v = val; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
188 super (symbol); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
189 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
190 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
191 void assignNoCb (char[] val) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
192 v = val; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
193 if (pos > sv.length) pos = sv.length; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
194 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
195 void opAssign (char[] val) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
196 assignNoCb (val); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
197 endEvent; |
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 char[] opCall () { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
200 return v; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
201 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
202 alias opCall opCast; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
203 |
112
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
204 override char[] endEdit () { |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
205 endEvent; |
112
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
206 return sv; |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
207 } |
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 protected: |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
210 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
|
211 } |
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 /** Integer content. */ |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
214 class IntContent : AStringContent |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
215 { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
216 /** Create a content with _symbol name symbol. */ |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
217 this (char[] symbol, int val = 0) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
218 assignNoCb (val); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
219 super (symbol); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
220 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
221 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
222 void assignNoCb (int val) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
223 v = val; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
224 sv = Int.toString (v); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
225 if (pos > sv.length) pos = sv.length; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
226 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
227 void opAssign (int val) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
228 assignNoCb (val); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
229 endEvent; |
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 int opCall () { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
232 return v; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
233 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
234 alias opCall opCast; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
235 |
112
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
236 override char[] endEdit () { |
123
d3b2cefd46c9
minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
237 try { |
d3b2cefd46c9
minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
238 v = Int.toInt (sv); |
d3b2cefd46c9
minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
239 } catch (Exception e) { |
d3b2cefd46c9
minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
240 logger.warn (e.msg); |
d3b2cefd46c9
minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
241 } |
124
a2ef6b549101
Dynamic minimal size changing is now fully supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
242 sv = Int.toString (v); |
a2ef6b549101
Dynamic minimal size changing is now fully supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
243 endEvent; |
112
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
244 return sv; |
105
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 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
247 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
|
248 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
|
249 } |
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 /** Double content. */ |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
252 class DoubleContent : AStringContent |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
253 { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
254 /** Create a content with _symbol name symbol. */ |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
255 this (char[] symbol, double val = 0) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
256 assignNoCb (val); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
257 super (symbol); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
258 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
259 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
260 void assignNoCb (double val) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
261 v = val; |
124
a2ef6b549101
Dynamic minimal size changing is now fully supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
262 sv = Float.toString (v, 8, 4); |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
263 if (pos > sv.length) pos = sv.length; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
264 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
265 void opAssign (double val) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
266 assignNoCb (val); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
267 endEvent; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
268 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
269 double opCall () { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
270 return v; |
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 alias opCall opCast; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
273 |
112
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
274 override char[] endEdit () { |
123
d3b2cefd46c9
minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
275 try { |
d3b2cefd46c9
minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
276 v = Float.toFloat (sv); |
d3b2cefd46c9
minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
277 } catch (Exception e) { |
d3b2cefd46c9
minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
278 logger.warn (e.msg); |
d3b2cefd46c9
minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
279 } |
124
a2ef6b549101
Dynamic minimal size changing is now fully supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
280 sv = Float.toString (v, 8, 4); |
a2ef6b549101
Dynamic minimal size changing is now fully supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
123
diff
changeset
|
281 endEvent; |
112
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
282 return sv; |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
283 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
284 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
285 protected: |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
286 double v; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
287 } |
112
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
288 |
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 /** 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
|
290 * |
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 * 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
|
292 // 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
|
293 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
|
294 { |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
295 /** CTOR. |
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 * Params: |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
298 * 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
|
299 * 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
|
300 */ |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
301 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
|
302 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
|
303 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
|
304 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
|
305 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
|
306 } |
112
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
307 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
|
308 //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
|
309 } |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
310 |
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
|
311 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
|
312 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
|
313 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
|
314 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
|
315 return; |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
316 } |
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
|
317 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
|
318 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
|
319 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
|
320 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
|
321 } |
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 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
|
323 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
|
324 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
|
325 endEvent; |
112
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
326 } |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
327 |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
328 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
|
329 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
|
330 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
|
331 v = i; |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
332 goto break1; |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
333 } |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
334 |
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
|
335 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
|
336 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
|
337 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
|
338 |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
339 break1: |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
340 endEvent; |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
341 return sv; |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
342 } |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
343 |
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
|
344 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
|
345 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
|
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 |
112
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
348 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
|
349 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
|
350 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
|
351 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
|
352 } |
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
|
353 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
|
354 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
|
355 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
|
356 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
|
357 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
|
358 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
|
359 } |
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
|
360 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
|
361 } |
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
|
362 |
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
|
363 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
|
364 } |