adapted collections shape rendering

This commit is contained in:
2025-07-19 21:53:42 +02:00
parent f00aa86962
commit a48478e394

View File

@ -1,19 +1,47 @@
#import "/src/cetz.typ": draw
#import "/src/core/utils.typ": normalize-measure
#import "/src/consts.typ": *
#import "/src/core/utils.typ": normalize-measure, normalize-units
#let name = "collections"
#let normalize-offset(offset) = {
let dx = 0pt
let dy = 0pt
if type(offset) == array {
if offset.len() >= 2 {
dx = offset.at(0)
dy = offset.at(1)
}
} else if type(offset) == dictionary {
dx = offset.at("dx", default: dx)
dy = offset.at("dx", default: dy)
} else {
dx = offset
dy = offset
}
return (
x: normalize-units(dx),
y: normalize-units(dy)
)
}
#let render(x, y, p, bottom) = {
let m = measure(p.display-name)
let style = p.resolved-style
let w = m.width / 1pt
let h = m.height / 1pt
let dx = COLLECTIONS-DX
let dy = COLLECTIONS-DY
let total-w = w + PAR-PAD.last() * 2 / 1pt + calc.abs(dx)
let total-h = h + PAR-PAD.first() * 2 / 1pt + calc.abs(dy)
let name = box(
p.display-name,
inset: style.inset,
fill: style.fill,
stroke: style.stroke
)
let m = normalize-measure(name)
let offset = normalize-offset(style.offset)
let w = m.width
let h = m.height
let dx = offset.x
let dy = offset.y
let total-w = w + calc.abs(dx)
let total-h = h + calc.abs(dy)
let x0 = x - total-w / 2
let x1 = x0 + calc.abs(dx)
@ -47,29 +75,34 @@
fill: style.fill,
stroke: style.stroke
)
draw.rect(
(r2.at(0), r2.at(1)),
(r2.at(2), r2.at(3)),
fill: style.fill,
stroke: style.stroke
)
draw.content(
((r2.at(0) + r2.at(2)) / 2, (r2.at(1) + r2.at(3)) / 2),
p.display-name,
(
(r2.at(0) + r2.at(2)) / 2,
(r2.at(1) + r2.at(3)) / 2
),
name,
anchor: "mid"
)
}
#let get-size(par) = {
let m = normalize-measure(par.display-name)
let m = normalize-measure(box(
par.display-name,
inset: par.resolved-style.inset
))
// w + COLLECTIONS-PAD.last() * 2 + calc.abs(COLLECTIONS-DX) * 1pt
// h + COLLECTIONS-PAD.first() * 2 + calc.abs(COLLECTIONS-DY) * 1pt
let offset = normalize-offset(par.resolved-style.offset)
let dx = offset.x
let dy = offset.y
return m
return (
width: m.width + calc.abs(dx),
height: m.height + calc.abs(dy)
)
}
#let default-style = (
:
inset: (x: 3pt, y: 5pt),
offset: (3pt, 3pt)
)