2 summary:: A layout that organizes views in a grid
3 categories:: GUI>Layout
4 related:: Classes/HLayout, Classes/VLayout, Classes/StackLayout, Guides/GUI-Layout-Management
9 note:: GridLayout is only implemented in strong::Qt GUI:: ::
11 GridLayout distributes its space into a strong::grid of rows and columns::, where each item can occupy strong::one or more cells::.
13 You can construct the layout in two ways using link::#*rows:: and link::#*columns::. In the former constructor you pass arrays of items by rows, and in the latter by columns. Items can also be added later using link::#-add:: and link::#-addSpanning::. To remove an item, simply use link::Classes/View#-remove:: for views, or link::Classes/QObject#-destroy:: for views or layouts.
15 It is possible to add more than one view into the same cell. The last added view will be the top-most. However, it is most probably more convenient to use a link::Classes/StackLayout:: for that purpose.
17 The layout manages the grid size automatically: you can add an item at any row and cell number. When items are added or removed, the grid will re-adjust according to the last occupied row and column.
19 subsection:: Fine tuning
21 Each item can be assigned an strong::alignment:: either at layout link::#*rows#construction:: or later using link::#-setAlignment::. An item will then get at most its default size, if available (see: link::Classes/View#-sizeHint::), and will be aligned within its cell according to the specified alignment.
23 Each row or column can be assigned a strong::stretch factor:: using link::#-setRowStretch:: and link::#-setColumnStretch::. Rows or columns that would otherwise get equal space are then distributed according to the relative proportions of their stretch factors.
25 Each row or column can also be assigned a strong::minimum:: size using link::#-setMinRowHeight:: and link::#-setMinColumnWidth::, to override the size contraints imposed by the contained views.
27 In addition to adjusting the spacing between cells using link::Classes/QLayout#-spacing:: you can control the spacing between rows and between columns separately using link::#-hSpacing:: and link::#-vSpacing::.
29 subsection:: Leaving empty space
31 You can leave any cell empty by not placing any item into it, or at link::#*rows#construction:: using code::nil:: instead of a view or another layout. Note though that the empty cells will always be regarded as freely stretchable and will not impose any constraints on space distribution.
42 Creates a GridLayout and fills each row with an array of items given as arguments.
46 Each argument is an Array of items to form a consecutive row. An item can be a strong::view::, another strong::layout::, or strong::nil:: for an empty cell.
50 You can make an item span more than one cell by wrapping it into an Array, followed by pairs of (\rows, number) and/or (\columns, number). You can also assign an alignment to an item by following it with a pair of (\align, alignment). \rows, \columns, and \align can be abbreviated with \r, \c, and \a, respectively.
52 The simplified syntax for placing key-value pairs into an array comes handy (see link::Reference/Syntax-Shortcuts#creating_arrays_with_key-value_pairs::, and the example below).
57 w=Window().layout_( GridLayout.rows(
58 [Slider2D(), Slider2D(), [Slider(), rows:2]],
59 [Slider2D(), Slider2D()],
60 [[Slider().orientation_(\horizontal), columns:2]]
67 Creates a GridLayout and fills each column with an array of items given as arguments.
71 Each argument is an Array of items to form a consecutive column. An item can be a strong::view::, another strong::layout::, or strong::nil:: for an empty cell.
75 To make an item span several cells, or assign an alignment to it, the same instructions as for link::#*rows:: apply.
83 Adds an item into the cell at specified row and column.
86 The item can be a strong::view:: or another strong::layout::.
95 A symbol denoting the alignment, or nil.
99 Adds an item into the grid so as to occupy several cells.
102 The item can be a strong::view:: or another strong::layout::.
111 The amount of cells to occupy in vertical direction.
113 argument:: columnSpan
114 The amount of cells to occpy in horizontal direction.
117 A symbol denoting the alignment, or nil.
121 The spacing between columns, in Integer amount of pixels.
125 The spacing between rows, in Integer amount of pixels.
127 METHOD:: setRowStretch
129 Sets the stretch factor of a row. By default rows have a stretch factor of 0. If a larger factor is assigned to a row, rows will get their space redistributed according to the relative proportions of their factors.
137 METHOD:: setColumnStretch
139 Sets the stretch factor of a column. By default columns have a stretch factor of 0. If a larger factor is assigned to a column, columns will get their space redistributed according to the relative proportions of their factors.
142 The index of a column.
147 METHOD:: setAlignment
149 Sets the alignment of an item managed by the layout.
152 A view or a layout managed by this layout, or a Point of which x denotes the column index and y the row index of an item.
155 A symbol denoting the alignment.
157 METHOD:: minRowHeight
159 Gets the minimum height assigned to a row.
164 METHOD:: setMinRowHeight
166 Sets the minimum height of row.
172 An Integer amount of pixels.
174 METHOD:: minColumnWidth
176 Gets the minimum width assigned to a column.
179 The index of a column.
181 METHOD:: setMinColumnWidth
183 Sets the minimum width of a column.
186 The index of a column.
189 An Integer amount of pixels.