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