GtkAlignment Constructor

GtkAlignment ([double xalign = 0.5 [, double yalign = 0.5 [, double xscale = 1.0 [, double yscale = 1.0]]]]);

GtkAlignment is a container widget that controls the alignment and size of it's child.

A GtkAlignment widget has four settings:

  • xalign: This parameter is used to horizontally place the child. It's value can be anything between 0 (left) and 1 (right). The default is 0.5, which centers the child widget relative to the GtkAlignment container.
  • yalign: This parameter is used to vertically place the child. It's value can be anything between 0 (top) and 1 (bottom). It defaults to 0.5.
  • xscale: It defines the ammount of horizontal free space in the GtkAlignment container that the child will be extended to occupy. 0 means the child won't extend, 1 means it'll extend over all the available free space.
  • yscale: It defines the ammount of vertical free space that the child will be extended to occupy. Ranges from 0 (the child won't extend) to 1 (extend over all the available free space).

Example 17. GtkAlignment usage demonstration

<?php
//Checking for php-gtk
if( !class_exists('gtk')) {
	die('Please load the php-gtk2 module in your php.ini' . "\r\n");
}

//A GtkVBox that will hold the GtkAlignment widgets and GtkHSeparators
$vbox = new GtkVBox();

//Let's create four GtkAlignment containers with different settings,
// each holding a button


//First GtkAlignment container. 

//Positioning the button at the top-left of the window,
// not allowing it to extend:
$align1 = new GtkAlignment(0, 0, 0, 0);
//Let's push the button down and right, with padding on the top and left:
$align1->set_padding(100, 100, 100, 100);
//Creating a button.
$button1 = new GtkButton('Padding of 100 pixels', false);
//Adding button1 to the first GtkAlignment container
$align1->add($button1);
//Packing the GtkAlignment container into the GtkVBox
$vbox->pack_start($align1, true, true);

//Adding a GtkHSeparator, to see the different GtkAlignment containers better
$vbox->pack_start(new GtkHSeparator(), false, false, 3);


//Second GtkAlignment container. 

//This container will center it's child,
// while not allowing it to extend to occupy all free space
$align2 = new GtkAlignment(0.5, 0.5, 0, 0);
//Creating a new button
$button2 = new GtkButton('Centered, does not extend');
//Adding button2 to the second GtkAlignment container
$align2->add($button2);
//Packing the GtkAlignment container into the GtkVBox
$vbox->pack_start($align2, true, true);

//Adding a GtkHSeparator, to see the different GtkAlignment containers better
$vbox->pack_start(new GtkHSeparator(), false, false, 3);


//Third GtkAlignment container. 

//This container will center it's child, allowing it extend
// into 75% (0.75) of the *free space* in the container
$align3 = new GtkAlignment(0.5, 0.5, 0.75, 0.75);
//Creating a new button
$button3 = new GtkButton("Centered, extends an extra \r\n75% of empty space");
//Adding button3 to the third GtkAlignment container
$align3->add($button3);
//Packing the GtkAlignment container into the GtkVBox
$vbox->pack_start($align3, true, true);

//Adding a GtkHSeparator, to see the different GtkAlignment containers better
$vbox->pack_start(new GtkHSeparator(), false, false, 3);


//Fourth GtkAlignment container. 

//This container will right-align it's child, without extending it
$align4 = new GtkAlignment(1, 0.5, 0, 0);
//Creating a new button
$button4 = new GtkButton("Right-aligned, doesn't extend");
//Adding button4 to the fourth GtkAlignment container
$align4->add($button4);
//Packing the GtkAlignment container into the GtkVBox
$vbox->pack_start($align4, true, true);


//Preparing the window
$win = new gtkwindow();
$win->set_position(Gtk::WIN_POS_CENTER);
$win->set_title('GtkAlignment demo');

//Adding the GtkVBox to the window
$win->add($vbox);
//Connecting the destroy signal
$win->connect_simple('destroy',array('gtk','main_quit'));
//Showing the window's content
$win->Show_All();
//Main loop
Gtk::main();

?>