Alex Cushing
Alex Cushing

Reputation: 286

How to wrap input text in text-field using the Racket GUI plugin

Just need a basic example of a text-field% that wraps input

(define blogPost%
  (class horizontal-panel%
    (super-new)
    (define (callback button event)
      (define title-new-value (send titleoutput get-value))
      (define new-value (send output get-value))
      (save title-new-value new-value))
      ;;(display title-new-value)
      ;;(display new-value))
    (define button (new button% (label "Submit")
                        (vert-margin 0)
                        (parent this)
                        (callback callback)))
    (define titleoutput (new text-field% (label "    title")
                             (min-height 20)
                             (min-width 200)
                             (parent this)))
    (define output (new text-field% (label "blog")
                        (min-height 450)
                        (min-width 400)
                        (stretchable-width 300)
                        (vert-margin 0)
                        (parent this)))
    ))


(define f (new frame% (label "prism blog post GUI") (min-width 400) (min-height 500)))

(define tib (new blogPost%
                 (parent f)))

(send f show #t)

there is more to this, basically it saves the user's input into a database which we are planning to have accessible and print to the screen. However, as is, the user when typing into the text field, just types horizontally on one line and it never word wraps and the enter button does not go to a new line. is this issue fixable?

Upvotes: 1

Views: 428

Answers (1)

Alex Knauth
Alex Knauth

Reputation: 8373

To allow multi-line inputs into a text field, you need to add [style '(multiple)] to the initialization arguments like this:

    (define output (new text-field% [label "blog"]
                        [style '(multiple)]
                        [min-height 450]
                        [min-width 400]
                        [stretchable-width 300]
                        [vert-margin 0]
                        [parent this]))

Then the text field allows newlines, and it wraps the text when a line gets too long.

The documentation for this is here. In that, it says:

There are two text field styles:

  • A single line of text is visible, and a special control event is generated when the user presses Return or Enter (when the text field has the focus) and the event is not handled by the text field’s frame or dialog (see on-traverse-char in top-level-window<%>).

  • Multiple lines of text are visible, and Enter is not handled specially.

Later, it specifies that the style argument is a list of symbols and says:

The style must contain exactly one of 'single or 'multiple; the former specifies a single-line field and the latter specifies a multiple-line field.

Upvotes: 1

Related Questions