An easy fix: Let the callback ignore calls, when the slider value
is the same as the last one.

Example:

(define substrate-slider
  (let ([last-value-seen -42])
    (make-slider pane
                 "[S]" 0 slider-max
                 (lambda (slider event)
                   (let ([n (send slider get-value)])
                     (unless (= n last-value-seen)
                       (set! last-value-seen n)
                       (set! s0 (exact->inexact (* smax (/ slider-max) n)))
                       (draw))))
                 (λ () s0)
                 (λ () smax))))

/Jens Axel


2012/4/1 Jens Axel Søgaard <[email protected]>:
> Hi All,
>
> I have a little problem with the attached program.
> Maybe, I am not 100% sure, the slider% calls the call-back
> more than once (maybe 4 times?) after the release of the mouse.
> The behaviour puzzles me.
>
> Is it the intended behaviour? If so, is there a better way
> to use the slider, than the one in the attached program?
>
> I found the following program by António Leitão from June 2011
> on the mailing list, which shows this oddity.
>
> (require racket/gui)
> (define frame (new frame% [label "Example"]))
> (new slider% [parent frame]
>             [label "Test"]
>             [min-value 0]
>             [max-value 10]
>             [callback (lambda (slider event)
>                         (display
>                          (format "~a@~a: ~a~%"
>                                  (send event get-event-type)
>                                  (send event get-time-stamp)
>                                  (send slider get-value))))])
>
> (send frame show #t)
>
> On my computer,  if I run the program, and then move the
> slider to 5 and release the mouse, I get this output:
>
> slider@-273484745: 0
> slider@-273484095: 1
> slider@-273482097: 5
> slider@-273482096: 5
> slider@-273482096: 5
> slider@-273482096: 5
> slider@-273482096: 5

--
Jens Axel Søgaard

____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Reply via email to