forked from HEL/rivet-typst
added range names and bit ranks
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
#import "../cetz.typ": draw
|
#import "../cetz.typ": draw
|
||||||
|
|
||||||
|
#let BACKGROUND-LAYER = -1
|
||||||
|
|
||||||
#let draw-track(config, schema, struct, pos) = draw.group(name: "track", {
|
#let draw-track(config, schema, struct, pos) = draw.group(name: "track", {
|
||||||
let colors = schema.at("colors", default: (:))
|
let colors = schema.at("colors", default: (:))
|
||||||
let total-width = struct.bits * config.bit-width
|
let total-width = struct.bits * config.bit-width
|
||||||
@@ -28,6 +30,7 @@
|
|||||||
let col = bit-colors.at(str(rank), default: config.background)
|
let col = bit-colors.at(str(rank), default: config.background)
|
||||||
|
|
||||||
// Background color
|
// Background color
|
||||||
|
draw.on-layer(BACKGROUND-LAYER, {
|
||||||
draw.rect(
|
draw.rect(
|
||||||
(rel: (j * config.bit-width, 0), to: pos),
|
(rel: (j * config.bit-width, 0), to: pos),
|
||||||
(rel: (config.bit-width, config.bit-height)),
|
(rel: (config.bit-width, config.bit-height)),
|
||||||
@@ -35,6 +38,7 @@
|
|||||||
stroke: none,
|
stroke: none,
|
||||||
name: str(rank)
|
name: str(rank)
|
||||||
)
|
)
|
||||||
|
})
|
||||||
|
|
||||||
if j != struct.bits - 1 {
|
if j != struct.bits - 1 {
|
||||||
let top = str(rank) + ".north-east"
|
let top = str(rank) + ".north-east"
|
||||||
@@ -73,6 +77,33 @@
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Names
|
// Names
|
||||||
|
for r in struct.ranges.values() {
|
||||||
|
let i0 = r.start
|
||||||
|
let i1 = r.end
|
||||||
|
if not config.ltr-bits {
|
||||||
|
(i0, i1) = (i1, i0)
|
||||||
|
}
|
||||||
|
let start = "bits." + str(i0) + ".north-west"
|
||||||
|
let end = "bits." + str(i1) + ".south-east"
|
||||||
|
draw.content(
|
||||||
|
(start, 50%, end),
|
||||||
|
r.name
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
let indices = if config.all-bit-i {
|
||||||
|
range(struct.start, struct.start + struct.bits)
|
||||||
|
} else {
|
||||||
|
struct.ranges.values().map(r => (r.start, r.end)).flatten().dedup()
|
||||||
|
}
|
||||||
|
for i in indices {
|
||||||
|
draw.content(
|
||||||
|
"bits." + str(i) + ".north",
|
||||||
|
anchor: "south",
|
||||||
|
str(i),
|
||||||
|
padding: 4pt // TODO: Maybe configurable
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
#let render(
|
#let render(
|
||||||
|
|||||||
Reference in New Issue
Block a user