[plt-scheme] Text field font troubles

From: Robby Findler (robby at cs.uchicago.edu)
Date: Thu Aug 7 15:24:15 EDT 2008

I think you want the change-style method of the text (using the
style-delta as an argument to that). See also begin-edit-sequence and

(If that's not enough help, I can adjust your program below to get you started.)


On Thu, Aug 7, 2008 at 11:59 AM, Sky O'Mara <skyo at ccs.neu.edu> wrote:
> Hi,
> I am using MrEd to write a program with a GUI that contains a text field to
> send feedback to the user. I would like to be able to insert segments of
> colored text into the text field, but I am running into a roadblock because
> I do not fully understand how styles work.
> Here is some example code to demonstrate what I have tried so far. The
> documentation does not seem to make it much clearer than this:
> #lang scheme/gui
> (define main-window
>  (new frame%
>       [label "Window"]
>       [width 500]
>       [height 500]))
> (define editor (new text%))
> (define canvas
>  (new editor-canvas%
>       [parent main-window]
>       [editor editor]))
> ;; insert-red-text : String editor<%> -> Void
> ;; Inserts red text into the editor.
> (define (insert-red-text str ed)
>  (let* ([snip (make-object string-snip% str)]
>         [style (send snip get-style)]
>         [delta (make-object style-delta%)]
>         [newdelta (send delta set-delta-foreground "Red")])
>    (send style set-delta newdelta)
>    (send snip set-style style)
>    (send ed insert snip)))
> (send main-window show #t)
> (send editor insert "Regular text...")
> (insert-red-text "Red text..." editor)
> The idea behind insert-red-text is to create a new snip% object, change its
> style to have a different color, and then insert the snip into the editor. I
> am not having luck getting it to work. The function inserts the text, but
> only in the default font.
> Any help would be much appreciated.
> - Sky O.
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Posted on the users mailing list.