Bogdanp / racket-gui-easy

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

view: fix scaling of image #50

Closed xioi closed 8 months ago

xioi commented 8 months ago

The image's #:size property doesn't work well with something like '(#f 300), it tries to treat both of them as integers when they are not both #f and that's the point. The problem happens in its internal scale function and I made it to scale either w or h following it original scale when one of them is #f so it can properly fit the frame. BTW I don't know if it is fine for 'fill mode...maybe it deserves further consideration.

The problem can be tested with this piece of code.

#lang racket/base

;;; (require "gui-easy-lib/gui/easy.rkt")
(require racket/gui/easy)

(define @height (obs 300))

(render
 (window
  (vpanel
   (slider
    300
    (λ (v) (obs-set! @height v))
    #:min-value 100
    #:max-value 800)
   (image
    #:size (obs-map @height (λ (h) (list #f h)))
    "path/to/photo.jpg")))) ;;; Whatever, a non-square-like photo
Bogdanp commented 8 months ago

Thanks!