Skip to content

Instantly share code, notes, and snippets.

@Metaxal
Last active July 23, 2023 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Metaxal/81b5451c7919a06c6a1f8b791b41a740 to your computer and use it in GitHub Desktop.
Save Metaxal/81b5451c7919a06c6a1f8b791b41a740 to your computer and use it in GitHub Desktop.
Usage example of tab-panel%
#lang racket/gui
(define fr (new frame% [label "Tab example"]))
(define (tab-panel-set-tab tp idx)
(send tp change-children
(λ (previous-children)
(list (list-ref tab-contents idx)))))
(define tp (new tab-panel%
[parent fr]
[choices '()]
[callback
;; When the user clicks on a tab, change the children.
(λ (tp ev)
(when (eq? (send ev get-event-type) 'tab-panel)
(tab-panel-set-tab tp (send tp get-selection))))]))
;; A list of tab "contents"
;; In reality, a tab-panel does not "contain" actual tabs, apart from the tab labels at the top.
;; It's the designer's duty to change the children of the tab panel when a tab is changed.
(define tab-contents
(for/list ([i 4])
(send tp append (format "Tab ~a" i))
(define tab
(new panel% [parent tp]
[min-width 400]
[min-height 300]))
(new message% [parent tab] [label (format "This is tab ~a" i)])
tab))
(send tp change-children (λ _ (list (first tab-contents))))
(send tp focus)
;; Change to tab programmatically:
(new button% [parent fr] [label "Change to tab 2"]
[callback (λ (bt ev)
(send tp set-selection 2)
(tab-panel-set-tab tp 2))])
(send fr show #t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment