[racket] GUI: text field on a canvas

From: Dmitry Pavlov (dpavlov at ipa.nw.ru)
Date: Thu Jul 17 16:22:29 EDT 2014

Hello,

I have the need to put a text field into a certain location of a canvas,
without decorations.
What I came up with so far is:

#lang racket
(require racket/gui)

(define frame (new frame% (label "Test")))
(define pasteboard (new pasteboard%))

(define editor-canvas
  (new editor-canvas%
       (editor pasteboard)
       (parent frame)
       (style '(no-border no-hscroll no-vscroll))))

(define t (new text%))
(define ts
  (new editor-snip%
       (editor t)
       (left-margin 0)
       (right-margin 0)
       (top-margin 0)
       (bottom-margin 0)
       (with-border? #t)))
(send pasteboard insert ts 0 0)

(define yellow-delta (send (make-object style-delta%)
                           set-delta-background (make-object color% "yellow")))
(send t change-style yellow-delta)
(send pasteboard set-caret-owner ts)

(send frame resize 100 100)
(send frame show #t)


Two questions:

1. Is it the most natural way to do what I need?
(I also looked into embedded-gui but did not find
anything that looks like an embedded text field).

2. What I see is:
http://imgur.com/Ws4R140
It is obvious that the text is off the (0,0) point where
it should be by about 5 pixels by x and y.
I tried placing it in (-5, -5) and got this:
http://imgur.com/WrSE1qG
Setting (with-border? #f) did not help.
How can it be fixed?

Best regards,

Dmitry

Posted on the users mailing list.