Compare commits
4 Commits
8bcedbfc53
...
99b9037719
Author | SHA1 | Date | |
---|---|---|---|
99b9037719 | |||
a51c6a976d | |||
06f4a2ec5b | |||
f061bd964e |
@ -24,6 +24,7 @@
|
|||||||
/// - width (float): TODO -> remove
|
/// - width (float): TODO -> remove
|
||||||
/// - height (float): TODO -> remove
|
/// - height (float): TODO -> remove
|
||||||
/// - full-page (bool): If true, the page will be resized to fit the diagram and take the background color
|
/// - full-page (bool): If true, the page will be resized to fit the diagram and take the background color
|
||||||
|
/// - all-bit-i (bool): If true, all bit indices will be rendered, otherwise, only the ends of each range will be displayed
|
||||||
/// -> dictionary
|
/// -> dictionary
|
||||||
#let config(
|
#let config(
|
||||||
default-font-family: "Ubuntu Mono",
|
default-font-family: "Ubuntu Mono",
|
||||||
@ -49,7 +50,8 @@
|
|||||||
left-labels: false,
|
left-labels: false,
|
||||||
width: 1200,
|
width: 1200,
|
||||||
height: 800,
|
height: 800,
|
||||||
full-page: false
|
full-page: false,
|
||||||
|
all-bit-i: true
|
||||||
) = {}
|
) = {}
|
||||||
|
|
||||||
/// Dark theme config
|
/// Dark theme config
|
||||||
|
@ -11,4 +11,5 @@
|
|||||||
/// This functions
|
/// This functions
|
||||||
/// - structures (dictionary): A schema dictionary, as returned by #doc-ref("schema.load")
|
/// - structures (dictionary): A schema dictionary, as returned by #doc-ref("schema.load")
|
||||||
/// - config (auto, dictionary): The configuration parameters, as returned by #doc-ref("config.config")
|
/// - config (auto, dictionary): The configuration parameters, as returned by #doc-ref("config.config")
|
||||||
#let render(structures, config: auto)
|
/// - width (ratio, length): The width of the generated figure
|
||||||
|
#let render(structures, config: auto, width: 100%) = {}
|
BIN
manual.pdf
BIN
manual.pdf
Binary file not shown.
@ -22,7 +22,8 @@
|
|||||||
left-labels: false,
|
left-labels: false,
|
||||||
width: 1200,
|
width: 1200,
|
||||||
height: 800,
|
height: 800,
|
||||||
full-page: false
|
full-page: false,
|
||||||
|
all-bit-i: true
|
||||||
) = {
|
) = {
|
||||||
return (
|
return (
|
||||||
default-font-family: default-font-family,
|
default-font-family: default-font-family,
|
||||||
@ -48,7 +49,8 @@
|
|||||||
left-labels: left-labels,
|
left-labels: left-labels,
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
full-page: full-page
|
full-page: full-page,
|
||||||
|
all-bit-i: all-bit-i
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#let version = version((0,0,1))
|
#let version = version((0,0,2))
|
||||||
|
|
||||||
#import "config.typ"
|
#import "config.typ"
|
||||||
#import "schema.typ"
|
#import "schema.typ"
|
@ -356,14 +356,27 @@
|
|||||||
// Draw rectangle around structure
|
// Draw rectangle around structure
|
||||||
shapes += draw-rect(border-col, bits-x, bits-y, bits-width, bit-h, thickness: 2)
|
shapes += draw-rect(border-col, bits-x, bits-y, bits-width, bit-h, thickness: 2)
|
||||||
|
|
||||||
|
let indices = range(struct.bits)
|
||||||
|
if not config.all-bit-i {
|
||||||
|
indices = ()
|
||||||
|
for r in struct.ranges.values() {
|
||||||
|
indices.push(r.start)
|
||||||
|
indices.push(r.end)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for i in range(struct.bits) {
|
for i in range(struct.bits) {
|
||||||
let bit-x = ox + i * bit-w
|
let bit-x = ox + i * bit-w
|
||||||
shapes += draw-text(
|
let real-i = struct.bits - i - 1 + start-bit
|
||||||
str(struct.bits - i - 1 + start-bit),
|
|
||||||
txt-col,
|
if real-i in indices {
|
||||||
bit-x + bit-w / 2,
|
shapes += draw-text(
|
||||||
oy + bit-h / 2
|
str(real-i),
|
||||||
)
|
txt-col,
|
||||||
|
bit-x + bit-w / 2,
|
||||||
|
oy + bit-h / 2
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// Draw separator
|
// Draw separator
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
@ -433,7 +446,7 @@
|
|||||||
return (shapes, desc-y)
|
return (shapes, desc-y)
|
||||||
}
|
}
|
||||||
|
|
||||||
#let render(config, structures) = {
|
#let render(config, structures, width: 100%) = {
|
||||||
set text(
|
set text(
|
||||||
font: config.default-font-family,
|
font: config.default-font-family,
|
||||||
size: config.default-font-size
|
size: config.default-font-size
|
||||||
@ -458,7 +471,7 @@
|
|||||||
|
|
||||||
set page(..params)
|
set page(..params)
|
||||||
|
|
||||||
canvas(length: 1pt, background: config.background, {
|
let cnvs = canvas(length: 1pt, background: config.background, {
|
||||||
let (shapes, _) = draw-structure(
|
let (shapes, _) = draw-structure(
|
||||||
config, main, structures,
|
config, main, structures,
|
||||||
ox: ox,
|
ox: ox,
|
||||||
@ -475,6 +488,32 @@
|
|||||||
fill: none
|
fill: none
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
layout(size => {
|
||||||
|
let m = measure(cnvs)
|
||||||
|
let w = m.width
|
||||||
|
let h = m.height
|
||||||
|
let base-w = if type(width) == ratio {
|
||||||
|
size.width * width
|
||||||
|
} else {
|
||||||
|
width
|
||||||
|
}
|
||||||
|
let r = if w == 0 {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
base-w / w
|
||||||
|
}
|
||||||
|
|
||||||
|
let new-w = w * r
|
||||||
|
let new-h = h * r
|
||||||
|
r *= 100%
|
||||||
|
|
||||||
|
box(
|
||||||
|
width: new-w,
|
||||||
|
height: new-h,
|
||||||
|
scale(x: r, y: r, cnvs, reflow: true)
|
||||||
|
)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#let make(config) = {
|
#let make(config) = {
|
||||||
|
@ -56,10 +56,10 @@
|
|||||||
return structures
|
return structures
|
||||||
}
|
}
|
||||||
|
|
||||||
#let render(structures, config: auto) = {
|
#let render(structures, width: 100%, config: auto) = {
|
||||||
if config == auto {
|
if config == auto {
|
||||||
config = conf.config()
|
config = conf.config()
|
||||||
}
|
}
|
||||||
let renderer_ = renderer.make(config)
|
let renderer_ = renderer.make(config)
|
||||||
(renderer_.render)(structures)
|
(renderer_.render)(structures, width: width)
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rivet"
|
name = "rivet"
|
||||||
version = "0.0.1"
|
version = "0.0.2"
|
||||||
compiler = "0.11.0"
|
compiler = "0.11.0"
|
||||||
repository = "https://git.kb28.ch/HEL/rivet-typst"
|
repository = "https://git.kb28.ch/HEL/rivet-typst"
|
||||||
entrypoint = "src/lib.typ"
|
entrypoint = "src/lib.typ"
|
||||||
|
Loading…
Reference in New Issue
Block a user