Classes are really nice and easy for tasks like this, it took me a little 
bit to get used to the class syntax, but now I love them.
I found that it helps to look at real code that uses classes, because the 
documentation quickly goes into quite advanced/special use cases.
You can use them to wrap-up/encapsulate a bunch of smaller gui parts and 
then just expose some methods that handle the updates etc. 

As always, I welcome people sharing alternative ways to write the same 
> code. 
>
Here you go:

#lang racket/gui

(define progress-bar%
  (class horizontal-pane%
    (super-new)

    (define gauge (new gauge%
                       [label #f]
                       [parent this]
                       [range 100]))

    ;; initialize to 100% with no auto resize
    ;; this way the label has the right size
    ;; so that everything can be seen
    ;; and it does not "wobble" around while filling up
    (define msg (new message%
                     [parent this]
                     [label "100%"]))

    (define/public (set-value val)
      (send gauge set-value val)
      (send msg set-label (string-append (~a val) "%")))

    ;; set back to 0%
    (set-value 0)))


(module+ main
  (define frame (new frame%
                     [label "Progress Bar"]
                     [width 300]))
  (define progress (new progress-bar% [parent frame]))

  (send frame show #t)
  (for ([i (in-range 1 101)])
    (sleep 0.05)
    (send progress set-value i)))


-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/0aed70ba-65e0-4d49-a1c4-f1b67faced92%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to