(module phone-buttons mzscheme (require (lib "class.ss") (lib "mred.ss" "mred")) (define ((make-button parent) label) (new button% [label (format "~a" label)] [parent parent])) (define frame (new frame% [label "test"])) (define row-1 (make-object horizontal-panel% frame)) (for-each (make-button row-1) '(1 2 3)) (define row-2 (make-object horizontal-panel% frame)) (for-each (make-button row-2) '(4 5 6)) (define row-3 (make-object horizontal-panel% frame)) (for-each (make-button row-3) '(7 8 9)) (define row-4 (make-object horizontal-panel% frame)) (for-each (make-button row-4) '(* 0 \#)) (send frame show #t))
(module simple-grid mzscheme (require (lib "class.ss") (lib "list.ss") (lib "plt-match.ss") (lib "mred.ss" "mred")) (provide simple-grid-panel%) (define simple-grid-panel% (class panel% (init [columns-per-row 3]) (define -columns-per-row columns-per-row) (super-new) (override container-size place-children) ;; container-size: (listof (list number number boolean boolean)) ;; -> (values number number) ;; Returns our container's minimum size, given the size of ;; the children. (define (container-size info) (let-values ([(child-width child-height) (uniform-child-size info)] [(number-of-rows) (ceiling (/ (length info) -columns-per-row))]) (values (* child-width -columns-per-row) (* child-height number-of-rows)))) ;; uniform-child-size: ;; (listof (list number number boolean boolean)) ;; -> (values number number) ;; returns the minimum width and height that all the children ;; can fit into. (define (uniform-child-size info) (let ([widths (map first info)] [heights (map second info)]) (values (apply max widths) (apply max heights)))) ;; place-children: (listof (list integer integer boolean boolean)) ;; integer integer -> ;; (listof (list integer integer integer integer) (define (place-children info width height) (let-values ([(child-width child-height) (uniform-child-size info)]) (let loop ([info info] [i 0]) (match info [(list (list width height horiz-stretch? vert-stretch?) rest ...) (cons (list (* child-width (remainder i -columns-per-row)) (* child-height (quotient i -columns-per-row)) width height) (loop rest (add1 i)))] [else empty])))))))
(define (phone-numbers) (define ((make-button parent) label) (new button% [label (format "~a" label)] [parent parent])) (define frame (new frame% [label "test"])) (define grid (new simple-grid-panel% [parent frame])) (for-each (make-button grid) '(1 2 3 4 5 6 7 8 9 * 0 \#)) (send frame show #t))
| CookbookForm | |
|---|---|
| TopicType: | Recipe |
| ParentTopic: | GUIRecipes |
| TopicOrder: | 999 |