comparison mde/gui/widget/layout.d @ 93:08a4ae11454b

Widgets now save dimensions without preventing structural changes in the base config file from applying. Widget dimensional data separated from other data in files, hence above change. Moved TextAdapter from TextWidget to IRenderer.
author Diggory Hardy <diggory.hardy@gmail.com>
date Tue, 21 Oct 2008 11:35:15 +0100
parents 085f2ca31914
children 9520cc0448e5
comparison
equal deleted inserted replaced
92:085f2ca31914 93:08a4ae11454b
59 * 59 *
60 * The content parameter is passed on to all children accepting an IContent. */ 60 * The content parameter is passed on to all children accepting an IContent. */
61 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent content) { 61 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent content) {
62 // Get grid size and check data 62 // Get grid size and check data
63 // Check sufficient data for type, align-flags, rows, cols, and possibly row/col widths. 63 // Check sufficient data for type, align-flags, rows, cols, and possibly row/col widths.
64 if (data.ints.length < 4) throw new WidgetDataException (this); 64 if (data.ints.length != 4) throw new WidgetDataException (this);
65 65
66 rows = data.ints[2]; 66 rows = data.ints[2];
67 cols = data.ints[3]; 67 cols = data.ints[3];
68 // Check: at least one sub-widget, ints length == 3 or also contains row & col widths, 68 // Check: at least one sub-widget, ints length == 3, strings' length is correct:
69 // strings' length is correct: 69 if (rows < 1 || cols < 1 || data.ints.length != 4 || data.strings.length != rows * cols)
70 if (rows < 1 || cols < 1 ||
71 (data.ints.length != 4 && data.ints.length != 4 + rows + cols) ||
72 data.strings.length != rows * cols)
73 throw new WidgetDataException (this); 70 throw new WidgetDataException (this);
74 this.data = data;
75 71
76 // Get all sub-widgets 72 // Get all sub-widgets
77 subWidgets.length = rows*cols; 73 subWidgets.length = rows*cols;
78 foreach (i, ref subWidget; subWidgets) { 74 foreach (i, ref subWidget; subWidgets) {
79 subWidget = mgr.makeWidget (data.strings[i], content); 75 subWidget = mgr.makeWidget (data.strings[i], content);
80 } 76 }
81 77
82 if (data.ints.length == 4 + rows + cols) 78 initWidths = mgr.dimData (id); // may be null, tested later
83 initWidths = cast(wdim[]) data.ints[4..$];
84 79
85 super (mgr, id, data); 80 super (mgr, id, data);
86 } 81 }
87 82
88 // Save column/row sizes. Currently always do so. 83 // Save column/row sizes. Currently always do so.
89 bool saveChanges (widgetID id) { 84 bool saveChanges () {
90 with (data) { 85 foreach (widget; subWidgets) // recurse on subwidgets
91 foreach (i, widget; subWidgets) // recurse on subwidgets 86 widget.saveChanges ();
92 widget.saveChanges (strings[i]); 87
93 88 mgr.setDimData (id, col.width ~ row.width);
94 ints = ints[0..4] ~ cast(int[])col.width ~ cast(int[])row.width;
95 }
96 mgr.setData (id, data);
97 return true; 89 return true;
98 } 90 }
99 protected: 91 protected:
100 WidgetData data;
101 } 92 }
102 93
103 94
104 /************************************************************************************************* 95 /*************************************************************************************************
105 * Trial layout of sub-widgets of one type only. 96 * Trial layout of sub-widgets of one type only.
112 WDCheck (data, 2, 1); 103 WDCheck (data, 2, 1);
113 104
114 OptionList optsList = OptionList.trial(); 105 OptionList optsList = OptionList.trial();
115 rows = optsList.list.length; 106 rows = optsList.list.length;
116 cols = 1; 107 cols = 1;
117 sWId = data.strings[0];
118 108
119 // Get all sub-widgets 109 // Get all sub-widgets
120 subWidgets.length = rows*cols; 110 subWidgets.length = rows*cols;
121 foreach (i, c; optsList.list) { 111 foreach (i, c; optsList.list) {
122 subWidgets[i] = mgr.makeWidget (sWId, c); 112 subWidgets[i] = mgr.makeWidget (data.strings[0], c);
123 } 113 }
124 super (mgr, id, data); 114 super (mgr, id, data);
125 } 115 }
126 116
127 bool saveChanges (widgetID id) { 117 bool saveChanges () {
128 // Since all sub-widgets have the same id, it only makes sense to call on one 118 // Since all sub-widgets have the same id, it only makes sense to call on one
129 if (subWidgets is null) 119 if (subWidgets is null)
130 return false; 120 return false;
131 return subWidgets[0].saveChanges (sWId); 121 return subWidgets[0].saveChanges;
132 } 122 }
133 123
134 private: 124 private:
135 OptionList optsList; 125 OptionList optsList;
136 widgetID sWId; // sub-widget's ID, for calling saveChanges FIXME no longer pass?
137 } 126 }
138 127
139 128
140 /************************************************************************************************* 129 /*************************************************************************************************
141 * Backend for grid-based (includes column/row) layout widgets. 130 * Backend for grid-based (includes column/row) layout widgets.
185 174
186 /** Responsible for calculating the minimal size and initializing some stuff. 175 /** Responsible for calculating the minimal size and initializing some stuff.
187 * 176 *
188 * As such, this must be the first function called after this(). */ 177 * As such, this must be the first function called after this(). */
189 void finalize () { 178 void finalize () {
190 if (initWidths) { 179 logger.trace ("initWidths.length: {}", initWidths.length);
191 debug assert (initWidths.length == cols + rows, "initWidths provided but has bad length"); 180 if (initWidths.length == cols + rows) {
192 col.setWidths (initWidths[0..cols]); 181 col.setWidths (initWidths[0..cols]);
193 row.setWidths (initWidths[cols..$]); 182 row.setWidths (initWidths[cols..$]);
194 initWidths = null; // free
195 } else { 183 } else {
196 col.setWidths; 184 col.setWidths;
197 row.setWidths; 185 row.setWidths;
198 } 186 }
187 initWidths = null; // free
199 188
200 mw = col.mw; 189 mw = col.mw;
201 mh = row.mw; 190 mh = row.mw;
202 w = col.w; 191 w = col.w;
203 h = row.w; 192 h = row.w;