[plt-scheme] Snips in snips - help for aligned-pasteboard

From: Jens Axel Soegaard (jensaxel at soegaard.net)
Date: Sat Mar 28 12:39:27 EDT 2009

Hi,

The goal of the program below is to implement a column and
row snips. A column snip simply display its elements in a row.
The idea is to make it easy to display (mathematical) vectors,
matrices and other constructs directly in the DrScheme REPL.

I am almost there. This column is displayed as expected:

(column->snip (make-column (list "Foo" "Bar" "Baz")))

However, if I display a column, which contains other
columns, something goes wrong, and the sub-columns
are displayed as empty.

(column->snip
    (make-column
     (list "a"
           (make-column (list "1" "2" "3"))
           "b"
           (make-column (list "x" "y" "z"))
           "c"
           (make-column (list "!" "?" "@")))))

Any clues?

/Jens Axel



#lang scheme/gui
(require mrlib/aligned-pasteboard)

;;; COMMON

(define (make-string-snip string)
  (make-object string-snip% string))

(define (insert-snip editor snip)
   (send editor insert snip))

(define (insert-snips editor snips)
  (for-each (λ (s) (insert-snip editor s)) snips))

(define (realign aligned-pasteboard)
   (let ([min-width  (send aligned-pasteboard get-aligned-min-width)]
         [min-height (send aligned-pasteboard get-aligned-min-height)])
     (send aligned-pasteboard realign min-width min-height)))


(define (element->snip elem)
   (cond [(string? elem) (make-string-snip elem)]
         [(column? elem) (column->snip elem)]
         [else (error 'element->snip "Unknown element type")]))

;;;

(define-struct column (elements))

(define (column->snip col)
   (let* ([pasteboard  (new vertical-pasteboard%)]
          [editor-snip (new editor-snip% [editor pasteboard]
                            [min-width 1] [min-height 1])]
          [frame       (new frame% [label "never shown, needed by canvas"])]
          [canvas      (new aligned-editor-canvas%
                            [parent frame] [editor pasteboard])])
     (send editor-snip show-border #f)
     (insert-snips pasteboard
                   (reverse (map element->snip (column-elements col))))
     (realign pasteboard)
     editor-snip))

(column->snip (make-column (list "Foo" "Bar" "Baz")))

(column->snip
    (make-column
     (list "a"
           (make-column (list "1" "2" "3"))
           "b"
           (make-column (list "x" "y" "z"))
           "c"
           (make-column (list "!" "?" "@")))))


Posted on the users mailing list.