PHP-GTK2 Newsletter

PHP-GTK2 Tips & Techniques
FREE Newsletter
by kksou



Sample Code 96: How to set align left and valign top in GtkTable - using GtkAlignment?
Written by kksou   
Friday, 17 November 2006
Problem

Please refer to How to set align left and valign top in GtkTable - using vbox and hbox?

This example achieves the same objective, but using GtkAlignment, as shown below:

How to set align left and valign top in GtkTable - using GtkAlignment?


Solution
  • Create a GtkAlignment. Set the first two arguments as 0, 0 to align the content to the top left.

Sample Code
1   
2   
3   
4   
5   
6   
7   
8   
9   
10   
11   
12   
13   
14   
15   
16   
17   
18   
19   
20   
21   
22   
23   
24   
25   
26   
27   
28   
29   
30   
<?php
$window = new GtkWindow();
$window->set_size_request(400, -1);
$window->connect_simple('destroy', array('Gtk','main_quit'));

$window->add($vbox = new GtkVBox());

// display title
$title = new GtkLabel("align=left and valign=top in GtkAlignment");
$title->modify_font(new PangoFontDescription("Times New Roman Italic 10"));
$title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff"));
$title->set_size_request(-1, 40);
$vbox->pack_start($title, 0, 0);

$gap = new GtkHBox();
$gap->set_size_request(-1, 10); // add a small gap btw title and table
$vbox->pack_start($gap, 0, 0);

$vbox->pack_start($hbox = new GtkHBox());
$hbox->pack_start(new GtkHBox());
$hbox->pack_start($table = new GtkTable(), 0, 0);
$hbox->pack_start(new GtkHBox());

$data = array(
array('', 'header1', 'header2', 'header3'),
array('row0', 1, "2.1\n2.2\n2.3", "3.1\n3.2\n3.3\n3.4"),
array('row1', "4.1\n4.2\n4.2", "5.1\n5.2", 6));

display_table ($table, $data);

  • Note that this is only 70% of the sample code. You have to be a registered member to see the entire sample code. Please login or register.
  • Registration is free and immediate.
  • Have some doubt about the registration? Please read this forum article.
Explanation

We make use of the code in How to set valign top in GtkTable? to display a 2D array.

What's new here:

  1. Set the first two arguments of GtkAlignment to 0, 0 to align the content to top left.
  2. Stuff the content into the GtkAlignment.

Related Links

User reviews

There are no user reviews yet.

Note: You have to be a registered member to leave a comment. Free registration here.

 
< Prev   Next >

Copyright © 2006-2008. kksou.com. All Rights Reserved