Bogdanp / racket-gui-easy

Declarative GUIs in Racket.
https://docs.racket-lang.org/gui-easy/index.html
134 stars 18 forks source link

button contract should allow bitmap%, not just label-text% #33

Closed cloudrac3r closed 1 year ago

cloudrac3r commented 1 year ago

The underlying button% handles a bitmap% argument just fine, even when it's an observable of a bitmap! Try this minimal example where I import the private button file directly, bypassing the contract:

#lang racket/base
(require racket/class
         racket/function
         images/icons/control
         images/icons/style
         images/icons/stickman
         (only-in racket/gui timer%)
         (except-in racket/gui/easy button)
         racket/gui/easy/private/view/button
         racket/gui/easy/operator)

(define/obs @ms (current-inexact-milliseconds))
(new timer%
     [notify-callback (λ () (:= @ms (current-inexact-milliseconds)))]
     [interval 10])
(define/obs @stickman
  (@ms . ~> . (λ (ms)
                (running-stickman-icon
                 (/ ms 1000)
                 #:height 32
                 #:head-color run-icon-color
                 #:arm-color "white"
                 #:body-color run-icon-color))))

(render
 (window
  #:size '(200 200)
  (button @stickman (λ () (println (obs-peek @ms))))))

Your button contract should allow bitmap% too.

The original button% class can also accept another special thing that you may wish to support, see https://docs.racket-lang.org/gui/button_.html for the full contract.

Bogdanp commented 1 year ago

Should be fixed. Thanks!