Next: , Previous: GtkIMMulticontext, Up: Top


122 GtkSizeGroup

Grouping widgets so they request the same size

122.1 Overview

<gtk-size-group> provides a mechanism for grouping a number of widgets together so they all request the same amount of space. This is typically useful when you want a column of widgets to have the same size, but you can't use a <gtk-table> widget.

In detail, the size requested for each widget in a <gtk-size-group> is the maximum of the sizes that would have been requested for each widget in the size group if they were not in the size group. The mode of the size group (see gtk-size-group-set-mode) determines whether this applies to the horizontal size, the vertical size, or both sizes.

Note that size groups only affect the amount of space requested, not the size that the widgets finally receive. If you want the widgets in a <gtk-size-group> to actually be the same size, you need to pack them in such a way that they get the size they request and not more. For example, if you are packing your widgets into a table, you would not include the ‘GTK_FILL’ flag.

<gtk-size-group> objects are referenced by each widget in the size group, so once you have added all widgets to a <gtk-size-group>, you can drop the initial reference to the size group with g-object-unref. If the widgets in the size group are subsequently destroyed, then they will be removed from the size group and drop their references on the size group; when all widgets have been removed, the size group will be freed.

Widgets can be part of multiple size groups; GTK+ will compute the horizontal size of a widget from the horizontal requisition of all widgets that can be reached from the widget by a chain of size groups of type ‘GTK_SIZE_GROUP_HORIZONTAL’ or ‘GTK_SIZE_GROUP_BOTH’, and the vertical size from the vertical requisition of all widgets that can be reached from the widget by a chain of size groups of type ‘GTK_SIZE_GROUP_VERTICAL’ or ‘GTK_SIZE_GROUP_BOTH’.

122.2 Usage

— Class: <gtk-size-group>

Derives from <gtk-buildable>, <gobject>.

This class defines the following slots:

mode
The directions in which the size group affects the requested sizes of its component widgets
ignore-hidden
If TRUE, unmapped widgets are ignored when determining the size of the group
— Function: gtk-size-group-new (mode <gtk-size-group-mode>) ⇒  (ret <gtk-size-group>)

Create a new <gtk-size-group>.

mode
the mode for the new size group.
ret
a newly created <gtk-size-group>
— Function: gtk-size-group-set-mode (self <gtk-size-group>) (mode <gtk-size-group-mode>)
— Method: set-mode

Sets the <gtk-size-group-mode> of the size group. The mode of the size group determines whether the widgets in the size group should all have the same horizontal requisition (‘GTK_SIZE_GROUP_MODE_HORIZONTAL’) all have the same vertical requisition (‘GTK_SIZE_GROUP_MODE_VERTICAL’), or should all have the same requisition in both directions (‘GTK_SIZE_GROUP_MODE_BOTH’).

size-group
a <gtk-size-group>
mode
the mode to set for the size group.
— Function: gtk-size-group-get-mode (self <gtk-size-group>) ⇒  (ret <gtk-size-group-mode>)
— Method: get-mode

Gets the current mode of the size group. See gtk-size-group-set-mode.

size-group
a <gtk-size-group>
ret
the current mode of the size group.
— Function: gtk-size-group-set-ignore-hidden (self <gtk-size-group>) (ignore_hidden bool)
— Method: set-ignore-hidden

Sets whether unmapped widgets should be ignored when calculating the size.

size-group
a <gtk-size-group>
ignore-hidden
whether unmapped widgets should be ignored when calculating the size

Since 2.8

— Function: gtk-size-group-get-ignore-hidden (self <gtk-size-group>) ⇒  (ret bool)
— Method: get-ignore-hidden

Returns if invisible widgets are ignored when calculating the size.

size-group
a <gtk-size-group>
ret
#t’ if invisible widgets are ignored.

Since 2.8

— Function: gtk-size-group-add-widget (self <gtk-size-group>) (widget <gtk-widget>)
— Method: add-widget

Adds a widget to a <gtk-size-group>. In the future, the requisition of the widget will be determined as the maximum of its requisition and the requisition of the other widgets in the size group. Whether this applies horizontally, vertically, or in both directions depends on the mode of the size group. See gtk-size-group-set-mode.

size-group
a <gtk-size-group>
widget
the <gtk-widget> to add
— Function: gtk-size-group-remove-widget (self <gtk-size-group>) (widget <gtk-widget>)
— Method: remove-widget

Removes a widget from a <gtk-size-group>.

size-group
a <gtk-size-grup>
widget
the <gtk-widget> to remove