Can't position Gnome2::Canvas within Gtk2::Frame

Hello everyone,
I'm yet another refugee from PerlMonks, who suggested I ask here.

I'm trying to draw a coloured bar inside a Gtk2::Frame.

The bar is drawn on a Gnome2::Canvas, contained within the frame. The bar should be as long as possible, but a fixed height. The bar should also be exactly in the middle of the frame.

My problem is that I can't find the size of the Gtk2::Frame that's actually drawn, therefore I can't set the size of the Gnome2::Canvas that would fill it, therefore I can't draw the coloured bar in the right place.

The example script draws a red bar whose width isn't long enough, and whose vertical position is slightly off of centre.

(The call to Gnome2::Canvas->get_size() just returns default values of 100x100, which is not related to the frame's actual size.)



use strict;
use diagnostics;
use warnings;
use Gtk2 '-init';
use Glib qw(TRUE FALSE);
use Gnome2::Canvas;
# Draw a Gtk2 window
my $window = Gtk2::Window->new();
$window->signal_connect('delete_event' => sub { Gtk2->main_quit; });
$window->set_default_size(500, 500);
my $vBox = Gtk2::VBox->new(FALSE, 0);
# Draw a Gtk2::Frame containing a Gnome2::Canvas
# The frame should be as long as possible, but only 50 pixels high
my $frameHeight = 50;
my $frame = Gtk2::Frame->new(undef);
$frame->set_size_request(-1, $frameHeight);
my $canvas = Gnome2::Canvas->new();
$vBox->pack_start($frame, FALSE, FALSE, 0);
# Draw a red bar, almost as long as the frame, but with a fixed height
my ($width, $height) = $canvas->get_size();
# Put the bar roughly in the middle; it's the best I can do at the moment
my $rect = Gnome2::Canvas::Item->new(
     x1 => 20,                                    
     y1 => 20,                                         
     x2 => ($width - 40),
     y2 => ($frameHeight - 20),          
     fill_color => '#FF0000',
     outline_color => '#000000',

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]