summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2021-04-16 08:43:52 -0400
committerDavid Thompson <dthompson2@worcester.edu>2021-04-16 08:43:52 -0400
commit1a2554e59ec394b56dad3417cf20002c84050278 (patch)
tree4b93718abcd1744381911777bd056ce46ffb5725
parent85995bba37b45e937d31d1f955729fab49f3e7df (diff)
node: Add replace method.
-rw-r--r--starling/node.scm9
1 files changed, 9 insertions, 0 deletions
diff --git a/starling/node.scm b/starling/node.scm
index dd5749c..cbb1027 100644
--- a/starling/node.scm
+++ b/starling/node.scm
@@ -59,6 +59,7 @@
on-attach
on-detach
attach-to
+ replace
detach
run-script
stop-scripts
@@ -349,6 +350,14 @@
(on-attach new-parent child))
new-children))
+(define-method (replace (parent-node <node>) . replacements)
+ (for-each (lambda (replacement)
+ (let ((old (child-ref parent-node (name replacement))))
+ (when old
+ (detach old))))
+ replacements)
+ (apply attach-to parent-node replacements))
+
(define-method (detach (node <node>))
(let ((p (parent node)))
(when p