[racket] Problem scrolling contents of text% in editor-snip%

From: Kieron Hardy (kieron.hardy at gmail.com)
Date: Mon May 14 18:32:46 EDT 2012

Hi all,

I'm having problems getting the contents in a text% to scroll within an
editor-snip%.

The attached code displays part of a long string within a text% object in a
smaller editor-snip% object. The print statements successfully show a few
of the edit locations at some selected (x, y) points in the editor.

I think I've tried all of the scrolling functions in each of the various
components (editor-canvas%, editor-admin%, editor-snip%, text%) and am
unable to change the portion of the string that displays. I'm probably
doing something stupid, can anyone give me any hints?

Cheers,

Kieron.

****

#lang racket/gui

(define f (instantiate frame% ("Pasteboard Test" #f 600 400)))
(define c (instantiate editor-canvas% (f)))

(define p (instantiate pasteboard% ()))
(send c set-editor p)

(send f show #t)

(define t (new text% [auto-wrap #f]))
(send t insert "hello world .... pasteboard one two three ... goodbye world
... alpha bravo charlie delta echo foxtrot golf hotel india juliet kilo
lima mike november oscar papa quebec romeo sierra tango uniform victor
whiskey xray yacht zulu" 0)

(define s (new editor-snip% [editor t]))

(send s set-min-width 250)
(send s set-max-width 250)

(send p insert s)

(printf "  text dimensions:(~a ~a) (~a ~a)~n"
        (send t get-min-width) (send t get-min-height)
        (send t get-max-width) (send t get-max-height))
(printf "  snip dimensions:(~a ~a) (~a ~a)~n"
        (send s get-min-width) (send s get-min-height)
        (send s get-max-width) (send s get-max-height))

;; print information about certain locations in the text
;(send t find-position x y at-eol? on-it? edge-close?)
(define at-eol? (box 0))
(define on-it? (box 0))
(define edge-close? (box 0))
(printf "  (5,5): ~a ~a ~a ~a~n"
        (send t find-position   5 5 at-eol? on-it? edge-close?) (unbox
at-eol?) (unbox on-it?) (unbox edge-close?))
(printf " (25,5): ~a ~a ~a ~a~n"
        (send t find-position  25 5 at-eol? on-it? edge-close?) (unbox
at-eol?) (unbox on-it?) (unbox edge-close?))
(printf "(100,5): ~a ~a ~a ~a~n"
        (send t find-position 100 5 at-eol? on-it? edge-close?) (unbox
at-eol?) (unbox on-it?) (unbox edge-close?))
(printf "(200,5): ~a ~a ~a ~a~n"
        (send t find-position 200 5 at-eol? on-it? edge-close?) (unbox
at-eol?) (unbox on-it?) (unbox edge-close?))
(printf "(400,5): ~a ~a ~a ~a~n"
        (send t find-position 400 5 at-eol? on-it? edge-close?) (unbox
at-eol?) (unbox on-it?) (unbox edge-close?))

;; scroll to certain locations in the text
(define (do-scroll-text)
  (printf "scroll:~a~n" (send (send t get-admin) scroll-to -400 0 50 50 #t
'none))
  (sleep 1.0)
  (printf "scroll:~a~n" (send t scroll-to s 200 0 50 50 #t 'start))
  (sleep 1.0)
  (printf "scroll:~a~n" (send p scroll-to s 400 5 50 50 #t 'start))
  (sleep 1.0)
  (printf "scroll:~a~n" (send t scroll-to s 800 5 50 50 #t 'start))
  (sleep 1.0)
  )

(thread do-scroll-text)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120514/94d2a1c2/attachment.html>

Posted on the users mailing list.