Skip to content

Commit dee836d

Browse files
authored
[add] missing styling options (#44)
1 parent af838f4 commit dee836d

File tree

5 files changed

+78
-21
lines changed

5 files changed

+78
-21
lines changed

src/decorations.typ

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33

44
// align: "left" (for rstick) or "right" (for lstick)
55
// brace: auto, none, "{", "}", "|", "[", ...
6-
#let lrstick(content, n, align, brace, label, pad: 0pt, x: auto, y: auto) = gate(
6+
#let lrstick(content, n, align, brace, label, pad: 0pt, x: auto, y: auto, fill: auto) = gate(
77
content,
88
x: x,
99
y: y,
1010
draw-function: draw-functions.draw-lrstick,
1111
size-hint: layout.lrstick-size-hint,
1212
box: false,
13+
fill: fill,
1314
floating: true,
1415
multi: if n == 1 { none } else {
1516
(
@@ -64,6 +65,10 @@
6465
/// -> length
6566
pad: 0pt,
6667

68+
/// How to color the brace.
69+
/// -> auto | color
70+
fill: auto,
71+
6772
/// One or more labels to add to the gate. See @gate.label.
6873
/// -> none | array | str | content | dictionary
6974
label: none,
@@ -72,7 +77,7 @@
7277

7378
y: auto
7479

75-
) = lrstick(body, n, right, brace, label, pad: pad, x: x, y: y)
80+
) = lrstick(body, n, right, brace, label, pad: pad, x: x, y: y, fill: fill)
7681

7782

7883

@@ -109,6 +114,10 @@
109114
/// -> length
110115
pad: 0pt,
111116

117+
/// How to color the brace.
118+
/// -> auto | color
119+
fill: auto,
120+
112121
/// One or more labels to add to the gate. See @gate.
113122
/// -> none | array | str | content | dictionary
114123
label: none,
@@ -117,7 +126,7 @@
117126

118127
y: auto
119128

120-
) = lrstick(body, n, left, brace, label, pad: pad, x: x, y: y)
129+
) = lrstick(body, n, left, brace, label, pad: pad, x: x, y: y, fill: fill)
121130

122131

123132

src/draw-functions.typ

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,26 @@
9090
#let draw-targ(item, draw-params) = {
9191
let size = item.data.size
9292
box({
93+
set circle(stroke: draw-params.wire)
94+
set line(stroke: draw-params.wire)
95+
set circle(stroke: item.stroke) if item.stroke != auto
96+
set line(stroke: item.stroke) if item.stroke != auto
9397
circle(
9498
radius: size,
95-
stroke: draw-params.wire,
9699
fill: utility.if-auto(item.fill, draw-params.background)
97100
)
98-
place(line(start: (size, 0pt), length: 2*size, angle: -90deg, stroke: draw-params.wire))
99-
place(line(start: (0pt, -size), length: 2*size, stroke: draw-params.wire))
101+
place(line(start: (size, 0pt), length: 2*size, angle: -90deg))
102+
place(line(start: (0pt, -size), length: 2*size))
100103
})
101104
}
102105

103106
#let draw-ctrl(gate, draw-params) = {
104107
let color = utility.if-auto(gate.fill, draw-params.color)
105108
if "show-dot" in gate.data and not gate.data.show-dot { return none }
106109
if gate.data.open {
107-
let stroke = utility.if-auto(gate.fill, draw-params.wire)
108-
box(circle(stroke: stroke, fill: draw-params.background, radius: gate.data.size))
110+
let stroke = utility.update-stroke(draw-params.wire, gate.stroke)
111+
let fill = utility.if-auto(gate.fill, draw-params.background)
112+
box(circle(stroke: stroke, fill: fill, radius: gate.data.size))
109113
} else {
110114
box(circle(fill: color, radius: gate.data.size))
111115
}
@@ -114,10 +118,11 @@
114118
#let draw-swap(gate, draw-params) = {
115119
box({
116120
let d = gate.data.size
117-
let stroke = draw-params.wire
121+
set line(stroke: draw-params.wire)
122+
set line(stroke: gate.stroke) if gate.stroke != auto
118123
box(width: d, height: d, {
119-
place(line(start: (-0pt, -0pt), end: (d, d), stroke: stroke))
120-
place(line(start: (d, 0pt), end: (0pt, d), stroke: stroke))
124+
place(line(start: (-0pt, -0pt), end: (d, d)))
125+
place(line(start: (d, 0pt), end: (0pt, d)))
121126
})
122127
})
123128
}
@@ -149,6 +154,8 @@
149154
set align(top)
150155
set curve(stroke: draw-params.wire)
151156
set line(stroke: draw-params.wire)
157+
set curve(stroke: gate.stroke) if gate.stroke != auto
158+
set line(stroke: gate.stroke) if gate.stroke != auto
152159
set rect(width: width, height: height)
153160

154161
utility.if-auto(gate.content, meter-symbol)
@@ -241,7 +248,10 @@
241248
if brace-symbol == auto and gate.multi == none {
242249
brace-symbol = none
243250
}
244-
brace = utility.create-brace(brace-symbol, gate.data.align, brace-height)
251+
brace = {
252+
set text(gate.fill) if gate.fill != auto
253+
utility.create-brace(brace-symbol, gate.data.align, brace-height)
254+
}
245255
}
246256

247257
let brace-size = measure(brace)

src/gates.typ

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@
310310
/// -> none | int
311311
target: none,
312312

