diff options
author | David Thompson <dthompson2@worcester.edu> | 2022-12-14 12:55:58 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2022-12-14 12:57:02 -0500 |
commit | a041ba88379729537cf1042d57a6c8bcfc269e5c (patch) | |
tree | 9285fa8ab0976d8457e2822c65e725342013a5c1 | |
parent | 7239651fec6c268e0ac93ffa4fc7430329ce397e (diff) |
node-2d: Add centering methods.
-rw-r--r-- | catbird/node-2d.scm | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/catbird/node-2d.scm b/catbird/node-2d.scm index ca5311e..0a1f683 100644 --- a/catbird/node-2d.scm +++ b/catbird/node-2d.scm @@ -55,6 +55,9 @@ align-left align-right align-top + center + center-horizontal + center-vertical default-height default-width expire-local-matrix @@ -704,6 +707,24 @@ A." (- (local-y a) (- (local-y b) (local-origin-y b))))) +(define (center-horizontal a b) + "Move the x position of A so that it is centered with B." + (set! (position-x b) + (+ (local-x a) + (/ (- (local-width a) (local-width b)) 2.0) + (- (local-x b) (local-origin-x b))))) + +(define (center-vertical a b) + "Move the y position of A so that it is centered with B." + (set! (position-y b) + (+ (local-y a) + (/ (- (local-height a) (local-height b)) 2.0) + (- (local-y b) (local-origin-y b))))) + +(define (center a b) + "Center B within A." + (center-horizontal a b) + (center-vertical a b)) ;;; |