comparison mde/gui/widget/layout.d @ 176:d5d5fe04ca6c

Fixes to CollapsibleWidget. Disabled AChildWidget.invariant.
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 12 Sep 2009 09:14:43 +0200
parents 1cbde9807293
children af40e9679436
comparison
equal deleted inserted replaced
175:1cbde9807293 176:d5d5fe04ca6c
468 468
469 /* All widgets in the grid, by row. Order: [ 0 1 ] 469 /* All widgets in the grid, by row. Order: [ 0 1 ]
470 * [ 2 3 ] */ 470 * [ 2 3 ] */
471 //IChildWidget[] subWidgets; (inherited from AParentWidget) 471 //IChildWidget[] subWidgets; (inherited from AParentWidget)
472 472
473 package AlignColumns col, row; // aligners for cols and rows 473 AlignColumns col, row; // aligners for cols and rows
474 // "rows" allocated in col and row; return value of *.addRows(): 474 // "rows" allocated in col and row; return value of *.addRows():
475 size_t colR = size_t.max, rowR = size_t.max; 475 size_t colR = size_t.max, rowR = size_t.max;
476 } 476 }
477 477
478 478
486 * Cells should be of type IChildWidget. 486 * Cells should be of type IChildWidget.
487 * 487 *
488 * Cells are not directly interacted with, but minimal widths for each column are passed, and 488 * Cells are not directly interacted with, but minimal widths for each column are passed, and
489 * callback functions are used to adjust the width of any column. 489 * callback functions are used to adjust the width of any column.
490 *************************************************************************************************/ 490 *************************************************************************************************/
491 package class AlignColumns 491 private class AlignColumns
492 { 492 {
493 /** Get an aligner. 493 /** Get an aligner.
494 * 494 *
495 * Will be shared with other layouts with the same id which have the same 495 * Will be shared with other layouts with the same id which have the same
496 * parent or if the parents share an aligner. 496 * parent or if the parents share an aligner.
870 wdim[] width; // only adjusted within the class 870 wdim[] width; // only adjusted within the class
871 wdim[] pos; /// ditto 871 wdim[] pos; /// ditto
872 wdim spacing; // used by genPositions (which cannot access the layout class's data) 872 wdim spacing; // used by genPositions (which cannot access the layout class's data)
873 wdim w,mw; // current & minimal widths 873 wdim w,mw; // current & minimal widths
874 874
875 package struct CallbackStruct { 875 private struct CallbackStruct {
876 void delegate (size_t,wdim,int) setWidth; // set width of a column, with resize direction 876 void delegate (size_t,wdim,int) setWidth; // set width of a column, with resize direction
877 void delegate (uint,uint) sADD; // setupAlignDimData dlgs 877 void delegate (uint,uint) sADD; // setupAlignDimData dlgs
878 void delegate () newMW; // propegate or finalize minimal width change 878 void delegate () newMW; // propegate or finalize minimal width change
879 } 879 }
880 CallbackStruct cbs[]; 880 CallbackStruct cbs[];
881 881
882 protected: 882 private:
883 /* Minimal width for each column. 883 /* Minimal width for each column.
884 * 884 *
885 * Set by setWidths. */ 885 * Set by setWidths. */
886 wdim[] minWidth; 886 wdim[] minWidth;
887 size_t cols, rows; // number of columns and rows (wrong way round when AlignColumns 887 size_t cols, rows; // number of columns and rows (wrong way round when AlignColumns
908 908
909 invariant 909 invariant
910 { 910 {
911 if (setupWidths) { 911 if (setupWidths) {
912 assert (width.length == cols, "invariant: bad width length"); 912 assert (width.length == cols, "invariant: bad width length");
913 assert (minCellWidths.length == rows * cols, "minCellWidths: bad length");
914 wdim[] checkMinWidth = new wdim[cols];
915 for (size_t c = 0; c < cols; ++c) {
916 for (size_t r = 0; r < rows; ++r) {
917 wdim mcw = minCellWidths[c+r*cols];
918 if (checkMinWidth[c] < mcw)
919 checkMinWidth[c] = mcw;
920 }
921 }
922 assert (checkMinWidth == minWidth);
923
913 wdim x = 0; 924 wdim x = 0;
914 foreach (i,w; width) { 925 foreach (i,w; width) {
915 assert (minWidth[i] <= w, "invariant: min size not reached"); // even when "not sizable", cols may get enlarged 926 assert (minWidth[i] <= w, "invariant: min size not reached"); // even when "not sizable", cols may get enlarged
916 assert (x == pos[i], "invariant: position wrong"); 927 assert (x == pos[i], "invariant: position wrong");
917 x += w + spacing; 928 x += w + spacing;