-(define (stack-molecules axis dir padding mols)
+(define-public (stack-molecules axis dir padding mols)
"Stack molecules MOLS in direction AXIS,DIR, using PADDING."
(if (null? mols)
'()
(if (pair? mols)
- (ly-combine-molecule-at-edge (car mols) axis dir
+ (ly:molecule-combine-at-edge (car mols) axis dir
(stack-molecules axis dir padding (cdr mols))
padding
)
))
+(define-public (stack-lines dir padding baseline mols)
+ "Stack vertically with a baseline-skip."
+ (if (null? mols)
+ '()
+ (if (null? (cdr mols))
+ (car mols)
+ (ly:molecule-combine-at-edge (car mols) Y dir
+ (stack-lines dir padding baseline (cdr mols))
+ padding baseline
+ )
+ )))
-
-(define (fontify-text font-metric text)
+(define-public (fontify-text font-metric text)
"Set TEXT with font FONT-METRIC, returning a molecule."
- (let* ((b (ly-text-dimension font-metric text)))
- (ly-make-molecule
- (ly-fontify-atom font-metric `(text ,text)) (car b) (cdr b))
+ (let* ((b (ly:text-dimension font-metric text)))
+ (ly:make-molecule
+ (ly:fontify-atom font-metric `(text ,text)) (car b) (cdr b))
))
-(define (other-axis a)
- (remainder (+ a 1) 2))
-
-(define (bracketify-molecule mol axis thick protusion padding)
+(define-public (bracketify-molecule mol axis thick protusion padding)
"Add brackets around MOL, producing a new molecule."
- (let* (
- (ext (ly-get-molecule-extent mol axis))
- (lb (ly-bracket axis ext -1 thick protusion))
- (rb (ly-bracket axis ext 1 thick protusion))
- )
- (set! mol (ly-combine-molecule-at-edge mol (other-axis axis) 1 lb padding))
- (set! mol (ly-combine-molecule-at-edge mol (other-axis axis) -1 rb padding))
+ (let* ((ext (ly:molecule-get-extent mol axis))
+ (lb (ly:bracket axis ext thick (- protusion)))
+ (rb (ly:bracket axis ext thick protusion)))
+ (set! mol (ly:molecule-combine-at-edge mol (other-axis axis) 1 lb padding))
+ (set! mol (ly:molecule-combine-at-edge mol (other-axis axis) -1 rb padding))
mol
))
-
-
-(define (box-molecule xext yext)
+(define-public (make-filled-box-molecule xext yext)
"Make a filled box."
- (ly-make-molecule
+ (ly:make-molecule
(list 'filledbox (- (car xext)) (cdr xext)
(- (car yext)) (cdr yext))
xext yext)
)
-(define (widen-interval iv amount)
- (cons (- (car iv) amount)
- (+ (cdr iv) amount))
-)
+
+(define-public (box-grob-molecule grob)
+ "Make a box of exactly the extents of the grob. The box precisely
+encloses the contents.
+"
+ (let* ((xext (ly:get-extent grob grob 0))
+ (yext (ly:get-extent grob grob 1))
+ (thick 0.1))
+
+ (ly:molecule-add (make-filled-box-molecule xext (cons (- (car yext) thick) (car yext) ))
+ (make-filled-box-molecule xext (cons (cdr yext) (+ (cdr yext) thick) ))
+ (make-filled-box-molecule (cons (cdr xext) (+ (cdr xext) thick)) yext)
+ (make-filled-box-molecule (cons (- (car xext) thick) (car xext)) yext))))
-(define (box-grob-molecule grob)
- "Make a box of exactly the extents of the grob."
- (let* ((xext (ly-get-extent grob grob 0))
- (yext (ly-get-extent grob grob 1))
- (mol (ly-make-molecule '() '(10000 . -10000) '(10000 . -10000)))
- (thick 0.1)
+;; TODO merge this and prev function.
+(define-public (box-molecule mol thick padding)
+ "Add a box around MOL, producing a new molecule."
+ (let* (
+ (x-ext (interval-widen (ly:molecule-get-extent mol 0) padding))
+ (y-ext (interval-widen (ly:molecule-get-extent mol 1) padding))
+ (y-rule (make-filled-box-molecule (cons 0 thick) y-ext))
+ (x-rule (make-filled-box-molecule (interval-widen x-ext thick)
+ (cons 0 thick)))
)
- (display "hoi")
- (set! mol (ly-add-molecule mol (box-molecule xext (cons (car yext) (+ (car yext) thick)))))
- (set! mol (ly-add-molecule mol (box-molecule xext (cons (- (cdr yext) thick) (cdr yext)))))
- (set! mol (ly-add-molecule mol (box-molecule (cons (car xext) (+ (car xext) thick)) yext)))
- (set! mol (ly-add-molecule mol (box-molecule (cons (- (cdr xext) thick) (cdr xext)) yext)))
- mol
- ))
+ (set! mol (ly:molecule-combine-at-edge mol X 1 y-rule padding))
+ (set! mol (ly:molecule-combine-at-edge mol X -1 y-rule padding))
+ (set! mol (ly:molecule-combine-at-edge mol Y 1 x-rule 0.0))
+ (set! mol (ly:molecule-combine-at-edge mol Y -1 x-rule 0.0))
+
+ mol))