annotate mde/content/AStringContent.d @ 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. Content restrutured a lot: New IContent module, Content module includes more functionality. New ContentLoader module to manage content loading/saving/translation. Translation module moved to content dir and cut down to reflect current usage. File format unchanged except renames: FontOptions -> Font, VideoOptions -> Screen. Font render mode and LCD filter options are now enums. GUI loading needs to create content (and set type for enums), but doesn't save/load value. Some setup of mainSchedule moved to mde.mainLoop. Content callbacks are called on content change now. ContentLists are set up implicitly from content symbols. Not as fast but much easier! Bug-fix in the new MTTagReader. Renamed MT *Reader maker functions to avoid confusion in paths.d. New mde.setup.logger module to allow logger setup before any other module's static this().
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 07 Feb 2009 12:46:03 +0000
parents 41582439a42b
children 2476790223b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
1 /* LICENSE BLOCK
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
2 Part of mde: a Modular D game-oriented Engine
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
3 Copyright © 2007-2008 Diggory Hardy
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
4
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify it under the terms
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
6 of the GNU General Public License as published by the Free Software Foundation, either
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
7 version 2 of the License, or (at your option) any later version.
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
8
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
11 See the GNU General Public License for more details.
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
12
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
13 You should have received a copy of the GNU General Public License
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
15
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
16 /** The content system − string-based editable content.
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
17 */
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
18 module mde.content.AStringContent;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
19 public import mde.content.Content;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
20
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
21 //FIXME: efficient conversions? Need to dup result when formatting a string anyway?
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
22 import Int = tango.text.convert.Integer;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
23 import Float = tango.text.convert.Float;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
24 import derelict.sdl.keysym;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
25
115
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
26 import tango.util.log.Log : Log, Logger;
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
27 private Logger logger;
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
28 static this () {
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
29 logger = Log.getLogger ("mde.content.AStringContent");
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
30 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
31
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
32 /** 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
33 *
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
34 * 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
35 * 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
36 *
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
37 * 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
38 * 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
39 * 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
40 abstract class AStringContent : Content
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
41 {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
42 protected this (char[] symbol) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
43 super (symbol);
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
44 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
45
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
46 /// 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
47 override char[] toString (uint i) {
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
48 return i == 0 ? sv
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
49 : i == 1 ? name_
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
50 : i == 2 ? desc_
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
51 : null;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
52 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
53
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
54 /** Acts on a keystroke and returns the new value.
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
55 *
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
56 * 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
57 char[] keyStroke (ushort sym, char[] i) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
58 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
59 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
60 if (k >= 0x20) {
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
61 if (k == 0x7f) { // delete
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
62 size_t p = pos;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
63 if (p < sv.length) ++p;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
64 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
65 ++p;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
66 sv = sv[0..pos] ~ sv[p..$];
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
67 } else { // insert character
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
68 char[] tail = sv[pos..$];
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
69 sv.length = sv.length + i.length;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
70 size_t npos = pos+i.length;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
71 if (tail) sv[npos..$] = tail.dup; // cannot assign with overlapping ranges
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
72 sv[pos..npos] = i;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
73 pos = npos;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
74 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
75 } 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
76 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
77 } // 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
78 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
79 char[] tail = sv[pos..$];
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
80 if (pos) --pos;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
81 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
82 --pos;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
83 sv = sv[0..pos] ~ tail;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
84 } else if (sym == SDLK_LEFT) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
85 if (pos) --pos;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
86 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
87 --pos;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
88 } else if (sym == SDLK_RIGHT) {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
89 if (pos < sv.length) ++pos;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
90 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
91 ++pos;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
92 } 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
93 pos = 0;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
94 } 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
95 pos = sv.length;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
96 } else
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
97 debug logger.trace ("Unhandled symbol: {}", sym);
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
98 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
99 return sv;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
100 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
101
119
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
102 /** 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
103 *
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
104 * NOTE: unused. */
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
105 size_t editIndex () {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
106 size_t i = 0;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
107 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
108 if (!(sv[p] & 0x80) || sv[p] & 0x40)
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
109 ++i;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
110 return i;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
111 }
119
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
112 /** 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
113 *
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
114 * 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
115 void editIndex (size_t i) {
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
116 pos = 0;
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
117 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
118 if (pos < sv.length) ++pos;
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
119 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
120 ++pos;
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
121 }
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
122 }
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
123
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
124 /** Call after editing a string; return new string (may be changed/reverted). */
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
125 char[] endEdit ();
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
126
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
127 protected:
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
128 char[] sv; // string of value; updated on assignment for displaying and editing
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
129 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
130 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
131
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
132 class BoolContent : AStringContent
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
133 {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
134 /** 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
135 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
136 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
137 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
138 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
139 sv = v ? "true" : "false";
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
140 super (symbol);
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
141 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
142
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
143 // 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
144 void assignNoCng (bool val) {
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
145 v = val;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
146 sv = v ? "true" : "false";
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
147 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
148 endEvent;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
149 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
150 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
151 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
152 endCng;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
153 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
154 bool opCall () {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
155 return v;
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 alias opCall opCast;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
158
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
159 override char[] endEdit () {
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
160 v = sv && (sv[0] == 't' || sv[0] == 'T' || sv[0] == '1');
124
a2ef6b549101 Dynamic minimal size changing is now fully supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
161 sv = v ? "true" : "false";
a2ef6b549101 Dynamic minimal size changing is now fully supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
162 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
163 endCng;
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
164 return sv;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
165 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
166
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
167 // 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
168 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
169 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
170 }
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
171
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
172 protected:
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
173 bool v;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
174 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
175
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
176 /** Text content. */
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
177 class StringContent : AStringContent
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
178 {
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
179 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
180 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
181 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
182 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
183 super (symbol);
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
184 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
185
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
186 void assignNoCng (char[] val) {
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
187 v = val;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
188 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
189 endEvent;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
190 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
191 void 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
192 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
193 endCng;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
194 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
195 char[] opCall () {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
196 return v;
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 alias opCall opCast;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
199
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
200 override char[] endEdit () {
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
201 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
202 endCng;
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
203 return sv;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
204 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
205
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
206 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
207 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
208 }
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
209
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
210 protected:
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
211 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
212 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
213
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
214 /** Integer content. */
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
215 class IntContent : AStringContent
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
216 {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
217 /** 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
218 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
219 auto valp = symbol in changed.intData;
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
220 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
221 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
222 sv = Int.toString (v);
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
223 super (symbol);
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
224 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
225
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
226 void assignNoCng (int val) {
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
227 v = val;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
228 sv = Int.toString (v);
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
229 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
230 endEvent;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
231 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
232 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
233 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
234 endCng;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
235 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
236 int opCall () {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
237 return v;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
238 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
239 alias opCall opCast;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
240
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
241 override char[] endEdit () {
123
d3b2cefd46c9 minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 119
diff changeset
242 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
243 v = Int.toInt (sv);
d3b2cefd46c9 minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 119
diff changeset
244 } catch (Exception e) {
d3b2cefd46c9 minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 119
diff changeset
245 logger.warn (e.msg);
d3b2cefd46c9 minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 119
diff changeset
246 }
124
a2ef6b549101 Dynamic minimal size changing is now fully supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
247 sv = Int.toString (v);
a2ef6b549101 Dynamic minimal size changing is now fully supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
248 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
249 endCng;
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
250 return sv;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
251 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
252
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
253 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
254 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
255 }
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
256
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
257 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
258 int v;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
259 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
260
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
261 /** Double content. */
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
262 class DoubleContent : AStringContent
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 /** 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
265 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
266 auto valp = symbol in changed.doubleData;
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
267 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
268 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
269 sv = Float.toString (v, 8, 4);
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
270 super (symbol);
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
271 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
272
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
273 void assignNoCng (double val) {
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
274 v = val;
124
a2ef6b549101 Dynamic minimal size changing is now fully supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
275 sv = Float.toString (v, 8, 4);
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
276 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
277 endEvent;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
278 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
279 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
280 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
281 endCng;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
282 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
283 double opCall () {
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
284 return v;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
285 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
286 alias opCall opCast;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
287
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
288 override char[] endEdit () {
123
d3b2cefd46c9 minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 119
diff changeset
289 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
290 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
291 } catch (Exception e) {
d3b2cefd46c9 minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 119
diff changeset
292 logger.warn (e.msg);
d3b2cefd46c9 minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 119
diff changeset
293 }
124
a2ef6b549101 Dynamic minimal size changing is now fully supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
294 sv = Float.toString (v, 8, 4);
a2ef6b549101 Dynamic minimal size changing is now fully supported.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
295 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
296 endCng;
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
297 return sv;
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
298 }
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
299
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 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
301 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
302 }
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
303
105
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
304 protected:
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
305 double v;
08651e8a8c51 Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
306 }
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
307
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
308 /** 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
309 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
310 {
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
311 /** CTOR.
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
312 *
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
313 * Params:
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
314 * 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
315 * 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
316 */
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
317 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
318 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
319 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
320 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
321 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
322 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
323 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
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 enums[v].assignFromParent (true);
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
326 sv = enums[v].name_;
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
327 // 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
328 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
329 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
330 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
331 }
41582439a42b Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
332
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
333 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
334 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
335 endCng;
128
41582439a42b Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
336 }
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
337 // 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
338 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
339 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
340 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
341 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
342 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
343 }
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
344 }
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
345 logger.warn ("EnumContent {} assigned invalid enumeration: {}; valid: {}", symbol, enumSym, 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
346 }
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
347 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
348 //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
349 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
350 }
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 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
352 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
353 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
354 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
355 return;
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
356 }
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
357 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
358 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
359 v = val;
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
360 sv = enums[v].name_;
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
361 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
362 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
363 }
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
364
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
365 override char[] endEdit () {
115
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
366 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
367 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
368 assignNoCng (i);
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
369 goto break1;
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
370 }
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
371
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
372 sv = enums[v].name_; // sv was edited; revert
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
373 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
374 if (pos > sv.length) pos = sv.length;
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
375
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
376 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
377 endCng;
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
378 return sv;
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
379 }
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
380
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
381 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
382 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
383 }
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
384
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
385 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
386 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
387 }
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
388
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
389 // 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
390 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
391
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
392 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
393 // 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
394 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
395 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
396 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
397 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
398 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
399 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
400 }
41582439a42b Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
401
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 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
403 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
404 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
405
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
406 /** 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
407 * 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
408 *
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
409 * Also should not save its value, since the parent stores the value. */
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
410 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
411 /** 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
412 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
413 this.parent = parent;
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
414 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
415 super (symbol);
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
416 }
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
417
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
418 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
419 v = val;
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
420 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
421 }
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
422 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
423 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
424 }
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
425 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
426 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
427 }
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
428
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
429 override char[] endEdit () {
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
430 v = sv && (sv[0] == 't' || sv[0] == 'T' || sv[0] == '1');
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
431 parent.childAssign (i);
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
432 return sv;
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
433 }
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
434
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
435 protected:
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
436 EnumContent parent;
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 124
diff changeset
437 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
438 }
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
439 }