Version 0 of Complex scrolling

Updated 2003-10-08 18:37:16

ulis, 2003-10-08: A handy proc to scroll the title and the body.

http://perso.wanadoo.fr/maurice.ulis/tcl/complexscroll.gif


The proc:

  proc complexscroll {w width height {theight 20}} \
  {
    frame $w
    canvas $w.c0 -height $theight -width $width \
      -xscrollcommand [list $w.hs set] -bg beige \
      -highlightthickness 0 -selectborderwidth 0 \
      -bd 1 -relief solid
    canvas $w.c1 -height $height -width $width \
      -yscrollcommand [list $w.vs set] -bg white \
      -highlightthickness 0 -selectborderwidth 0 \
      -bd 1 -relief solid
    scrollbar $w.hs -orient horizontal -command [list xview $w]
    scrollbar $w.vs -command [list $w.c1 yview]
    grid $w.c0 -row 0 -column 0 -sticky new
    grid $w.c1 -row 1 -column 0 -sticky nsew
    grid $w.hs -row 2 -column 0 -sticky new
    grid $w.vs -row 0 -column 1 -sticky nse -rowspan 2
    grid rowconfigure $w 1 -weight 1
    grid columnconfigure $w 0 -weight 1
    return $w
  }
  proc xview {w args} \
  {
    eval [linsert $args 0 $w.c0 xview]
    eval [linsert $args 0 $w.c1 xview]
  }

A little test:

  wm title . "complex scroll"
  pack [complexscroll .cs 250 150] -fill both -expand 1
  set x 0
  foreach title {firstname lastname address birthday occupation} \
  {
    .cs.c0 create text $x 8 -anchor nw -text " $title "
    for {set y 8} {$y < 200} {incr y 24} \
    { .cs.c1 create text $x $y -anchor nw -text " $title " }
    incr x 80
  }
  .cs.c0 configure -scrollregion [.cs.c0 bbox all]
  .cs.c1 configure -scrollregion [.cs.c1 bbox all]

Category Example