added range names and bit ranks

This commit is contained in:
2025-11-21 18:08:59 +01:00
parent aeb413abb4
commit 26d11301a2

View File

@@ -1,5 +1,7 @@
#import "../cetz.typ": draw
#let BACKGROUND-LAYER = -1
#let draw-track(config, schema, struct, pos) = draw.group(name: "track", {
let colors = schema.at("colors", default: (:))
let total-width = struct.bits * config.bit-width
@@ -28,13 +30,15 @@
let col = bit-colors.at(str(rank), default: config.background)
// Background color
draw.rect(
(rel: (j * config.bit-width, 0), to: pos),
(rel: (config.bit-width, config.bit-height)),
fill: col,
stroke: none,
name: str(rank)
)
draw.on-layer(BACKGROUND-LAYER, {
draw.rect(
(rel: (j * config.bit-width, 0), to: pos),
(rel: (config.bit-width, config.bit-height)),
fill: col,
stroke: none,
name: str(rank)
)
})
if j != struct.bits - 1 {
let top = str(rank) + ".north-east"
@@ -73,6 +77,33 @@
)
// 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(