Skip to content

GridLayout

#include <GridLayout.hpp>

Inherits: Layout

A layout that arranges children in a 2D grid.

GridLayout divides the available space into a fixed grid of rows and columns. Children position themselves using the col, row, colSpan, and rowSpan fields in their LayoutSpec.

Example Usage:

// Create a 3x2 grid (3 columns, 2 rows) with 1 cell spacing
auto grid = std::make_shared<Container>(
std::make_shared<GridLayout>(3, 2, 1, 1)
);
// Add widgets specifying their grid position
auto widget1 = std::make_shared<Label>("Top-left");
auto widget2 = std::make_shared<Label>("Top-right");
auto widget3 = std::make_shared<Label>("Bottom (spans 3 cols)");
grid->addChild(widget1, LayoutSpec{.col = 0, .row = 0});
grid->addChild(widget2, LayoutSpec{.col = 2, .row = 0});
grid->addChild(widget3, LayoutSpec{.col = 0, .row = 1, .colSpan = 3});
ReturnNameDescription
GridLayout inlineCreates a grid layout.
voidapplyApplies the grid layout.

inline

inline GridLayout(int cols, int rows, int gapX, int gapY)

Creates a grid layout.

  • cols Number of columns

  • rows Number of rows

  • gapX Horizontal spacing between columns in cells (default: 0)

  • gapY Vertical spacing between rows in cells (default: 0)


void apply(std::vector< core::ChildSlot > & children, core::Rect inner)

Applies the grid layout.

ReturnNameDescription
intcols
introws
intgapX
intgapY

int cols

int rows

int gapX

int gapY