313+
/// How to stroke the meter.
314+
/// -> auto | stroke
315+
stroke: auto,
316+
313317
/// The number of qubits that the meter spans.
314318
/// -> int
315319
n: 1,
@@ -346,9 +350,9 @@
346350
}
347351
label = process-args.process-label-arg(label, default-dy: 0.5em, default-pos: top)
348352
if target == none and n == 1 {
349-
gate(body, x: x, y: y, fill: fill, radius: radius, draw-function: draw-functions.draw-meter, label: label)
353+
gate(body, x: x, y: y, fill: fill, stroke: stroke, radius: radius, draw-function: draw-functions.draw-meter, label: label)
350354
} else {
351-
mqgate(body, x: x, y: y, n: n, target: target, fill: fill, radius: radius, box: true, wire-count: wire-count, wire-stroke: wire-stroke, draw-function: draw-functions.draw-meter, label: label)
355+
mqgate(body, x: x, y: y, n: n, target: target, fill: fill, stroke: stroke, radius: radius, box: true, wire-count: wire-count, wire-stroke: wire-stroke, draw-function: draw-functions.draw-meter, label: label)
352356
}
353357
}
354358

@@ -484,6 +488,10 @@
484488
/// -> none | auto | color | gradient | tiling
485489
fill: none,
486490

491+
/// How to stroke the target.
492+
/// -> auto | stroke
493+
stroke: auto,
494+
487495
/// Radius of the target symbol.
488496
/// -> length
489497
size: 4.3pt,
@@ -521,6 +529,7 @@
521529
wire-count: wire-count,
522530
wire-stroke: wire-stroke,
523531
fill: if fill == true {auto} else if fill == false {none} else {fill},
532+
stroke: stroke,
524533
data: (size: size),
525534
label: label,
526535
wire-label: wire-label
@@ -546,10 +555,15 @@
546555
/// -> bool
547556
open: false,
548557

549-
/// How to fill or stroke the circle if `open: true`.
550-
/// -> none | color | stroke
558+
/// How to fill the circle.
559+
/// -> auto | none | color
551560
fill: auto,
552561

562+
563+
/// How to stroke the circle if `open: true`.
564+
/// -> auto | stroke | color
565+
stroke: auto,
566+
553567
/// The radius of the circle.
554568
/// -> length
555569
size: 2.3pt,
@@ -568,6 +582,7 @@
568582
draw-functions.draw-ctrl(gate, draw-params)
569583
),
570584
fill: fill,
585+
stroke: stroke,
571586
data: (open: open, size: size),
572587
label: process-args.process-label-arg(label, default-pos: top + right, default-dx: -.5em)
573588
)
@@ -588,13 +603,19 @@
588603
/// How many wires up or down the target wire lives.
589604
/// -> int
590605
..n,
591-
606+
607+
/// Wire count for the control wire.
608+
/// -> int
592609
wire-count: 1,
593610

594611
/// The size of the target symbol.
595612
/// -> length.
596613
size: 7pt,
597614

615+
/// How to stroke the swap gate.
616+
/// -> auto | stroke
617+
stroke: auto,
618+
598619
label: none,
599620

600621
/// One or more labels to add to the control wire. See @mqgate.wire-label.
@@ -625,7 +646,8 @@
625646
wire-stroke: wire-stroke,
626647
data: (size: size),
627648
label: label,
628-
wire-label: wire-label
649+
wire-label: wire-label,
650+
stroke: stroke
629651
)
630652
}
631653

@@ -657,10 +679,15 @@
657679
/// -> bool
658680
open: false,
659681

660-
/// How to fill or stroke the circle if `open: true`.
661-
/// none | color
682+
/// How to fill the circle.
683+
/// -> auto | none | color
662684
fill: auto,
663685

686+
687+
/// How to stroke the circle if `open: true`.
688+
/// -> auto | stroke | color
689+
stroke: auto,
690+
664691
/// The radius of the control circle.
665692
/// -> length
666693
size: 2.3pt,
@@ -694,6 +721,7 @@
694721
draw-function: draw-functions.draw-ctrl,
695722
wire-count: wire-count,
696723
fill: fill,
724+
stroke: stroke,
697725
data: (open: open, size: size, show-dot: show-dot),
698726
label: label,
699727
wire-label: wire-label,
2.53 KB
Loading

tests/gates/custom-colors/test.typ

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,15 @@
33

44

55
#quantum-circuit(
6-
gate($X$, fill: gray), phase($text(a, fill: #red)$, fill: red), phase($text(a, fill: #red)$, fill: .7pt + red, open: true), gate($F_m$, radius: 100%), gate($F#h(.2em)$, radius: (right: 100%), fill: green), targ(fill: auto), targ(fill: blue), ctrl(fill: blue), ctrl(fill: .7pt + blue, open: true), ctrl(fill: blue), ctrl(fill: .7pt + blue, open: true), 1
6+
// setwire(2),
7+
gate($X$, fill: gray), phase($text(a, fill: #red)$, fill: red), phase($text(a, fill: #red)$, stroke: .7pt + red, open: true), gate($F_m$, radius: 100%), gate($F#h(.2em)$, radius: (right: 100%), fill: green), targ(fill: auto), targ(fill: blue), ctrl(fill: blue), ctrl(stroke: .7pt + blue, open: true), ctrl(fill: blue), ctrl(stroke: .7pt + blue, open: true), 1
8+
)
9+
10+
#pagebreak()
11+
12+
#quantum-circuit(
13+
lstick(fill: blue, n: 2)[], swap(0, stroke: 2pt), targ(0, stroke: red), 1, meter(stroke: blue),
14+
rstick(fill: blue, n: 2)[], [\ ],
15+
1, ctrl(open: true, fill: red, stroke: green),
16+
phase(open: true, fill: red, stroke: green)[],
717
)

0 commit comments

Comments
 (0)