gtk.grid

Module for Grid class

Types 3

gtk.grid.Grid is a container which arranges its child widgets in rows and columns.

!An example GtkGrid

It supports arbitrary positions and horizontal/vertical spans.

Children are added using gtk.grid.Grid.attach. They can span multiple rows or columns. It is also possible to add a child next to an existing child, using gtk.grid.Grid.attachNextTo. To remove a child from the grid, use gtk.grid.Grid.remove.

The behaviour of gtk.grid.Grid when several children occupy the same grid cell is undefined.

GtkGrid as GtkBuildable

Every child in a gtk.grid.Grid has access to a custom gtk.buildable.Buildable element, called <layout>. It can by used to specify a position in the grid and optionally spans. All properties that can be used in the <layout> element are implemented by gtk.grid_layout_child.GridLayoutChild.

It is implemented by gtk.widget.Widget using gtk.layout_manager.LayoutManager.

To showcase it, here is a simple example:

<object class="GtkGrid" id="my_grid">
  <child>
    <object class="GtkButton" id="button1">
      <property name="label">Button 1</property>
      <layout>
        <property name="column">0</property>
        <property name="row">0</property>
      </layout>
    </object>
  </child>
  <child>
    <object class="GtkButton" id="button2">
      <property name="label">Button 2</property>
      <layout>
        <property name="column">1</property>
        <property name="row">0</property>
      </layout>
    </object>
  </child>
  <child>
    <object class="GtkButton" id="button3">
      <property name="label">Button 3</property>
      <layout>
        <property name="column">2</property>
        <property name="row">0</property>
        <property name="row-span">2</property>
      </layout>
    </object>
  </child>
  <child>
    <object class="GtkButton" id="button4">
      <property name="label">Button 4</property>
      <layout>
        <property name="column">0</property>
        <property name="row">1</property>
        <property name="column-span">2</property>
      </layout>
    </object>
  </child>
</object>

It organizes the first two buttons side-by-side in one cell each. The third button is in the last column but spans across two rows. This is defined by the row-span property. The last button is located in the second row and spans across two columns, which is defined by the column-span property.

CSS nodes

gtk.grid.Grid uses a single CSS node with name grid.

Accessibility

Until GTK 4.10, gtk.grid.Grid used the gtk.types.AccessibleRole.Group role.

Starting from GTK 4.12, gtk.grid.Grid uses the gtk.types.AccessibleRole.Generic role.

Methods
GType _gType() @property
Grid self()Returns `this`, for use in `with` statements.
GridGidBuilder builder()Get builder for [gtk.grid.Grid] Returns: New builder object
int baselineRow() @propertyGet `baselineRow` property. Returns: The row to align to the baseline when valign is using baseline alignment.
void baselineRow(int propval) @propertySet `baselineRow` property. Params: propval = The row to align to the baseline when valign is using baseline alignment.
bool columnHomogeneous() @propertyGet `columnHomogeneous` property. Returns: If true, the columns are all the same width.
void columnHomogeneous(bool propval) @propertySet `columnHomogeneous` property. Params: propval = If true, the columns are all the same width.
int columnSpacing() @propertyGet `columnSpacing` property. Returns: The amount of space between two consecutive columns.
void columnSpacing(int propval) @propertySet `columnSpacing` property. Params: propval = The amount of space between two consecutive columns.
bool rowHomogeneous() @propertyGet `rowHomogeneous` property. Returns: If true, the rows are all the same height.
void rowHomogeneous(bool propval) @propertySet `rowHomogeneous` property. Params: propval = If true, the rows are all the same height.
int rowSpacing() @propertyGet `rowSpacing` property. Returns: The amount of space between two consecutive rows.
void rowSpacing(int propval) @propertySet `rowSpacing` property. Params: propval = The amount of space between two consecutive rows.
void attach(gtk.widget.Widget child, int column, int row, int width, int height)Adds a widget to the grid.
void attachNextTo(gtk.widget.Widget child, gtk.widget.Widget sibling, gtk.types.PositionType side, int width, int height)Adds a widget to the grid.
int getBaselineRow()Returns which row defines the global baseline of grid. Returns: the row index defining the global baseline
gtk.widget.Widget getChildAt(int column, int row)Gets the child of grid whose area covers the grid cell at column, row.
bool getColumnHomogeneous()Returns whether all columns of grid have the same width. Returns: whether all columns of grid have the same width.
uint getColumnSpacing()Returns the amount of space between the columns of grid. Returns: the column spacing of grid
gtk.types.BaselinePosition getRowBaselinePosition(int row)Returns the baseline position of row.
bool getRowHomogeneous()Returns whether all rows of grid have the same height. Returns: whether all rows of grid have the same height.
uint getRowSpacing()Returns the amount of space between the rows of grid. Returns: the row spacing of grid
void insertColumn(int position)Inserts a column at the specified position.
void insertNextTo(gtk.widget.Widget sibling, gtk.types.PositionType side)Inserts a row or column at the specified position.
void insertRow(int position)Inserts a row at the specified position.
void queryChild(gtk.widget.Widget child, out int column, out int row, out int width, out int height)Queries the attach points and spans of child inside the given [gtk.grid.Grid].
void remove(gtk.widget.Widget child)Removes a child from grid.
void removeColumn(int position)Removes a column from the grid.
void removeRow(int position)Removes a row from the grid.
void setBaselineRow(int row)Sets which row defines the global baseline for the entire grid.
void setColumnHomogeneous(bool homogeneous)Sets whether all columns of grid will have the same width.
void setColumnSpacing(uint spacing)Sets the amount of space between columns of grid.
void setRowBaselinePosition(int row, gtk.types.BaselinePosition pos)Sets how the baseline should be positioned on row of the grid, in case that row is assigned more space than is requested.
void setRowHomogeneous(bool homogeneous)Sets whether all rows of grid will have the same height.
void setRowSpacing(uint spacing)Sets the amount of space between rows of grid.
Constructors
this(void * ptr, Flag!"Take" take)
this()Creates a new grid widget. Returns: the new [gtk.grid.Grid]

Fluent builder implementation template for gtk.grid.Grid

Methods
T baselineRow(int propval)Set `baselineRow` property. Params: propval = The row to align to the baseline when valign is using baseline alignment. Returns: Builder instance for fluent chaining
T columnHomogeneous(bool propval)Set `columnHomogeneous` property. Params: propval = If true, the columns are all the same width. Returns: Builder instance for fluent chaining
T columnSpacing(int propval)Set `columnSpacing` property. Params: propval = The amount of space between two consecutive columns. Returns: Builder instance for fluent chaining
T rowHomogeneous(bool propval)Set `rowHomogeneous` property. Params: propval = If true, the rows are all the same height. Returns: Builder instance for fluent chaining
T rowSpacing(int propval)Set `rowSpacing` property. Params: propval = The amount of space between two consecutive rows. Returns: Builder instance for fluent chaining

Fluent builder for gtk.grid.Grid

Methods
Grid build()Create object from builder. Returns: New object