]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/snippets/new/three-sided-box.ly
Issue 5148/2: three-sided-box snippet: use #:properties keyword
[lilypond.git] / Documentation / snippets / new / three-sided-box.ly
1 \version "2.18.0"
2
3 \header {
4   lsrtags = "rhythms, scheme-language, text"
5
6   texidoc = "
7 This example shows how to add a markup command to get a three sided box
8 around some text (or other markup).
9
10 "
11   doctitle = "Three-sided box"
12 }
13 % New command to add a three sided box, with sides north, west and south
14 % Based on the box-stencil command defined in scm/stencil.scm
15 % Note that ";;" is used to comment a line in Scheme
16 #(define-public (NWS-box-stencil stencil thickness padding)
17    "Add a box around STENCIL, producing a new stencil."
18    (let* ((x-ext (interval-widen (ly:stencil-extent stencil X) padding))
19           (y-ext (interval-widen (ly:stencil-extent stencil Y) padding))
20           (y-rule (make-filled-box-stencil (cons 0 thickness) y-ext))
21           (x-rule (make-filled-box-stencil
22                    (interval-widen x-ext thickness) (cons 0 thickness))))
23      ;; (set! stencil (ly:stencil-combine-at-edge stencil X 1 y-rule padding))
24      (set! stencil (ly:stencil-combine-at-edge stencil X LEFT y-rule padding))
25      (set! stencil (ly:stencil-combine-at-edge stencil Y UP x-rule 0.0))
26      (set! stencil (ly:stencil-combine-at-edge stencil Y DOWN x-rule 0.0))
27      stencil))
28
29 % The corresponding markup command, based on the \box command defined
30 % in scm/define-markup-commands.scm
31 #(define-markup-command (NWS-box layout props arg) (markup?)
32    #:properties ((thickness 0.1) (font-size 0) (box-padding 0.2))
33    "Draw a box round @var{arg}.  Looks at @code{thickness},
34 @code{box-padding} and @code{font-size} properties to determine line
35 thickness and padding around the markup."
36    (let ((pad (* (magstep font-size) box-padding))
37          (m (interpret-markup layout props arg)))
38      (NWS-box-stencil m thickness pad)))
39
40 % Test it:
41
42 \relative c' {
43   c1^\markup { \NWS-box ABCD }
44   c1^\markup { \NWS-box \note #"4" #1.0 }
45 }