[racket] toy graphical list editor

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon May 23 23:02:07 EDT 2011

At Mon, 23 May 2011 16:04:24 +0200, Marijn wrote:
> 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?

My preference for this sort of problem is to abandon MVC and let the
GUI represent the model. That is, to build the result list in this
case, I'd traverse the GUI hierarchy to extract the elements.

To keep the model separate, though, I don't have a better suggestion
than a doubly-linked list.

> 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%?

When a text field has a non-empty string as its initial value, the
minimum width is based on the string. If the initial value is an empty
string, then a default is used, and the default turns out to be wider
than one character. The "insert" buttons create empty fields, while the
three initial fields have non-empty initial content.

Posted on the users mailing list.