summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2022-12-14 12:54:57 -0500
committerDavid Thompson <dthompson2@worcester.edu>2022-12-14 12:57:02 -0500
commit7239651fec6c268e0ac93ffa4fc7430329ce397e (patch)
treed4fc0f669d45f0dcbff80fd6b7769c7ca60b35f1
parentb14358dc829b1b866016c364219d59f1e34ba474 (diff)
node-2d: Fix placement/alignment methods to properly use local space.
-rw-r--r--catbird/node-2d.scm41
1 files changed, 29 insertions, 12 deletions
diff --git a/catbird/node-2d.scm b/catbird/node-2d.scm
index eb39b6b..ca5311e 100644
--- a/catbird/node-2d.scm
+++ b/catbird/node-2d.scm
@@ -655,38 +655,55 @@
(define* (place-right a b #:key (padding 0.0))
"Adjust B's x position coordinate so that it is PADDING distance to
the right of A."
- (set! (position-x b) (+ (position-x a) (width a) padding)))
+ (set! (position-x b)
+ (+ (local-x a) (local-width a) padding
+ (- (local-origin-x b) (local-x b)))))
(define* (place-left a b #:key (padding 0.0))
"Adjust B's x position coordinate so that it is PADDING distance to
the left of A."
- (set! (position-x b) (- (position-x a) (width b) padding)))
+ (set! (position-x b)
+ (- (local-x a) (local-width b) padding
+ (- (local-x b) (local-origin-x b)))))
(define* (place-above a b #:key (padding 0.0))
"Adjust B's y position coordinate so that it is PADDING distance above
A."
- (set! (position-y b) (+ (position-y a) (height a) padding)))
+ (set! (position-y b)
+ (+ (local-y a) (local-height a) padding
+ (- (local-origin-y b) (local-y b)))))
(define* (place-below a b #:key (padding 0.0))
"Adjust B's y position coordinate so that it is PADDING distance below
A."
- (set! (position-y b) (- (position-y a) (height b) padding)))
+ (set! (position-y b)
+ (- (local-y a) (local-height b) padding
+ (- (local-y b) (local-origin-y b)))))
+
+(define (align-right a b)
+ "Align the right side of B with the right side of A."
+ (set! (position-x b)
+ (+ (local-x a) (local-width a)
+ (- (local-origin-x b) (local-x b)))))
(define (align-left a b)
"Align the left side of B with the left side of A."
- (set! (position-x b) (position-x a)))
+ (set! (position-x b)
+ (- (local-x a)
+ (- (local-x b) (local-origin-x b)))))
-(define (align-right a b)
- "Align the right side of B with the right side of A."
- (set! (position-x b) (+ (position-x a) (width a))))
+(define (align-top a b)
+ "Align the top of B with the top of A."
+ (set! (position-y b)
+ (+ (local-y a) (local-height a)
+ (- (local-origin-y b) (local-y b)))))
(define (align-bottom a b)
"Align the bottom of B with the bottom of A."
- (set! (position-y b) (position-y a)))
+ (set! (position-y b)
+ (- (local-y a)
+ (- (local-y b) (local-origin-y b)))))
-(define (align-top a b)
- "Align the top of B with the top of A."
- (set! (position-y b) (+ (position-y a) (height a))))
;;;