Class GridLayout

Inheritance Relationships

Base Type

Class Documentation

class GridLayout : public nanogui::Layout

Grid layout.

Widgets are arranged in a grid that has a fixed grid resolution resolution along one of the axes. The layout orientation indicates the fixed dimension; widgets are also appended on this axis. The spacing between items can be specified per axis. The horizontal/vertical alignment can be specified per row and column.

Public Functions

GridLayout(Orientation orientation = Orientation::Horizontal, int resolution = 2, Alignment alignment = Alignment::Middle, int margin = 0, int spacing = 0)

Create a 2-column grid layout by default.

Parameters
  • orientation: The fixed dimension of this GridLayout.

  • resolution: The number of rows or columns in the grid (depending on the Orientation).

  • alignment: How widgets should be aligned within each grid cell.

  • margin: The amount of spacing to add around the border of the grid.

  • spacing: The amount of spacing between widgets added to the grid.

Orientation orientation() const

The Orientation of this GridLayout.

void setOrientation(Orientation orientation)

Sets the Orientation of this GridLayout.

int resolution() const

The number of rows or columns (depending on the Orientation) of this GridLayout.

void setResolution(int resolution)

Sets the number of rows or columns (depending on the Orientation) of this GridLayout.

int spacing(int axis) const

The spacing at the specified axis (row or column number, depending on the Orientation).

void setSpacing(int axis, int spacing)

Sets the spacing for a specific axis.

void setSpacing(int spacing)

Sets the spacing for all axes.

int margin() const

The margin around this GridLayout.

void setMargin(int margin)

Sets the margin of this GridLayout.

Alignment alignment(int axis, int item) const

The Alignment of the specified axis (row or column number, depending on the Orientation) at the specified index of that row or column.

void setColAlignment(Alignment value)

Sets the Alignment of the columns.

void setRowAlignment(Alignment value)

Sets the Alignment of the rows.

void setColAlignment(const std::vector<Alignment> &value)

Use this to set variable Alignment for columns.

void setRowAlignment(const std::vector<Alignment> &value)

Use this to set variable Alignment for rows.

virtual Vector2i preferredSize(NVGcontext *ctx, const Widget *widget) const

See Layout::preferredSize.

virtual void performLayout(NVGcontext *ctx, Widget *widget) const

See Layout::performLayout.

Protected Functions

void computeLayout(NVGcontext *ctx, const Widget *widget, std::vector<int> *grid) const

Compute the maximum row and column sizes.

Protected Attributes

Orientation mOrientation

The Orientation defining this GridLayout.

Alignment mDefaultAlignment[2]

The default Alignment for this GridLayout.

std::vector<Alignment> mAlignment[2]

The actual Alignment being used.

int mResolution

The number of rows or columns before starting a new one, depending on the Orientation.

Vector2i mSpacing

The spacing used for each dimension.

int mMargin

The margin around this GridLayout.