[plt-scheme] Text field font troubles

From: praimon (praimon at gmail.com)
Date: Fri Aug 8 17:52:47 EDT 2008

Hi,
I'm just beginning to learn about gui, so the hint didn't help
and I had to resort to the much more convoluted:

(define (insert-red-text str ed)
  (let* ([style (make-object style-list%)]
         [delta (make-object style-delta%)]
         [basic (send style basic-style)])
    (send ed set-style-list style)
    (send delta set-delta-foreground "Red")
    (send ed change-style
          (send style find-or-create-style basic delta))
    (send ed insert str)))

If I saw the intended solution, that might also answer another
question of mine: When dealing with text, what are the
advantages of using snips (which I don't really understand)
in place of strings (which get automatically converted to snips
anyway).

The lack of worked-out examples in the gui manual makes
it a difficult learning experience, so all examples presented
here are much appreciated.
regards,
praimon


On Thu, Aug 7, 2008 at 3:24 PM, Robby Findler <robby at cs.uchicago.edu> wrote:
> 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
> end-edit-sequence.
>
> (If that's not enough help, I can adjust your program below to get you started.)
>
> Robby
>
> 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
>>
>>
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>


Posted on the users mailing list.