How would you implement that?<br><br><br><br>Another iteration<br><br><br>#lang scheme/gui<br><br>(define grid-pasteboard%<br> (class pasteboard%<br> (init-field w h)<br> (define/override (insert snip r c) (super insert snip (* c w) (* r h)))<br>
(super-new)))<br><br><br>;; accepts data-grid (list of columns)<br>(define data-grid-pasteboard%<br> (class pasteboard%<br> (init-field data-grid<br> (col-widths '(75 55 65))<br> (row-height 16)<br>
)<br> <br> ;; create new list that is the cumulative sum of the source list<br> (define (cumulative-sums offsets)<br> (foldl (lambda (offset cum-list) <br> (append cum-list (list (+ offset (last cum-list)))))<br>
(list 0) ; start from 0<br> offsets))<br> ;; column widths -> col offsets <br> (define (column-offsets col-widths)<br> (cumulative-sums (drop-right col-widths 1)))<br> ;; <br> <br>
(define col-offset<br> (let ((offsets (column-offsets col-widths)))<br> (lambda (col) (list-ref offsets col))))<br> ;; rows are all the same height<br> (define (row-offset row)<br> (* row row-height))<br>
;; initialise pasteboard<br> <br> (define/override (insert snip row col) <br> (super insert snip (col-offset col) (row-offset row)))<br> (define (grid-ref datagrid row col)<br> (list-ref (list-ref datagrid col) row)<br>
)<br> (super-new)<br> (for ([col (in-range (length data-grid))])<br> (for ([row (in-range (length (car data-grid)))])<br> (insert (make-object string-snip% (grid-ref data-grid row col))<br> row col)<br>
))<br> <br> ))<br>(define f (new frame% [label "Simple Edit"]<br> [width 200]<br> [height 200]))<br>(define c (new editor-canvas% [parent f]))<br>(define t (new grid-pasteboard% (w 66) (h 16)))<br>
(send t insert (make-object string-snip% "at23") 2 3)<br>(send t insert (make-object string-snip% "at23") 2 2)<br>(send t insert (make-object string-snip% "at23") 3 2)<br>(send t insert (make-object string-snip% "at23") 1 1)<br>
(send t insert (make-object string-snip% "at23") 0 0)<br>(send c set-editor t)<br>(send f show #t)<br><br>;; <br><br>(define f2 (new frame% [label "Simple Edit"]<br> [width 200]<br> [height 200]))<br>
(define c2 (new editor-canvas% [parent f2]))<br>(define t2 (new data-grid-pasteboard% <br> (data-grid <br> '(("name" "Stephen" "Patrick")<br> ("age" "39" "38")<br>
("eye-colour" "green" "blue")<br> ))))<br>(send c2 set-editor t2)<br>(send f2 show #t)<br><br><br><div class="gmail_quote">On Tue, Sep 8, 2009 at 2:01 PM, praimon <span dir="ltr"><<a href="mailto:praimon@gmail.com">praimon@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi,<br>
Thanks for your work. It seems we have this conversation every year or two.<br>
One of the most important features of the directory-table widget is the ability<br>
to manually resize the columns. Otherwise, either some of the data will be<br>
hidden/lost or the table needs to be too large (so as to accomodate<br>
any conceivable<br>
data entry).<br>
regards,<br>
<font color="#888888">praimon<br>
</font><div><div></div><div class="h5"><br>
On Tue, Sep 8, 2009 at 2:15 AM, Stephen De<br>
Gabrielle<<a href="mailto:spdegabrielle@gmail.com">spdegabrielle@gmail.com</a>> wrote:<br>
> Hi, people have asked about a data grid on this list a few times.<br>
><br>
> This is the simplest possible approach. I've tried and abandoned other<br>
> approaches when I realised they were too much work for my available free<br>
> time.<br>
><br>
> Comments appreciated.<br>
><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><br>--<br>Stephen De Gabrielle<br><a href="mailto:stephen.degabrielle@acm.org">stephen.degabrielle@acm.org</a><br>Telephone +44 (0)20 85670911<br>Mobile +44 (0)79 85189045<br>
<a href="http://www.degabrielle.name/stephen">http://www.degabrielle.name/stephen</a><br><br>