`GtkGrid` is a container which arranges its child widgets in rows and columns.
![An example GtkGrid](grid.png)
It supports arbitrary positions and horizontal/vertical spans.
Children are added using [[email protected]]. They can span multiple rows or columns. It is also possible to add a child next to an
existing child, using [[email protected]_next_to]. To remove a child from the grid, use [[email protected]].
The behaviour of `GtkGrid` when several children occupy the same grid cell is undefined.
GtkGrid as GtkBuildable
Every child in a `GtkGrid` has access to a custom [[email protected]] 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 [
[email protected]].
It is implemented by `GtkWidget` using [[email protected]].
To showcase it, here is a simple example:
```xml <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
`GtkGrid` uses a single CSS node with name `grid`.
Accessibility
`GtkGrid` uses the gtk_accessible_role_group role.
- public void attach (Widget child, int column, int row, int width = 1, int height = 1)
Adds a widget to the grid.
- public void attach_next_to (Widget child, Widget? sibling, PositionType side, int width = 1, int height = 1)
Adds a widget to the grid.
- public int get_baseline_row ()
Returns which row defines the global baseline of
this.
- public unowned Widget? get_child_at (int column, int row)
Gets the child of this whose area
covers the grid cell at column
, row
.
- public bool get_column_homogeneous ()
Returns whether all columns of this
have the same width.
- public uint get_column_spacing ()
Returns the amount of space between the columns of
this.
- public BaselinePosition get_row_baseline_position (int row)
Returns the baseline position of row
.
- public bool get_row_homogeneous ()
Returns whether all rows of this
have the same height.
- public uint get_row_spacing ()
Returns the amount of space between the rows of
this.
- public void insert_column (int position)
Inserts a column at the specified position.
- public void insert_next_to (Widget sibling, PositionType side)
Inserts a row or column at the specified position.
- public void insert_row (int position)
Inserts a row at the specified position.
- public void query_child (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 `GtkGrid`.
- public void remove (Widget child)
Removes a child from this.
- public void remove_column (int position)
Removes a column from the grid.
- public void remove_row (int position)
Removes a row from the grid.
- public void set_baseline_row (int row)
Sets which row defines the global baseline for the entire grid.
- public void set_column_homogeneous (bool homogeneous)
Sets whether all columns of this
will have the same width.
- public void set_column_spacing (uint spacing)
Sets the amount of space between columns of
this.
- public void set_row_baseline_position (int row, 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.
- public void set_row_homogeneous (bool homogeneous)
Sets whether all rows of this will
have the same height.
- public void set_row_spacing (uint spacing)
Sets the amount of space between rows of
this.