Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list-view: avoid more work when keys don't change #58

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions gui-easy-lib/gui/easy/private/view/list.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,15 @@
[stretchable-height h-s?]))
(define keys-to-children
(get-keys-to-children the-panel))
(define entries (peek @entries))
(define keys (map key-proc entries))
(send the-panel set-context 'current-keys keys)
(begin0 the-panel
(with-container-sequence the-panel
(for ([e (in-list (peek @entries))])
(define k (key-proc e))
(for ([e (in-list entries)]
[k (in-list keys)])
(define v (make-view k (make-keyed-obs k e)))
(define w (send v create the-panel))
(define w (send v create the-panel)) ;; noqa
(add-child-handlers! the-panel v)
(add-child the-panel v w)
(hash-set! keys-to-children k v)))))
Expand All @@ -122,8 +125,10 @@
(add-child-handlers! v child-v)
(add-child v child-v child-w)
(hash-set! keys-to-children k child-v)))))
(for ([(old-k old-v) (in-hash keys-to-children)])
(unless (member old-k new-keys)
(unless (equal? new-keys (send v get-context 'current-keys null))
(send v set-context 'current-keys new-keys)
(for ([(old-k old-v) (in-hash keys-to-children)]
#:unless (member old-k new-keys))
(define old-w (get-child v old-v))
(define focused? (send old-w has-focus?))
(send old-v destroy old-w)
Expand All @@ -135,11 +140,11 @@
(define children (send v get-children))
(cond
[(null? children) (send v focus)]
[else (send (last children) focus)]))))
(send v change-children
(λ (_)
(for/list ([k (in-list new-keys)])
(get-child v (hash-ref keys-to-children k))))))]
[else (send (last children) focus)])))
(send v change-children
(λ (_)
(for/list ([k (in-list new-keys)])
(get-child v (hash-ref keys-to-children k)))))))]
[@alignment
(send/apply v set-alignment val)]
[@enabled?
Expand Down
Loading