Mercurial > projects > mde
comparison mde/gui/widget/layout.d @ 92:085f2ca31914
Shared alignments supported in more complex cases.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Tue, 21 Oct 2008 09:57:19 +0100 |
parents | 4d5d53e4f881 |
children | 08a4ae11454b |
comparison
equal
deleted
inserted
replaced
91:4d5d53e4f881 | 92:085f2ca31914 |
---|---|
112 WDCheck (data, 2, 1); | 112 WDCheck (data, 2, 1); |
113 | 113 |
114 OptionList optsList = OptionList.trial(); | 114 OptionList optsList = OptionList.trial(); |
115 rows = optsList.list.length; | 115 rows = optsList.list.length; |
116 cols = 1; | 116 cols = 1; |
117 sWId = data.strings[0]; | |
117 | 118 |
118 // Get all sub-widgets | 119 // Get all sub-widgets |
119 subWidgets.length = rows*cols; | 120 subWidgets.length = rows*cols; |
120 foreach (i, c; optsList.list) { | 121 foreach (i, c; optsList.list) { |
121 subWidgets[i] = mgr.makeWidget (data.strings[0], c); | 122 subWidgets[i] = mgr.makeWidget (sWId, c); |
122 } | 123 } |
123 super (mgr, id, data); | 124 super (mgr, id, data); |
125 } | |
126 | |
127 bool saveChanges (widgetID id) { | |
128 // Since all sub-widgets have the same id, it only makes sense to call on one | |
129 if (subWidgets is null) | |
130 return false; | |
131 return subWidgets[0].saveChanges (sWId); | |
124 } | 132 } |
125 | 133 |
126 private: | 134 private: |
127 OptionList optsList; | 135 OptionList optsList; |
136 widgetID sWId; // sub-widget's ID, for calling saveChanges FIXME no longer pass? | |
128 } | 137 } |
129 | 138 |
130 | 139 |
131 /************************************************************************************************* | 140 /************************************************************************************************* |
132 * Backend for grid-based (includes column/row) layout widgets. | 141 * Backend for grid-based (includes column/row) layout widgets. |
136 * | 145 * |
137 * Since a grid with either dimension zero is not useful, there must be at least one sub-widget. | 146 * Since a grid with either dimension zero is not useful, there must be at least one sub-widget. |
138 * | 147 * |
139 * The grid has no border but has spacing between widgets. | 148 * The grid has no border but has spacing between widgets. |
140 *************************************************************************************************/ | 149 *************************************************************************************************/ |
141 abstract class GridWidget : Widget | 150 abstract class GridWidget : ParentWidget |
142 { | 151 { |
143 //BEGIN Creation & saving | 152 //BEGIN Creation & saving |
144 /** Partial constructor for a grid layout widget. | 153 /** Partial constructor for a grid layout widget. |
145 * | 154 * |
146 * Deriving classes should check data lengths, and set rows, cols, and the subWidgets array, | 155 * Deriving classes should check data lengths, and set rows, cols, and the subWidgets array, |
147 * before calling this super constructor. (If it's necessary to call super(...) first, | 156 * before calling this super constructor. (If it's necessary to call super(...) first, |
148 * the call to genCachedConstructionData can be moved to the derived this() methods.) | 157 * the call to genCachedConstructionData can be moved to the derived this() methods.) |
149 * | 158 * |
150 * Derived constructors may also set initWidths to the array of column widths followed by | 159 * Derived constructors may also set initWidths to the array of column widths followed by |
151 * row heights used to initially set the row/column dimensions. */ | 160 * row heights used to initially set the row/column dimensions. |
161 * | |
162 * Sub-widgets are finalized here, so no methods should be called on sub-widgets before calling | |
163 * this super. */ | |
152 protected this (IWidgetManager mgr, widgetID id, WidgetData data) { | 164 protected this (IWidgetManager mgr, widgetID id, WidgetData data) { |
153 super (mgr, id, data); | 165 super (mgr, id, data); |
154 | 166 |
155 // Create cell aligners with appropriate col/row adjustment function | 167 // Create cell aligners with appropriate col/row adjustment function |
156 if (data.ints[1] & 1) | 168 if (data.ints[1] & 1) |
161 if (data.ints[1] & 2) | 173 if (data.ints[1] & 2) |
162 row = AlignColumns.getInstance (id~"R", rows); // id must be unique to that for cols! | 174 row = AlignColumns.getInstance (id~"R", rows); // id must be unique to that for cols! |
163 else | 175 else |
164 row = (new AlignColumns (rows)); | 176 row = (new AlignColumns (rows)); |
165 row.addSetCallback (&setRowHeight); | 177 row.addSetCallback (&setRowHeight); |
166 | 178 } |
167 // Calculate cached construction data | 179 |
168 genCachedConstructionData; | 180 /** Prior to finalizing but after sub-widgets are finalized, some information needs to be |
181 * passed to the AlignColumns. */ | |
182 void prefinalize () { | |
183 genCachedConstructionData; // min widths, sizableness | |
169 } | 184 } |
170 | 185 |
171 /** Responsible for calculating the minimal size and initializing some stuff. | 186 /** Responsible for calculating the minimal size and initializing some stuff. |
172 * | 187 * |
173 * As such, this must be the first function called after this(). */ | 188 * As such, this must be the first function called after this(). */ |
174 wdim minWidth () { | 189 void finalize () { |
175 if (!alignInit) { // assumes col & row.width are initialized simultaneously | 190 if (initWidths) { |
176 alignInit = true; | 191 debug assert (initWidths.length == cols + rows, "initWidths provided but has bad length"); |
177 if (initWidths) { | 192 col.setWidths (initWidths[0..cols]); |
178 debug assert (initWidths.length == cols + rows, "initWidths provided but has bad length"); | 193 row.setWidths (initWidths[cols..$]); |
179 col.setWidths (initWidths[0..cols]); | 194 initWidths = null; // free |
180 row.setWidths (initWidths[cols..$]); | 195 } else { |
181 initWidths = null; // free | 196 col.setWidths; |
182 } else { | 197 row.setWidths; |
183 col.setWidths; | 198 } |
184 row.setWidths; | 199 |
185 } | 200 mw = col.mw; |
186 | 201 mh = row.mw; |
187 mw = col.mw; | 202 w = col.w; |
188 mh = row.mw; | 203 h = row.w; |
189 w = col.w; | 204 |
190 h = row.w; | 205 // Tell subwidgets their new sizes. Positions are given by a later call to setPosition. |
191 | 206 foreach (i,widget; subWidgets) { |
192 // Tell subwidgets their new sizes. Positions are given by a later call to setPosition. | 207 // Resizing direction is arbitrarily set to negative: |
193 foreach (i,widget; subWidgets) { | 208 widget.setWidth (col.width[i % cols], -1); |
194 // Resizing direction is arbitrarily set to negative: | 209 widget.setHeight (row.width[i / cols], -1); |
195 widget.setWidth (col.width[i % cols], -1); | 210 } |
196 widget.setHeight (row.width[i / cols], -1); | |
197 } | |
198 } | |
199 return mw; | |
200 } | 211 } |
201 //END Creation & saving | 212 //END Creation & saving |
202 | 213 |
203 //BEGIN Size & position | 214 //BEGIN Size & position |
204 bool isWSizable () { | 215 bool isWSizable () { |
277 /* Calculations which need to be run whenever a new sub-widget structure is set | 288 /* Calculations which need to be run whenever a new sub-widget structure is set |
278 * (i.e. to produce cached data calculated from construction data). | 289 * (i.e. to produce cached data calculated from construction data). |
279 * Also need to be re-run if the renderer changes. | 290 * Also need to be re-run if the renderer changes. |
280 * | 291 * |
281 * rows, cols and subWidgets must be set before calling. Part of the set-up for AlignColumns | 292 * rows, cols and subWidgets must be set before calling. Part of the set-up for AlignColumns |
282 * (col and row). */ | 293 * (col and row). subWidgets need to know their minimal size and resizability. */ |
283 void genCachedConstructionData () { | 294 void genCachedConstructionData () { |
284 // Will only change if renderer changes: | 295 // Will only change if renderer changes: |
296 // NOTE shared AlignColumns get this set by all sharing GridWidgets | |
285 col.spacing = row.spacing = mgr.renderer.layoutSpacing; | 297 col.spacing = row.spacing = mgr.renderer.layoutSpacing; |
286 | 298 |
287 // Calculate the minimal column and row sizes: | 299 // Calculate the minimal column and row sizes: |
288 // AlignColumns (row, col) takes care of initializing minWidth. | 300 // AlignColumns (row, col) takes care of initializing minWidth. |
289 foreach (i,widget; subWidgets) { | 301 foreach (i,widget; subWidgets) { |
359 wdim dragX, dragY; // coords where drag starts | 371 wdim dragX, dragY; // coords where drag starts |
360 //END Col/row resizing callback | 372 //END Col/row resizing callback |
361 | 373 |
362 myIt cols, rows; // number of cells in grid | 374 myIt cols, rows; // number of cells in grid |
363 wdim[] initWidths; // see this / setInitialSize | 375 wdim[] initWidths; // see this / setInitialSize |
364 bool alignInit; // have AlignColumns instances been initialized? | |
365 | 376 |
366 /* All widgets in the grid, by row. Order: [ 0 1 ] | 377 /* All widgets in the grid, by row. Order: [ 0 1 ] |
367 * [ 2 3 ] */ | 378 * [ 2 3 ] */ |
368 IChildWidget[] subWidgets; | 379 //IChildWidget[] subWidgets; |
369 | 380 |
370 AlignColumns col, row; | 381 AlignColumns col, row; |
371 } | 382 } |
372 | 383 |
373 | 384 |