[racket] question/problem on racket/gui and "on-paint" flooding

From: Mag. Dr. Nikolaus Klepp (dr.klepp at gmx.at)
Date: Tue Jun 11 16:19:43 EDT 2013

As I'm writing a real-world application in racket (and it's a great tool to do 
so!) I just ran into another problem: 

When a a panel% has a visible scrollbar and there are enough children to 
actually use that scrollbar, then all children get flooded with on-paint 
calls when the scrollbar is used. 

To be precise, the problem is not that the children get lots of on-paint, but 
that invisible children get that calls, too, which results in a pileup of 
on-paint calls that block the application when the drawing operation is 
expensive.

In my case I have several dozen graphs to present and even touching the 
scrollbar results in a desaster. 

Is there a workaround, say, can I find out if a child is visible at all?



Example code - just scroll around and watch how often the first child is 
redrawn, even when invisible:

#lang racket

(require racket/gui)
(require plot)

(define counter 0)
 
(define frame (new frame% [label "on-paint flooding"] [min-height 800] 
[min-width 800]))
(define panel (new vertical-panel%  [parent frame] [style '(auto-hscroll 
auto-vscroll)]))

(for-each 
 (λ (a)
   (new canvas% 
        [parent panel] [min-height 150] [min-width 150]
        [paint-callback (λ (c dc)
                          (when (= a 0) (set! counter (add1 counter)))
                          (define-values (w h) (send dc get-size))
                          ; uncomment the following line to see the effect on 
expensive rendering:
                          ; (plot/dc (function (λ (x) (sin (* 4 x))) -1 1) dc 
0 0 w h )
                          (send dc draw-text (format "~a" counter) 0 0))]))
 '(0 1 2 3 4 5 6 7 8 9 10))

(send frame show #t)



Nik


-- 


Posted on the users mailing list.