It derives from <GtkWidget>.
Arranges its child widgets in rows and columns.
It supports arbitrary positions and horizontal/vertical spans.
Children are added using grid:attach. They
can span multiple rows or columns. It is also possible to add a child
next to an existing child, using grid:attach-next-to. To remove a child from the grid,
use grid:remove.
The behaviour of <GtkGrid> when several children
occupy the same grid cell is undefined.
Every child in a <GtkGrid> has access to a custom
<GtkBuildable> 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 <GtkGridLayoutChild>.
It is implemented by <GtkWidget> using
<GtkLayoutManager>.
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.
<GtkGrid> uses a single CSS node with name
grid.
Until GTK 4.10, <GtkGrid> used the
Gtk.AccessibleRole.group role.
Starting from GTK 4.12, <GtkGrid> uses the
Gtk.AccessibleRole.generic role.
The row to align to the baseline when valign is using baseline alignment.
Its value is a 32-bit integer.
Set it with (set! (grid:baseline-row self) value).
If #t, the columns are all the same width.
Its value is a boolean.
Set it with (set! (grid:column-homogeneous self) value).
The amount of space between two consecutive columns.
Its value is a 32-bit integer.
Set it with (set! (grid:column-spacing self) value).
If #t, the rows are all the same height.
Its value is a boolean.
Set it with (set! (grid:row-homogeneous self) value).
The amount of space between two consecutive rows.
Its value is a 32-bit integer.
Set it with (set! (grid:row-spacing self) value).
Adds a widget to the grid.
The position of child is determined by column and row. The number of “cells” that child will occupy is determined by width and height.
Passed: a <GtkGrid>.
Passed: a <GtkWidget>.
the widget to add
Passed: a 32-bit integer.
the column number to attach the left side of child to
Passed: a 32-bit integer.
the row number to attach the top side of child to
Passed: a 32-bit integer.
the number of columns that child will span
Passed: a 32-bit integer.
the number of rows that child will span
Adds a widget to the grid.
The widget is placed next to sibling, on the side determined by
side. When sibling is #f, the widget is placed in
row (for left or right placement) or column 0 (for top or bottom
placement), at the end indicated by side.
Attaching widgets labeled [1], [2], [3] with
@sibling == %NULL and @side == %GTK_POS_LEFT yields a
layout of [3][2][1].
Passed: a <GtkGrid>.
Passed: a <GtkWidget>.
the widget to add
Passed: a <GtkWidget>, or #f.
the child of self that child will be placed next to, or
#f to place child at the beginning or end
Passed: a <GtkPositionType>, or one of its
symbols.
the side of sibling that child is positioned next to
Passed: a 32-bit integer.
the number of columns that child will span
Passed: a 32-bit integer.
the number of rows that child will span
Returns which row defines the global baseline of self.
Gets the child of self whose area covers the grid cell at column, row.
Passed: a <GtkGrid>.
Passed: a 32-bit integer.
the left edge of the cell
Passed: a 32-bit integer.
the top edge of the cell
Returned: a <GtkWidget>, or #f.
the child at the given position
Returns whether all columns of self have the same width.
Returns the amount of space between the columns of self.
Returns the baseline position of row.
See grid:set-row-baseline-position.
Passed: a <GtkGrid>.
Passed: a 32-bit integer.
a row index
Returned: a <GtkBaselinePosition>.
the baseline position of row
Returns whether all rows of self have the same height.
Returns the amount of space between the rows of self.
Inserts a column at the specified position.
Children which are attached at or to the right of this position are moved one column to the right. Children which span across this position are grown to span the new column.
Inserts a row or column at the specified position.
The new row or column is placed next to sibling, on the side
determined by side. If side is
top or bottom, a
row is inserted. If side is left of
right, a column is inserted.
Passed: a <GtkGrid>.
Passed: a <GtkWidget>.
the child of self that the new row or column will be placed next to
Passed: a <GtkPositionType>, or one of its
symbols.
the side of sibling that child is positioned next to
Inserts a row at the specified position.
Children which are attached at or below this position are moved one row down. Children which span across this position are grown to span the new row.
Creates a new grid widget.
Returned: a <GtkWidget>.
the new <GtkGrid>
Queries the attach points and spans of child inside the given
<GtkGrid>.
Passed: a <GtkGrid>.
Passed: a <GtkWidget>.
a <GtkWidget> child of self
Returned: a 32-bit integer.
the column used to attach the left side of child
Returned: a 32-bit integer.
the row used to attach the top side of child
Returned: a 32-bit integer.
the number of columns child spans
Returned: a 32-bit integer.
the number of rows child spans
Removes a child from self.
The child must have been added with grid:attach or grid:attach-next-to.
Passed: a <GtkGrid>.
Passed: a <GtkWidget>.
the child widget to remove
Removes a column from the grid.
Children that are placed in this column are removed, spanning children that overlap this column have their width reduced by one, and children after the column are moved to the left.
Removes a row from the grid.
Children that are placed in this row are removed, spanning children that overlap this row have their height reduced by one, and children below the row are moved up.
Sets which row defines the global baseline for the entire grid.
Each row in the grid can have its own local baseline, but only one of those is global, meaning it will be the baseline in the parent of the self.
Sets whether all columns of self will have the same width.
Sets the amount of space between columns of self.
Sets how the baseline should be positioned on row of the grid, in case that row is assigned more space than is requested.
The default baseline position is center.
Passed: a <GtkGrid>.
Passed: a 32-bit integer.
a row index
Passed: a <GtkBaselinePosition>, or one
of its symbols.
Sets whether all rows of self will have the same height.