4 Commits

Author SHA1 Message Date
1dd66fd587 Merge pull request 'Support for non-consecutive ranges' (#13) from rajayonin/rivet-typst:non-consecutive-ranges into dev
Reviewed-on: #13
Reviewed-by: Louis Heredero <louis@herdac.ch>
2025-10-21 06:02:04 +00:00
c7c777f5fa ensure first and last bits are included when all-bit-i is set 2025-10-20 19:06:53 +02:00
7ef7f653b7 support for non-consecutive ranges
Paints the start/end line of a range if there was no previous range.
2025-10-20 18:01:28 +02:00
dd6d38a282 fixed README example usage 2025-05-03 00:54:38 +02:00
2 changed files with 31 additions and 3 deletions

View File

@@ -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)
```

View File

@@ -407,6 +407,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 +458,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
@@ -464,6 +470,28 @@
let line-x = if config.ltr-bits {start-x + width} else {start-x}
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_
@@ -568,4 +596,4 @@
config: config,
render: render.with(config)
)
}
}