GridLayout

extends Layout

The GridLayout class represents a layout that positions objects in a grid. To create a GridLayout object and apply it to a collection, use the layout function:

let gl = msc.layout("grid", {numCols: 2, hGap: 10});
collection.layout = gl;

Properties

propertyexplanationtypedefault value
cellBounds the bounds of the grid cellsArray of Rectangle[]
colGapthe vertical gap between adjacent columns in the gridNumber5
colOffsetthe number of pixels to shift every other row vertically in the gridNumber0
dirthe direction in which the items are added to each grid cellArray[“l2r”, “t2b”]
group the group that uses this layoutGroup
horzCellAlignmentthe horizontal alignment of item in each grid cellString“left”
numColsthe number of columns in the gridNumberundefined
numRowsthe number of rows in the gridNumberundefined
rowGapthe horizontal gap between adjacent rows in the gridNumber5
rowOffsetthe number of pixels to shift every other row horizontally in the gridNumber0
type the type of the layoutString“grid”
vertCellAlignmentthe vertical alignment of item in each grid cellString“bottom”

The direction of a grid layout consists of two components: horizontal and vertical. For the horizontal component, there are two options: left to right (l2r), and right to left (r2l); for the vertical component, there are also two options: top to bottom (t2b), and bottom to top (b2t). The order of these two components also matters. The figure below illustrates all the possible directions based on these two components.

grid directions

Figure 1: possible grid directions

Methods inherited from Layout

methodexplanationreturn type
clone() returns a copy of this layoutvoid
run() apply this layoutvoid