I have a text% instance for which I want to optionally set the default
style (font face and size).  I want it to persist even if all text
within the editor is erased.  (My first attempt using the change-style
method failed this requirement.)  I've come up with the following, but
is this the simplest/best way?

;; editor: (is-a/c text%)
;; face: (or/c string? #f)
;; size: (or/c real? #f)
(define (set-default-style editor face size)
  (when (or face size)
    (define (make-delta)
      (define delta (make-object racket:style-delta%))
      (when face
        (send delta set-face face))
      (when size
        (send delta set-delta 'change-size size))
      delta)
    (define style-list (send editor get-style-list))
    (define root-style (send style-list basic-style))
    (define new-default (send style-list find-or-create-style root-style 
(make-delta)))
    (send style-list replace-named-style "Standard" new-default)))

Thanks.

David

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to