Grid Layouts#
Grid layouts display multiple child elements in a table or grid.
Grids will automatically resize to contain all child elements if possible and each row and column will automatically resize to display the children as well.
A new grid can be created with the grid()
function in the
eg-overlay-ui
module.
See also
See the example for uigrid
for details on child alignment
and row/column spanning.
Functions#
Classes#
- class eg-overlay-ui.uigrid#
A grid layout container. Grid layout containers arrange their child elements into an aligned grid or table.
Grids must have a known number of columns and rows when they are created. This can not be changed after a grid is created.
Example#local ui = require 'eg-overlay-ui' local function txt(t) return ui.text(t, 0xFFFFFFFF, ui.fonts.regular) end -- a 3x3 grid local grid = ui.grid(3, 3) local a = txt('Top Left', ) local b = txt('Top Middle & Right') local c = txt('Middle') local d = txt('Bottom Left & Middle') local e = txt('Bottom Right') -- arrange elements in this pattern -- -- +-------------+-----------------------+ -- | Top Left | Top Middle & Right | -- +-------------+-----------------------+ -- | Middle | | -- +----------------------+ Bottom Right + -- | Bottom Left & Middle | | -- +----------------------+--------------+ grid:attach(a, 1, 1, 1, 1, 'start' , 'start') -- Top Left grid:attach(b, 1, 2, 1, 2, 'end' , 'start') -- Top Middle & Right grid:attach(c, 2, 1, 1, 2, 'middle', 'start') -- Middle grid:attach(d, 3, 1, 1, 2, 'middle', 'middle') -- Bottom Left & Middle grid:attach(e, 2, 3, 2, 1, 'middle', 'middle') -- Bottom Right
- attach(uielement, row, col, rowspan, colspan, halign, valign)#
Attach a UI element to this grid at the given
row
andcol
. If there was already an element at this location it will be removed first.Normally the element will only occupy one cell. This can be changed by providing appropriate values for
rowspan
andcolspan
.Element alignment is specified by
halign
andvalign
.- Parameters:
uielement – A UI element.
row (
integer
) – Row number. This must be between 1 and the number of rows specified ingrid()
.column (
integer
) – Column number. This must be between 1 and the number of columns specified ingrid()
.rowspan (
integer
) – The number of rows this element will span. This must be between 1 and the number of remaining rows in the grid.colspan (
integer
) – The number of columns this element will span. This must be between 1 and the number of remaining columns remaining in the grid.horizalign (
string
) – Horizontal alignment.'start'
,'middle'
,'end'
, or'fill'
.vertalign (
string
) – Vertical alignment.'start'
,'middle'
,'end'
, or'fill'
.
Version History
Version
Notes
0.3.0
Added
- detach(row, col)#
Remove the element located at
row
andcol
.If no element was located in this position, this function will do nothing.
Version History
Version
Notes
0.3.0
Added
- rowspacing([row, ]spacing)#
Set the spacing between
row
and the next row tospacing
pixels.If
row
is omitted, all rows will be set to usespacing
.Version History
Version
Notes
0.3.0
Added
- colspacing([column, ]spacing)#
Set the spacing between
column
and the next column tospacing
pixels.If
column
is omitted, all columns will usespacing
.Version History
Version
Notes
0.3.0
Added
Note
The following methods are inherited from
uielement
- x([position])#
Set or get the current position X.
Important
It is normally not necessary to manually position an element.
Version History
Version
Notes
0.3.0
Added
- y([position])#
Set or get the current position Y.
Important
It is normally not necessary to manually position an element.
Version History
Version
Notes
0.3.0
Added
- width([value])#
Get or set the element’s width.
Important
It is normally not necessary to manually set an element’s size.
Version History
Version
Notes
0.3.0
Added
- height([value])#
Get or set the element’s height.
Important
It is normally not necessary to manually set an element’s size.
Version History
Version
Notes
0.3.0
Added