CLASS:: GridLayout summary:: A layout that organizes views in a grid categories:: GUI>Layout related:: Classes/HLayout, Classes/VLayout, Classes/StackLayout, Guides/GUI-Layout-Management DESCRIPTION:: GridLayout distributes its space into a strong::grid of rows and columns::, where each item can occupy strong::one or more cells::. 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. 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. 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. subsection:: Fine tuning 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. 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. Each row or column can also be assigned a strong::minimum:: size using link::#-setMinRowHeight:: and link::#-setMinColumnWidth::, to override the size constraints imposed by the contained views. In addition to adjusting the spacing between cells using link::Classes/Layout#-spacing:: you can control the spacing between rows and between columns separately using link::#-hSpacing:: and link::#-vSpacing::. subsection:: Leaving empty space 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. CLASSMETHODS:: PRIVATE:: key PRIVATE:: qtClass METHOD:: rows Creates a GridLayout and fills each row with an array of items given as arguments. argument:: ... rows 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. discussion:: 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. For possible alignment values see link::Reference/gui_alignments::. 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). Example: Code:: ( w=Window().layout_( GridLayout.rows( [Slider2D(), Slider2D(), [Slider(), rows:2]], [Slider2D(), Slider2D()], [[Slider().orientation_(\horizontal), columns:2]] )).front; ) :: METHOD:: columns Creates a GridLayout and fills each column with an array of items given as arguments. argument:: ... cols 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. discussion:: To make an item span several cells, or assign an alignment to it, the same instructions as for link::#*rows:: apply. INSTANCEMETHODS:: METHOD:: add Adds an item into the cell at specified row and column. argument:: item The item can be a strong::view:: or another strong::layout::. argument:: row The row index. argument:: column The column index. argument:: align A symbol denoting the alignment, or nil. See link::Reference/gui_alignments:: for possible values. METHOD:: addSpanning Adds an item into the grid so as to occupy several cells. argument:: item The item can be a strong::view:: or another strong::layout::. argument:: row The row index. argument:: column The column index. argument:: rowSpan The amount of cells to occupy in vertical direction. argument:: columnSpan The amount of cells to occupy in horizontal direction. argument:: align A symbol denoting the alignment, or nil. See link::Reference/gui_alignments:: for possible values. METHOD:: hSpacing The spacing between columns, in Integer amount of pixels. METHOD:: vSpacing The spacing between rows, in Integer amount of pixels. METHOD:: setRowStretch 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. argument:: row The index of a row. argument:: factor An Integer. METHOD:: setColumnStretch 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. argument:: column The index of a column. argument:: factor An Integer. METHOD:: setAlignment Sets the alignment of an item managed by the layout. argument:: item 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. argument:: align A symbol denoting the alignment. See link::Reference/gui_alignments:: for possible values. METHOD:: minRowHeight Gets the minimum height assigned to a row. argument:: row The index of a row. METHOD:: setMinRowHeight Sets the minimum height of row. argument:: row The index of a row. argument:: height An Integer amount of pixels. METHOD:: minColumnWidth Gets the minimum width assigned to a column. argument:: column The index of a column. METHOD:: setMinColumnWidth Sets the minimum width of a column. argument:: column The index of a column. argument:: width An Integer amount of pixels.