[plt-scheme] Layout and grids with MrEd?
Hi everyone,
I'm starting to write a tutorial on MrEd. (My motivating way to learn
something new is to try to explain it).
But I'm running into some awkward code that I want to fix before posting
this to the Schematics Cookbook. It involves writing a grid% class to
practice with simple geometry management:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define simple-grid%
(class object%
(init parent)
(init [columns-per-row 3])
(define -columns-per-row columns-per-row)
(define main-panel (new vertical-panel%
[parent parent]))
(super-new)
(define current-column-position (void))
(define current-row-panel (void))
(define (make-new-row!)
(set! current-row-panel
(new horizontal-panel%
[parent main-panel]
[alignment '(center center)]))
(set! current-column-position 0))
(make-new-row!)
(define/public (with-parent f)
(cond [(= current-column-position -columns-per-row)
(make-new-row!)
(with-parent f)]
[else
(f current-row-panel)
(set! current-column-position
(add1 current-column-position))]))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
The problem with it is that this grid% is not really a peer with the other
layout containers (horizontal-panel%, vertical-panel%), and rather than
writing the ideal code:
(define a-frame (new frame% [label ""]))
(define a-grid (new simple-grid% [parent a-frame]))
(for-each
(lambda (msg)
(new message% [label msg] [parent a-grid]))
'("this" "is" "a" "test" "hi" "mom"))
I'm instead writing:
(define a-frame (new frame% [label ""]))
(define a-grid (new simple-grid% [parent a-frame]))
(for-each
(lambda (msg)
(send a-grid with-parent
(lambda (p) (new message% [label msg] [parent p]))))
'("this" "is" "a" "test" "hi" "mom"))
I'm trying to compose panels together, but the result isn't observing the
closure property I want.
I've been reading through the MrEd documentation to see what I can do to
make *simple-grid%* a real container, and I suppose I should just bite the
bullet, inherit from *panel%*, and write *container-size* and
*place-children* methods as described in:
http://download.plt-scheme.org/doc/301/html/mred/mred-Z-H-3.html#node_sec_2.2.3
I was wondering if there were anything else I could do to reuse the
functionality that *horizontal-panel%* and *vertical-panel%* provide, or
if I'll have to just recode their logic.
Just in case people are interested in really rough drafts, here's what
I've written so far on a MrEd tutorial:
http://hkn.eecs.berkeley.edu/~dyoo/plt/mr-ed-notes.txt
I'm not linking it to my main site yet because they are in a really rough
state right now; I'm still fumbling toward proficiency.
Hope this helps!