From 26d11301a2690ccb144135ea861c9efd7f6baebb Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Fri, 21 Nov 2025 18:08:59 +0100 Subject: [PATCH] added range names and bit ranks --- src/render/structure.typ | 45 +++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/src/render/structure.typ b/src/render/structure.typ index d896801..ca66c78 100644 --- a/src/render/structure.typ +++ b/src/render/structure.typ @@ -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(