[plt-scheme] Styling MrEd GUI components

From: Stephen De Gabrielle (stephen at degabrielle.name)
Date: Sun Mar 30 16:46:05 EDT 2008

You could draw/animate your own green button using the drawing toolkit.

sort of like this 1-d scatter thingy

;  make new widget'scatter-chart%'
;; do this all in Pretty Big language (DrScheme only)
(define scatter-chart% (class pane% ()
                         (init-field parent)

                         ; Make the drawing area
                         (super-instantiate () (parent parent) ;
instantiate this FIRST
                           [min-width 100] [stretchable-width #f]
                           (min-height 200) [stretchable-height #f])


                         ;; internal data
                         (define list-of-points '()) ;; start with empty list
                         (define canvas (new canvas% [parent this]

                                             (paint-callback (lambda
(canvas dc) (draw-chart)))

                                             [min-width 100]
[stretchable-width #f]
                                             [min-height 200]
[stretchable-height #f]

                                             ))
                         (define dc (send canvas get-dc)) ; Get the
canvas's drawing context
                         ; Make some pens and brushes for use later
                         (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))


                         ;; public methods
                         ;; add-point : new-point
                         (define/public (add-point new-point)

                           (set! list-of-points (cons new-point
list-of-points)) ;; add to the list
                           (send dc draw-rectangle 0 new-point 200 1))
;; and draw the line
                         ;; draw-chart : draw a chart based on the
list of integers supplied
                         ;; see
http://download.plt-scheme.org/doc/371/html/mred/mred-Z-H-397.html
                         (define/public (draw-chart)
                           (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-points ))
                         (draw-chart))) ; draw it for the first time
when this class is instantiated

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

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

(send new-my-widget draw-chart)
; Draw the face
(define (go)

  (map (lambda (y)



       (send new-my-widget add-point y) ; add a point at a time
         (sleep/yield 0.05)) ; draw it slowly
       '(10 30 22 77 78 79 17 65 97 54 55 56 57 91 33 55 95 99 125 155
157 159 188 187 186 191))) ;; list of datapoints

(go)  ;; !!!



On Sun, Mar 30, 2008 at 5:49 AM, Ben Simon <benjisimon at gmail.com> wrote:

> On Mon, Mar 10, 2008 at 9:22 AM, Matthew Flatt <mflatt at cs.utah.edu> wrote:
>
> > At Sun, 9 Mar 2008 23:45:03 -0400, "Ben Simon" wrote:
> > > How do I style MrEd components? That is, how could I make a button
> > red, or a
> > > border green?  I see where I can make use of different fonts, but
> > that's
> > > about all I see in terms of controlling the Look & Feel of the
> > components.
> > [...useful comments trimmed]
> >
>
>
> >
> > More generally, you can derive a sub-class of `canvas%' and draw
> > anything as a control.
> >
>
> There doesn't happen to be a way to use this approach, and somehow embed a
> container like a vertical-panel% in the resulting canvas%, is there?
>
> The idea being that I might make a component that uses a canvas to draw a
> green border, and then embed other GUI components (say, a series of buttons)
> in this newly drawn area.
>
> I've poked around the docs and don't see a way to do it, but I thought I
> should get confirmation from the pros.
>
> -Ben
>
>
> --
> Have an idea for software? I can make it happen -
> http://www.ideas2executables.com
> My Blog: http://benjisimon.blogspot.com
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>


-- 
Cheers,

Stephen

--
Stephen De Gabrielle
s.degabrielle at ucl.ac.uk
Telephone +44 (0)20 7679 5242 (x45242)
Mobile                  079 851 890 45
Project: Making Sense of Information (MaSI)
http://www.uclic.ucl.ac.uk/annb/MaSI.html

UCLIC: University College London Interaction Centre
http://www.uclic.ucl.ac.uk/

Remax House - 31/32 Alfred Place
London - WC1E 7DP
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20080330/a5a28e94/attachment.html>

Posted on the users mailing list.