GridProtocol

public protocol GridProtocol : OrientableProtocol, WidgetProtocol

GtkGrid 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 [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.

  • ptr

    Untyped pointer to the underlying GtkGrid instance.

    Declaration

    Swift

    var ptr: UnsafeMutableRawPointer! { get }
  • grid_ptr Default implementation

    Typed pointer to the underlying GtkGrid instance.

    Default Implementation

    Return the stored, untyped pointer as a typed pointer to the GtkGrid instance.

    Declaration

    Swift

    var grid_ptr: UnsafeMutablePointer<GtkGrid>! { get }
  • Required Initialiser for types conforming to GridProtocol

    Declaration

    Swift

    init(raw: UnsafeMutableRawPointer)

Grid Class

  • Bind a GridPropertyName source 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 : ObjectProtocol

    Parameters

    source_property

    the source property to bind

    target

    the target object to bind to

    target_property

    the target property to bind to

    flags

    the flags to pass to the Binding

    transform_from

    ValueTransformer to use for forward transformation

    transform_to

    ValueTransformer to use for backwards transformation

    Return Value

    binding reference or nil in case of an error

  • get(property:) Extension method

    Get the value of a Grid property

    Declaration

    Swift

    @inlinable
    func get(property: GridPropertyName) -> GLibObject.Value

    Parameters

    property

    the property to get the value for

    Return Value

    the value of the named property

  • set(property:value:) Extension method

    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

    property

    the property to get the value for

    Return Value

    the value of the named property

Grid Class: GridProtocol extension (methods and fields)

  • 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.

    Declaration

    Swift

    @inlinable
    func attach<WidgetT>(child: WidgetT, column: Int, row: Int, width: Int, height: Int) where WidgetT : WidgetProtocol
  • Adds a widget to the grid.

    The widget is placed next to sibling, on the side determined by side. When sibling is nil, 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` == `nil and side` == `GTK_POS_LEFT yields 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 method

    Returns which row defines the global baseline of grid.

    Declaration

    Swift

    @inlinable
    func getBaselineRow() -> Int
  • getChildAt(column:row:) Extension method

    Gets the child of grid whose area covers the grid cell at column, row.

    Declaration

    Swift

    @inlinable
    func getChildAt(column: Int, row: Int) -> WidgetRef!
  • getColumnHomogeneous() Extension method

    Returns whether all columns of grid have the same width.

    Declaration

    Swift

    @inlinable
    func getColumnHomogeneous() -> Bool
  • getColumnSpacing() Extension method

    Returns 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 [methodGtk.Grid.set_row_baseline_position].

    Declaration

    Swift

    @inlinable
    func getRowBaselinePosition(row: Int) -> GtkBaselinePosition
  • getRowHomogeneous() Extension method

    Returns whether all rows of grid have the same height.

    Declaration

    Swift

    @inlinable
    func getRowHomogeneous() -> Bool
  • getRowSpacing() Extension method

    Returns 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:side:) Extension method

    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 GTK_POS_TOP or GTK_POS_BOTTOM, a row is inserted. If side is GTK_POS_LEFT of GTK_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)
  • Queries the attach points and spans of child inside the given GtkGrid.

    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 [methodGtk.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 grid will 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)
  • 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 GTK_BASELINE_POSITION_CENTER.

    Declaration

    Swift

    @inlinable
    func setRowBaselinePosition(row: Int, pos: GtkBaselinePosition)
  • setRow(homogeneous:) Extension method

    Sets whether all rows of grid will 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)
  • baselineRow Extension method

    Returns which row defines the global baseline of grid.

    Declaration

    Swift

    @inlinable
    var baselineRow: Int { get nonmutating set }
  • columnHomogeneous Extension method

    Returns whether all columns of grid have the same width.

    Declaration

    Swift

    @inlinable
    var columnHomogeneous: Bool { get nonmutating set }
  • columnSpacing Extension method

    Returns the amount of space between the columns of grid.

    Declaration

    Swift

    @inlinable
    var columnSpacing: Int { get nonmutating set }
  • rowHomogeneous Extension method

    Returns whether all rows of grid have the same height.

    Declaration

    Swift

    @inlinable
    var rowHomogeneous: Bool { get nonmutating set }
  • rowSpacing Extension method

    Returns the amount of space between the rows of grid.

    Declaration

    Swift

    @inlinable
    var rowSpacing: Int { get nonmutating set }