From a041ba88379729537cf1042d57a6c8bcfc269e5c Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 14 Dec 2022 12:55:58 -0500 Subject: node-2d: Add centering methods. --- catbird/node-2d.scm | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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)) ;;; -- cgit v1.2.3