Hi,
Just a couple of observations.

You have:
$canvas->set_center_scroll_region(FALSE);

In order to centralise the red bar, I find that I need to specify that as TRUE.

It seems to me that you haven't specified any size for the canvas, and that it would therefore be expected to be the default size of (100, 100).
You have specified a window size of (500, 500) and $window->get_size() does, indeed, return (500, 500).

You might also try the gtk-perl mailing list for some assistance, given that good help from this forum is a little slow in coming.

Update: On re-reading your post, I see that I haven't really told you much that you hadn't already worked out for yourself. Sorry 'bout that.
It does seem that the slight off-centredness that you see is because the red bar is specified to be between 20 and $width-40.
Change that to x2 => ($width - 20) and it should be centred. Alternatively, specify x1 => 40 and you'll also achieve centring (though the red bar will then be shorter by 20).

I don't know how to centre a non-default size canvas. I expected this to work:
$canvas->set_size(400, 100); $canvas->set_center_scroll_region(TRUE); $frame->add($canvas);

but the canvas size is still (100, 100).So I tried:
$canvas->set_center_scroll_region(TRUE); $canvas->set_size(400, 100); $frame->add($canvas);

and the canvas size is then the specified (400, 100) but "centred" for a canvas size of (100, 100) and therefore completely off centre.

Cheers,
Rob

In reply to Re: Can't position Gnome2::Canvas within Gtk2::Frame by syphilis
in thread Can't position Gnome2::Canvas within Gtk2::Frame by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.