diff options
-rw-r--r-- | catbird/node.scm | 15 |
1 files 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 @@ <observer> <asset-container>) ;; 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 <node>)) + (set! (children node) (sort-by-rank/ascending (children node)))) + (define-method (on-boot (node <node>)) #t) +(define-method (on-change (node <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 <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) |