summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2022-12-27 08:56:24 -0500
committerDavid Thompson <dthompson2@worcester.edu>2022-12-27 08:56:31 -0500
commit426fd37f5f8b22c157628a26391b379b555abd0e (patch)
tree93f607d6b7567d9d1a4f9f8abff1325483381eec
parent985cd0fdb9d120d2e923c6b9928c0fe863e6c7ce (diff)
node: Make rank mutable.
-rw-r--r--catbird/node.scm15
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)