Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Dynamic Item Selection
#lang racket/gui
(define font-faces (get-face-list))
(define my-combo-field%
(class combo-field%
(define (construct-menu)
(let ((menu (send this get-menu))
(prefix (send this get-value)))
(for ([item (in-list (send menu get-items))])
(send item delete))
(for ([face (in-list font-faces)] #:when (string-prefix? face prefix))
(new menu-item% [parent menu]
[label face]
[callback (lambda (c e) (send this set-value face))]))))
(define/override (on-popup event)
(super on-popup event)
(define f (new frame% [label "Hello"] [width 400] [height 600]))
(define option1 (new group-box-panel% [parent f]
[label "Option 1"]
[border 10]
[stretchable-height #f]))
(define my-combo (new my-combo-field% [parent option1] [label "A combo"] [choices '()]))
(define option2 (new group-box-panel% [parent f]
[label "Option 2"]
[border 10]))
(define my-lb #f)
(define (on-filter c e)
(define prefix (send c get-value))
(when my-lb
(define candidates (filter (lambda (face) (string-prefix? face prefix)) font-faces))
(send my-lb set candidates)))
(define my-text-field (new text-field% [parent option2] [label "Filter"] [callback on-filter]))
(set! my-lb (new list-box% [parent option2] [label "Fonts"] [choices font-faces]))
(send f show #t)

This comment has been minimized.

Copy link
Owner Author

alex-hhh commented Feb 15, 2019


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.