Package: gtk

Class gtk-container

Superclasses

gtk-widget, gtk-buildable, g-object, common-lisp:standard-object, common-lisp:t

Documented Subclasses

Direct Slots

border-width
The border-width property of type :uint (Read / Write)
The width of the empty border outside the containers children.
Allowed values: <= 65535
Default value: 0
child
The child property of type gtk-widget (Write)
Can be used to add a new child to the container.
resize-mode
The resize-mode property of type gtk-resize-mode (Read / Write)
Specify how resize events are handled.
Warning: Resize modes are deprecated since version 3.12 and should not be used in newly written code. They are not necessary anymore since frame clocks and might introduce obscure bugs if used.
Default value: :parent

Details

Base class for widgets which contain other widgets.

A GTK user interface is constructed by nesting widgets inside widgets. Container widgets are the inner nodes in the resulting tree of widgets: they contain other widgets. So, for example, you might have a gtk-window widget containing a gtk-frame widget containing a gtk-label widget. If you wanted an image instead of a textual label inside the frame, you might replace the gtk-label widget with a gtk-image widget.

There are two major kinds of container widgets in GTK. Both are subclasses of the abstract gtk-container base class.

The first type of container widget has a single child widget and derives from the gtk-bin class. These containers are decorators, which add some kind of functionality to the child. For example, a gtk-button widget makes its child into a clickable button. A gtk-frame widget draws a frame around its child and a gtk-window widget places its child widget inside a toplevel window.

The second type of container can have more than one child. Its purpose is to manage layout. This means that these containers assign sizes and positions to their children. For example, a gtk-grid widget arranges the widgets it contains in a two-dimensional grid.

Height for width geometry management
GTK uses a height-for-width and width-for-height geometry management system. Height-for-width means that a widget can change how much vertical space it needs, depending on the amount of horizontal space that it is given and similar for width-for-height.

There are some things to keep in mind when implementing container widgets that make use of the height for width geometry management system. First, it is important to note that a container must prioritize one of its dimensions, that is to say that a widget or container can only have a gtk-size-request-mode mode that is :height-for-width or :width-for-height. However, every widget and container must be able to respond to the APIs for both dimensions, i.e. even if a widget has a request mode that is height-for-width, it is possible that its parent will request its sizes using the width-for-height APIs.

Child properties
The gtk-container widget introduces child properties. These are object properties that are not specific to either the container or the contained widget, but rather to their relation. Typical examples of child properties are the position or pack-type of a widget which is contained in a gtk-box widget.

Use the gtk-container-class-find-child-property or gtk-container-class-list-child-properties functions to get information about existing child properties.

To obtain or to set the value of a child property, use the gtk-container-child-property, gtk-container-child-get, or gtk-container-child-set functions. To emit notification about child property changes, use the gtk-widget-child-notify function.

GtkContainer as GtkBuildable

The gtk-container implementation of the gtk-buildable interface supports a <packing> element for children, which can contain multiple <property> elements that specify child properties for the child.

Child properties can also be marked as translatable using the same "translatable", "comments" and "context" attributes that are used for regular properties.

Containers can have a <focus-chain> element containing multiple <widget> elements, one for each child that should be added to the focus chain. The "name" attribute gives the ID of the widget.

Example: Child properties in UI definitions
<object class="GtkBox">
  <child>
    <object class="GtkEntry" id="entry1"/>
    <packing>
      <property name="pack-type">start</property>
    </packing>
  </child>
  <child>
    <object class="GtkEntry" id="entry2"/>
  </child>
  <focus-chain>
    <widget name="entry1"/>
    <widget name="entry2"/>
  </focus-chain>
</object>    

Signal Details

The "add" signal
 lambda (container widget)    :run-first      
The "check-resize" signal
 lambda (container)    :run-last      
The "remove" signal
 lambda (container widget)    :run-first      
The "set-focus-child" signal
 lambda (container widget)    :run-first      
 

Slot Access Functions

Inherited Slot Access Functions

See also

2021-9-12