[racket] Text snip bleaches canvas space that does not belong to it
Hello,
I need a text snip on a canvas that paints itself strictly in some defined WxH bounds.
I need no interactive moving or resizing, only interactive editing.
Here is a code I have come up with, which also displays a window with the snip and a grid.
The grid facilitates the visual check of the text snip bounds.
(require racket/gui
racket/draw)
(define my-pasteboard%
(class pasteboard%
(super-new)
(define/augment (can-select? snip on?)
#f)
(define/augment (can-interactive-move? snip)
#f)
(define/augment (can-interactive-resize? snip)
#f)))
(define frame (new frame% (label "Test")))
(define pasteboard (new my-pasteboard%))
(define my-canvas%
(class editor-canvas%
(super-new)
(define/override (on-paint)
(super on-paint)
(define dc (send this get-dc))
;; Draw a 10x10 grid with cell size 20x20 pixels
(for ((x (in-range 10))) (send dc draw-line (* x 20) 0 (* x 20) 200))
(for ((y (in-range 10))) (send dc draw-line 0 (* y 20) 200 (* y 20)))
)))
(define editor-canvas
(new my-canvas%
(editor pasteboard)
(vertical-inset 0) (horizontal-inset 0)
(parent frame)
(style '(no-border no-hscroll no-vscroll))))
(send frame resize 200 200)
(send frame show #t)
(define text-obj (new text%))
(send text-obj insert "Hello" 0)
(define text-snip (new editor-snip%
(editor text-obj)
(left-margin 0) (right-margin 0) (top-margin 0) (bottom-margin 0)
(left-inset 0) (right-inset 0) (top-inset 0) (bottom-inset 0)
(with-border? #f)
(min-width 40)
(max-width 40)
(min-height 20)
(max-height 20)))
(send pasteboard insert text-snip 40 60)
(send pasteboard set-caret-owner text-snip)
When I click on the snip in the window and try to add a "!" character after
the "Hello" text, I get this:
http://imgur.com/cikwlqh
It is obvious that the text snip (or something associated with it)
expanded its supposed area of rendering by 3-4 pixels in all directions.
And if I do silly things, like pressing "Enter", things get even worse.
Can that be avoided somehow?
Best regards,
Dmitry