Advertisement
Guest User

tab-panel% example

a guest
Dec 21st, 2012
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 1.27 KB | None | 0 0
  1. #lang racket/gui
  2.  
  3. (define my-tab-panel%
  4.   (class tab-panel%
  5.     (super-new
  6.      [callback (λ(tp e)
  7.                  (send tp active-child (send tp get-selection)))])
  8.     (define child-panels '())
  9.     (define/public (add-child-panel p label)
  10.       (set! child-panels (append child-panels (list p)))
  11.       (send this append label)
  12.       ; without this, all the panels will be shown initially
  13.       ; (we only want the first child to be shown at first)
  14.       (when (> (length child-panels) 1)
  15.         (send this delete-child p)))
  16.    
  17.     (define/public (active-child n)
  18.       (send this change-children
  19.             (lambda (children)
  20.               (list (list-ref child-panels n)))))
  21.     ))
  22.  
  23. (define my-tab%
  24.   (class vertical-panel%
  25.     (init parent)
  26.     (init-field label)
  27.     (super-new [parent parent])
  28.     (send parent add-child-panel this label)
  29.     ))
  30.  
  31. (define f (new frame% [label "my-frame"]
  32.                       [min-width 200] [min-height 200]))
  33.  
  34. (define tp (new my-tab-panel% [parent f]
  35.                 [choices '()]))
  36. (define tab1 (new my-tab% [parent tp] [label "Tab 1"]))
  37. (define tab2 (new my-tab% [parent tp] [label "Tab 2"]))
  38.  
  39. (new button% [parent tab1] [label "Button 1"])
  40. (new message% [parent tab2] [label "Message"])
  41.  
  42. (send f show #t)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement