gtk.grid
Module for [Grid] class
Types 3
gtk.grid.Grid is a container which arranges its child widgets in rows and columns.
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.
int baselineRow() @property nothrowGet `baselineRow` property. Returns: The row to align to the baseline when valign is using baseline alignment.void baselineRow(int propval) @property nothrowSet `baselineRow` property. Params: propval = The row to align to the baseline when valign is using baseline alignment.bool columnHomogeneous() @property nothrowGet `columnHomogeneous` property. Returns: If true, the columns are all the same width.void columnHomogeneous(bool propval) @property nothrowSet `columnHomogeneous` property. Params: propval = If true, the columns are all the same width.int columnSpacing() @property nothrowGet `columnSpacing` property. Returns: The amount of space between two consecutive columns.void columnSpacing(int propval) @property nothrowSet `columnSpacing` property. Params: propval = The amount of space between two consecutive columns.bool rowHomogeneous() @property nothrowGet `rowHomogeneous` property. Returns: If true, the rows are all the same height.void rowHomogeneous(bool propval) @property nothrowSet `rowHomogeneous` property. Params: propval = If true, the rows are all the same height.int rowSpacing() @property nothrowGet `rowSpacing` property. Returns: The amount of space between two consecutive rows.void rowSpacing(int propval) @property nothrowSet `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) nothrowAdds a widget to the grid.void attachNextTo(gtk.widget.Widget child, gtk.widget.Widget sibling, gtk.types.PositionType side, int width, int height) nothrowAdds a widget to the grid.int getBaselineRow() nothrowReturns which row defines the global baseline of grid. Returns: the row index defining the global baselinegtk.widget.Widget getChildAt(int column, int row) nothrowGets the child of grid whose area covers the grid cell at column, row.bool getColumnHomogeneous() nothrowReturns whether all columns of grid have the same width. Returns: whether all columns of grid have the same width.uint getColumnSpacing() nothrowReturns the amount of space between the columns of grid. Returns: the column spacing of gridgtk.types.BaselinePosition getRowBaselinePosition(int row) nothrowReturns the baseline position of row.bool getRowHomogeneous() nothrowReturns whether all rows of grid have the same height. Returns: whether all rows of grid have the same height.uint getRowSpacing() nothrowReturns the amount of space between the rows of grid. Returns: the row spacing of gridvoid insertNextTo(gtk.widget.Widget sibling, gtk.types.PositionType side) nothrowInserts a row or column at the specified position.void queryChild(gtk.widget.Widget child, out int column, out int row, out int width, out int height) nothrowQueries the attach points and spans of child inside the given [gtk.grid.Grid].void setColumnHomogeneous(bool homogeneous) nothrowSets whether all columns of grid will have the same width.void setRowBaselinePosition(int row, gtk.types.BaselinePosition pos) nothrowSets 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) nothrowSets whether all rows of grid will have the same height.Fluent builder implementation template for gtk.grid.Grid
T baselineRow(int propval) nothrowSet `baselineRow` property. Params: propval = The row to align to the baseline when valign is using baseline alignment. Returns: Builder instance for fluent chainingT columnHomogeneous(bool propval) nothrowSet `columnHomogeneous` property. Params: propval = If true, the columns are all the same width. Returns: Builder instance for fluent chainingT columnSpacing(int propval) nothrowSet `columnSpacing` property. Params: propval = The amount of space between two consecutive columns. Returns: Builder instance for fluent chainingT rowHomogeneous(bool propval) nothrowSet `rowHomogeneous` property. Params: propval = If true, the rows are all the same height. Returns: Builder instance for fluent chainingT rowSpacing(int propval) nothrowSet `rowSpacing` property. Params: propval = The amount of space between two consecutive rows. Returns: Builder instance for fluent chainingFluent builder for gtk.grid.Grid