Thanks for the info Matthew.<br><br>My misunderstanding of how the
editor-snip% and text% classes work led me to believe that it should be
possible to scroll a message string displayed within an editor-snip% and text%
combination.<br>
<br>Eventually I gave up trying to make those work the way I wanted. After reviewing
the documentation, I changed my approach to the problem I had, to wit, display
and move (scroll) some text message within some area on a
pasteboard%. I post here the code from my working solution, along with a
little demonstration of its use, in case it might be useful for
others.<br>
<br>If anyone knows of other solutions, or has suggestions to improve or otherwise make my solution more idiomatic, please do let me know.<br><br>Cheers,<br><br>Kieron.<br><br> ****<br><br>(module moving-text-snip racket/gui<br>
<br> ; Define a sub-class of editor-snip% that has a pasteboard%,<br>
; which displays a string-snip% encapsulating the required text.<br> ; start-moving-text creates a thread that moves the string-snip% across the pasteboard%,<br> ; moving (scrolling) the text message through the area displayed by the class.<br>
; stop-moving-text kills the thread. <br> ;<br> ; To do: <br> ; Deal with resizing the display area.<br> ; Add ability to change message or sleep time or amount to move per tick.<br> ; Add ability to scroll left to right.<br>
; Add ability to scroll up and down.<br> <br> (provide moving-text-snip%)<br> (define moving-text-snip%<br> (class editor-snip%<br> (init [message-text #f])<br> <br> (init-field [sleep-time 0.03] [pixels-per-tick 1])<br>
<br> (define display-pasteboard (new pasteboard%))<br> <br> (super-new [editor display-pasteboard])<br> <br> (define message-string-snip (make-object string-snip% message-text))<br> (send display-pasteboard insert message-string-snip)<br>
<br> (inherit get-min-width get-max-width get-min-height get-max-height get-inset)<br> <br> (define text-mover-thread #f)<br><br> (define/public (start-text-moving)<br> (printf "start-text-moving: thread:~a~n" text-mover-thread)<br>
(when (equal? text-mover-thread #f)<br> ; get the size of the area displaying the moving text<br> (printf " container: dimensions: min:(~a ~a) max:(~a ~a)~n" <br> (get-min-width) (get-min-height) <br>
(get-max-width) (get-max-height))<br><br> (define scroll-start-pos (get-max-width))<br><br> ; get the size of the string-snip%<br> (define x1 (box 0))<br> (define y1 (box 0))<br>
(define x2 (box 0))<br> (define y2 (box 0))<br> (send display-pasteboard get-snip-location message-string-snip x1 y1 #f)<br> (send display-pasteboard get-snip-location message-string-snip x2 y2 #t)<br>
(define message-snip-width (- (unbox x2) (unbox x1)))<br> (define message-snip-height (- (unbox y2) (unbox y1)))<br> (printf " snip: dimensions:(~a ~a)->(~a ~a) size:(~a ~a)~n" <br>
(unbox x1) (unbox y1) <br> (unbox x2) (unbox y2) <br> message-snip-width message-snip-height)<br> <br> (define scroll-end-pos (- message-snip-width))<br><br>
; move the string-snip% across the pasteboard% some number of pixels per tick, with some delay between ticks<br>
(define current-pos scroll-start-pos)<br> (define (do-scroll-text)<br> (send display-pasteboard move-to message-string-snip current-pos 0)<br> (sleep sleep-time)<br> (set! current-pos (if (<= current-pos scroll-end-pos) scroll-start-pos (- current-pos pixels-per-tick)))<br>
(do-scroll-text)<br> ) <br> (set! text-mover-thread (thread do-scroll-text))<br> ))<br> <br> (define/public (stop-text-moving)<br> (printf "stop-text-moving: thread:~a~n" text-mover-thread)<br>
(when (not (equal? text-mover-thread #f))<br> (kill-thread text-mover-thread)<br> (set! text-mover-thread #f)<br> ))<br> )))<br><br>****<br><br>#lang racket/gui<br><br>(require "moving-text-snip.rkt")<br>
<br>(define f (instantiate frame% ("Moving-Text-Module Test" #f 600 400)))<br>(define c (instantiate editor-canvas% (f)))<br>(define p (instantiate pasteboard% ()))<br>(send c set-editor p)<br>(send f show #t)<br>
<br>(define s <br> (new moving-text-snip%<br> [message-text "hello world .... one two three ... goodbye world ... alpha bravo charlie delta ... "]))<br><br>(send s set-min-width 250)<br>(send s set-max-width 250)<br>
<br>(send s set-min-height 50)<br>(send s set-max-height 50)<br><br>(send p insert s)<br><br>(define x (box 0))<br>(define y (box 0))<br>(define w (box 0))<br>(define h (box 0))<br><br>(send (send p get-admin) get-view x y w h #f)<br>
(printf "canvas: position:(~a ~a) dimensions:(~a ~a)~n" <br> (unbox x) (unbox y)<br> (unbox w) (unbox h)) <br><br>(printf "start text moving~n")<br>(send s start-text-moving)<br>
<br>(thread<br> (thunk<br> (sleep 5)<br> (printf "try to start text moving that's already moving~n")<br> (send s start-text-moving)<br> (sleep 5)<br> (printf "stop text moving~n")<br>
(send s stop-text-moving)<br> ))<br><br>