[racket] GUI: text field on a canvas

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Fri Jul 18 01:22:15 EDT 2014

You can put the text% object directly into the editor-canvas if you want.
Also, the 5 pixels is part of the margin I believe and you can set it to 0
if you want.

Robby

On Friday, July 18, 2014, Dmitry Pavlov <dpavlov at ipa.nw.ru> wrote:

> 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
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140718/b86af699/attachment-0001.html>

Posted on the users mailing list.