Skip to content

grid ​

In any application, you always have to deal with the correct alignment of objects in the scene. Grid is a classic two-dimensional layout that can be used not only in 2D, but also in 3D space.

The grid works in two modes. On an entity without geometry (e.g. a-entity), the items keep their own size and are arranged in a centred grid; the cell size is given by the largest item. On an entity with geometry (e.g. a-plane), the items are fitted into the area of that geometry, see Grid with its own geometry.

Example ​

Grid with its own geometry ​

When the grid entity has its own geometry (e.g. a-plane or a-box), the grid splits that area into equally sized cells and fits every item into its cell. The gaps between cells are set by padding (in percent of the grid size). This is the mode the menu primitive uses.

How the items are fitted is set by sizing:

  • geometry (default) – sets the width and height of the item's geometry. The primitive is kept, so a box stays a box with its depth. Items without geometry get a plane. The x/y scale of the item is reset to 1.
  • scale – keeps the item's geometry and scales the item (with its children) in x/y to fit its cell while keeping its aspect ratio. Useful for composed primitives such as a-ar-button.
  • none – only positions the items, their size is not changed.

TIP

If an item must not be resized at all, use sizing: none, or wrap it in an a-entity and let the grid size the wrapper instead. Children marked with the data-layout-excluded attribute are ignored by the grid.

Props ​

PropertyTypeDefaultDescription
columnsnumber2Number of grid columns.
rowsnumber2Number of grid rows. The layout currently derives the rows from columns and the number of items.
spacingnumber0Spacing between items in metres. Used only when the grid entity has no geometry.
paddingvec210 10Total gaps between and around the cells in percent of the grid width and height. Used only when the grid entity has a geometry.
sizingenum(geometry, scale, none)geometryHow items are fitted into their cells when the grid entity has a geometry. See Grid with its own geometry.