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

Thanks a bunch!
I merged your code into mine, and played with it a bit, and stumbled on a working solution using Gnome2::Canvas. (Your script using Gtk2::Gdk::Cairo::Context also works perfectly.)
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 $frame = Gtk2::Frame->new(undef);
$frame->set_size_request(-1, 50);
my $canvas = Gnome2::Canvas->new();
$vBox->pack_start($frame, FALSE, FALSE, 0);
# The ->show_all() call here makes everything work (for some reason)
my $rect = $canvas->allocation();
# Draw a red bar, almost as long as the frame, but with a fixed height,
#   centred in the middle
my ($width, $height) = $canvas->get_size();
# (The Gtk2::Frame is 490x50, so the Gnome2::Canvas should be 488x48)
#print "canvas w $width h $height\n";
my $canvasItem = Gnome2::Canvas::Item->new(
     x1 => 20,                                    
     y1 => 20,                                                  
     x2 => ($width - 20),
     y2 => ($height - 20),          
     fill_color => '#FF0000',
     outline_color => '#000000',

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