GridProtocol
public protocol GridProtocol : OrientableProtocol, WidgetProtocol
GtkGrid is a container which arranges its child widgets in
rows and columns.

It supports arbitrary positions and horizontal/vertical spans.
Children are added using [methodGtk.Grid.attach]. They can span multiple
rows or columns. It is also possible to add a child next to an existing
child, using [methodGtk.Grid.attach_next_to]. To remove a child from the
grid, use [methodGtk.Grid.remove].
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 [ifaceGtk.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 [classGtk.GridLayoutChild].
It is implemented by GtkWidget using [classGtk.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
GtkGrid uses a single CSS node with name grid.
Accessibility
GtkGrid uses the GTK_ACCESSIBLE_ROLE_GROUP role.
The GridProtocol protocol exposes the methods and properties of an underlying GtkGrid instance.
The default implementation of these can be found in the protocol extension below.
For a concrete class that implements these methods and properties, see Grid.
Alternatively, use GridRef as a lighweight, unowned reference if you already have an instance you just want to use.
-
Untyped pointer to the underlying
GtkGridinstance.Declaration
Swift
var ptr: UnsafeMutableRawPointer! { get } -
grid_ptrDefault implementationTyped pointer to the underlying
GtkGridinstance.Default Implementation
Return the stored, untyped pointer as a typed pointer to the
GtkGridinstance.Declaration
Swift
var grid_ptr: UnsafeMutablePointer<GtkGrid>! { get } -
Required Initialiser for types conforming to
GridProtocolDeclaration
Swift
init(raw: UnsafeMutableRawPointer)
-
bind(property:Extension methodto: _: flags: transformFrom: transformTo: ) Bind a
GridPropertyNamesource property to a given target object.Declaration
Swift
@discardableResult @inlinable func bind<Q, T>(property source_property: GridPropertyName, to target: T, _ target_property: Q, flags f: BindingFlags = .default, transformFrom transform_from: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }, transformTo transform_to: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }) -> BindingRef! where Q : PropertyNameProtocol, T : ObjectProtocolParameters
source_propertythe source property to bind
targetthe target object to bind to
target_propertythe target property to bind to
flagsthe flags to pass to the
Bindingtransform_fromValueTransformerto use for forward transformationtransform_toValueTransformerto use for backwards transformationReturn Value
binding reference or
nilin case of an error -
get(property:Extension method) Get the value of a Grid property
Declaration
Swift
@inlinable func get(property: GridPropertyName) -> GLibObject.ValueParameters
propertythe property to get the value for
Return Value
the value of the named property
-
set(property:Extension methodvalue: ) Set the value of a Grid property. Note that this will only have an effect on properties that are writable and not construct-only!
Declaration
Swift
@inlinable func set(property: GridPropertyName, value v: GLibObject.Value)Parameters
propertythe property to get the value for
Return Value
the value of the named property
-
attach(child:Extension methodcolumn: row: width: height: ) Adds a widget to the grid.
The position of
childis determined bycolumnandrow. The number of “cells” thatchildwill occupy is determined bywidthandheight.Declaration
Swift
@inlinable func attach<WidgetT>(child: WidgetT, column: Int, row: Int, width: Int, height: Int) where WidgetT : WidgetProtocol -
attachNextTo(child:Extension methodsibling: side: width: height: ) Adds a widget to the grid.
The widget is placed next to
sibling, on the side determined byside. Whensiblingisnil, the widget is placed in row (for left or right placement) or column 0 (for top or bottom placement), at the end indicated byside.Attaching widgets labeled
[1],[2],[3]withsibling` == `nilandside` == `GTK_POS_LEFTyields a layout of[3](#2)(#1).Declaration
Swift
@inlinable func attachNextTo<WidgetT>(child: WidgetT, sibling: WidgetT?, side: GtkPositionType, width: Int, height: Int) where WidgetT : WidgetProtocol -
getBaselineRow()Extension methodReturns which row defines the global baseline of
grid.Declaration
Swift
@inlinable func getBaselineRow() -> Int -
getChildAt(column:Extension methodrow: ) Gets the child of
gridwhose area covers the grid cell atcolumn,row.Declaration
Swift
@inlinable func getChildAt(column: Int, row: Int) -> WidgetRef! -
getColumnHomogeneous()Extension methodReturns whether all columns of
gridhave the same width.Declaration
Swift
@inlinable func getColumnHomogeneous() -> Bool -
getColumnSpacing()Extension methodReturns the amount of space between the columns of
grid.Declaration
Swift
@inlinable func getColumnSpacing() -> Int -
getRowBaselinePosition(row:Extension method) Returns the baseline position of
row.See [method
Gtk.Grid.set_row_baseline_position].Declaration
Swift
@inlinable func getRowBaselinePosition(row: Int) -> GtkBaselinePosition -
getRowHomogeneous()Extension methodReturns whether all rows of
gridhave the same height.Declaration
Swift
@inlinable func getRowHomogeneous() -> Bool -
getRowSpacing()Extension methodReturns the amount of space between the rows of
grid.Declaration
Swift
@inlinable func getRowSpacing() -> Int -
insertColumn(position:Extension method) 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.
Declaration
Swift
@inlinable func insertColumn(position: Int) -
insertNextTo(sibling:Extension methodside: ) Inserts a row or column at the specified position.
The new row or column is placed next to
sibling, on the side determined byside. IfsideisGTK_POS_TOPorGTK_POS_BOTTOM, a row is inserted. IfsideisGTK_POS_LEFTofGTK_POS_RIGHT, a column is inserted.Declaration
Swift
@inlinable func insertNextTo<WidgetT>(sibling: WidgetT, side: GtkPositionType) where WidgetT : WidgetProtocol -
insertRow(position:Extension method) 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.
Declaration
Swift
@inlinable func insertRow(position: Int) -
query(child:Extension methodcolumn: row: width: height: ) Queries the attach points and spans of
childinside the givenGtkGrid.Declaration
Swift
@inlinable func query<WidgetT>(child: WidgetT, column: UnsafeMutablePointer<gint>! = nil, row: UnsafeMutablePointer<gint>! = nil, width: UnsafeMutablePointer<gint>! = nil, height: UnsafeMutablePointer<gint>! = nil) where WidgetT : WidgetProtocol -
remove(child:Extension method) Removes a child from
grid.The child must have been added with [method
Gtk.Grid.attach] or [methodGtk.Grid.attach_next_to].Declaration
Swift
@inlinable func remove<WidgetT>(child: WidgetT) where WidgetT : WidgetProtocol -
removeColumn(position:Extension method) 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.
Declaration
Swift
@inlinable func removeColumn(position: Int) -
removeRow(position:Extension method) 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.
Declaration
Swift
@inlinable func removeRow(position: Int) -
setBaseline(row:Extension method) 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
grid.Declaration
Swift
@inlinable func setBaseline(row: Int) -
setColumn(homogeneous:Extension method) Sets whether all columns of
gridwill have the same width.Declaration
Swift
@inlinable func setColumn(homogeneous: Bool) -
setColumn(spacing:Extension method) Sets the amount of space between columns of
grid.Declaration
Swift
@inlinable func setColumn(spacing: Int) -
setRowBaselinePosition(row:Extension methodpos: ) Sets how the baseline should be positioned on
rowof the grid, in case that row is assigned more space than is requested.The default baseline position is
GTK_BASELINE_POSITION_CENTER.Declaration
Swift
@inlinable func setRowBaselinePosition(row: Int, pos: GtkBaselinePosition) -
setRow(homogeneous:Extension method) Sets whether all rows of
gridwill have the same height.Declaration
Swift
@inlinable func setRow(homogeneous: Bool) -
setRow(spacing:Extension method) Sets the amount of space between rows of
grid.Declaration
Swift
@inlinable func setRow(spacing: Int) -
baselineRowExtension methodReturns which row defines the global baseline of
grid.Declaration
Swift
@inlinable var baselineRow: Int { get nonmutating set } -
columnHomogeneousExtension methodReturns whether all columns of
gridhave the same width.Declaration
Swift
@inlinable var columnHomogeneous: Bool { get nonmutating set } -
columnSpacingExtension methodReturns the amount of space between the columns of
grid.Declaration
Swift
@inlinable var columnSpacing: Int { get nonmutating set } -
rowHomogeneousExtension methodReturns whether all rows of
gridhave the same height.Declaration
Swift
@inlinable var rowHomogeneous: Bool { get nonmutating set } -
rowSpacingExtension methodReturns the amount of space between the rows of
grid.Declaration
Swift
@inlinable var rowSpacing: Int { get nonmutating set }
View on GitHub
Install in Dash
GridProtocol Protocol Reference