in reply to Tk: Aligning the items in seperate canvases
Update: My following "solution" wasn't adequate. I was thinking you wanted to reposition the scrollbars and rectangles to the center, but of course that wasn't what you wanted at all. I'm still trying to figure out a concise way to do this, but please don't go by what I originally wrote below ...
Update 2: My reponse to zentara below gives a much better solution, but it's still not as good as the one by BrowserUK below. His answer is clearly the best if you're willing to allow scrolling outside of the scrollable region; the rectangles stay centered after multiple zoom-in and zoom-out operations. (Nice job, BrowserUK)
One possible way would be to retrieve the current coordinates of each scrollbar, in your AlignAll subroutine, calculate its width, and then use the same width but place it centered at 0.5, using the methods get and set:
sub AlignAll{ my ($x1, $y1, $x2, $y2); my $i; my $location; + foreach $i (0 .. 3) { # Reposition scrollbar to the middle my $sbar = $sc[$i]->Subwidget('xscrollbar'); my @range = $sbar->get(); my $size = ($range[1] - $range[0]) / 2; $sbar->set(0.5 - $size, 0.5 + $size); + ($x1, $y1, $x2, $y2) = $sc[$i]->bbox('rect'); $location =int(($x1+$x2)/2); warn("$location"); } }
There may well be a better/easier way to do this (if there is, my money's on the the Tk master :-)), but I believe this will do what you want.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Tk: Aligning the items in seperate canvases
by wjw (Priest) on Nov 03, 2006 at 17:54 UTC | |
|
Re^2: Tk: Aligning the items in seperate canvases
by tcarmeli (Beadle) on Nov 09, 2006 at 10:55 UTC |