in reply to Tk: Aligning the items in seperate canvases
Check out the following sub, and test it a few times. Sometimes it will align, as long as there are not any random placements in the high range. Then find the line I've commented out, and uncomment it. That will always bring all 4 into the range, but not perfectly aligned. Like I said, you might be able to expand the scrollregion, so the scrollbar dosn't get locked into the far right position.
Another option which you might try, ( I'm thru fiddling with this :-) ) is to pick a x position on the screen, then scroll all canvases to the 0 position, then in a loop, scroll them 1 unit at a time until the boxe's screen position line up.
Someone else may figure something out, but unless you expand your scrollregion, the scrolled-window sliders will lock you up occaisionally.
sub AlignAll{ my ($x1, $y1, $x2, $y2); my $i; my $location; my %pos; foreach $i (0 .. 3) { ($x1, $y1, $x2, $y2) = $sc[$i]->bbox('rect'); $location =int(($x1+$x2)/2); warn("$location"); $pos{$i} = $location; $sc[$i]->xviewMoveto( $location/$initial_width ); } my @pos; foreach my $key (keys %pos ){ push @pos, $pos{$key}; } print "@pos\n"; my $max = &max(@pos); print "$max\n"; #move them all to the most right one, #since those are already at right scroll limit foreach $i (0 .. 3) { print $i," ",join ' ',$sc[$i]->xview(),"\n"; my $diff = $pos{$i} - $max; ############################################### ############################################### #try it with this line # $sc[$i]->xviewScroll($diff, 'units'); ############################################### } } sub max { my $max; for (@_) { $max = $_ if $_ > $max } return $max; } ########################################
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Tk: Aligning the items in seperate canvases
by liverpole (Monsignor) on Nov 03, 2006 at 21:04 UTC | |
by zentara (Cardinal) on Nov 04, 2006 at 13:07 UTC |