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.
<?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.