PHP-GTK
Wednesday, October 22, 2014 
download | documentation | applications | faq | changelog | resources 


search for in the  


previousBoxes - GtkHBox and GtkVBox
Fixed layoutnext

Last updated: Sun, 12 May 2013
view this page in English

While it's very easy to create dynamic layouts with GtkBoxes, it's very hard to layout widgets so that e.g. the labels on the left of the interaction widgets have the same width, regardless of their content. If you need tabular layouts, GtkTable is the right choice. Widgets can span several columns and rows, and can have different padding margins.

Example 7.2. Tabular layout

<?php
$w = new GtkWindow();
$w->set_title('GtkTable test');
$w->connect_simple('destroy', array('gtk', 'main_quit'));
 
$lbl1   = new GtkLabel('Email address:');
$lbl2   = new GtkLabel('Id:');
$lbl3   = new GtkLabel('Name:');
$align3 = new GtkAlignment(0.0, 0.5, 0, 0);
$align3->add($lbl3);
$txt1   = new GtkEntry();
$txt2   = new GtkEntry();
$txt3   = new GtkEntry();
 
$table  = new GtkTable(2, 2);
$table->attach($lbl1  , 0, 1, 0, 1, 0);
$table->attach($lbl2  , 0, 1, 1, 2, 0);
$table->attach($align3, 0, 1, 2, 3, Gtk::FILL);
$table->attach($txt1  , 1, 2, 0, 1);
$table->attach($txt2  , 1, 2, 1, 2);
$table->attach($txt3  , 1, 2, 2, 3);
 
$w->add($table);
$w->show_all();
Gtk::main();
?>

When running the example, you see that the Id label is centered horizontally. By default, widgets are filled in both directions and take all the available space, which is ok for most widgets. For GtkLabel however, it's not optimal: Labels should be aligned at one side. As the set_justify() function justifies the text for multiline labels only, we need to use a GtkAlignment to align the label properly - label Name shows the result.


User Contributed Notes
tutorials.packing.table.php
add a note about notes
There are no user contributed notes for this page.


previousBoxes - GtkHBox and GtkVBox
Fixed layoutnext

Last updated: Sun, 12 May 2013
view this page in English


credits 

PHP  Copyright © 2001-2014 The PHP Group
 All rights reserved.
Last updated: Sun May 12 20:51:01 2013 CEST