Hi Matthew,

On 05/24/11 05:02, Matthew Flatt wrote:
> 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.

After changing all the values to "1", when pressing an insert-button
*sometimes* the window is resized horizontally (slightly larger width)
and *sometimes* the window flickers to slightly larger horizontally, but
remains the same width. According to `get-graphical-min-size' the
horizontal width stays constant at, for me, 58. I wrote another program
which exhibits this flickering behavior for me which I attached. Again
the size output seems to be fine, at least on the granularity
instrumented. Is this expected behavior?

Thanks,

Marijn
#lang racket/gui

(define (get-size)
  (call-with-values (lambda ()(send items get-graphical-min-size))
                    (λ (a b) (write a)(display " ,  ")(write b)(newline)) ))

(define f (new frame% [label "List Editor"]))
(define items (new vertical-pane% (parent f))) (get-size)

;(un)comment this line to change the smaller size of the flicker
;(new text-field% (parent f) (label "") (init-value "1")) (get-size)

(send f show #t) (get-size)

(for-each (λ (v)
            (get-size)
            (new text-field% (parent items) (label "") (init-value 
(number->string v))))
          '(1 2 2 3 4 4 5 2 2 3 4 3 4 2 3 4 2 5 1 2 4 1 5 2 3 4 3 3 4))

Attachment: signature.asc
Description: OpenPGP digital signature

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

Reply via email to