Chapter 51. Fixed Container

Inheritance Hierarchy

Object
   +--- Widget
         +--- Container
               +--- Fixed
         

The Fixed container allows you to place widgets at a fixed position within it's window, relative to it's upper left hand corner. The position of the widgets can be changed dynamically.

There are only three functions associated with the fixed widget:

$fixed = new Gtk::Fixed();

$fixed->put( $widget, $x, $y );

$fixed->move( $widget, $x, $y );

The new() function allows you to create a new Fixed container.

put() places a $widget in the Fixed at the position specified by $x and $y.

move() allows the specified widget to be moved to a new position.

51.1. Fixed Example

The following example illustrates how to use the Fixed Container.

Fixed Container Example Source

      
#!/usr/bin/perl -w

use Gtk;
use strict;

set_locale Gtk;
init Gtk;

my $false = 0;
my $true = 1;

my $x = 50;
my $y = 50;

my $window;
my $fixed;
my $button;

# Create a new window
$window = new Gtk::Window( "toplevel" );
$window->set_title( "Fixed Container" );
$window->signal_connect( "destroy", sub { Gtk->exit( 0 ); } );

# Sets the border width of the window.
$window->border_width( 10 );

# Create a Fixed Container
$fixed = new Gtk::Fixed();
$window->add( $fixed );
$fixed->show();

for my $i ( 1..3 )
{
   # Creates a new button with the label "Press me"
   $button = new Gtk::Button( "Press me" );

   # When the button receives the "clicked" signal, it will call the
   # function move_button() passing it the Fixed Container as its
   # argument.
   $button->signal_connect( "clicked", \&move_button, $fixed );

   # This packs the button into the fixed containers window.
   $fixed->put( $button, $i * 50, $i * 50 );

   # The final step is to display this newly created widget.
   $button->show();
}

# Display the window
$window->show();

main Gtk;
exit( 0 );



### Subroutines

# This callback function moves the button to a new position
# in the Fixed container.
sub move_button
{
   my ( $widget, $fixed ) = @_;

   $x = ( $x + 30 ) % 300;
   $y = ( $y + 50 ) % 300;
   $fixed->move( $widget, $x, $y );
}


# END EXAMPLE PROGRAM
      
   

Fixed Example Screenshot