[plt-scheme] can't get height right when making a widget for mred

From: Stephen De Gabrielle (stephen at degabrielle.name)
Date: Fri Sep 21 09:35:04 EDT 2007

Hi,

I'm trying my hand at making a simple widget.

I've done something wrong and it is twice as high as it should be.

Please look at my code below and let me know where I have gone wrong.

Cheers,

Stephen


; language 'Pretty Big'


;make new widget
(define scatter-chart% (class pane% ()
                         (init-field parent)
                         ; Make the drawing area
                         (define pane (new pane% (parent parent))) ; this
doesn't help
                         (define canvas (new canvas% [parent pane]
                                                     [min-width 100]
[stretchable-width #f]
                                                     [min-height 200]
[stretchable-height #f]
                                                     ))
                         ; Get the canvas's drawing context
                         (define dc (send canvas get-dc))
                         ; Make some pens and brushes
                         (define no-pen (make-object pen% "BLACK" 1
'transparent))
                         (define blue-brush (make-object brush% "BLUE"
'solid))
                         (define yellow-brush (make-object brush% "YELLOW"
'solid))
                         (define/public (redraw-chart list-of-integers)
                           (send dc set-pen no-pen)
                           (send dc set-brush blue-brush)
                           (send dc draw-rectangle 0 0 100 200)  ; big blue
rectangle
                           (send dc set-brush yellow-brush)
                           (map
                            (lambda (y) (send dc draw-rectangle 0 y 200 1))
; draw a line for each integer.
                            list-of-integers ))
                         (super-instantiate () (parent parent)
                           (min-height 200) [stretchable-height #f]
                            [min-width 100] [stretchable-width #f]
                           )
                         ))

; Make a  frame
(define frame (new frame% [label "scatter-chart% Example"]
                          [width 100]
                          [height 200]))


(define new-my-widget (new scatter-chart% (parent frame) ))
; Show the frame
(send frame show #t)
; Wait a second to let the window get ready
(sleep/yield 1)

; Draw
(send new-my-widget redraw-chart '(10 30 22 77 78 79  33 55 95 99 125 155
157 159 188 187 186 191))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20070921/d1fed19f/attachment.html>

Posted on the users mailing list.