annotate mde/content/AStringContent.d @ 175:1cbde9807293

Compile/link-time fixes for ldc & non-debug builds. Moved WidgetManager to widget/ Reverted IChildWidget to an interface, not an abstract class. Introduced a work-around for a compiler problem. May not cover all cases.
author Diggory Hardy <diggory.hardy@gmail.com>
date Fri, 11 Sep 2009 20:56:53 +0200
parents e45226d3deae
children
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
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
21 import Ascii = tango.text.Ascii;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
22 import Util = tango.text.Util;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
23 //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
24 import Int = tango.text.convert.Integer;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
25 import Float = tango.text.convert.Float;
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
26 import Math = tango.math.Math;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
27 import derelict.sdl.keysym;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
28
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
29 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
30 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
31 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
32 logger = Log.getLogger ("mde.content.AStringContent");
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
33 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
34
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
35 private {
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
36 // Returns the length of memory to allocate, when len is the min required.
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
37 // Returns at least 66, since formatting from int/float requires this.
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
38 size_t allocLength (size_t len) {
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
39 return len < 33 ? 66 : len * 2;
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
40 }
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
41 }
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
42
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
43 /** Union of all content types here - for dynamic cast checking against several
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
44 * types. */
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
45 union UnionContent {
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
46 AStringContent asc;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
47 BoolContent bc;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
48 StringContent sc;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
49 IntContent ic;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
50 DoubleContent dc;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
51 EnumContent ec;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
52 }
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
53
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
54 /** Base class for content containing a simple value editable as text.
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
55 *
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
56 * Derived classes should implement endEdit to convert sv and assign its value
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
57 * to self, then call endEvent.
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
58 *
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
59 * On assignation by this or opAssign the value should be converted to a string
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
60 * and assigned to sv, and pos should be clamped to [0,sv.length] (i.e. enforce
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
61 * 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
62 abstract class AStringContent : Content
105
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 protected this (char[] symbol) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
65 super (symbol);
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
66 svBuf.length = allocLength (0);
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
67 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
68
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
69 /// 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
70 override char[] toString (uint i) {
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
71 return i == 0 ? sv
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
72 : i == 1 ? name_
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
73 : i == 2 ? desc_
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
74 : null;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
75 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
76
162
2476790223b8 First drag and drop support: can drag from AStringContentWidget to any content editable. No visual feedback while dragging.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
77 /** Set the content via conversion to/from string. */
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
78 override bool set (IContent c) {
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
79 if (c !is null) {
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
80 sv = c.toString (0).dup;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
81 return endEdit;
162
2476790223b8 First drag and drop support: can drag from AStringContentWidget to any content editable. No visual feedback while dragging.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
82 }
2476790223b8 First drag and drop support: can drag from AStringContentWidget to any content editable. No visual feedback while dragging.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
83 return false;
2476790223b8 First drag and drop support: can drag from AStringContentWidget to any content editable. No visual feedback while dragging.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
84 }
2476790223b8 First drag and drop support: can drag from AStringContentWidget to any content editable. No visual feedback while dragging.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
85
167
620d4ea30228 Context menus: added a clipboard (functions accessible from main menu rather than context menu).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
86 /** Set value directly from a string. */
620d4ea30228 Context menus: added a clipboard (functions accessible from main menu rather than context menu).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
87 override void opAssign (char[] str) {
620d4ea30228 Context menus: added a clipboard (functions accessible from main menu rather than context menu).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
88 sv = str.dup;
620d4ea30228 Context menus: added a clipboard (functions accessible from main menu rather than context menu).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
89 return endEdit;
620d4ea30228 Context menus: added a clipboard (functions accessible from main menu rather than context menu).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
90 }
620d4ea30228 Context menus: added a clipboard (functions accessible from main menu rather than context menu).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
91
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
92 /** Acts on a keystroke to edit the value as a string.
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
93 *
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
94 * After this has been used to edit the string, endEdit should be called
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
95 * to convert back to the native value type.
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
96 *
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
97 * 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
98 char[] keyStroke (ushort sym, char[] i) {
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
99 // This routine relies on the folowing: svBuf[0..sv.length] == sv
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
100 if (sv.ptr !is svBuf.ptr) {
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
101 // sv may be within svBuf but not starting at its beginning
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
102 //NOTE: to further optimise, try to avoid a realloc on the heap
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
103 svBuf = new char[allocLength (sv.length)];
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
104 svBuf[0..sv.length] = sv;
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
105 }
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
106 //NOTE (optimise): dup is used several times for temporary storage
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
107 //perhaps could be optimised by a dup func using thread-local buffer?
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
108 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
109 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
110 if (k >= 0x20) {
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
111 if (k == 0x7f) { // delete
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
112 size_t p = pos;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
113 if (p < sv.length) ++p;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
114 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
115 ++p;
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
116 size_t l = sv.length - (p-pos);
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
117 sv[pos..l] = sv[p..$].dup;
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
118 sv = sv[0..l];
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
119 } else { // insert character
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
120 char[] tail = sv[pos..$];
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
121 size_t l = sv.length + i.length;
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
122 if (svBuf.length < l)
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
123 svBuf.length = allocLength (l);
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
124 size_t npos = pos+i.length;
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
125 if (tail) svBuf[npos..l] = tail.dup;
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
126 svBuf[pos..npos] = i;
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
127 sv = svBuf[0..l];
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
128 pos = npos;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
129 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
130 } 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
131 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
132 } // 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
133 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
134 char[] tail = sv[pos..$];
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
135 size_t l = pos;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
136 if (pos) --pos;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
137 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
138 --pos;
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
139 l = sv.length - (l - pos);
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
140 sv[pos..l] = tail.dup;
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
141 sv = sv[0..l];
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
142 } else if (sym == SDLK_LEFT) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
143 if (pos) --pos;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
144 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
145 --pos;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
146 } else if (sym == SDLK_RIGHT) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
147 if (pos < sv.length) ++pos;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
148 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
149 ++pos;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
150 } 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
151 pos = 0;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
152 } 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
153 pos = sv.length;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
154 } else
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
155 debug logger.trace ("Unhandled symbol: {}", sym);
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 return sv;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
158 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
159
119
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
160 /** 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
161 *
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
162 * NOTE: unused. */
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
163 size_t editIndex () {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
164 size_t i = 0;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
165 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
166 if (!(sv[p] & 0x80) || sv[p] & 0x40)
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
167 ++i;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
168 return i;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
169 }
119
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
170 /** 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
171 *
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
172 * 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
173 void editIndex (size_t i) {
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
174 pos = 0;
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
175 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
176 if (pos < sv.length) ++pos;
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
177 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
178 ++pos;
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
179 }
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
180 }
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
181
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
182 /** Call after editing a string.
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
183 *
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
184 * Returns: true if string successfully converted to value.
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
185 *
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
186 * Should never throw; should reset sv at least when returning false. */
175
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
187 abstract bool endEdit ();
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
188
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
189 protected:
167
620d4ea30228 Context menus: added a clipboard (functions accessible from main menu rather than context menu).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
190 //TODO: copy-on-assign, copy-on-edit, or what?
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
191 /* String version of value (for toString(0) and editing).
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
192 * WARNING: This must point to mutable memory (for endEdit), and
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
193 * when keyStroke can be called we must have svBuf[0..sv.length] == sv. */
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
194 char[] sv;
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
195 char[] svBuf; // buffer to reduce reallocs
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
196 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
197 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
198
170
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 167
diff changeset
199 class BoolContent : AStringContent, IBoolContent
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
200 {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
201 /** Create a content with _symbol name symbol. */
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
202 this (char[] symbol) {
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
203 auto valp = symbol in changed.boolData;
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
204 if (valp)
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
205 v = *valp;
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
206 sv = v ? "true" : "false";
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
207 super (symbol);
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
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
210 // Assign without adding change to save changeset
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
211 void assignNoCng (bool val) {
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
212 v = val;
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
213 sv = v ? "true" : "false";
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
214 if (pos > sv.length) pos = sv.length;
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
215 endEvent;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
216 }
170
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 167
diff changeset
217 override void opAssign (bool val) {
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
218 assignNoCng (val);
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
219 endCng;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
220 }
170
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 167
diff changeset
221 override bool opCall () {
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
222 return v;
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 alias opCall opCast;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
225
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
226 override bool endEdit () {
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
227 try {
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
228 sv = Util.trim (Ascii.toLower (sv)); // NOTE: sv must be in mutable memory
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
229 if (sv == "false")
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
230 v = 0;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
231 else if (sv == "true")
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
232 v = 1;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
233 else // throws if can't convert to int:
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
234 v = (Int.toLong (sv) != 0);
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
235 } catch (Exception e) {
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
236 logger.error (e.msg);
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
237 sv = v ? "true" : "false";
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
238 return false;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
239 }
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
240 sv = v ? "true" : "false";
124
a2ef6b549101 Dynamic minimal size changing is now fully supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
241 endEvent;
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
242 endCng;
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
243 return true;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
244 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
245
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
246 // Add change to changeset
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
247 void endCng () {
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
248 changed.boolData[symbol] = v;
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
249 }
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
250
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
251 protected:
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
252 bool v;
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
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
255 /** Text content. */
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
256 class StringContent : AStringContent
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
257 {
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
258 this (char[] symbol) {
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
259 auto valp = symbol in changed.charAData;
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
260 if (valp)
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
261 v = *valp;
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
262 super (symbol);
105
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
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
265 void assignNoCng (char[] val) {
167
620d4ea30228 Context menus: added a clipboard (functions accessible from main menu rather than context menu).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
266 v = val.dup;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
267 if (pos > sv.length) pos = sv.length;
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
268 endEvent;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
269 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
270 void opAssign (char[] val) {
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
271 assignNoCng (val);
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
272 endCng;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
273 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
274 char[] opCall () {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
275 return v;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
276 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
277 alias opCall opCast;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
278
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
279 override bool endEdit () {
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
280 endEvent;
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
281 endCng;
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
282 return true;
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
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
285 void endCng () {
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
286 changed.charAData[symbol] = v;
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
287 }
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
288
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
289 protected:
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
290 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
291 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
292
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
293 /** Integer content. */
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
294 class IntContent : AStringContent
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
295 {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
296 /** Create a content with _symbol name symbol. */
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
297 this (char[] symbol) {
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
298 super (symbol);
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
299 auto valp = symbol in changed.intData;
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
300 if (valp)
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
301 v = *valp;
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
302 sv = Int.format (svBuf, v);
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
303 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
304
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
305 override bool set (IContent c) {
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
306 UnionContent uc;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
307 uc.bc = cast (BoolContent) c;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
308 if (uc.bc !is null) {
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
309 this = uc.bc();
162
2476790223b8 First drag and drop support: can drag from AStringContentWidget to any content editable. No visual feedback while dragging.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
310 return true;
2476790223b8 First drag and drop support: can drag from AStringContentWidget to any content editable. No visual feedback while dragging.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
311 }
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
312 uc.ic = cast (IntContent) c;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
313 if (uc.ic !is null) {
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
314 this = uc.ic();
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
315 return true;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
316 }
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
317 uc.dc = cast (DoubleContent) c;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
318 if (uc.dc !is null) {
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
319 this = Math.rndint (uc.dc()); // round to nearest
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
320 return true;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
321 }
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
322 return super.set (c);
162
2476790223b8 First drag and drop support: can drag from AStringContentWidget to any content editable. No visual feedback while dragging.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
323 }
2476790223b8 First drag and drop support: can drag from AStringContentWidget to any content editable. No visual feedback while dragging.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
324
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
325 void assignNoCng (int val) {
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
326 v = val;
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
327 sv = Int.format (svBuf, v);
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
328 if (pos > sv.length) pos = sv.length;
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
329 endEvent;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
330 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
331 void opAssign (int val) {
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
332 assignNoCng (val);
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
333 endCng;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
334 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
335 int opCall () {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
336 return v;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
337 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
338 alias opCall opCast;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
339
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
340 override bool 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
341 try {
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
342 // use toFloat to allow decimal points and exponents
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
343 v = Math.rndint (Float.toFloat (sv));
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
344 } catch (Exception e) {
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
345 logger.error (e.msg);
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
346 sv = Int.format (svBuf, v);
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
347 return false;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
348 }
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
349 sv = Int.format (svBuf, v);
124
a2ef6b549101 Dynamic minimal size changing is now fully supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
350 endEvent;
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
351 endCng;
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
352 return true;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
353 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
354
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
355 void endCng () {
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
356 changed.intData[symbol] = v;
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
357 }
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
358
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
359 protected:
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
360 int v;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
361 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
362
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
363 /** Floating-point content. */
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
364 class DoubleContent : AStringContent
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
365 {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
366 /** Create a content with _symbol name symbol. */
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
367 this (char[] symbol) {
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
368 super (symbol);
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
369 auto valp = symbol in changed.doubleData;
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
370 if (valp)
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
371 v = *valp;
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
372 sv = Float.format (svBuf, v, 8, 4);
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
373 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
374
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
375 override bool set (IContent c) {
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
376 UnionContent uc;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
377 uc.bc = cast (BoolContent) c;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
378 if (uc.bc !is null) {
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
379 this = uc.bc();
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
380 return true;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
381 }
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
382 uc.ic = cast (IntContent) c;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
383 if (uc.ic !is null) {
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
384 this = uc.ic();
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
385 return true;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
386 }
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
387 uc.dc = cast (DoubleContent) c;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
388 if (uc.dc !is null) {
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
389 this = uc.dc();
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
390 return true;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
391 }
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
392 return super.set (c);
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
393 }
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
394
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
395 void assignNoCng (double val) {
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
396 v = val;
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
397 sv = Float.format (svBuf, v, 8, 4);
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
398 if (pos > sv.length) pos = sv.length;
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
399 endEvent;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
400 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
401 void opAssign (double val) {
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
402 assignNoCng (val);
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
403 endCng;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
404 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
405 double opCall () {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
406 return v;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
407 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
408 alias opCall opCast;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
409
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
410 override bool 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
411 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
412 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
413 } catch (Exception e) {
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
414 logger.error (e.msg);
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
415 sv = Float.format (svBuf, v, 8, 4);
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
416 return false;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
417 }
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
418 sv = Float.format (svBuf, v, 8, 4);
124
a2ef6b549101 Dynamic minimal size changing is now fully supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
419 endEvent;
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
420 endCng;
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
421 return true;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
422 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
423
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
424 void endCng () {
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
425 changed.doubleData[symbol] = v;
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
426 }
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
427
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
428 protected:
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
429 double v;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
430 }
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
431
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
432 /** A content representing an enumeration. */
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
433 class EnumContent : AStringContent, IContentList
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
434 {
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
435 /** CTOR.
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
436 *
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
437 * Params:
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
438 * 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
439 * 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
440 */
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
441 this (char[] symbol, char[][] enumSymbols) {
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
442 super (symbol);
128
41582439a42b Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
443 this.enumSymbols = enumSymbols;
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
444 enums.length = enumSymbols.length;
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
445 char[] symPeriod = symbol~'.';
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
446 foreach (i, ref e; enums) {
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
447 e = new EnumValueContent (this, i, symPeriod~enumSymbols[i]);
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
448 }
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
449 enums[v].assignFromParent (true);
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
450 sv = enums[v].name_;
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
451 // Re-set the value if a saved value is found:
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
452 auto valp = symbol in changed.enumValData;
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
453 if (valp)
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
454 assignNoCng = *valp;
128
41582439a42b Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
455 }
41582439a42b Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
456
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
457 void opAssign (size_t val) {
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
458 assignNoCng (val);
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
459 endCng;
128
41582439a42b Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
460 }
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
461 // Assign by enum symbol name (for ContentLoader)
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
462 void assignNoCng (char[] enumSym) {
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
463 foreach (i,e; enumSymbols) {
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
464 if (e == enumSym) {
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
465 assignNoCng (i);
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
466 return;
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
467 }
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
468 }
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
469 logger.error ("EnumContent {} assigned invalid enumeration: {}; valid: {}", symbol, enumSym, enumSymbols);
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
470 }
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
471 size_t opCall () {
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
472 //debug logger.trace ("EnumContent {} returning value: {} ({})",symbol, enumSymbols[v], v);
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
473 return v;
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
474 }
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
475 alias opCall opCast;
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
476 void assignNoCng (size_t val) {
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
477 if (val >= enums.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
478 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
479 return;
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
480 }
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
481 enums[v] .assignFromParent (false);
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
482 enums[val].assignFromParent (true);
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
483 v = val;
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
484 sv = enums[v].name_;
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
485 if (pos > sv.length) pos = sv.length;
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
486 endEvent;
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
487 }
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
488
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
489 override bool 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
490 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
491 if (sv == e.name_) {
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
492 assignNoCng (i);
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
493 goto break1;
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
494 }
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
495
164
c13bded1bed3 Some (somewhat pointless) memory optimisations for AStringContent.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
496 sv = enums[v].name_; // sv was edited; revert
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
497 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
498 if (pos > sv.length) pos = sv.length;
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
499 return false;
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
500
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
501 break1:
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
502 endCng;
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
503 return true;
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
504 }
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
505
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
506 void endCng () {
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
507 changed.enumValData[symbol] = enumSymbols[v];
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
508 }
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
509
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
510 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
511 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
512 }
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
513
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
514 // Interface functions that don't make sense for an emuneration:
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
515 override void append (Content) {}
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
516
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
517 protected:
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
518 // Called by child; change this if true, assert current value if false
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
519 void childAssign (size_t val) {
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
520 debug assert (val < enums.length, "cA out of bounds");
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
521 if (enums[val].v)
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
522 this = val;
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
523 else
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
524 enums[val].assignFromParent (v == val);
128
41582439a42b Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
525 }
41582439a42b Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
526
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
527 size_t v; // value (i.e. enums[v] is value)
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
528 EnumValueContent[] enums;
128
41582439a42b Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
529 char[][] enumSymbols; // saved for getStructOf
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
530
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
531 /** Special version of BoolContent for each enumeration to update the
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
532 * parent Enum.
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
533 *
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
534 * Also should not save its value, since the parent stores the value. */
170
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 167
diff changeset
535 //NOTE: Could extend IBoolContent instead of BoolContent now.
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
536 private class EnumValueContent : BoolContent {
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
537 /** New enumeration of parent with index num. */
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
538 this (EnumContent parent, size_t num, char[] symbol) {
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
539 this.parent = parent;
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
540 i = num;
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
541 super (symbol);
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
542 }
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
543
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
544 override void assignNoCng (bool val) {
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
545 v = val;
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
546 parent.childAssign (i);
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
547 }
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
548 override void opAssign (bool val) {
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
549 assignNoCng (val);
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
550 }
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
551 void assignFromParent (bool val) { // don't call back to parent
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
552 super.assignNoCng (val);
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
553 }
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
554
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
555 override bool endEdit () {
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
556 if (super.endEdit) {
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
557 parent.childAssign (i);
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
558 return true; // value accepted by BoolContent, not necessarily by EnumContent
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
559 }
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
560 return false;
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
561 }
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
562
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
563 protected:
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
564 EnumContent parent;
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
565 size_t i;
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
566 }
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
567 }
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
568
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
569 debug (mdeUnitTest) {
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
570 unittest {
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
571 bool throws (void delegate() dg) {
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
572 bool r = false;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
573 try {
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
574 dg();
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
575 } catch (Exception e) {
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
576 r = true;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
577 }
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
578 return r;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
579 }
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
580
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
581 StringContent sc = new StringContent ("unittest.sc");
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
582 IntContent ic = new IntContent ("unittest.ic");
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
583 BoolContent bc = new BoolContent ("unittest.bc");
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
584 DoubleContent dc = new DoubleContent ("unittest.dc");
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
585
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
586 logger.info ("You should see some \"invalid literal\" errors:");
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
587 sc = "16";
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
588 ic.set = sc;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
589 assert (ic() == 16);
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
590 sc = "five"; // fails
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
591 ic.set = sc;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
592 assert (ic.toString(0) == "16");
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
593
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
594 bc.set = ic;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
595 assert (bc());
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
596 sc = "fALse";
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
597 bc.set = sc;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
598 assert (!bc());
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
599
165
bb2f1a76346d Fixed a few bugs; most notably changing the translation reloads the text on PopupMenuWidgets now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 164
diff changeset
600 sc = "2.5";
bb2f1a76346d Fixed a few bugs; most notably changing the translation reloads the text on PopupMenuWidgets now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 164
diff changeset
601 ic.set = sc; // parses as float and rounds
bb2f1a76346d Fixed a few bugs; most notably changing the translation reloads the text on PopupMenuWidgets now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 164
diff changeset
602 assert (ic() == 2); // rounds to even
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
603 sc = "31.5";
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
604 dc.set = sc;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
605 ic.set = dc; // rounds to even
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
606 assert (ic() == 32);
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
607 dc = -1.5;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
608 ic.set = dc; // rounds to even
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
609 assert (ic() == -2);
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
610
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
611 bc.set = dc; // fails: not included conversion
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
612 assert (!bc());
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
613 bc.set = ic;
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
614 assert (bc());
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
615
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
616 logger.info ("Unittest complete.");
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
617 }
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
618 }