Created
February 15, 2019 01:49
-
-
Save alex-hhh/20f03dcf2f7f340d20b95cb36da39f61 to your computer and use it in GitHub Desktop.
Dynamic Item Selection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) | |
(construct-menu)) | |
(init) | |
(super-new) | |
)) | |
(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) |
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