Compare commits
6 Commits
v0.3.0
...
fix-consec
| Author | SHA1 | Date | |
|---|---|---|---|
| b6f2fd99b8 | |||
|
6f13df815f
|
|||
| 1dd66fd587 | |||
| c7c777f5fa | |||
| 7ef7f653b7 | |||
|
dd6d38a282
|
@@ -36,6 +36,6 @@ For more information, see the [manual](manual.pdf)
|
||||
To use this package, simply import `schema` from [rivet](https://typst.app/universe/package/rivet) and call `schema.load` to parse a schema description. Then use `schema.render` to render it, et voilà !
|
||||
```typ
|
||||
#import "@preview/rivet:0.3.0": schema
|
||||
#let doc = schema.load("path/to/schema.yaml")
|
||||
#let doc = schema.load(yaml("path/to/schema.yaml"))
|
||||
#schema.render(doc)
|
||||
```
|
||||
BIN
manual.pdf
BIN
manual.pdf
Binary file not shown.
28
manual.typ
28
manual.typ
@@ -152,6 +152,34 @@ The range name (or key) defines the left- and rightmost bits (e.g. `7-4` goes fr
|
||||
}
|
||||
```
|
||||
|
||||
=== Start <format-start>
|
||||
|
||||
By default, structures start at bit 0, but you may want to number bits from 1, or another arbitrary value. To do this, you can set the `start` property of a structure to the desired start value. For example,
|
||||
|
||||
```json
|
||||
"main": {
|
||||
"bits": 8,
|
||||
"start": 4,
|
||||
"ranges": {
|
||||
"11-7": { ... },
|
||||
"6-4": { ... }
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#let start-schema = (structures: (main: (bits: 8, start: 4, ranges: ("11-7": (name: ""), "6-4": (name: "")))))
|
||||
|
||||
would render as
|
||||
|
||||
#align(
|
||||
center,
|
||||
schema.render(
|
||||
schema.load(start-schema),
|
||||
width: 50%
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
== Range <format-range>
|
||||
|
||||
A range represents a group of consecutive bits. It can have a name (displayed in the bit cells), a description (displayed under the structure) and / or values.
|
||||
|
||||
@@ -387,8 +387,10 @@
|
||||
}
|
||||
let range-boundaries = ()
|
||||
for r in struct.ranges.values() {
|
||||
let i = to-real-i(if config.ltr-bits {r.start} else {r.end})
|
||||
range-boundaries.push(i)
|
||||
let start-i = to-real-i(if config.ltr-bits {r.start} else {r.end})
|
||||
let end-i = to-real-i(if config.ltr-bits {r.end} else {r.start}) + 1
|
||||
range-boundaries.push(start-i)
|
||||
range-boundaries.push(end-i)
|
||||
}
|
||||
|
||||
// Draw colors
|
||||
@@ -407,6 +409,11 @@
|
||||
indices.push(r.start)
|
||||
indices.push(r.end)
|
||||
}
|
||||
// ensure first and last bits are included
|
||||
if not indices.contains(0) { indices.insert(0, struct.start) }
|
||||
if not indices.contains(struct.bits + struct.start - 1) {
|
||||
indices.push(struct.bits + struct.start - 1)
|
||||
}
|
||||
}
|
||||
|
||||
for i in range(struct.bits) {
|
||||
@@ -453,8 +460,9 @@
|
||||
let desc-y = bits-y + bit-h * 2
|
||||
|
||||
// Names + simple descriptions
|
||||
for range_ in ranges {
|
||||
for (i, range_) in ranges.enumerate() {
|
||||
let start-i = to-real-i(if config.ltr-bits {range_.start} else {range_.end})
|
||||
let end-i = to-real-i(if config.ltr-bits {range_.end} else {range_.start})
|
||||
let start-x = bits-x + start-i * bit-w
|
||||
let width = rng.bits(range_) * bit-w
|
||||
|
||||
@@ -465,6 +473,28 @@
|
||||
shapes += draw-line(border-col, (line-x, bits-y), (line-x, bits-y + bit-h))
|
||||
shapes += draw-text(range_.name, txt-col, name-x, name-y, fill: bg-col)
|
||||
|
||||
// paint end line only if needed
|
||||
if (
|
||||
start-i != 0
|
||||
and end-i != struct.bits - 1
|
||||
and ranges
|
||||
.at(
|
||||
i
|
||||
+ {
|
||||
if config.ltr-bits and i < ranges.len() - 1 { 1 } else { -1 }
|
||||
},
|
||||
)
|
||||
.end
|
||||
!= range_.start - 1
|
||||
) {
|
||||
line-x += if config.ltr-bits { -width } else { width }
|
||||
shapes += draw-line(
|
||||
border-col,
|
||||
(line-x, bits-y),
|
||||
(line-x, bits-y + bit-h),
|
||||
)
|
||||
}
|
||||
|
||||
if range_.description != "" {
|
||||
let shapes_
|
||||
(shapes_, desc-x, desc-y) = draw-description(
|
||||
|
||||
Reference in New Issue
Block a user