Skip to content

Commit bd202ee

Browse files
committed
shapes: allow changing text args in stretched-glyph shape
1 parent 86c61c5 commit bd202ee

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

docs/manual.pdf

159 Bytes
Binary file not shown.

src/shapes.typ

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -566,23 +566,20 @@
566566
/// h(5mm)
567567
/// }
568568
///
569-
/// - size (length): Font size for the glyph, defining its overall scale without affecting its stretch length.
569+
/// - ..args (any): Arguments given to the `text()` element containing the glyph.
570+
/// Useful for changing color or the font size (defining overall scale without affecting its stretch length).
570571
///
571-
/// #for (i, size) in (1em, 2em, 5em).enumerate() {
572-
/// let s = fletcher.shapes.brace.with(size: size)
573-
/// let l = box(
572+
/// #diagram({
573+
/// let l(key, value) = box(
574574
/// stroke: (dash: "dashed", thickness: 0.5pt),
575575
/// inset: 10pt,
576-
/// raw("size: " + repr(size)),
576+
/// raw(key + ": " + value)
577577
/// )
578-
/// diagram(node((i, 0), l,
579-
/// inset: 0pt,
580-
/// shape: s,
581-
/// stroke: teal,
582-
/// fill: teal.lighten(90%),
583-
/// ))
584-
/// h(5mm)
585-
/// }
578+
/// let n(i, key, value) = node((i, 0), l(key, value),
579+
/// shape: fletcher.shapes.brace.with(..((key): eval(value))))
580+
/// n(1, "size", "3em")
581+
/// n(2, "fill", "red")
582+
/// })
586583
///
587584
/// - label (content): Content to be placed at the top/bottom/left/right of the glyph, depending on #param[stretched-glyph][dir].
588585
///
@@ -610,7 +607,7 @@
610607
/// h(5mm)
611608
/// }
612609
///
613-
#let stretched-glyph(node, extrude, glyph: sym.brace.b, dir: bottom, sep: 0pt, length: 100%, size: 1em, label: none, label-sep: 0.25em) = {
610+
#let stretched-glyph(node, extrude, glyph: sym.brace.b, dir: bottom, sep: 0pt, length: 100%, label: none, label-sep: 0.25em, ..args) = {
614611
assert(type(dir) == alignment, message: "Expected direction, got " + repr(type(dir)))
615612

616613
let (w, h) = node.size
@@ -628,7 +625,7 @@
628625
length = span*float(length.ratio) + length.length
629626

630627
let obj = {
631-
let stretched = text(size, $ stretch(glyph, size: #length) $)
628+
let stretched = text($ stretch(glyph, size: #length) $, ..args)
632629
draw.content(pos, stretched, anchor: dir-to-anchor(dir.inv()), name: "content")
633630

634631
if label != none {

tests/node/enclose/test.typ

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,9 @@ Nested enclose nodes
128128
#import fletcher.shapes
129129

130130
#diagram(
131-
// debug: 10,
132131
node-fill: blue.transparentize(80%),
133132
node((0,0), [1], name: <1>),
134133
edge("=>"),
135134
node((1,0.0), [2], name: <2>, shape: shapes.diamond),
136-
node(enclose: (<1>, <2>), shape: shapes.brace.with(dir: top, label: $f$), stroke: teal),
135+
node(enclose: (<1>, <2>), shape: shapes.brace.with(dir: top, label: $f$, fill: olive)),
137136
)

0 commit comments

Comments
 (0)