2.4 Right align the button
Written by kksou   
Monday, 17 March 2008

Objective

In the previous example, you have displayed the button in its default size as shown below:

2.3.gif

What if we want the button to be right aligned?

Overview

  • Create a GtkButton.
  • Create a GtkHBox.
  • First pack an expandable box into the hbox. Remember to set expand=true.
  • Then pack the button inside the hbox, set expand=false.
  • Finally pack the hbox inside the vbox, also set expand=false.

Sample Output

2.4.gif

Sample Code

1   
2   
3   
4   
5   
6   
7   
8   
9   
10   
11   
<?php
$window = new GtkWindow();
$window->connect_simple('destroy',array('Gtk','main_quit'));
$window->set_size_request(200, 100);
$vbox = new GtkVBox();
$window->add($vbox);

$button = new GtkButton('button label');
$hbox = new GtkHBox();
$hbox->pack_start(new GtkLabel(), true); // note 1
$hbox->pack_start($button, false); // note 2
  • 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

  1. Here our expandable box is an empty GtkLabel with expand=true. Note that you may also use an empty GtkHBox or GtkVBox. The effect is the same.
  2. expand=false will ensure that the button does not expand horizontally in the hbox.
  3. expand=false will ensure that the button does not expand vertically in the vbox.

The net result is that the empty GtkLabel, because of its expandable spring, will "push" the button on the way to the right of the window, as the following diagram illustrates.

2.41.gif



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