Posted to tcl by GPS at Sat Aug 04 07:56:09 GMT 2007view raw
- proc set-scroll-region {canvas id} {
- set subwin [$canvas itemcget $id -window]
- set w [max [winfo reqwidth $subwin] [winfo width $canvas]]
- set h [max [winfo reqheight $subwin] [winfo height $canvas]]
- $canvas itemconfigure $id -width $w -height $h
- set whalf [expr {$w / 2}]
- set hhalf [expr {$h / 2}]
- $canvas configure -scrollregion [list -$whalf -$hhalf $whalf $hhalf]
- }
- In proc ui I have this:
- grid [canvas $t.v.bottom.canvas \
- -xscrollcommand [list $t.v.bottom.xview set] \
- -yscrollcommand [list $t.v.bottom.yview set]] -row 0 -column 1 -sticky nesw
- set subwin [frame $t.v.bottom.canvas.area]
- set id [$t.v.bottom.canvas create window 0 0 -window $subwin]
- bind $subwin <Configure> [list set-scroll-region $t.v.bottom.canvas $id]
- Do you have any idea what I'm doing wrong? It seems to work some of the time, but other times (seemingly randomly) it doesn't. I assume it's some sort of idle callback issue with geometry management, but I'm not sure how to fix it.