From a48478e3948c8ee5117af16b0810212c7c74626a Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Sat, 19 Jul 2025 21:53:42 +0200 Subject: [PATCH] adapted collections shape rendering --- src/core/draw/participant/collections.typ | 79 ++++++++++++++++------- 1 file changed, 56 insertions(+), 23 deletions(-) diff --git a/src/core/draw/participant/collections.typ b/src/core/draw/participant/collections.typ index 57452d4..cc25798 100644 --- a/src/core/draw/participant/collections.typ +++ b/src/core/draw/participant/collections.typ @@ -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 + )) + + 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 - // h + COLLECTIONS-PAD.first() * 2 + calc.abs(COLLECTIONS-DY) * 1pt - - 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) ) \ No newline at end of file