| 30 | | /** Encapsulates a grid of Widgets. |
|---|
| 31 | | * |
|---|
| 32 | | * Currently there is no support for changing number of cells, sub-widgets or sub-widget properties |
|---|
| 33 | | * (namely isW/HSizable and minimal size) after this() has run. |
|---|
| 34 | | * |
|---|
| 35 | | * Since a grid with either dimension zero is not useful, there must be at least one sub-widget. |
|---|
| 36 | | * |
|---|
| 37 | | * The grid has no border but has spacing between widgets. */ |
|---|
| 38 | | /* TODO: |
|---|
| 39 | | separate positioning & sub-widget handling from creation/saving |
|---|
| 40 | | other types of layouts (e.g. lists from content) |
|---|
| 41 | | */ |
|---|
| 42 | | class GridLayoutWidget : Widget |
|---|
| | 30 | /************************************************************************************************* |
|---|
| | 31 | * Encapsulates a grid of Widgets. |
|---|
| | 32 | * |
|---|
| | 33 | * Currently there is no support for changing number of cells, sub-widgets or sub-widget properties |
|---|
| | 34 | * (namely isW/HSizable and minimal size) after this() has run. |
|---|
| | 35 | * |
|---|
| | 36 | * Since a grid with either dimension zero is not useful, there must be at least one sub-widget. |
|---|
| | 37 | * |
|---|
| | 38 | * The grid has no border but has spacing between widgets. |
|---|
| | 39 | *************************************************************************************************/ |
|---|
| | 40 | class GridLayoutWidget : GridWidget |
|---|
| 69 | | subWidget = window.makeWidget (data[i+3]); |
|---|
| 70 | | } |
|---|
| | 65 | subWidget = wind.makeWidget (data[i+3]); |
|---|
| | 66 | } |
|---|
| | 67 | super (wind, data); |
|---|
| | 68 | } |
|---|
| | 69 | /** Return construction data to recreate this GridLayoutWidget. */ |
|---|
| | 70 | int[] getCreationData () { |
|---|
| | 71 | int[] ret; |
|---|
| | 72 | ret.length = 3 + subWidgets.length; |
|---|
| | 73 | |
|---|
| | 74 | ret [0..3] = [widgetType, rows, cols]; // first data |
|---|
| | 75 | |
|---|
| | 76 | foreach (i,widget; subWidgets) // sub widgets |
|---|
| | 77 | ret[i+3] = window.addCreationData (widget); |
|---|
| | 78 | |
|---|
| | 79 | return ret; |
|---|
| | 80 | } |
|---|
| | 81 | } |
|---|
| | 82 | |
|---|
| | 83 | |
|---|
| | 84 | /************************************************************************************************* |
|---|
| | 85 | * Trial layout of sub-widgets of one type only. |
|---|
| | 86 | *************************************************************************************************/ |
|---|
| | 87 | class TrialLayout : GridWidget |
|---|
| | 88 | { |
|---|
| | 89 | this (IWindow wind, int[] data) { |
|---|
| | 90 | assert (false, "Not ready"); |
|---|
| | 91 | if (data.length != 6) throw new WidgetDataException; |
|---|
| | 92 | super (wind, data); |
|---|
| | 93 | |
|---|
| | 94 | rows = data[1]; |
|---|
| | 95 | cols = data[2]; |
|---|
| | 96 | |
|---|
| | 97 | // Get all sub-widgets |
|---|
| | 98 | subWidgets.length = rows*cols; |
|---|
| | 99 | foreach (i, ref subWidget; subWidgets) { |
|---|
| | 100 | //subWidget = new ContentWidget (data[3..6]); |
|---|
| | 101 | } |
|---|
| | 102 | } |
|---|
| | 103 | |
|---|
| | 104 | |
|---|
| | 105 | } |
|---|
| | 106 | |
|---|
| | 107 | |
|---|
| | 108 | /************************************************************************************************* |
|---|
| | 109 | * Backend for grid-based (includes column/row) layout widgets. |
|---|
| | 110 | * |
|---|
| | 111 | * A deriving class must at least do some work in it's constructor (see Ddoc for this() below) |
|---|
| | 112 | * and provide an implementation of getCreationData() (unless Widget's version is sufficient). |
|---|
| | 113 | * |
|---|
| | 114 | * Since a grid with either dimension zero is not useful, there must be at least one sub-widget. |
|---|
| | 115 | * |
|---|
| | 116 | * The grid has no border but has spacing between widgets. |
|---|
| | 117 | *************************************************************************************************/ |
|---|
| | 118 | class GridWidget : Widget |
|---|
| | 119 | { |
|---|
| | 120 | //BEGIN Creation & saving |
|---|
| | 121 | /** Partial constructor for a grid layout widget. |
|---|
| | 122 | * |
|---|
| | 123 | * Deriving classes should check data length, and set rows, cols, and the subWidgets array, |
|---|
| | 124 | * before calling this super constructor. (If it's necessary to call super(...) first, |
|---|
| | 125 | * the call to genCachedConstructionData can be moved to the derived this() methods.) */ |
|---|
| | 126 | protected this (IWindow wind, int[] data) { |
|---|
| | 127 | super (wind, data); |
|---|
| | 128 | |
|---|
| | 129 | // Needn't be set before genCachedConstructionData is called: |
|---|
| | 130 | col.setColWidth = &setColWidth; |
|---|
| | 131 | row.setColWidth = &setRowHeight; |
|---|