Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lang racket
- (require racket/gui/base)
- (require (planet williams/table-panel:1:2/table-panel))
- ; The top-level frame
- (define frame
- (instantiate frame%
- ("Test")))
- (define scrolling-panel
- (new vertical-panel%
- (parent frame)
- (style '(auto-hscroll auto-vscroll))))
- (define n-columns 10)
- (define n-rows 20)
- (define table-panel
- (new table-panel%
- (parent scrolling-panel)
- (alignment '(center center))
- (spacing 0)
- (column-stretchability #f)
- (row-stretchability #f)
- (stretchable-width #t)
- (stretchable-height #t)
- (horiz-margin 0)
- (vert-margin 0)
- (dimensions (list (+ 1 n-rows) (+ 1 n-columns)))
- ))
- (new button%
- (parent table-panel)
- (stretchable-width #t)
- (horiz-margin 0)
- (vert-margin 0)
- (label "/"))
- (for ((i (in-range n-columns)))
- (new button%
- (parent table-panel)
- (stretchable-width #t)
- (horiz-margin 0)
- (vert-margin 0)
- (label (number->string (+ 1 i)))))
- (define yellow-color (make-object color% 255 255 0))
- (define white-color (make-object color% 255 255 255))
- (define my-text-field%
- (class text-field%
- (super-new)
- (define/override (on-focus on?)
- (send this set-field-background (if on? yellow-color white-color)))
- (define/override (on-subwindow-char ctl event)
- (define key-code (send event get-key-code))
- (when (equal? key-code 'escape)
- ;; We can not just "unfocus" the text field,
- ;; so we send the focus to the main window instead
- (send frame focus))
- (super on-subwindow-char ctl event))
- ))
- (for ((j (in-range n-rows)))
- (new button%
- (parent table-panel)
- (horiz-margin 0)
- (vert-margin 0)
- (stretchable-width #t)
- (stretchable-height #t)
- (label (number->string (+ 1 j))))
- (for ((i (in-range n-columns)))
- (new my-text-field%
- (parent table-panel) (label #f)
- (horiz-margin 0)
- (vert-margin 0)
- (callback
- (lambda (ctl event)
- (define type (send event get-event-type))
- (when (equal? type 'text-field-enter)
- (send frame focus))))
- )))
- (send frame resize 600 400)
- (send frame show #t)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement