Hi,

I'm trying to implement a toy graphical list editor program to get a
feel for GUI programming in racket. Basic idea is a graphical
representation of a list with text-field%s alternated with buttons to
insert items and on the side of each text-field% a button to remove that
item. When the program is destroyed it should print the constructed list
on the console (when started from one). My understanding so far calls
for a doubly-linked list to hold the items (and their graphical
manifestation), although this seems very unlispy... Is there a better way?

Sample code showing graphical layout and rudimentary functioning of the
program is attached.

Side-question: why does pressing an insert-button resize the top-level
frame%?

Any help appreciated,

Marijn

#lang racket/gui

(define f (new frame% [label "List Editor"]))

(define items (new vertical-pane% (parent f)))

(define (create-item val parent)
  (define v (new vertical-panel% (parent parent)))
  (define ins (new button% (parent v) (label "insert")
                   (callback (λ (b e) (create-item "" items))) ))
  (define h (new horizontal-pane% (parent v)))
  (define t (new text-field% (parent h) (label "") (init-value val)))
  (define del (new button% (parent h) (label "del")
                   (callback (λ (b e) (send parent delete-child v))) ))
  v)
   
(for-each (λ (v) (create-item v items)) '("1" "2" "3"))
   
(new button% (parent f) (label "append") (callback (λ (b e) (create-item "" 
items))))

(send f show #t)

Attachment: signature.asc
Description: OpenPGP digital signature

_________________________________________________
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Reply via email to