[plt-scheme] scroll-to

From: Mike T. Machenry (dskippy at ccs.neu.edu)
Date: Wed Dec 4 21:34:24 EST 2002


  I am calling set-caret-owner on deeply nested texts in a an editor
that may or may not be visible in the canvas. I have been trying to
use a function that I wrote to scroll the canvas to the proper spot.
For some reason it has not effect on the scroll position of the canvas.
My expected result is that the canvas will scroll to show the entirety
the snip es3 (or as much as it can starting from the top) but the scroll
bar sits still and does nothing. This is my code:

(define f (instantiate frame% () (width 200) (height 200) (label "F")))
(define pb (instantiate pasteboard% ()))
(define ec (instantiate editor-canvas% () (editor pb) (parent f)))
(define (make-snip)
  (instantiate editor-snip% ()
    (min-width 100)
    (min-height 90)
    (editor (instantiate text% ()))))
(define es1 (make-snip))
(define es2 (make-snip))
(define es3 (make-snip))
(send pb insert es1 0 0)
(send pb insert es2 0 100)
(send pb insert es3 0 200)
(send f show #t)

;; scroll-to ((is-a?/c snip%) . -> . void?)
;; scroll a snips parent to show it in the visible area
(define (scroll-to snip)
  (let* ([editor (send (send snip get-admin) get-editor)]
         [left (box 0)]
         [right (box 0)]
         [top (box 0)]
         [bottom (box 0)])
    (send editor get-snip-location snip left top #f)
    (send editor get-snip-location snip right bottom #t)
    (send editor scroll-to snip 0 0
          (- (unbox right) (unbox left))
          (- (unbox bottom) (unbox top))
          #t 'start)))


Posted on the users mailing list.