start fiddling with layout

main
Matthew Butterick 3 years ago
parent e9955c9d25
commit 1f537a1233

@ -8,13 +8,13 @@
($point? $size? . -> . $point?)
($point (+ ($point-x p0) ($size-width p1)) (+ ($point-y p0) ($size-height p1))))
(define/contract (size char)
(define/contract (size q)
(quad? . -> . $size?)
($size 1 1))
(quad-size q))
(define/contract (advance char)
(define/contract (advance q)
(quad? . -> . $size?)
($size 1 0))
(quad-size q))
(define (min-x rect) ($point-x ($rect-origin rect)))
(define (width rect) ($size-width ($rect-size rect)))
@ -44,6 +44,11 @@
(and (<= (min-x outer-aRect) (min-x inner-bRect)) (<= (max-x inner-bRect) (max-x outer-aRect))
(<= (min-y outer-aRect) (min-y inner-bRect)) (<= (max-y inner-bRect) (max-y outer-aRect))))
(define (make-debug-size q)
;; TODO: calculate real size. This is temp to make layout loop work
(set-quad-size! q ($size (length (or (quad-elems q) null)) 0))
q)
(define-pass (layout qs)
#:pre (list-of has-no-position?)
#:post (list-of has-position?)
@ -51,8 +56,9 @@
(define (quad-fits? q posn)
(rect-contains-rect? frame ($rect posn (size q))))
(for/fold ([posn0 ($point 0 0)]
#:result qs)
([q (in-list qs)])
#:result (filter has-position? qs))
([q (in-list (map make-debug-size qs))]
#:when (quad-size q))
(define first-posn-on-next-line ($point 0 (add1 ($point-y posn0))))
(define other-possible-posns (list first-posn-on-next-line))
(define posn1 (for/first ([posn (in-list (cons posn0 other-possible-posns))]
@ -60,5 +66,5 @@
posn))
(unless posn1
(error 'no-posn-that-fits))
(set-quad-posn! q posn1)
(set-quad-origin! q posn1)
(posn-add posn1 (advance q))))
Loading…
Cancel
Save