GTK+ 2.0 Tutorial
<<< Previous | Container Widgets | Next >>>

# The Alignment widget

The alignment widget allows you to place a widget within its window at a position and size relative to the size of the Alignment widget itself. For example, it can be very useful for centering a widget within the window.

There are only two functions associated with the Alignment widget:

    GtkWidget* gtk_alignment_new( gfloat xalign,
                                  gfloat yalign,
                                  gfloat xscale,
                                  gfloat yscale );

    void gtk_alignment_set( GtkAlignment *alignment,
                            gfloat        xalign,
                            gfloat        yalign,
                            gfloat        xscale,
                            gfloat        yscale );

The first function creates a new Alignment widget with the specified parameters. The second function allows the alignment parameters of an exisiting Alignment widget to be altered.

All four alignment parameters are floating point numbers which can range from 0.0 to 1.0. The `xalign` and `yalign` arguments affect the position of the widget placed within the Alignment widget. The `xscale` and `yscale` arguments effect the amount of space allocated to the widget.

A child widget can be added to this Alignment widget using:

        gtk_container_add (GTK_CONTAINER (alignment), child_widget);

For an example of using an Alignment widget, refer to the example for the Progress Bar widget.

<<< Previous | Home | Next >>>
Container Widgets | Up | Fixed Container