How to change the color of multiple lines of text in a Racket GUI application?

I am experimenting with the Racket GUI Toolkit and trying to get a healthy color change effect coming from using ASCII art on the screen. I have a callback that changes color, but I cannot figure out how to call it in order to get the corresponding result.

At first I tried to use message control to draw text, and then I would change the color of the text from there, but as far as possible I can say that there is no way to change the color of the message text. So I switched to using

Any ideas on how to do this?

+5
source share
2 answers

, text% class ( editor-canvas% ). change-style , , .

:

#lang racket/gui

(define frame (new frame% [label "Test"] [width 300] 
                                         [height 300]))
(define text (new text%))
(define canvas (new editor-canvas% [parent frame] 
                                   [editor text]))

(define style-delta (make-object style-delta% 
                                 'change-normal-color))

;; do some red
(send style-delta set-delta-foreground "red")
(send text change-style style-delta)
(send text insert "Hello world in red\n")

;; do some blue
(send style-delta set-delta-foreground "blue")
(send text change-style style-delta)
(send text insert "Now available in blue")

(send frame show #t)
+7

change.

:

#lang racket/gui

(define frame (new frame% [label "Test"] [width 300] 
                                         [height 300]))
(define text (new text%))
(define canvas (new editor-canvas% [parent frame] 
                                   [editor text]))

(define style-delta (make-object style-delta%))

;; do some red
(send style-delta set-delta-foreground "red")
(send text change-style style-delta)
(send text insert "Hello world in red\n")

;; do some blue
(send style-delta set-delta-foreground "blue")
(send text change-style style-delta)
(send text insert "Now available in blue\n")

;; do some modern
(send style-delta set-delta-foreground "black")
(send style-delta set-family 'modern)
(send text change-style style-delta)
(send text insert "Now available in modern\n(fixed width)")

(send frame show #t)
0

All Articles