The OpenNET Project / Index page

[ новости /+++ | форум | теги | ]

Каталог документации / Раздел "Perl" / Оглавление документа

Chapter 50. Aspect Frames

Inheritance Hierarchy

Object
   +--- Widget
         +--- Container
               +--- Bin
                     +--- Frame
                           +--- AspectFrame
         

The aspect frame widget is like a frame widget, except that it also enforces the aspect ratio (that is, the ratio of the width to the height) of the child widget to have a certain value, adding extra space if necessary. This is useful, for instance, if you want to preview a larger image. The size of the preview should vary when the user resizes the window, but the aspect ratio needs to always match the original image.

To create a new aspect frame use:

$aspect = new Gtk::AspectFrame( $label,
                                $xalign,
                                $yalign,
                                $ratio,
                                $obey_child );

The $xalign and $yalign arguments specify the horizontal and vertical alignment, and varies from 0.0 (left or top aligned) to 1.0 (right or bottom aligned). If $obey_child is true, the aspect ratio of a child widget will match the aspect ratio of the ideal size it requests. Otherwise, it is given by $ratio.

To change the options of an existing aspect frame, you can use:

$aspect->frame_set( $xalign, $yalign, $ratio, $obey_child );

50.1. Aspect Frame Example

As an example, the following program uses an AspectFrame to present a drawing area whose aspect ratio will always be 2:1, no matter how the user resizes the top-level window.

Aspect Frame Example Source

      
#!/usr/bin/perl -w

use 
Gtk
;
use 
strict
;

set_locale Gtk;
init Gtk;


my
 $false = 0;

my
 $true = 1;


my
 $window;

my
 $aspect;

my
 $drawing_area;


# Create the window
$window = new Gtk::Window( "toplevel" );
$window->set_title( "Aspect Frame" );
$window->signal_connect( "destroy", 
sub
 { Gtk->
exit
( 0 ); } );
$window->border_width( 10 );

# Create an aspect_frame and add it to our toplevel window
$aspect = new Gtk::AspectFrame( "2x1", 0.5, 0.5, 2, $false );

$window->add( $aspect );
$aspect->show();

# Now add a child widget to the aspect frame
$drawing_area = new Gtk::DrawingArea();

# Ask for a 200x200 window, but the AspectFrame will give us a 200x100
# window since we are forcing a 2x1 aspect ratio
$drawing_area->set_usize( 200, 200 );
$aspect->add( $drawing_area );
$drawing_area->show();

$window->show();
main Gtk;

exit
( 0 );


# END EXAMPLE PROGRAM
      
   

AspectFrame Example Screenshot




Партнёры:
PostgresPro
Inferno Solutions
Hosting by Hoster.ru
Хостинг:

Закладки на сайте
Проследить за страницей
Created 1996-2024 by Maxim Chirkov
Добавить, Поддержать, Вебмастеру