Grid

A table layout: a fixed grid of columns and rows, each independently sized to its content (autoSize), a fixed pixel size (absolute) or a weighted share of the leftover space (percent). Widgets and nested sizers are placed into cells by column/row and may span several columns or rows. Within its cell a child fills the available space by default, or keeps its preferred size and aligns (start/center/end) — see GridItem.

This is Deft's analog of WinForms' TableLayoutPanel: pick the column and row counts, mark each track auto or percent (or pixels), and drop children into cells without computing any coordinates. add returns a GridItem whose fluent span/aligned/pad methods read better than positional arguments:

auto grid = new Grid(2, 2);
grid.setColumn(0, GridTrack.autoSize);
grid.setColumn(1, GridTrack.percent(100));
grid.add(label, 0, 0).aligned(HAlign.right, VAlign.middle);
grid.add(field, 1, 0);                       // fills its cell
grid.add(footer, 0, 1).span(2, 1);           // spans both columns

Tracks default to autoSize. Auto track sizes are measured from the cells that do not span (a spanning child is placed across the already-computed tracks but does not enlarge them).

Constructors

this
this(int columns, int rows)

Create a grid with columns columns and rows rows, all autoSize.

Members

Functions

add
GridItem add(Widget widget, int column, int row)

Place widget in the cell at column/row. Returns a GridItem whose fluent span/aligned/alignH/alignV/pad methods configure it.

addSizer
GridItem addSizer(Sizer sizer, int column, int row)

Place a nested sizer in the cell at column/row; see add.

columnCount
int columnCount()

Number of columns.

layout
void layout(Rect area)
Undocumented in source. Be warned that the author may not have intended to support it.
length
size_t length()

Number of placed children.

preferredSize
Size preferredSize()
Undocumented in source. Be warned that the author may not have intended to support it.
rowCount
int rowCount()

Number of rows.

setColumn
void setColumn(int index, GridTrack track)

Set the sizing rule for column index.

setRow
void setRow(int index, GridTrack track)

Set the sizing rule for row index.

setSpacing
void setSpacing(int horizontal, int vertical)

Set the pixel gap between columns (horizontal) and rows (vertical).

Inherited Members

From Sizer

items
SizerItem[] items;
Undocumented in source.
layout
void layout(Rect availableArea)

Arrange the children within availableArea.

preferredSize
Size preferredSize()

The natural size this sizer would like, given its children.

add
SizerItem add(Widget widget)

Add a widget child and return its SizerItem for fluent configuration: box.add(w).proportion(1).pad(Padding.all(8)).alignV(VAlign.middle). A bare add(w) gives a non-stretching child (proportion 0) with no padding.

addSizer
SizerItem addSizer(Sizer sizer)

Add a nested sizer and return its SizerItem for fluent configuration.

length
size_t length()

Number of child items.

Meta