From 426fd37f5f8b22c157628a26391b379b555abd0e Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 27 Dec 2022 08:56:24 -0500 Subject: node: Make rank mutable. --- catbird/node.scm | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/catbird/node.scm b/catbird/node.scm index c58f2ae..6899d7d 100644 --- a/catbird/node.scm +++ b/catbird/node.scm @@ -68,7 +68,7 @@ ) ;; An integer value that determines priority order for ;; updating/rendering. - (rank #:getter rank #:init-value 0 #:init-keyword #:rank) + (rank #:accessor rank #:init-value 0 #:init-keyword #:rank #:observe? #t) ;; List of children, sorted by rank. (children #:accessor children #:init-value '()) ;; Children indexed by name for fast lookup. @@ -78,9 +78,18 @@ (next-method) (on-boot node)) +(define-method (sort-children (node )) + (set! (children node) (sort-by-rank/ascending (children node)))) + (define-method (on-boot (node )) #t) +(define-method (on-change (node ) slot-name old new) + (case slot-name + ((rank) + ;; Re-sort parent when rank of child node changes. + (and=> (parent node) sort-children)))) + (define-method (reboot (node )) (for-each-child detach node) (with-agenda (agenda node) (reset-agenda)) @@ -147,8 +156,8 @@ new-children) ;; Add the new children and sort them by their rank so that ;; updating/rendering happens in the desired order. - (set! (children new-parent) - (sort-by-rank/ascending (append new-children (children new-parent)))) + (set! (children new-parent) (append new-children (children new-parent))) + (sort-children new-parent) ;; Attach children to the parent, triggering initial enter/attach ;; hooks. (for-each (lambda (child) -- cgit v1.2.3