GtkBox

GtkBox — A container box

Functions

Properties

GtkBaselinePosition baseline-position Read / Write
gboolean homogeneous Read / Write
gint spacing Read / Write

Types and Values

struct GtkBox
struct GtkBoxClass

Object Hierarchy

    GObject
    ╰── GInitiallyUnowned
        ╰── GtkWidget
            ╰── GtkContainer
                ╰── GtkBox
                    ├── GtkButtonBox
                    ├── GtkColorChooserWidget
                    ├── GtkInfoBar
                    ├── GtkShortcutLabel
                    ├── GtkShortcutsSection
                    ├── GtkShortcutsGroup
                    ╰── GtkStackSwitcher

Implemented Interfaces

GtkBox implements AtkImplementorIface, GtkBuildable and GtkOrientable.

Includes

#include <gtk/gtk.h>

Description

The GtkBox widget organizes child widgets into a rectangular area.

The rectangular area of a GtkBox is organized into either a single row or a single column of child widgets depending upon the orientation. Thus, all children of a GtkBox are allocated one dimension in common, which is the height of a row, or the width of a column.

GtkBox uses a notion of packing. Packing refers to adding widgets with reference to a particular position in a GtkContainer. For a GtkBox, there are two reference positions: the start and the end of the box. For a vertical GtkBox, the start is defined as the top of the box and the end is defined as the bottom. For a horizontal GtkBox the start is defined as the left side and the end is defined as the right side.

Use repeated calls to gtk_box_pack_start() to pack widgets into a GtkBox from start to end. Use gtk_box_pack_end() to add widgets from end to start. You may intersperse these calls and add widgets from both ends of the same GtkBox.

Because GtkBox is a GtkContainer, you may also use gtk_container_add() to insert widgets into the box. Use gtk_container_remove() to remove widgets from the GtkBox.

Use gtk_box_set_homogeneous() to specify whether or not all children of the GtkBox are forced to get the same amount of space.

Use gtk_box_set_spacing() to determine how much space will be minimally placed between all children in the GtkBox. Note that spacing is added between the children.

Use gtk_box_reorder_child() to move a GtkBox child to a different place in the box.

Note that a single-row or single-column GtkGrid provides exactly the same functionality as GtkBox.

CSS nodes

GtkBox uses a single CSS node with name box.

In horizontal orientation, the nodes of the children are always arranged from left to right. So :first-child will always select the leftmost child, regardless of text direction.

Functions

gtk_box_new ()

GtkWidget *
gtk_box_new (GtkOrientation orientation,
             gint spacing);

Creates a new GtkBox.

Parameters

orientation

the box’s orientation.

 

spacing

the number of pixels to place by default between children.

 

Returns

a new GtkBox.

Since: 3.0


gtk_box_pack_start ()

void
gtk_box_pack_start (GtkBox *box,
                    GtkWidget *child);

Adds child to box , packed with reference to the start of box . The child is packed after any other child packed with reference to the start of box .

Parameters

box

a GtkBox

 

child

the GtkWidget to be added to box

 

gtk_box_pack_end ()

void
gtk_box_pack_end (GtkBox *box,
                  GtkWidget *child);

Adds child to box , packed with reference to the end of box . The child is packed after (away from end of) any other child packed with reference to the end of box .

Parameters

box

a GtkBox

 

child

the GtkWidget to be added to box

 

gtk_box_get_homogeneous ()

gboolean
gtk_box_get_homogeneous (GtkBox *box);

Returns whether the box is homogeneous (all children are the same size). See gtk_box_set_homogeneous().

Parameters

box

a GtkBox

 

Returns

TRUE if the box is homogeneous.


gtk_box_set_homogeneous ()

void
gtk_box_set_homogeneous (GtkBox *box,
                         gboolean homogeneous);

Sets the “homogeneous” property of box , controlling whether or not all children of box are given equal space in the box.

Parameters

box

a GtkBox

 

homogeneous

a boolean value, TRUE to create equal allotments, FALSE for variable allotments

 

gtk_box_get_spacing ()

gint
gtk_box_get_spacing (GtkBox *box);

Gets the value set by gtk_box_set_spacing().

Parameters

box

a GtkBox

 

Returns

spacing between children


gtk_box_set_spacing ()

void
gtk_box_set_spacing (GtkBox *box,
                     gint spacing);

Sets the “spacing” property of box , which is the number of pixels to place between children of box .

Parameters

box

a GtkBox

 

spacing

the number of pixels to put between children

 

gtk_box_reorder_child ()

void
gtk_box_reorder_child (GtkBox *box,
                       GtkWidget *child,
                       gint position);

Moves child to a new position in the list of box children. The list contains widgets packed GTK_PACK_START as well as widgets packed GTK_PACK_END, in the order that these widgets were added to box .

A widget’s position in the box children list determines where the widget is packed into box . A child widget at some position in the list will be packed just after all other widgets of the same packing type that appear earlier in the list.

Parameters

box

a GtkBox

 

child

the GtkWidget to move

 

position

the new position for child in the list of children of box , starting from 0. If negative, indicates the end of the list

 

gtk_box_query_child_packing ()

void
gtk_box_query_child_packing (GtkBox *box,
                             GtkWidget *child,
                             GtkPackType *pack_type);

Obtains information about how child is packed into box .

Parameters

box

a GtkBox

 

child

the GtkWidget of the child to query

 

pack_type

pointer to return location for pack-type child property.

[out][optional]

gtk_box_set_child_packing ()

void
gtk_box_set_child_packing (GtkBox *box,
                           GtkWidget *child,
                           GtkPackType pack_type);

Sets the way child is packed into box .

Parameters

box

a GtkBox

 

child

the GtkWidget of the child to set

 

pack_type

the new value of the pack-type child property

 

gtk_box_get_baseline_position ()

GtkBaselinePosition
gtk_box_get_baseline_position (GtkBox *box);

Gets the value set by gtk_box_set_baseline_position().

Parameters

box

a GtkBox

 

Returns

the baseline position

Since: 3.10


gtk_box_set_baseline_position ()

void
gtk_box_set_baseline_position (GtkBox *box,
                               GtkBaselinePosition position);

Sets the baseline position of a box. This affects only horizontal boxes with at least one baseline aligned child. If there is more vertical space available than requested, and the baseline is not allocated by the parent then position is used to allocate the baseline wrt the extra space available.

Parameters

box

a GtkBox

 

position

a GtkBaselinePosition

 

Since: 3.10

Types and Values

struct GtkBox

struct GtkBox;

struct GtkBoxClass

struct GtkBoxClass {
  GtkContainerClass parent_class;
};

Members

Property Details

The “baseline-position” property

  “baseline-position”        GtkBaselinePosition

The position of the baseline aligned widgets if extra space is available.

Flags: Read / Write

Default value: GTK_BASELINE_POSITION_CENTER


The “homogeneous” property

  “homogeneous”              gboolean

Whether the children should all be the same size.

Flags: Read / Write

Default value: FALSE


The “spacing” property

  “spacing”                  gint

The amount of space between children.

Flags: Read / Write

Allowed values: >= 0

Default value: 0

See Also

GtkFrame, GtkGrid, GtkLayout