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.)
 
---
 
#!/usr/bin/perl
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);
$window->set_border_width(5);
 
my $vBox = Gtk2::VBox->new(FALSE, 0);
$window->add($vBox);
 
# 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_border_width(0);
$frame->set_size_request(-1, 50);
 
my $canvas = Gnome2::Canvas->new();
$frame->add($canvas);
$vBox->pack_start($frame, FALSE, FALSE, 0);
 
# The ->show_all() call here makes everything work (for some reason)
$window->show_all();
 
my $rect = $canvas->allocation();
$canvas->set_scroll_region(
        0,
        0,
        $rect->width,
        $rect->height,
);
 
# 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(
    $canvas->root(),
    'Gnome2::Canvas::Rect',       
     x1 => 20,                                    
     y1 => 20,                                                  
     x2 => ($width - 20),
     y2 => ($height - 20),          
     fill_color => '#FF0000',
     outline_color => '#000000',
);
 
$canvasItem->raise_to_top();
 
$window->show_all();
Gtk2->main;


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