Package ch.bailu.gtk.gtk
Class Grid
- All Implemented Interfaces:
PointerInterface
`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 [method@Gtk.Grid.attach]. They can span multiple
rows or columns. It is also possible to add a child next to an existing
child, using [method@Gtk.Grid.attach_next_to]. To remove a child from the
grid, use [method@Gtk.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 [iface@Gtk.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 [class@Gtk.GridLayoutChild].
It is implemented by `GtkWidget` using [class@Gtk.LayoutManager].
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.
rows and columns.
![An example GtkGrid](grid.png)
It supports arbitrary positions and horizontal/vertical spans.
Children are added using [method@Gtk.Grid.attach]. They can span multiple
rows or columns. It is also possible to add a child next to an existing
child, using [method@Gtk.Grid.attach_next_to]. To remove a child from the
grid, use [method@Gtk.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 [iface@Gtk.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 [class@Gtk.GridLayoutChild].
It is implemented by `GtkWidget` using [class@Gtk.LayoutManager].
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class ch.bailu.gtk.gtk.Widget
Widget.OnDestroy, Widget.OnDestroyNotify, Widget.OnDirectionChanged, Widget.OnHide, Widget.OnKeynavFailed, Widget.OnMap, Widget.OnMnemonicActivate, Widget.OnMoveFocus, Widget.OnQueryTooltip, Widget.OnRealize, Widget.OnShow, Widget.OnStateFlagsChanged, Widget.OnTickCallback, Widget.OnUnmap, Widget.OnUnrealize
Nested classes/interfaces inherited from class ch.bailu.gtk.gobject.Object
Object.OnBindingTransformFunc, Object.OnDuplicateFunc, Object.OnNotify, Object.OnToggleNotify, Object.OnWeakNotify
-
Field Summary
Fields inherited from class ch.bailu.gtk.gtk.Widget
SIGNAL_ON_DESTROY, SIGNAL_ON_DIRECTION_CHANGED, SIGNAL_ON_HIDE, SIGNAL_ON_KEYNAV_FAILED, SIGNAL_ON_MAP, SIGNAL_ON_MNEMONIC_ACTIVATE, SIGNAL_ON_MOVE_FOCUS, SIGNAL_ON_QUERY_TOOLTIP, SIGNAL_ON_REALIZE, SIGNAL_ON_SHOW, SIGNAL_ON_STATE_FLAGS_CHANGED, SIGNAL_ON_UNMAP, SIGNAL_ON_UNREALIZE
Fields inherited from class ch.bailu.gtk.gobject.Object
SIGNAL_ON_NOTIFY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionImplements interfaceAccessible
.Implements interfaceBuildable
.Implements interfaceConstraintTarget
.Implements interfaceOrientable
.void
Adds a widget to the grid.void
attachNextTo
(Widget child, Widget sibling, int side, int width, int height) Adds a widget to the grid.int
Returns which row defines the global baseline of @grid.getChildAt
(int column, int row) Gets the child of @grid whose area covers the grid
cell at @column, @row.static ClassHandler
boolean
Returns whether all columns of @grid have the same width.int
Returns the amount of space between the columns of @grid.static int
static long
static TypeSystem.TypeSize
int
getRowBaselinePosition
(int row) Returns the baseline position of @row.boolean
Returns whether all rows of @grid have the same height.int
Returns the amount of space between the rows of @grid.static long
static TypeSystem.TypeSize
void
insertColumn
(int position) Inserts a column at the specified position.void
insertNextTo
(Widget sibling, int side) Inserts a row or column at the specified position.void
insertRow
(int position) Inserts a row at the specified position.void
Queries the attach points and spans of @child inside the given `GtkGrid`.void
Removes a child from @grid.void
removeColumn
(int position) Removes a column from the grid.void
removeRow
(int position) Removes a row from the grid.void
setBaselineRow
(int row) Sets which row defines the global baseline for the entire grid.void
setColumnHomogeneous
(boolean homogeneous) Sets whether all columns of @grid will have the same width.void
setColumnSpacing
(int spacing) Sets the amount of space between columns of @grid.void
setRowBaselinePosition
(int row, int pos) Sets how the baseline should be positioned on @row of the
grid, in case that row is assigned more space than is requested.void
setRowHomogeneous
(boolean homogeneous) Sets whether all rows of @grid will have the same height.void
setRowSpacing
(int spacing) Sets the amount of space between rows of @grid.Methods inherited from class ch.bailu.gtk.gtk.Widget
actionSetEnabled, actionSetEnabled, activate, activateAction, activateAction, activateActionVariant, activateActionVariant, activateDefault, addController, addCssClass, addCssClass, addMnemonicLabel, addTickCallback, allocate, childFocus, computeBounds, computeExpand, computePoint, computeTransform, contains, createPangoContext, createPangoLayout, createPangoLayout, disposeTemplate, dragCheckThreshold, errorBell, getAllocatedBaseline, getAllocatedHeight, getAllocatedWidth, getAllocation, getAncestor, getCanFocus, getCanTarget, getChildVisible, getClipboard, getCssClasses, getCssName, getCursor, getDefaultDirection, getDirection, getDisplay, getFirstChild, getFocusable, getFocusChild, getFocusOnClick, getFontMap, getFontOptions, getFrameClock, getHalign, getHasTooltip, getHeight, getHexpand, getHexpandSet, getLastChild, getLayoutManager, getMapped, getMarginBottom, getMarginEnd, getMarginStart, getMarginTop, getName, getNative, getNextSibling, getOpacity, getOverflow, getPangoContext, getParent, getPreferredSize, getPrevSibling, getPrimaryClipboard, getRealized, getReceivesDefault, getRequestMode, getRoot, getScaleFactor, getSensitive, getSettings, getSize, getSizeRequest, getStateFlags, getStyleContext, getTemplateChild, getTemplateChild, getTooltipMarkup, getTooltipText, getValign, getVexpand, getVexpandSet, getVisible, getWidth, grabFocus, hasCssClass, hasCssClass, hasDefault, hasFocus, hasVisibleFocus, hide, inDestruction, initTemplate, insertActionGroup, insertActionGroup, insertAfter, insertBefore, isAncestor, isDrawable, isFocus, isSensitive, isVisible, keynavFailed, listMnemonicLabels, map, measure, mnemonicActivate, observeChildren, observeControllers, onDestroy, onDirectionChanged, onHide, onKeynavFailed, onMap, onMnemonicActivate, onMoveFocus, onQueryTooltip, onRealize, onShow, onStateFlagsChanged, onUnmap, onUnrealize, pick, queueAllocate, queueDraw, queueResize, realize, removeController, removeCssClass, removeCssClass, removeMnemonicLabel, removeTickCallback, setCanFocus, setCanTarget, setChildVisible, setCssClasses, setCursor, setCursorFromName, setCursorFromName, setDefaultDirection, setDirection, setFocusable, setFocusChild, setFocusOnClick, setFontMap, setFontOptions, setHalign, setHasTooltip, setHexpand, setHexpandSet, setLayoutManager, setMarginBottom, setMarginEnd, setMarginStart, setMarginTop, setName, setName, setOpacity, setOverflow, setParent, setReceivesDefault, setSensitive, setSizeRequest, setStateFlags, setTooltipMarkup, setTooltipMarkup, setTooltipText, setTooltipText, setValign, setVexpand, setVexpandSet, setVisible, shouldLayout, show, sizeAllocate, snapshotChild, triggerTooltipQuery, unmap, unparent, unrealize, unsetStateFlags
Methods inherited from class ch.bailu.gtk.gobject.Object
addToggleRef, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, disconnect, disconnect, dupData, dupData, dupQdata, forceFloating, freezeNotify, get, get, getData, getData, getProperty, getProperty, getQdata, interfaceFindProperty, interfaceInstallProperty, isFloating, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, replaceData, replaceData, replaceQdata, runDispose, set, set, setData, setData, setDataFull, setDataFull, setProperty, setProperty, setQdata, setQdataFull, stealData, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref
Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Constructor Details
-
Grid
-
Grid
public Grid()Creates a new grid widget.
-
-
Method Details
-
getClassHandler
-
attach
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.- Parameters:
child
- the widget to addcolumn
- the column number to attach the left side of @child torow
- the row number to attach the top side of @child towidth
- the number of columns that @child will spanheight
- the number of rows that @child will span
-
attachNextTo
public void attachNextTo(@Nonnull Widget child, @Nullable Widget sibling, int side, int width, int height) Adds a widget to the grid.
The widget is placed next to @sibling, on the side determined by
@side. When @sibling is %NULL, 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]`.- Parameters:
child
- the widget to addsibling
- the child of @grid that @child will be placed next to, or %NULL to place @child at the beginning or endside
- the side of @sibling that @child is positioned next towidth
- the number of columns that @child will spanheight
- the number of rows that @child will span
-
getBaselineRow
public int getBaselineRow()Returns which row defines the global baseline of @grid.- Returns:
- the row index defining the global baseline
-
getChildAt
Gets the child of @grid whose area covers the grid
cell at @column, @row.- Parameters:
column
- the left edge of the cellrow
- the top edge of the cell- Returns:
- the child at the given position
-
getColumnHomogeneous
public boolean getColumnHomogeneous()Returns whether all columns of @grid have the same width.- Returns:
- whether all columns of @grid have the same width.
-
getColumnSpacing
public int getColumnSpacing()Returns the amount of space between the columns of @grid.- Returns:
- the column spacing of @grid
-
getRowBaselinePosition
public int getRowBaselinePosition(int row) Returns the baseline position of @row.
See [method@Gtk.Grid.set_row_baseline_position].- Parameters:
row
- a row index- Returns:
- the baseline position of @row
-
getRowHomogeneous
public boolean getRowHomogeneous()Returns whether all rows of @grid have the same height.- Returns:
- whether all rows of @grid have the same height.
-
getRowSpacing
public int getRowSpacing()Returns the amount of space between the rows of @grid.- Returns:
- the row spacing of @grid
-
insertColumn
public void insertColumn(int position) 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.- Parameters:
position
- the position to insert the column at
-
insertNextTo
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.- Parameters:
sibling
- the child of @grid that the new row or column will be placed next toside
- the side of @sibling that @child is positioned next to
-
insertRow
public void insertRow(int position) 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.- Parameters:
position
- the position to insert the row at
-
queryChild
public void queryChild(@Nonnull Widget child, @Nullable Int column, @Nullable Int row, @Nullable Int width, @Nullable Int height) Queries the attach points and spans of @child inside the given `GtkGrid`.- Parameters:
child
- a `GtkWidget` child of @gridcolumn
- the column used to attach the left side of @childrow
- the row used to attach the top side of @childwidth
- the number of columns @child spansheight
- the number of rows @child spans
-
remove
Removes a child from @grid.
The child must have been added with
[method@Gtk.Grid.attach] or [method@Gtk.Grid.attach_next_to].- Parameters:
child
- the child widget to remove
-
removeColumn
public void removeColumn(int position) 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.- Parameters:
position
- the position of the column to remove
-
removeRow
public void removeRow(int position) 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.- Parameters:
position
- the position of the row to remove
-
setBaselineRow
public void setBaselineRow(int row) 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.- Parameters:
row
- the row index
-
setColumnHomogeneous
public void setColumnHomogeneous(boolean homogeneous) Sets whether all columns of @grid will have the same width.- Parameters:
homogeneous
- %TRUE to make columns homogeneous
-
setColumnSpacing
public void setColumnSpacing(int spacing) Sets the amount of space between columns of @grid.- Parameters:
spacing
- the amount of space to insert between columns
-
setRowBaselinePosition
public void setRowBaselinePosition(int row, int pos) 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.- Parameters:
row
- a row indexpos
- a `GtkBaselinePosition`
-
setRowHomogeneous
public void setRowHomogeneous(boolean homogeneous) Sets whether all rows of @grid will have the same height.- Parameters:
homogeneous
- %TRUE to make rows homogeneous
-
setRowSpacing
public void setRowSpacing(int spacing) Sets the amount of space between rows of @grid.- Parameters:
spacing
- the amount of space to insert between rows
-
asAccessible
Implements interfaceAccessible
. Call this to get access to interface functions.- Overrides:
asAccessible
in classWidget
- Returns:
Accessible
-
asBuildable
Implements interfaceBuildable
. Call this to get access to interface functions.- Overrides:
asBuildable
in classWidget
- Returns:
Buildable
-
asConstraintTarget
Implements interfaceConstraintTarget
. Call this to get access to interface functions.- Overrides:
asConstraintTarget
in classWidget
- Returns:
ConstraintTarget
-
asOrientable
Implements interfaceOrientable
. Call this to get access to interface functions.- Returns:
Orientable
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-